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:
@@ -2,4 +2,4 @@
|
||||
'@backstage/cli-node': minor
|
||||
---
|
||||
|
||||
Added parallel worker utilities: `runParallelWorkers`, `runWorkerQueueThreads`, `runWorkerThreads`, `parseParallelismOption`, and `getEnvironmentParallelism`. These were moved from the `@backstage/cli` internal code.
|
||||
Added parallel worker utilities: `runParallelWorkers`, `runWorkerQueueThreads`, and `runWorkerThreads`. These were moved from the `@backstage/cli` internal code.
|
||||
|
||||
@@ -86,9 +86,6 @@ export interface BackstagePackageJson {
|
||||
version: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export function getEnvironmentParallelism(): number;
|
||||
|
||||
// @public
|
||||
export class GitUtils {
|
||||
static listChangedFiles(ref: string): Promise<string[]>;
|
||||
@@ -204,20 +201,13 @@ export class PackageRoles {
|
||||
static getRoleInfo(role: string): PackageRoleInfo;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type ParallelismOption = boolean | string | number | null | undefined;
|
||||
|
||||
// @public
|
||||
export type ParallelWorkerOptions<TItem> = {
|
||||
parallelismFactor?: number;
|
||||
parallelismSetting?: ParallelismOption;
|
||||
items: Iterable<TItem>;
|
||||
worker: (item: TItem) => Promise<void>;
|
||||
};
|
||||
|
||||
// @public
|
||||
export function parseParallelismOption(parallel: ParallelismOption): number;
|
||||
|
||||
// @public
|
||||
export function runParallelWorkers<TItem>(
|
||||
options: ParallelWorkerOptions<TItem>,
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -20,7 +20,7 @@ import { resolve as resolvePath } from 'node:path';
|
||||
import * as tar from 'tar';
|
||||
import { createDistWorkspace } from './packager';
|
||||
import { buildPackage, Output } from './builder';
|
||||
import { PackageGraph, getEnvironmentParallelism } from '@backstage/cli-node';
|
||||
import { PackageGraph } from '@backstage/cli-node';
|
||||
|
||||
const BUNDLE_FILE = 'bundle.tar.gz';
|
||||
const SKELETON_FILE = 'skeleton.tar.gz';
|
||||
@@ -52,7 +52,6 @@ export async function buildBackend(options: BuildBackendOptions) {
|
||||
configPaths,
|
||||
buildDependencies: !skipBuildDependencies,
|
||||
buildExcludes: [pkg.name],
|
||||
parallelism: getEnvironmentParallelism(),
|
||||
skeleton: SKELETON_FILE,
|
||||
minify,
|
||||
});
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
import fs from 'fs-extra';
|
||||
import { resolve as resolvePath } from 'node:path';
|
||||
import { buildBundle, getModuleFederationRemoteOptions } from './bundler';
|
||||
import {
|
||||
BackstagePackageJson,
|
||||
getEnvironmentParallelism,
|
||||
} from '@backstage/cli-node';
|
||||
import { BackstagePackageJson } from '@backstage/cli-node';
|
||||
import { loadCliConfig } from '../../config/lib/config';
|
||||
|
||||
interface BuildAppOptions {
|
||||
@@ -39,7 +36,6 @@ export async function buildFrontend(options: BuildAppOptions) {
|
||||
await buildBundle({
|
||||
targetDir,
|
||||
entry: 'src/index',
|
||||
parallelism: getEnvironmentParallelism(),
|
||||
statsJsonEnabled: writeStats,
|
||||
moduleFederationRemote: options.isModuleFederationRemote
|
||||
? await getModuleFederationRemoteOptions(
|
||||
|
||||
@@ -36,7 +36,6 @@ export type BundlingOptions = {
|
||||
isDev: boolean;
|
||||
frontendConfig: Config;
|
||||
getFrontendAppConfigs(): AppConfig[];
|
||||
parallelism?: number;
|
||||
additionalEntryPoints?: string[];
|
||||
// Path to append to the detected public path, e.g. '/public'
|
||||
publicSubPath?: string;
|
||||
@@ -63,7 +62,6 @@ export type BuildOptions = BundlingPathsOptions & {
|
||||
// Target directory, defaulting to paths.targetDir
|
||||
targetDir?: string;
|
||||
statsJsonEnabled: boolean;
|
||||
parallelism?: number;
|
||||
schema?: ConfigSchema;
|
||||
frontendConfig: Config;
|
||||
frontendAppConfigs: AppConfig[];
|
||||
@@ -75,7 +73,6 @@ export type BuildOptions = BundlingPathsOptions & {
|
||||
export type BackendBundlingOptions = {
|
||||
checksEnabled: boolean;
|
||||
isDev: boolean;
|
||||
parallelism?: number;
|
||||
inspectEnabled: boolean;
|
||||
inspectBrkEnabled: boolean;
|
||||
require?: string;
|
||||
|
||||
@@ -86,11 +86,6 @@ type Options = {
|
||||
*/
|
||||
buildExcludes?: string[];
|
||||
|
||||
/**
|
||||
* Controls amount of parallelism in some build steps.
|
||||
*/
|
||||
parallelism?: number;
|
||||
|
||||
/**
|
||||
* If set, creates a skeleton tarball that contains all package.json files
|
||||
* with the same structure as the workspace dir.
|
||||
|
||||
Reference in New Issue
Block a user