From 80ade9354be5909f90b33047039db8b74165807f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Wed, 18 Oct 2023 15:15:55 +0200 Subject: [PATCH] fix(core): ensure CNW works without .yarnrc with custom registry (#18937) --- .../create-nx-workspace/src/utils/package-manager.ts | 2 +- packages/devkit/src/tasks/install-packages-task.ts | 10 ++++++++++ packages/nx/src/command-line/migrate/command-object.ts | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/create-nx-workspace/src/utils/package-manager.ts b/packages/create-nx-workspace/src/utils/package-manager.ts index 9400fe7b25812..6d0281c29c3c7 100644 --- a/packages/create-nx-workspace/src/utils/package-manager.ts +++ b/packages/create-nx-workspace/src/utils/package-manager.ts @@ -1,5 +1,5 @@ import { execSync } from 'child_process'; -import { existsSync, readFileSync, writeFileSync } from 'fs'; +import { existsSync, writeFileSync } from 'fs'; import { join } from 'path'; /* diff --git a/packages/devkit/src/tasks/install-packages-task.ts b/packages/devkit/src/tasks/install-packages-task.ts index 99ceaf4a2a653..64dbc5a46fbb7 100644 --- a/packages/devkit/src/tasks/install-packages-task.ts +++ b/packages/devkit/src/tasks/install-packages-task.ts @@ -42,6 +42,16 @@ export function installPackagesTask( cwd: join(tree.root, cwd), stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit', }; + // ensure local registry from process is not interfering with the install + // when we start the process from temp folder the local registry would override the custom registry + if ( + process.env.npm_config_registry && + process.env.npm_config_registry.match( + /^https:\/\/registry\.(npmjs\.org|yarnpkg\.com)/ + ) + ) { + delete process.env.npm_config_registry; + } execSync(pmc.install, execSyncOptions); } } diff --git a/packages/nx/src/command-line/migrate/command-object.ts b/packages/nx/src/command-line/migrate/command-object.ts index 5582a5eaa40e6..5bca8fec40cf3 100644 --- a/packages/nx/src/command-line/migrate/command-object.ts +++ b/packages/nx/src/command-line/migrate/command-object.ts @@ -111,6 +111,16 @@ function runMigration() { if (p === null) { runLocalMigrate(); } else { + // ensure local registry from process is not interfering with the install + // when we start the process from temp folder the local registry would override the custom registry + if ( + process.env.npm_config_registry && + process.env.npm_config_registry.match( + /^https:\/\/registry\.(npmjs\.org|yarnpkg\.com)/ + ) + ) { + delete process.env.npm_config_registry; + } execSync(`${p} _migrate ${process.argv.slice(3).join(' ')}`, { stdio: ['inherit', 'inherit', 'inherit'], });