Skip to content

Commit

Permalink
fix(@angular/build): use Node.js available parallelism for default wo…
Browse files Browse the repository at this point in the history
…rker count

The Node.js `os.availableParallelism` API now provides more accurate values
when used within containers such as many CI environments. This provides a
better default when using resource limited CI setups. The value is still
set to a maximum default of four. However, the `NG_BUILD_MAX_WORKERS`
environment variable can be used to set the value to an explicit value
if required.

(cherry picked from commit dd07049)
  • Loading branch information
clydin authored and alan-agius4 committed Jun 18, 2024
1 parent 86e031d commit 7360a34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/angular/build/src/utils/environment-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { availableParallelism } from 'node:os';

function isDisabled(variable: string): boolean {
return variable === '0' || variable.toLowerCase() === 'false';
}
Expand Down Expand Up @@ -74,7 +76,9 @@ export const allowMinify = debugOptimize.minify;
*
*/
const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS'];
export const maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable : 4;
export const maxWorkers = isPresent(maxWorkersVariable)
? +maxWorkersVariable
: Math.min(4, availableParallelism());

const parallelTsVariable = process.env['NG_BUILD_PARALLEL_TS'];
export const useParallelTs = !isPresent(parallelTsVariable) || !isDisabled(parallelTsVariable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { availableParallelism } from 'node:os';

function isDisabled(variable: string): boolean {
return variable === '0' || variable.toLowerCase() === 'false';
}
Expand Down Expand Up @@ -74,7 +76,9 @@ export const allowMinify = debugOptimize.minify;
*
*/
const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS'];
export const maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable : 4;
export const maxWorkers = isPresent(maxWorkersVariable)
? +maxWorkersVariable
: Math.min(4, availableParallelism());

const parallelTsVariable = process.env['NG_BUILD_PARALLEL_TS'];
export const useParallelTs = !isPresent(parallelTsVariable) || !isDisabled(parallelTsVariable);
Expand Down

0 comments on commit 7360a34

Please sign in to comment.