From 1f9381ee269db5a13a09e51b3981eb090e31f650 Mon Sep 17 00:00:00 2001 From: elrrrrrrr Date: Thu, 29 Jun 2023 14:52:00 +0800 Subject: [PATCH] fix: update source registry --- app/core/service/PackageManagerService.ts | 15 ++++++--------- .../package/SavePackageVersionController.test.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/core/service/PackageManagerService.ts b/app/core/service/PackageManagerService.ts index 5c92814e..3cc88b30 100644 --- a/app/core/service/PackageManagerService.ts +++ b/app/core/service/PackageManagerService.ts @@ -163,11 +163,9 @@ export class PackageManagerService extends AbstractService { }; // add _registry_name field to cmd.packageJson - if (!cmd.packageJson._source_registry_name) { - const registry = await this.getSourceRegistry(pkg); - if (registry) { - cmd.packageJson._source_registry_name = registry.name; - } + const registry = await this.getSourceRegistry(pkg); + if (registry) { + cmd.packageJson._source_registry_name = registry.name; } // https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object @@ -832,11 +830,10 @@ export class PackageManagerService extends AbstractService { await this.bugVersionService.fixPackageBugVersions(bugVersion, fullname, data.versions); } // set _source_registry_name in full manifestDist - if (!data._source_registry_name && isFullManifests) { - if (registry) { - data._source_registry_name = registry?.name; - } + if (registry) { + data._source_registry_name = registry?.name; } + const distBytes = Buffer.from(JSON.stringify(data)); const distIntegrity = await calculateIntegrity(distBytes); etag = `"${distIntegrity.shasum}"`; diff --git a/test/port/controller/package/SavePackageVersionController.test.ts b/test/port/controller/package/SavePackageVersionController.test.ts index 0bf1e791..2a794503 100644 --- a/test/port/controller/package/SavePackageVersionController.test.ts +++ b/test/port/controller/package/SavePackageVersionController.test.ts @@ -179,6 +179,10 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () pkgEntity.registryId = ''; await packageRepository.savePackage(pkgEntity!); + res = await app.httpRequest() + .get(`/${pkg.name}`); + assert.equal(res.body._source_registry_name, 'default'); + pkg = await TestUtil.getFullPackage({ name, version: '2.0.0' }); res = await app.httpRequest() .put(`/${pkg.name}`) @@ -189,6 +193,10 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () pkgEntity = await packageRepository.findPackage('@cnpm', 'publish-package-test'); assert(pkgEntity?.registryId); + + res = await app.httpRequest() + .get(`/${pkg.name}`); + assert.equal(res.body._source_registry_name, 'self'); }); it('should publish on user custom scopes', async () => {