Skip to content

Commit

Permalink
fix: only syncUpstream in default registry
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Jun 27, 2023
1 parent 5069696 commit ef90e21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/core/service/PackageSyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class PackageSyncerService extends AbstractService {
// 1. 其次从 task.data.registryId (创建单包同步任务时传入)
// 2. 接着根据 scope 进行计算 (作为子包依赖同步时候,无 registryId)
// 3. 最后返回 default registryId (可能 default registry 也不存在)
public async initSpecRegistry(task: Task, pkg: Package | null = null, scope?: string): Promise<Registry | null> {
public async initSpecRegistry(task: Task, pkg: Package | null = null, scope?: string): Promise<Registry> {
const registryId = pkg?.registryId || (task.data as SyncPackageTaskOptions).registryId;
let targetHost: string = this.config.cnpmcore.sourceRegistry;
let registry: Registry | null = null;
Expand Down Expand Up @@ -362,7 +362,7 @@ export class PackageSyncerService extends AbstractService {
const taskQueueHighWaterSize = this.config.cnpmcore.taskQueueHighWaterSize;
const taskQueueInHighWaterState = taskQueueLength >= taskQueueHighWaterSize;
const skipDependencies = taskQueueInHighWaterState ? true : !!originSkipDependencies;
const syncUpstream = !!(!taskQueueInHighWaterState && this.config.cnpmcore.sourceRegistryIsCNpm && this.config.cnpmcore.syncUpstreamFirst);
const syncUpstream = !!(!taskQueueInHighWaterState && this.config.cnpmcore.sourceRegistryIsCNpm && this.config.cnpmcore.syncUpstreamFirst && registry.name === PresetRegistryName.default);
const logUrl = `${this.config.cnpmcore.registry}/-/package/${fullname}/syncs/${task.taskId}/log`;
this.logger.info('[PackageSyncerService.executeTask:start] taskId: %s, targetName: %s, attempts: %s, taskQueue: %s/%s, syncUpstream: %s, log: %s',
task.taskId, task.targetName, task.attempts, taskQueueLength, taskQueueHighWaterSize, syncUpstream, logUrl);
Expand Down
31 changes: 31 additions & 0 deletions test/core/service/PackageSyncerService/executeTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,37 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => {
});
});

it('should ignore syncUpstreamFirst', async () => {
await scopeManagerService.createScope({
name: '@dnpm',
registryId: registry.registryId,
});
app.mockHttpclient('https://custom.npmjs.com/@dnpm/banana', 'GET', {
data: await TestUtil.readFixturesFile('r.cnpmjs.org/cnpmcore-test-sync-deprecated.json'),
persist: false,
});
app.mockHttpclient('https://custom.npmjs.com/@dnpm/banana/-/banana-0.0.0.tgz', 'GET', {
data: await TestUtil.readFixturesFile('registry.npmjs.org/foobar/-/foobar-1.0.0.tgz'),
persist: false,
});
mock(app.config.cnpmcore, 'sourceRegistry', 'https://r.cnpmjs.org');
mock(app.config.cnpmcore, 'sourceRegistryIsCNpm', true);
mock(app.config.cnpmcore, 'syncUpstreamFirst', true);

const name = '@dnpm/banana';
await packageSyncerService.createTask(name);
const task = await packageSyncerService.findExecuteTask();
assert(task);
assert.equal(task.targetName, name);
await packageSyncerService.executeTask(task);
const stream = await packageSyncerService.findTaskLog(task);
assert(stream);
const log = await TestUtil.readStreamToLog(stream);
// console.log(log);
assert(log.includes('syncUpstream: false'));

});

it('should sync from target registry & default registry', async () => {
await packageSyncerService.createTask('cnpm-pkg', { registryId: registry.registryId });
await packageSyncerService.createTask('npm-pkg');
Expand Down

0 comments on commit ef90e21

Please sign in to comment.