Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support + wildcast #694

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/core/service/PackageVersionFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ export class PackageVersionFileService extends AbstractService {
if (!pkgConfig?.version) {
throw new ForbiddenError(`"${fullname}" is not allow to unpkg files, see ${unpkgWhiteListUrl}`);
}
if (pkgConfig.version !== '*' && !semver.satisfies(pkgVersion, pkgConfig.version)) {

// satisfies 默认不会包含 prerelease 版本
// https://docs.npmjs.com/about-semantic-versioning#using-semantic-versioning-to-specify-update-types-your-package-can-accept
// [x, *] 代表任意版本,这里统一通过 semver 来判断
if (!semver.satisfies(pkgVersion, pkgConfig.version, { includePrerelease: true })) {
throw new ForbiddenError(`"${fullname}@${pkgVersion}" not satisfies "${pkgConfig.version}" to unpkg files, see ${unpkgWhiteListUrl}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ describe('test/port/controller/PackageVersionFileController/listFiles.test.ts',
bar: {
version: '1.0.0',
},
baz: {
version: '*',
},
},
},
});
Expand Down Expand Up @@ -988,6 +991,25 @@ describe('test/port/controller/PackageVersionFileController/listFiles.test.ts',
assert.equal(res.status, 200);
assert(res.body.name);

pkg = await TestUtil.getFullPackage({
name: 'baz',
version: '0.3.0-rc15',
versionObject: {
description: 'work with utf8mb4 💩, 𝌆 utf8_unicode_ci, foo𝌆bar 🍻',
},
});
await app.httpRequest()
.put(`/${pkg.name}`)
.set('authorization', publisher.authorization)
.set('user-agent', publisher.ua)
.send(pkg)
.expect(201);
res = await app.httpRequest()
.get('/baz/0.3.0-rc15/files/package.json')
.expect('content-type', 'application/json; charset=utf-8');
assert.equal(res.status, 200);
assert(res.body.name);

pkg = await TestUtil.getFullPackage({
name: 'bar',
version: '0.3.0-rc15',
Expand Down
Loading