Skip to content

Commit f29b744

Browse files
committed
refactor(@angular-devkit/build-angular): remove hardcoded Node.js version in application builder
This commit removed the hard coded Node.js version in application builder server config and instead passes the Angular CLI supported Node.js versions that are currently stamped using Bazel.
1 parent def1303 commit f29b744

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/angular_devkit/build_angular/src/builders/application/execute-build.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { generateIndexHtml } from '../../tools/esbuild/index-html-generator';
2222
import { extractLicenses } from '../../tools/esbuild/license-extractor';
2323
import {
2424
calculateEstimatedTransferSizes,
25+
getSupportedNodeTargets,
2526
logBuildStats,
2627
logMessages,
2728
transformSupportedBrowsersToTargets,
@@ -114,17 +115,12 @@ export async function executeBuild(
114115

115116
// Server application code
116117
if (serverEntryPoint) {
118+
const nodeTargets = getSupportedNodeTargets();
117119
bundlerContexts.push(
118120
new BundlerContext(
119121
workspaceRoot,
120122
!!options.watch,
121-
createServerCodeBundleOptions(
122-
options,
123-
// NOTE: earlier versions of Node.js are not supported due to unsafe promise patching.
124-
// See: https://github.com/angular/angular/pull/50552#issue-1737967592
125-
[...target, 'node18.13'],
126-
codeBundleCache,
127-
),
123+
createServerCodeBundleOptions(options, [...target, ...nodeTargets], codeBundleCache),
128124
() => false,
129125
),
130126
);

packages/angular_devkit/build_angular/src/tools/esbuild/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import fs from 'node:fs/promises';
1414
import path from 'node:path';
1515
import { promisify } from 'node:util';
1616
import { brotliCompress } from 'node:zlib';
17+
import { coerce } from 'semver';
1718
import { Spinner } from '../../utils/spinner';
1819
import { BundleStats, generateBuildStatsTable } from '../webpack/utils/stats';
1920
import { InitialFileRecord } from './bundler-context';
@@ -290,3 +291,18 @@ export function transformSupportedBrowsersToTargets(supportedBrowsers: string[])
290291

291292
return transformed;
292293
}
294+
295+
const SUPPORTED_NODE_VERSIONS = '0.0.0-ENGINES-NODE';
296+
297+
/**
298+
* Transform supported Node.js versions to esbuild target.
299+
* @see https://esbuild.github.io/api/#target
300+
*/
301+
export function getSupportedNodeTargets(): string[] {
302+
if (SUPPORTED_NODE_VERSIONS.charAt(0) === '0') {
303+
// Unlike `pkg_npm`, `ts_library` which is used to run unit tests does not support substitutions.
304+
return [];
305+
}
306+
307+
return SUPPORTED_NODE_VERSIONS.split('||').map((v) => 'node' + coerce(v)?.version);
308+
}

0 commit comments

Comments
 (0)