Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): update ESM loader to work with No…
Browse files Browse the repository at this point in the history
…de.js 18.19.0

In Node.js 18.19 ESM loaders works the same way as Node.js 20.9+

Closes #26648
  • Loading branch information
alan-agius4 committed Dec 12, 2023
1 parent 72bd0ab commit 7a50df5
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { workerData } from 'node:worker_threads';
import { satisfies } from 'semver';

let IS_NODE_18: boolean | undefined;
function isNode18(): boolean {
return (IS_NODE_18 ??= process.versions.node.startsWith('18.'));
let SUPPORTS_IMPORT_FLAG: boolean | undefined;
function supportsImportFlag(): boolean {
return (SUPPORTS_IMPORT_FLAG ??= satisfies(process.versions.node, '>= 18.19'));
}

/** Call the initialize hook when running on Node.js 18 */
export function callInitializeIfNeeded(
initialize: (typeof import('./loader-hooks'))['initialize'],
): void {
if (isNode18()) {
if (!supportsImportFlag()) {
initialize(workerData);
}
}

export function getESMLoaderArgs(): string[] {
if (isNode18()) {
if (!supportsImportFlag()) {
return [
'--no-warnings', // Suppress `ExperimentalWarning: Custom ESM Loaders is an experimental feature...`.
'--loader',
Expand Down

0 comments on commit 7a50df5

Please sign in to comment.