Skip to content
This repository was archived by the owner on Sep 26, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions os/env/path-extender-windows/path-extender-windows.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions os/env/path-extender-windows/path-extender-windows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 })
})
Expand Down Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions os/env/path-extender-windows/path-extender-windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down