From 62d529a8b714c57ed604ef8b73724a93b8306d31 Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Mon, 21 Aug 2023 17:06:46 -0400 Subject: [PATCH] fix(core): do not remove drive letter if running from a temp directory on windows --- packages/devkit/src/utils/package-json.ts | 6 ++++++ packages/nx/src/utils/path.ts | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/packages/devkit/src/utils/package-json.ts b/packages/devkit/src/utils/package-json.ts index 0a2f7d4d550036..4e9bc834b59997 100644 --- a/packages/devkit/src/utils/package-json.ts +++ b/packages/devkit/src/utils/package-json.ts @@ -465,6 +465,12 @@ export function ensurePackage( dir: dirSync().name, }; + // check if the platform is windows, and if the drive letters of the temp directory and current directory match + // if the drive letters do not match, we need to make sure that we do not remove the letter while trying to generate files + if (process.platform == 'win32' && tempDir[0] !== process.cwd[0]) { + process.env.NX_WINDOWS_DRIVE_LETTERS_MISMATCH = 'true'; + } + console.log(`Fetching ${pkg}...`); const packageManager = detectPackageManager(); const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true'; diff --git a/packages/nx/src/utils/path.ts b/packages/nx/src/utils/path.ts index df6ab83a7b22a6..36a425e140b449 100644 --- a/packages/nx/src/utils/path.ts +++ b/packages/nx/src/utils/path.ts @@ -1,6 +1,11 @@ import * as path from 'path'; function removeWindowsDriveLetter(osSpecificPath: string): string { + // This process is running from a temp directory (which is normally on C:) while the cwd is on a different drive letter + // do not remove the drive letter in this scenario + if (process.env.NX_WINDOWS_DRIVE_LETTERS_MISMATCH === 'true') { + return osSpecificPath; + } return osSpecificPath.replace(/^[A-Z]:/, ''); }