From f8886021d8fa32eee0199cac94b879bca4984d6c Mon Sep 17 00:00:00 2001 From: amishabenramani Date: Sat, 26 Sep 2026 15:46:54 +0200 Subject: [PATCH] fix: persist literal Windows bin path --- .../path-extender-windows.docs.mdx | 4 ++-- .../path-extender-windows.spec.ts | 14 +++++++------- .../path-extender-windows/path-extender-windows.ts | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/os/env/path-extender-windows/path-extender-windows.docs.mdx b/os/env/path-extender-windows/path-extender-windows.docs.mdx index 45b66c0..63cf711 100644 --- a/os/env/path-extender-windows/path-extender-windows.docs.mdx +++ b/os/env/path-extender-windows/path-extender-windows.docs.mdx @@ -5,7 +5,7 @@ description: 'A module for adding a new directory to the Path environment variab ## Usage -This adds a `PNPM_HOME` environment variable with the specified directory. And prepends the value of `PNPM_HOME` to the `Path`: +This adds a `PNPM_HOME` environment variable with the specified directory and prepends the resolved directory to `Path`: ```ts import { addDirToWindowsEnvPath } from '@pnpm/os.env.path-extender-windows' @@ -21,7 +21,7 @@ await addDirToWindowsEnvPath('C:\\pnpm', { overwriteProxyVar: true, }) //> PNPM_HOME=C:\pnpm -// Path=%PNPM_HOME%;C:\foo;C:\bar +// Path=C:\pnpm;C:\foo;C:\bar ``` This prepends `C:\pnpm` to the `Path` (no additional environment variable is created: diff --git a/os/env/path-extender-windows/path-extender-windows.spec.ts b/os/env/path-extender-windows/path-extender-windows.spec.ts index 0d9763f..2686ff4 100644 --- a/os/env/path-extender-windows/path-extender-windows.spec.ts +++ b/os/env/path-extender-windows/path-extender-windows.spec.ts @@ -138,12 +138,12 @@ HKEY_CURRENT_USER\\Environment action: 'updated', variable: 'Path', oldValue: currentPathInRegistry, - newValue: `%PNPM_HOME%;${currentPathInRegistry}`, + newValue: `${pnpmHomeDirNormalized};${currentPathInRegistry}`, }, ]) expect(execa).toHaveBeenNthCalledWith(3, 'reg', ['query', regKey], { windowsHide: false }) expect(execa).toHaveBeenNthCalledWith(4, 'reg', ['add', regKey, '/v', 'PNPM_HOME', '/t', 'REG_SZ', '/d', pnpmHomeDirNormalized, '/f'], { windowsHide: false }) - expect(execa).toHaveBeenNthCalledWith(5, 'reg', ['add', regKey, '/v', 'Path', '/t', 'REG_EXPAND_SZ', '/d', `%PNPM_HOME%;${currentPathInRegistry}`, '/f'], { windowsHide: false }) + expect(execa).toHaveBeenNthCalledWith(5, 'reg', ['add', regKey, '/v', 'Path', '/t', 'REG_EXPAND_SZ', '/d', `${pnpmHomeDirNormalized};${currentPathInRegistry}`, '/f'], { windowsHide: false }) expect(execa).toHaveBeenNthCalledWith(6, 'setx', ['REFRESH_ENV_VARS', '1'], { windowsHide: false }) expect(execa).toHaveBeenNthCalledWith(7, 'reg', ['delete' ,regKey, '/v', 'REFRESH_ENV_VARS', '/f'], { windowsHide: false }) }) @@ -192,10 +192,10 @@ HKEY_CURRENT_USER\\Environment action: 'updated', variable: 'Path', oldValue: currentPathInRegistry, - newValue: `%PNPM_HOME%\\bin;${currentPathInRegistry}`, + newValue: `${path.join(pnpmHomeDirNormalized, 'bin')};${currentPathInRegistry}`, }, ]) - expect(execa).toHaveBeenNthCalledWith(5, 'reg', ['add', regKey, '/v', 'Path', '/t', 'REG_EXPAND_SZ', '/d', `%PNPM_HOME%\\bin;${currentPathInRegistry}`, '/f'], { windowsHide: false }) + expect(execa).toHaveBeenNthCalledWith(5, 'reg', ['add', regKey, '/v', 'Path', '/t', 'REG_EXPAND_SZ', '/d', `${path.join(pnpmHomeDirNormalized, 'bin')};${currentPathInRegistry}`, '/f'], { windowsHide: false }) }) test('successful first time installation when no additional env variable is used', async () => { @@ -333,11 +333,11 @@ HKEY_CURRENT_USER\\Environment variable: 'Path', action: 'updated', oldValue: currentPathInRegistry, - newValue: `%PNPM_HOME%;${currentPathInRegistry}`, + newValue: `${pnpmHomeDirNormalized};${currentPathInRegistry}`, }, ]) expect(execa).toHaveBeenNthCalledWith(3, 'reg', ['query', regKey], { windowsHide: false }) - expect(execa).toHaveBeenNthCalledWith(4, 'reg', ['add', regKey, '/v', 'Path', '/t', 'REG_EXPAND_SZ', '/d', `%PNPM_HOME%;${currentPathInRegistry}`, '/f'], { windowsHide: false }) + expect(execa).toHaveBeenNthCalledWith(4, 'reg', ['add', regKey, '/v', 'Path', '/t', 'REG_EXPAND_SZ', '/d', `${pnpmHomeDirNormalized};${currentPathInRegistry}`, '/f'], { windowsHide: false }) expect(execa).toHaveBeenNthCalledWith(5, 'setx', ['REFRESH_ENV_VARS', '1'], { windowsHide: false }) expect(execa).toHaveBeenNthCalledWith(6, 'reg', ['delete' ,regKey, '/v', 'REFRESH_ENV_VARS', '/f'], { windowsHide: false }) }) @@ -418,7 +418,7 @@ HKEY_CURRENT_USER\\Environment variable: 'Path', action: 'updated', oldValue: '%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;%USERPROFILE%\\.config\\etc;.pnpm\\home;C:\\Windows;', - newValue: '%PNPM_HOME%;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;%USERPROFILE%\\.config\\etc;.pnpm\\home;C:\\Windows;', + newValue: `${pnpmHomeDirNormalized};%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;%USERPROFILE%\\.config\\etc;.pnpm\\home;C:\\Windows;`, }, ]) expect(execa).toHaveBeenNthCalledWith(3, 'reg', ['query', regKey], { windowsHide: false }) diff --git a/os/env/path-extender-windows/path-extender-windows.ts b/os/env/path-extender-windows/path-extender-windows.ts index af761bd..3cc4787 100644 --- a/os/env/path-extender-windows/path-extender-windows.ts +++ b/os/env/path-extender-windows/path-extender-windows.ts @@ -71,8 +71,8 @@ async function _addDirToWindowsEnvPath (dir: string, opts: AddDirToWindowsEnvPat overwrite: opts.overwriteProxyVar ?? false })) const pathEntry = opts.proxyVarSubDir - ? `%${opts.proxyVarName}%${path.sep}${opts.proxyVarSubDir}` - : `%${opts.proxyVarName}%` + ? path.join(addedDir, opts.proxyVarSubDir) + : addedDir changes.push(await addToPath(registryOutput, pathEntry, opts.position)) } else { changes.push(await addToPath(registryOutput, addedDir, opts.position))