From 764ee19029f1abc0458a70f9587c70dcd806b0c0 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 7 Feb 2022 17:42:32 +0100 Subject: [PATCH] cli: switch to looping parallel workers + fix bump test log ordering Signed-off-by: Patrik Oldsberg --- .../cli/src/commands/versions/bump.test.ts | 22 ++++++++--------- packages/cli/src/lib/parallel.ts | 24 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/cli/src/commands/versions/bump.test.ts b/packages/cli/src/commands/versions/bump.test.ts index 2dadd06d1d..ae1a4c4627 100644 --- a/packages/cli/src/commands/versions/bump.test.ts +++ b/packages/cli/src/commands/versions/bump.test.ts @@ -127,8 +127,8 @@ describe('bump', () => { }); expect(logs.filter(Boolean)).toEqual([ 'Using default pattern glob @backstage/*', - 'Checking for updates of @backstage/theme', 'Checking for updates of @backstage/core', + 'Checking for updates of @backstage/theme', 'Checking for updates of @backstage/core-api', 'Some packages are outdated, updating', 'unlocking @backstage/core@^1.0.3 ~> 1.0.6', @@ -252,19 +252,19 @@ describe('bump', () => { }); expect(logs.filter(Boolean)).toEqual([ 'Using custom pattern glob @{backstage,backstage-extra}/*', - 'Checking for updates of @backstage/theme', - 'Checking for updates of @backstage-extra/custom-two', - 'Checking for updates of @backstage-extra/custom', 'Checking for updates of @backstage/core', + 'Checking for updates of @backstage-extra/custom', + 'Checking for updates of @backstage-extra/custom-two', + 'Checking for updates of @backstage/theme', 'Checking for updates of @backstage/core-api', 'Some packages are outdated, updating', - 'unlocking @backstage-extra/custom@^1.0.1 ~> 1.1.0', 'unlocking @backstage/core@^1.0.3 ~> 1.0.6', + 'unlocking @backstage-extra/custom@^1.0.1 ~> 1.1.0', 'unlocking @backstage/core-api@^1.0.6 ~> 1.0.7', 'unlocking @backstage/core-api@^1.0.3 ~> 1.0.7', 'bumping @backstage-extra/custom-two in a to ^2.0.0', - 'bumping @backstage/theme in b to ^2.0.0', 'bumping @backstage-extra/custom-two in b to ^2.0.0', + 'bumping @backstage/theme in b to ^2.0.0', 'Running yarn install to install new versions', '⚠️ The following packages may have breaking changes:', ' @backstage-extra/custom-two : 1.0.0 ~> 2.0.0', @@ -348,14 +348,14 @@ describe('bump', () => { }); expect(logs.filter(Boolean)).toEqual([ 'Using default pattern glob @backstage/*', - 'Checking for updates of @backstage/theme', 'Checking for updates of @backstage/core', - 'Package info not found, ignoring package @backstage/theme', - 'Package info not found, ignoring package @backstage/core', 'Checking for updates of @backstage/theme', - 'Checking for updates of @backstage/core', - 'Package info not found, ignoring package @backstage/theme', 'Package info not found, ignoring package @backstage/core', + 'Package info not found, ignoring package @backstage/theme', + 'Checking for updates of @backstage/core', + 'Checking for updates of @backstage/theme', + 'Package info not found, ignoring package @backstage/core', + 'Package info not found, ignoring package @backstage/theme', 'All Backstage packages are up to date!', ]); diff --git a/packages/cli/src/lib/parallel.ts b/packages/cli/src/lib/parallel.ts index e1a56770fd..f8af967d22 100644 --- a/packages/cli/src/lib/parallel.ts +++ b/packages/cli/src/lib/parallel.ts @@ -72,21 +72,19 @@ export async function runParallelWorkers( ? parseParallelismOption(parallelismSetting) : getEnvironmentParallelism(); - const iterator = items[Symbol.iterator](); - - async function pop() { - const el = iterator.next(); - if (el.done) { - return; - } - - await worker(el.value); - await pop(); - } + const sharedIterator = items[Symbol.iterator](); + const sharedIterable = { + [Symbol.iterator]: () => sharedIterator, + }; + const workerCount = Math.max(Math.floor(parallelismFactor * parallelism), 1); return Promise.all( - Array(Math.max(Math.floor(parallelismFactor * parallelism), 1)) + Array(workerCount) .fill(0) - .map(() => pop()), + .map(async () => { + for (const value of sharedIterable) { + await worker(value); + } + }), ); }