Skip to content

Commit

Permalink
fix: publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Jul 21, 2023
1 parent 9ca483c commit 61d50b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 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
48 changes: 44 additions & 4 deletions test/core/service/PackageSyncerService/executeTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
log = await TestUtil.readStreamToLog(stream);
// console.log(log);
assert(log.includes('Synced version 1.0.0 already exists, skip publish, try to set in local manifest'));
assert(log.includes('] 🟢 Synced updated 1 versions'));
assert(log.includes('] 🟢 Synced updated'));
assert(log.includes('] 🚧 Syncing versions 1 => 2'));
app.mockAgent().assertNoPendingInterceptors();
await mock.restore();
Expand All @@ -622,7 +622,7 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
log = await TestUtil.readStreamToLog(stream);
// console.log(log);
assert(log.includes('] 🐛 Remote version 1.0.0 not exists on local abbreviated manifests, need to refresh'));
assert(log.includes('] 🟢 Synced updated 1 versions'));
assert(log.includes('] 🟢 Synced updated'));
assert(log.includes('] 🚧 Syncing versions 2 => 2'));
app.mockAgent().assertNoPendingInterceptors();
await mock.restore();
Expand Down Expand Up @@ -1000,7 +1000,7 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
assert(stream);
log = await TestUtil.readStreamToLog(stream);
// console.log(log);
assert(log.includes('] 🟢 Synced updated 0 versions, removed 1 versions'));
assert(log.includes('removed 1 versions'));
assert(log.includes('] 🟢 Removed version 1.0.0 success'));
const r = await packageManagerService.listPackageFullManifests('@cnpmcore', 'test-sync-package-has-two-versions');
assert(Object.keys(r.data!.versions).length === 1);
Expand Down Expand Up @@ -1882,7 +1882,7 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
assert(stream);
let log = await TestUtil.readStreamToLog(stream);
// console.log(log);
assert(log.includes('🟢 Synced version 2.0.0 success, different meta: {"peerDependenciesMeta":{"bufferutil":{"optional":true},"utf-8-validate":{"optional":true}},"os":["linux"],"cpu":["x64"]}'));
assert(log.includes('Synced version 2.0.0 success, different meta: {"peerDependenciesMeta":{"bufferutil":{"optional":true},"utf-8-validate":{"optional":true}},"os":["linux"],"cpu":["x64"],"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"}}'));
assert(log.includes('Z] 👉👉👉👉👉 Tips: sync test tips here 👈👈👈👈👈'));
assert(log.includes(', skipDependencies: false'));
let manifests = await packageManagerService.listPackageFullManifests('', name);
Expand Down 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 61d50b7

Please sign in to comment.