diff --git a/packages/angular_devkit/build_angular/src/utils/action-executor.ts b/packages/angular_devkit/build_angular/src/utils/action-executor.ts index 8c7e3d50fde5..94b4053ed616 100644 --- a/packages/angular_devkit/build_angular/src/utils/action-executor.ts +++ b/packages/angular_devkit/build_angular/src/utils/action-executor.ts @@ -11,9 +11,9 @@ import * as os from 'os'; import * as path from 'path'; import { serialize } from 'v8'; import { BundleActionCache } from './action-cache'; +import { maxWorkers } from './environment-options'; import { I18nOptions } from './i18n-options'; import { InlineOptions, ProcessBundleOptions, ProcessBundleResult } from './process-bundle'; -import { maxWorkers } from './workers'; let workerFile = require.resolve('./process-bundle'); workerFile = @@ -35,7 +35,7 @@ export class BundleActionExecutor { } private static executeMethod(worker: JestWorker, method: string, input: unknown): Promise { - return ((worker as unknown) as Record Promise>)[method](input); + return (worker as unknown as Record Promise>)[method](input); } private ensureLarge(): JestWorker { diff --git a/packages/angular_devkit/build_angular/src/utils/environment-options.ts b/packages/angular_devkit/build_angular/src/utils/environment-options.ts index 0603ad907597..48700186053e 100644 --- a/packages/angular_devkit/build_angular/src/utils/environment-options.ts +++ b/packages/angular_devkit/build_angular/src/utils/environment-options.ts @@ -83,3 +83,15 @@ export const cachingBasePath = (() => { // Build profiling const profilingVariable = process.env['NG_BUILD_PROFILING']; export const profilingEnabled = isPresent(profilingVariable) && isEnabled(profilingVariable); + +/** + * Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available. + * This cause `Error: Call retries were exceeded` errors when trying to use them. + * + * @see https://github.com/nodejs/node/issues/28762 + * @see https://github.com/webpack-contrib/terser-webpack-plugin/issues/143 + * @see https://ithub.com/angular/angular-cli/issues/16860#issuecomment-588828079 + * + */ +const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS']; +export const maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable : 4; diff --git a/packages/angular_devkit/build_angular/src/utils/index.ts b/packages/angular_devkit/build_angular/src/utils/index.ts index 43a3a70cae25..8e5b242fb8ed 100644 --- a/packages/angular_devkit/build_angular/src/utils/index.ts +++ b/packages/angular_devkit/build_angular/src/utils/index.ts @@ -16,4 +16,3 @@ export * from './normalize-source-maps'; export * from './normalize-optimization'; export * from './normalize-builder-schema'; export * from './url'; -export * from './workers'; diff --git a/packages/angular_devkit/build_angular/src/utils/workers.ts b/packages/angular_devkit/build_angular/src/utils/workers.ts deleted file mode 100644 index d0e47eb850cc..000000000000 --- a/packages/angular_devkit/build_angular/src/utils/workers.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import { cpus } from 'os'; -/** - * Use CPU count -1 with limit to 7 for workers not to clog the system. - * Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available. - * This cause `Error: Call retries were exceeded` errors when trying to use them. - * - * See: - * - * https://github.com/nodejs/node/issues/28762 - * - * https://github.com/webpack-contrib/terser-webpack-plugin/issues/143 - * - * https://github.com/angular/angular-cli/issues/16860#issuecomment-588828079 - * - */ -export const maxWorkers = Math.max(Math.min(cpus().length, 8) - 1, 1); diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts index 575e852a53b4..4f9ef6228dbe 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts +++ b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts @@ -23,13 +23,14 @@ import { debug, } from 'webpack'; import { AssetPatternClass } from '../../browser/schema'; -import { BuildBrowserFeatures, maxWorkers } from '../../utils'; +import { BuildBrowserFeatures } from '../../utils'; import { WebpackConfigOptions } from '../../utils/build-options'; import { findCachePath } from '../../utils/cache-path'; import { allowMangle, allowMinify, cachingDisabled, + maxWorkers, profilingEnabled, shouldBeautify, } from '../../utils/environment-options';