From 3df085ea18414eb5dff833788bca23202f83bebb Mon Sep 17 00:00:00 2001 From: JG Date: Sat, 26 Sep 2026 00:48:03 +0900 Subject: [PATCH] fix: preserve unicode paths during windows setup --- os/env/path-extender-windows/path-extender-windows.spec.ts | 5 ++++- os/env/path-extender-windows/path-extender-windows.ts | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) 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..dbd308b 100644 --- a/os/env/path-extender-windows/path-extender-windows.spec.ts +++ b/os/env/path-extender-windows/path-extender-windows.spec.ts @@ -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, @@ -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 () => { diff --git a/os/env/path-extender-windows/path-extender-windows.ts b/os/env/path-extender-windows/path-extender-windows.ts index af761bd..69ad7fb 100644 --- a/os/env/path-extender-windows/path-extender-windows.ts +++ b/os/env/path-extender-windows/path-extender-windows.ts @@ -40,7 +40,7 @@ export type PathExtenderWindowsReport = EnvVariableChange[] export async function addDirToWindowsEnvPath (dir: string, opts?: AddDirToWindowsEnvPathOpts): Promise { // 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}`) @@ -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) } }