Skip to content
This repository was archived by the owner on Sep 26, 2026. It is now read-only.
Open
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
5 changes: 4 additions & 1 deletion os/env/path-extender-windows/path-extender-windows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ HKEY_CURRENT_USER\\Environment
})

test('successful first time installation', async () => {
const currentPathInRegistry = '%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;%USERPROFILE%\\.config\\etc;'
const currentPathInRegistry = 'C:\\Users\\Jozef Steinhübl\\bin;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;'

execa['mockResolvedValueOnce']({
failed: false,
Expand Down Expand Up @@ -141,11 +141,14 @@ HKEY_CURRENT_USER\\Environment
newValue: `%PNPM_HOME%;${currentPathInRegistry}`,
},
])
expect(execa).toHaveBeenNthCalledWith(1, 'chcp', [], { windowsHide: false })
expect(execa).toHaveBeenNthCalledWith(2, 'chcp', ['65001'], { windowsHide: false })
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(6, 'setx', ['REFRESH_ENV_VARS', '1'], { windowsHide: false })
expect(execa).toHaveBeenNthCalledWith(7, 'reg', ['delete' ,regKey, '/v', 'REFRESH_ENV_VARS', '/f'], { windowsHide: false })
expect(execa).toHaveBeenNthCalledWith(8, 'chcp', ['936'], { windowsHide: false })
})

test('successful first time installation with proxyVarSubDir', async () => {
Expand Down
6 changes: 3 additions & 3 deletions os/env/path-extender-windows/path-extender-windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type PathExtenderWindowsReport = EnvVariableChange[]
export async function addDirToWindowsEnvPath (dir: string, opts?: AddDirToWindowsEnvPathOpts): Promise<PathExtenderWindowsReport> {
// Use `chcp` to make `reg` use utf8 encoding for output.
// Otherwise, the non-ascii characters in the environment variables will become garbled characters.
const chcpResult = await execa('chcp')
const chcpResult = await execa('chcp', [], EXEC_OPTS)
const cpMatch = /\d+/.exec(chcpResult.stdout) ?? []
if (cpMatch.length === 0) {
throw new PnpmError('CHCP', `exec chcp failed: ${chcpResult.stderr}`)
Expand All @@ -49,13 +49,13 @@ export async function addDirToWindowsEnvPath (dir: string, opts?: AddDirToWindow
if (chcpResult.failed || !(cpBak > 0)) {
throw new PnpmError('CHCP', `exec chcp failed: ${cpBak}, ${chcpResult.stderr}`)
}
await execa('chcp', ['65001'])
await execa('chcp', ['65001'], EXEC_OPTS)
try {
const report = await _addDirToWindowsEnvPath(dir, opts)
await refreshEnvVars()
return report
} finally {
await execa('chcp', [cpBak.toString()])
await execa('chcp', [cpBak.toString()], EXEC_OPTS)
}
}

Expand Down