diff --git a/app/core/service/PackageSyncerService.ts b/app/core/service/PackageSyncerService.ts index 54538cbb..f94b954c 100644 --- a/app/core/service/PackageSyncerService.ts +++ b/app/core/service/PackageSyncerService.ts @@ -33,7 +33,7 @@ import { Registry } from '../entity/Registry'; import { BadRequestError } from 'egg-errors'; import { ScopeManagerService } from './ScopeManagerService'; import { EventCorkAdvice } from './EventCorkerAdvice'; -import { SyncDeleteMode } from '../../common/constants'; +import { PresetRegistryName, SyncDeleteMode } from '../../common/constants'; type syncDeletePkgOptions = { task: Task, @@ -372,6 +372,14 @@ export class PackageSyncerService extends AbstractService { } logs.push(`[${isoNow()}] 🚧 log: ${logUrl}`); + if (registry?.name === PresetRegistryName.self) { + logs.push(`[${isoNow()}] ❌❌❌❌❌ ${fullname} has been published to the self registry, skip sync ❌❌❌❌❌`); + await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); + this.logger.info('[PackageSyncerService.executeTask:fail] taskId: %s, targetName: %s, invalid registryId', + task.taskId, task.targetName); + return; + } + if (pkg && pkg?.registryId !== registry?.registryId) { if (pkg.registryId) { logs.push(`[${isoNow()}] ❌❌❌❌❌ ${fullname} registry is ${pkg.registryId} not belong to ${registry?.registryId}, skip sync ❌❌❌❌❌`); diff --git a/test/core/service/PackageSyncerService/executeTask.test.ts b/test/core/service/PackageSyncerService/executeTask.test.ts index 809d5eaf..08411d18 100644 --- a/test/core/service/PackageSyncerService/executeTask.test.ts +++ b/test/core/service/PackageSyncerService/executeTask.test.ts @@ -719,6 +719,48 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => { }); + it('should skip self registry', async () => { + const name = '@cnpmcore/test-self-sync'; + const { user } = await userService.create({ + name: 'test-user', + password: 'this-is-password', + email: 'hello@example.com', + ip: '127.0.0.1', + }); + + const registry = await registryManagerService.ensureSelfRegistry(); + + const publishCmd = { + scope: '@cnpmcore', + name: 'test-self-sync', + version: '1.0.0', + description: '1.0.0', + readme: '', + registryId: registry.registryId, + packageJson: { name, test: 'test', version: '1.0.0' }, + dist: { + content: Buffer.alloc(0), + }, + isPrivate: false, + publishTime: new Date(), + skipRefreshPackageManifests: false, + }; + const pkgVersion = await packageManagerService.publish(publishCmd, user); + assert(pkgVersion.version === '1.0.0'); + + await packageSyncerService.createTask(name); + const task = await packageSyncerService.findExecuteTask(); + assert(task); + await packageSyncerService.executeTask(task); + + const stream = await packageSyncerService.findTaskLog(task); + assert(stream); + const log = await TestUtil.readStreamToLog(stream); + // console.log(log); + assert(log.includes(`${name} has been published to the self registry, skip sync ❌❌❌❌❌`)); + + }); + it('should updated package manifests when version insert duplicated', async () => { // https://www.npmjs.com/package/@cnpmcore/test-sync-package-has-two-versions const name = '@cnpmcore/test-sync-package-has-two-versions';