From 3623fe9118be14eedd1a04351df5e15b3d7a289a Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 12 Dec 2023 16:48:17 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): update ESM loader to work with Node.js 18.19.0 In Node.js 18.19 ESM loaders works the same way as Node.js 20.9+ Closes #26648 (cherry picked from commit 7a50df5c046b65bb196408dd2c4771d5deccd034) --- .../esm-in-memory-loader/node-18-utils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/node-18-utils.ts b/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/node-18-utils.ts index 344248434c2b..9fb9bae880d6 100644 --- a/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/node-18-utils.ts +++ b/packages/angular_devkit/build_angular/src/utils/server-rendering/esm-in-memory-loader/node-18-utils.ts @@ -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',