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:
@@ -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);
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user