Remove dead parallelism options and narrow public API

The parallelism fields on bundler types (BundlingOptions, BuildOptions,
BackendBundlingOptions) and createDistWorkspace Options were defined but
never read — fully dead code. Likewise the parallelismSetting option on
ParallelWorkerOptions was never passed by any caller.

Also narrows the cli-node public API to only export the three runner
functions and their option types, keeping getEnvironmentParallelism and
parseParallelismOption as internal utilities.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-22 16:49:55 +01:00
parent 06c2015e5b
commit 649d3ca3b6
9 changed files with 11 additions and 53 deletions
+1 -3
View File
@@ -14,10 +14,8 @@
* limitations under the License.
*/
export type { ParallelismOption, ParallelWorkerOptions } from './parallel';
export type { ParallelWorkerOptions } from './parallel';
export {
parseParallelismOption,
getEnvironmentParallelism,
runParallelWorkers,
runWorkerQueueThreads,
runWorkerThreads,
@@ -66,14 +66,18 @@ describe('getEnvironmentParallelism', () => {
});
describe('runParallelWorkers', () => {
afterEach(() => {
delete process.env.BACKSTAGE_CLI_BUILD_PARALLEL;
});
it('executes work in parallel', async () => {
const started = new Array<number>();
const done = new Array<number>();
const waiting = new Array<() => void>();
process.env.BACKSTAGE_CLI_BUILD_PARALLEL = '4';
const work = runParallelWorkers({
items: [0, 1, 2, 3, 4],
parallelismSetting: 4,
parallelismFactor: 0.5, // 2 at a time
worker: async item => {
started.push(item);
+2 -23
View File
@@ -22,21 +22,8 @@ const defaultParallelism = Math.ceil(os.cpus().length / 2);
const PARALLEL_ENV_VAR = 'BACKSTAGE_CLI_BUILD_PARALLEL';
/**
* Options for configuring parallelism. Can be a boolean, string, number, null, or undefined.
* - Boolean: true uses default parallelism (half of CPUs), false uses 1
* - Number: explicit worker count
* - String: parsed as boolean or integer (e.g. "true", "4")
*
* @public
*/
export type ParallelismOption = boolean | string | number | null | undefined;
/**
* Parses a parallelism option value into a concrete worker count.
*
* @public
*/
export function parseParallelismOption(parallel: ParallelismOption): number {
if (parallel === undefined || parallel === null) {
return defaultParallelism;
@@ -64,11 +51,6 @@ export function parseParallelismOption(parallel: ParallelismOption): number {
);
}
/**
* Returns the parallelism value from the BACKSTAGE_CLI_BUILD_PARALLEL environment variable.
*
* @public
*/
export function getEnvironmentParallelism() {
return parseParallelismOption(process.env[PARALLEL_ENV_VAR]);
}
@@ -86,7 +68,6 @@ export type ParallelWorkerOptions<TItem> = {
* Defaults to 1.
*/
parallelismFactor?: number;
parallelismSetting?: ParallelismOption;
items: Iterable<TItem>;
worker: (item: TItem) => Promise<void>;
};
@@ -99,10 +80,8 @@ export type ParallelWorkerOptions<TItem> = {
export async function runParallelWorkers<TItem>(
options: ParallelWorkerOptions<TItem>,
) {
const { parallelismFactor = 1, parallelismSetting, items, worker } = options;
const parallelism = parallelismSetting
? parseParallelismOption(parallelismSetting)
: getEnvironmentParallelism();
const { parallelismFactor = 1, items, worker } = options;
const parallelism = getEnvironmentParallelism();
const sharedIterator = items[Symbol.iterator]();
const sharedIterable = {