Skip to content

Commit

Permalink
feat: add _npmUser (#491)
Browse files Browse the repository at this point in the history
> For private packages published in the current registry, add the
"_npmUser" field to align with the npm registry.

* 🧶 Add the "_npmUser" field for new scenarios, without modifying the
abbreviated data. Use the following command: curl -H 'Accept:
application/vnd.npm.install-v1+json'
'https://registry.npmjs.org/cnpmcore'
* ♻️ Existing data cannot be traced and will not be compensated.
-----

> 对于在当前 registry 发布的私有包,添加 _npmUser 字段,和公网 registry 保持一致
* 🧶 新增 _npmUser 字段,abbreviated 场景不做修改, (via `curl -H 'Accept:
application/vnd.npm.install-v1+json'
'https://registry.npmjs.org/cnpmcore'`)
* ♻️ 存量数据无法回溯,不做补偿
  • Loading branch information
elrrrrrrr authored Jun 2, 2023
1 parent f30e517 commit f7b5d5a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/core/service/PackageManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ export class PackageManagerService extends AbstractService {
cmd.packageJson._hasShrinkwrap = await hasShrinkWrapInTgz(cmd.dist.content || cmd.dist.localFile!);
}

// set _npmUser field to cmd.packageJson
cmd.packageJson._npmUser = {
// clean user scope prefix
name: publisher.displayName,
email: publisher.email,
};

// add _registry_name field to cmd.packageJson
if (!cmd.packageJson._source_registry_name) {
let registry: Registry | null;
Expand Down
45 changes: 45 additions & 0 deletions test/port/controller/package/SavePackageVersionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,51 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', ()
});

describe('[PUT /:fullname] save()', () => {
it('should set registry filed after publish', async () => {
mock(app.config.cnpmcore, 'allowPublishNonScopePackage', true);
const { pkg, user } = await TestUtil.createPackage({ name: 'non_scope_pkg', version: '1.0.0' });
const pkg2 = await TestUtil.getFullPackage({ name: pkg.name, version: '2.0.0' });
let res = await app.httpRequest()
.put(`/${pkg2.name}`)
.set('authorization', user.authorization)
.set('user-agent', user.ua)
.send(pkg2);

assert.equal(res.status, 201);

res = await app.httpRequest()
.get(`/${pkg2.name}`)
.expect(200);

const fullManifest = res.body;

res = await app.httpRequest()
.get(`/${pkg2.name}`)
.set('Accept', 'application/vnd.npm.install-v1+json')
.expect(200);

const abbreviatedManifest = res.body;

[ fullManifest, abbreviatedManifest ].forEach(manifest => {
Object.keys(manifest.versions).forEach(v => {
const version = manifest.versions[v];
assert(version);
assert.equal(version._source_registry_name, 'self');
assert(version.publish_time);
});
});

Object.keys(fullManifest.versions).forEach(v => {
const version = fullManifest.versions[v];
assert(version);
assert(version._cnpmcore_publish_time);
assert.deepEqual(version._npmUser, {
name: user.name,
email: user.email,
});
});

});
it('should 200 when package in current registry', async () => {
mock(app.config.cnpmcore, 'allowPublishNonScopePackage', true);
const { pkg, user } = await TestUtil.createPackage({ name: 'non_scope_pkg', version: '1.0.0' });
Expand Down

0 comments on commit f7b5d5a

Please sign in to comment.