Skip to content

Commit

Permalink
fix: publisher info
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Aug 4, 2023
1 parent 276b951 commit c830700
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/core/service/PackageManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface PublishPackageCmd {
// name don't include scope
name: string;
version: string;
description: string;
description?: string;
packageJson: PackageJSONType;
registryId?: string;
readme: string;
Expand Down Expand Up @@ -107,14 +107,14 @@ export class PackageManagerService extends AbstractService {
scope: cmd.scope,
name: cmd.name,
isPrivate: cmd.isPrivate,
description: cmd.description,
description: cmd.description || '',
registryId: cmd.registryId,
});
} else {
// update description
// will read database twice to update description by model to entity and entity to model
if (pkg.description !== cmd.description) {
pkg.description = cmd.description;
pkg.description = cmd.description || '';
}

/* c8 ignore next 3 */
Expand Down
10 changes: 5 additions & 5 deletions app/core/service/PackageSyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { downloadToTempfile } from '../../common/FileUtil';
import { TaskState, TaskType } from '../../common/enum/Task';
import { AbstractService } from '../../common/AbstractService';
import { TaskRepository } from '../../repository/TaskRepository';
import { PackageRepository } from '../../repository/PackageRepository';
import { PackageJSONType, PackageRepository } from '../../repository/PackageRepository';
import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository';
import { UserRepository } from '../../repository/UserRepository';
import { Task, SyncPackageTaskOptions, CreateSyncPackageTask } from '../entity/Task';
Expand Down Expand Up @@ -560,7 +560,7 @@ export class PackageSyncerService extends AbstractService {
logs.push(`[${isoNow()}] 📦 Add latest tag version "${fullname}: ${distTags.latest}"`);
specificVersions.push(distTags.latest);
}
const versions = specificVersions ? Object.values<any>(versionMap).filter(verItem => specificVersions.includes(verItem.version)) : Object.values<any>(versionMap);
const versions: PackageJSONType[] = specificVersions ? Object.values<any>(versionMap).filter(verItem => specificVersions.includes(verItem.version)) : Object.values<any>(versionMap);
logs.push(`[${isoNow()}] 🚧 Syncing versions ${existsVersionCount} => ${versions.length}`);
if (specificVersions) {
const availableVersionList = versions.map(item => item.version);
Expand Down Expand Up @@ -637,13 +637,13 @@ export class PackageSyncerService extends AbstractService {
continue;
}
syncIndex++;
const description: string = item.description;
const description = item.description;
// "dist": {
// "shasum": "943e0ec03df00ebeb6273a5b94b916ba54b47581",
// "tarball": "https://registry.npmjs.org/foo/-/foo-1.0.0.tgz"
// },
const dist = item.dist;
const tarball: string = dist && dist.tarball;
const tarball = dist && dist.tarball;
if (!tarball) {
lastErrorMessage = `missing tarball, dist: ${JSON.stringify(dist)}`;
logs.push(`[${isoNow()}] ❌ [${syncIndex}] Synced version ${version} fail, ${lastErrorMessage}`);
Expand Down Expand Up @@ -690,7 +690,7 @@ export class PackageSyncerService extends AbstractService {
};
try {
// 当 version 记录已经存在时,还需要校验一下 pkg.manifests 是否存在
const publisher = users.find(user => user.name === item._npmUser?.name) || users[0];
const publisher = users.find(user => user.displayName === 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}`);
Expand Down
4 changes: 4 additions & 0 deletions app/repository/PackageRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export type PackageJSONType = CnpmcorePatchInfo & {
hasInstallScript?: boolean;
dist?: DistType;
workspace?: string[];
_npmUser?: {
name: string;
email: string;
};
[key: string]: unknown;
};

Expand Down
9 changes: 7 additions & 2 deletions test/core/service/PackageSyncerService/executeTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2419,8 +2419,11 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
});

it('should resync history version if forceSyncHistory is true', async () => {
const manifest = JSON.parse((await TestUtil.readFixturesFile('registry.npmjs.org/foobar.json')).toString());
manifest.versions['1.0.0']._npmUser = { name: 'apple', email: '[email protected]' };
manifest.maintainers = [ ...manifest.maintainers, { name: 'apple', email: '[email protected]' }];
app.mockHttpclient('https://registry.npmjs.org/foobar', 'GET', {
data: await TestUtil.readFixturesFile('registry.npmjs.org/foobar.json'),
data: manifest,
persist: false,
repeats: 1,
});
Expand All @@ -2439,9 +2442,11 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
assert(task);
await packageSyncerService.executeTask(task);

// should sync publisher
const syncInfo = await packageManagerService.listPackageFullManifests('', 'foobar');
assert.equal(syncInfo.data?.versions['1.0.0']?._npmUser?.name, 'apple');

// resync
const manifest = JSON.parse((await TestUtil.readFixturesFile('registry.npmjs.org/foobar.json')).toString());
manifest.versions['1.0.0']._npmUser = { name: 'banana', email: '[email protected]' };
app.mockHttpclient('https://registry.npmjs.org/foobar', 'GET', {
data: manifest,
Expand Down

0 comments on commit c830700

Please sign in to comment.