From 1d6f70e9d95575d86679767efb66ac47e397b5cc Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Sat, 10 Jan 2026 10:34:37 +0000 Subject: [PATCH] fix(ng-dev): replace `node_version_from_nvmrc` with concrete version in Bazel module This change modifies the `sync-module-bazel` script to replace `node_version_from_nvmrc` with a concrete `node_version` derived from `.nvmrc` when processing the `node.toolchain` arguments. This workaround addresses a bug with `node_version_from_nvmrc` when used alongside `node_repositories` in `rules_nodejs` (specifically < 6.6.3), ensuring that the toolchain is correctly configured with the specific Node.js version and its corresponding repositories. --- .../sync-module-bazel/sync-module-bazel.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ng-dev/misc/sync-module-bazel/sync-module-bazel.ts b/ng-dev/misc/sync-module-bazel/sync-module-bazel.ts index 42111a508..c611fcbfe 100644 --- a/ng-dev/misc/sync-module-bazel/sync-module-bazel.ts +++ b/ng-dev/misc/sync-module-bazel/sync-module-bazel.ts @@ -47,6 +47,8 @@ const TS_VERSION_REGEXP = /ts_version(?:_from)? = ".*?"/; const TS_INTEGRITY_REGEXP = /ts_integrity = ".*?"/; /** RegExp that matches the Node.js version assignment in MODULE.bazel. */ const NODE_VERSION_REGEXP = /node_version = "(.*?)"/; +/** RegExp that matches the Node.js version from nvmrc assignment in MODULE.bazel. */ +const NODE_VERSION_FROM_NVMRC_REGEXP = /node_version_from_nvmrc = ".*?"/; /** RegExp that matches the Node.js repositories assignment in MODULE.bazel. */ const NODE_REPOSITORIES_REGEXP = /node_repositories = \{[\s\S]*?\}/; @@ -111,20 +113,27 @@ async function processNodeToolchainArgs( args: string, nvmrcVersion: string | undefined, ): Promise { - const useVersionFromNvm = args.includes('node_version_from_nvmrc'); const versionMatch = args.match(NODE_VERSION_REGEXP); let effectiveVersion = versionMatch?.[1]; - if (useVersionFromNvm) { + if (effectiveVersion === nvmrcVersion) { + return args; + } + + if (effectiveVersion) { + args = args.replace(NODE_VERSION_REGEXP, `node_version = "${nvmrcVersion}"`); + effectiveVersion = nvmrcVersion; + } else if (NODE_VERSION_FROM_NVMRC_REGEXP.test(args)) { if (!nvmrcVersion) { throw new Error('node_version_from_nvmrc used but .nvmrc not found'); } effectiveVersion = nvmrcVersion; - } else if (effectiveVersion && effectiveVersion !== nvmrcVersion) { - args = args.replace(NODE_VERSION_REGEXP, `node_version = "${nvmrcVersion}"`); - effectiveVersion = nvmrcVersion; + // TODO(alanagius): This is needed as currently 'node_version_from_nvmrc' is buggy with 'node_repositories'. + // This should be addressed in version of rules_nodejs > 6.6.2 + args = args.replace(NODE_VERSION_FROM_NVMRC_REGEXP, `node_version = "${nvmrcVersion}"`); } + if (!effectiveVersion) { return args; }