Skip to content

Commit

Permalink
fix: publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Jul 20, 2023
1 parent 9ca483c commit b745f3e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/core/service/PackageSyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,8 @@ export class PackageSyncerService extends AbstractService {
// check metaDataKeys, if different value, override exists one
// https://github.com/cnpm/cnpmjs.org/issues/1667
// need libc field https://github.com/cnpm/cnpmcore/issues/187
const metaDataKeys = [
'peerDependenciesMeta', 'os', 'cpu', 'libc', 'workspaces', 'hasInstallScript', 'deprecated',
];
// fix _npmUser field since https://github.com/cnpm/cnpmcore/issues/553
const metaDataKeys = [ 'peerDependenciesMeta', 'os', 'cpu', 'libc', 'workspaces', 'hasInstallScript', 'deprecated', '_npmUser' ];
let diffMeta: any;
for (const key of metaDataKeys) {
let remoteItemValue = item[key];
Expand Down Expand Up @@ -691,7 +690,8 @@ export class PackageSyncerService extends AbstractService {
};
try {
// 当 version 记录已经存在时,还需要校验一下 pkg.manifests 是否存在
const pkgVersion = await this.packageManagerService.publish(publishCmd, users[0]);
const publisher = users.find(user => user.name === item._npmUser?.name) || users[0];
const pkgVersion = await this.packageManagerService.publish(publishCmd, publisher);
updateVersions.push(pkgVersion.version);
logs.push(`[${isoNow()}] 🟢 [${syncIndex}] Synced version ${version} success, packageVersionId: ${pkgVersion.packageVersionId}, db id: ${pkgVersion.id}`);
} catch (err: any) {
Expand Down
40 changes: 40 additions & 0 deletions test/core/service/PackageSyncerService/executeTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,47 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
const pkg = await packageRepository.findPackage('', 'foobar');
app.expectLog(`[packageManagerService.unpublishPackage:skip] ${pkg?.packageId} already unpublished`);

});

it('should resync history version if forceSyncHistory is true', async () => {
app.mockHttpclient('https://registry.npmjs.org/foobar', 'GET', {
data: await TestUtil.readFixturesFile('registry.npmjs.org/foobar.json'),
persist: false,
repeats: 1,
});
app.mockHttpclient('https://registry.npmjs.org/foobar/-/foobar-1.0.0.tgz', 'GET', {
data: await TestUtil.readFixturesFile('registry.npmjs.org/foobar/-/foobar-1.0.0.tgz'),
persist: false,
repeats: 2,
});
app.mockHttpclient('https://registry.npmjs.org/foobar/-/foobar-1.1.0.tgz', 'GET', {
data: await TestUtil.readFixturesFile('registry.npmjs.org/foobar/-/foobar-1.1.0.tgz'),
persist: false,
repeats: 2,
});
await packageSyncerService.createTask('foobar', { skipDependencies: true });
let task = await packageSyncerService.findExecuteTask();
assert(task);
await packageSyncerService.executeTask(task);


// resync
const manifest = JSON.parse((await TestUtil.readFixturesFile('registry.npmjs.org/foobar.json')).toString());
manifest.versions['1.0.0']._npmUser = { name: 'banana', email: 'banana@cnpmjs.org' };
app.mockHttpclient('https://registry.npmjs.org/foobar', 'GET', {
data: manifest,
persist: false,
repeats: 1,
});
await packageSyncerService.createTask('foobar', { skipDependencies: true });
task = await packageSyncerService.findExecuteTask();
assert(task);
await packageSyncerService.executeTask(task);
const stream2 = await packageSyncerService.findTaskLog(task);
assert(stream2);
const log2 = await TestUtil.readStreamToLog(stream2);
// console.log(log2);
assert(/different meta: {"_npmUser":{"name":"banana","email":"banana@cnpmjs.org"}}/.test(log2));
});
});
});
Expand Down

0 comments on commit b745f3e

Please sign in to comment.