chore: replace mime package with constants (#5471)

* chore: replace mime package with constants

* Revert types/mime

* Revert types/mime

* Update lock file
This commit is contained in:
Marc Bernard
2025-11-14 01:59:14 -05:00
committed by GitHub
parent 265c94af37
commit ab3bf4a5d4
7 changed files with 20 additions and 25 deletions

View File

@@ -0,0 +1,6 @@
---
'@verdaccio/middleware': patch
'@verdaccio/api': patch
---
chore: replace mime package with constants

View File

@@ -50,8 +50,7 @@
"@verdaccio/store": "workspace:8.0.0-next-8.24", "@verdaccio/store": "workspace:8.0.0-next-8.24",
"debug": "4.4.3", "debug": "4.4.3",
"express": "4.21.2", "express": "4.21.2",
"lodash": "4.17.21", "lodash": "4.17.21"
"mime": "2.6.0"
}, },
"devDependencies": { "devDependencies": {
"@verdaccio/test-helper": "workspace:4.0.0-next-8.8", "@verdaccio/test-helper": "workspace:4.0.0-next-8.8",

View File

@@ -1,9 +1,8 @@
import { Router } from 'express'; import { Router } from 'express';
import _ from 'lodash'; import _ from 'lodash';
import mime from 'mime';
import { Auth } from '@verdaccio/auth'; import { Auth } from '@verdaccio/auth';
import { constants, errorUtils } from '@verdaccio/core'; import { HEADERS, constants, errorUtils } from '@verdaccio/core';
import { allow, media } from '@verdaccio/middleware'; import { allow, media } from '@verdaccio/middleware';
import { DIST_TAGS_API_ENDPOINTS } from '@verdaccio/middleware'; import { DIST_TAGS_API_ENDPOINTS } from '@verdaccio/middleware';
import { Storage } from '@verdaccio/store'; import { Storage } from '@verdaccio/store';
@@ -42,14 +41,14 @@ export default function (route: Router, auth: Auth, storage: Storage, logger: Lo
route.put( route.put(
DIST_TAGS_API_ENDPOINTS.tagging, DIST_TAGS_API_ENDPOINTS.tagging,
can('publish'), can('publish'),
media(mime.getType('json')), media(HEADERS.JSON),
addTagPackageVersionMiddleware addTagPackageVersionMiddleware
); );
route.put( route.put(
DIST_TAGS_API_ENDPOINTS.tagging_package, DIST_TAGS_API_ENDPOINTS.tagging_package,
can('publish'), can('publish'),
media(mime.getType('json')), media(HEADERS.JSON),
addTagPackageVersionMiddleware addTagPackageVersionMiddleware
); );

View File

@@ -1,9 +1,8 @@
import buildDebug from 'debug'; import buildDebug from 'debug';
import { Router } from 'express'; import { Router } from 'express';
import mime from 'mime';
import { Auth } from '@verdaccio/auth'; import { Auth } from '@verdaccio/auth';
import { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core'; import { API_MESSAGE, HEADERS, HTTP_STATUS } from '@verdaccio/core';
import { allow, expectJson, media } from '@verdaccio/middleware'; import { allow, expectJson, media } from '@verdaccio/middleware';
// import star from './star'; // import star from './star';
import { PUBLISH_API_ENDPOINTS } from '@verdaccio/middleware'; import { PUBLISH_API_ENDPOINTS } from '@verdaccio/middleware';
@@ -122,7 +121,7 @@ export default function publish(
router.put( router.put(
PUBLISH_API_ENDPOINTS.add_package, PUBLISH_API_ENDPOINTS.add_package,
can('publish'), can('publish'),
media(mime.getType('json')), media(HEADERS.JSON),
expectJson, expectJson,
publishPackage(storage, logger, 'publish one version') publishPackage(storage, logger, 'publish one version')
); );
@@ -130,7 +129,7 @@ export default function publish(
router.put( router.put(
PUBLISH_API_ENDPOINTS.publish_package, PUBLISH_API_ENDPOINTS.publish_package,
can('unpublish'), can('unpublish'),
media(mime.getType('json')), media(HEADERS.JSON),
expectJson, expectJson,
publishPackage(storage, logger, 'publish with revision') publishPackage(storage, logger, 'publish with revision')
); );

View File

@@ -49,8 +49,7 @@
"express": "4.21.2", "express": "4.21.2",
"express-rate-limit": "5.5.1", "express-rate-limit": "5.5.1",
"lodash": "4.17.21", "lodash": "4.17.21",
"lru-cache": "7.18.3", "lru-cache": "7.18.3"
"mime": "2.6.0"
}, },
"funding": { "funding": {
"type": "opencollective", "type": "opencollective",

View File

@@ -1,4 +1,3 @@
import mime from 'mime';
import request from 'supertest'; import request from 'supertest';
import { test } from 'vitest'; import { test } from 'vitest';
@@ -9,7 +8,7 @@ import { getApp } from './helper';
test('media is json', async () => { test('media is json', async () => {
const app = getApp([]); const app = getApp([]);
app.get('/json', media(mime.getType('json')), (req, res) => { app.get('/json', media(HEADERS.JSON), (req, res) => {
res.status(200).json(); res.status(200).json();
}); });
@@ -22,7 +21,7 @@ test('media is json', async () => {
test('media is json with charset', async () => { test('media is json with charset', async () => {
const app = getApp([]); const app = getApp([]);
app.get('/json', media(mime.getType('json')), (req, res) => { app.get('/json', media(HEADERS.JSON), (req, res) => {
res.status(200).json(); res.status(200).json();
}); });
@@ -35,7 +34,7 @@ test('media is json with charset', async () => {
test('media is not json', async () => { test('media is not json', async () => {
const app = getApp([]); const app = getApp([]);
app.get('/json', media(mime.getType('json')), (req, res) => { app.get('/json', media(HEADERS.JSON), (req, res) => {
res.status(HTTP_STATUS.OK).json({}); res.status(HTTP_STATUS.OK).json({});
}); });
@@ -48,7 +47,7 @@ test('media is not json', async () => {
test('missing content-type', async () => { test('missing content-type', async () => {
const app = getApp([]); const app = getApp([]);
app.get('/json', media(mime.getType('json')), (req, res) => { app.get('/json', media(HEADERS.JSON), (req, res) => {
res.status(HTTP_STATUS.OK).json({}); res.status(HTTP_STATUS.OK).json({});
}); });

10
pnpm-lock.yaml generated
View File

@@ -581,9 +581,6 @@ importers:
lodash: lodash:
specifier: 4.17.21 specifier: 4.17.21
version: 4.17.21 version: 4.17.21
mime:
specifier: 2.6.0
version: 2.6.0
devDependencies: devDependencies:
'@verdaccio/test-helper': '@verdaccio/test-helper':
specifier: workspace:4.0.0-next-8.8 specifier: workspace:4.0.0-next-8.8
@@ -965,9 +962,6 @@ importers:
lru-cache: lru-cache:
specifier: 7.18.3 specifier: 7.18.3
version: 7.18.3 version: 7.18.3
mime:
specifier: 2.6.0
version: 2.6.0
devDependencies: devDependencies:
'@verdaccio/logger': '@verdaccio/logger':
specifier: workspace:8.0.0-next-8.24 specifier: workspace:8.0.0-next-8.24
@@ -5723,10 +5717,10 @@ packages:
resolution: {integrity: sha512-fnzN9xAKb3IPEoKgAkbpDE+8Q5J+QoCThPTVv3oKDHUe5xBpENP7ZwXC6HZnXBmVPLK5zfUZrphPe6zeCTPyrQ==} resolution: {integrity: sha512-fnzN9xAKb3IPEoKgAkbpDE+8Q5J+QoCThPTVv3oKDHUe5xBpENP7ZwXC6HZnXBmVPLK5zfUZrphPe6zeCTPyrQ==}
'@types/mime@1.3.3': '@types/mime@1.3.3':
resolution: {integrity: sha512-Ys+/St+2VF4+xuY6+kDIXGxbNRO0mesVg0bbxEfB97Od1Vjpjx9KD1qxs64Gcb3CWPirk9Xe+PT4YiiHQ9T+eg==} resolution: {integrity: sha512-Ys+/St+2VF4+xuY6+kDIXGxbNRO0mesVg0bbxEfB97Od1Vjpjx9KD1qxs64Gcb3CWPirk9Xe+PT4YiiHQ9T+eg==, tarball: https://registry.npmjs.org/@types/mime/-/mime-1.3.3.tgz}
'@types/mime@3.0.4': '@types/mime@3.0.4':
resolution: {integrity: sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw==} resolution: {integrity: sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw==, tarball: https://registry.npmjs.org/@types/mime/-/mime-3.0.4.tgz}
'@types/minimatch@3.0.5': '@types/minimatch@3.0.5':
resolution: {integrity: sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==} resolution: {integrity: sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==}