From b745f3e5a9dd00e2b91a5d4f11e59c64f1e3c11c Mon Sep 17 00:00:00 2001 From: elrrrrrrr Date: Thu, 20 Jul 2023 21:29:44 +0800 Subject: [PATCH] fix: publisher --- app/core/service/PackageSyncerService.ts | 8 ++-- .../PackageSyncerService/executeTask.test.ts | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/core/service/PackageSyncerService.ts b/app/core/service/PackageSyncerService.ts index 8f62e06f7..df909c44c 100644 --- a/app/core/service/PackageSyncerService.ts +++ b/app/core/service/PackageSyncerService.ts @@ -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]; @@ -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) { diff --git a/test/core/service/PackageSyncerService/executeTask.test.ts b/test/core/service/PackageSyncerService/executeTask.test.ts index 97902e5d5..6e1c362d7 100644 --- a/test/core/service/PackageSyncerService/executeTask.test.ts +++ b/test/core/service/PackageSyncerService/executeTask.test.ts @@ -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)); }); }); });