TypeScript
fix(shared): preserve Windows shell PATH priority (#8748)
Utkarsh Patil929f7e6479d0
diff --git a/packages/shared/src/shell.test.ts b/packages/shared/src/shell.test.tsindex e032af50ca5..e3046c03abe 100644--- a/packages/shared/src/shell.test.ts+++ b/packages/shared/src/shell.test.ts@@ -460,7 +460,7 @@ effectIt.layer(NodeServices.layer)("resolveSpawnCommand", (it) => {});effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {- it.effect("returns the baseline no-profile PATH patch when node is already available", () =>+ it.effect("uses known CLI directories as a fallback without changing shell PATH priority", () =>Effect.gen(function* () {const readEnvironment = vi.fn((_names: ReadonlyArray<string>, options?: { loadProfile?: boolean }) =>@@ -483,6 +483,8 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {),).toEqual({PATH: [+ "C:\\Shell\\Bin",+ "C:\\Windows\\System32","C:\\Users\\testuser\\AppData\\Roaming\\npm","C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs","C:\\Users\\testuser\\AppData\\Local\\Volta\\bin",@@ -490,8 +492,6 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {"C:\\Users\\testuser\\.local\\bin","C:\\Users\\testuser\\.bun\\bin","C:\\Users\\testuser\\scoop\\shims",- "C:\\Shell\\Bin",- "C:\\Windows\\System32",].join(";"),});expect(readEnvironment).toHaveBeenCalledTimes(1);@@ -532,6 +532,7 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {PATH: ["C:\\Profile\\Node","C:\\Windows\\System32",+ "C:\\Shell\\Bin","C:\\Users\\testuser\\AppData\\Roaming\\npm","C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs","C:\\Users\\testuser\\AppData\\Local\\Volta\\bin",@@ -539,7 +540,6 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {"C:\\Users\\testuser\\.local\\bin","C:\\Users\\testuser\\.bun\\bin","C:\\Users\\testuser\\scoop\\shims",- "C:\\Shell\\Bin",].join(";"),FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm",FNM_MULTISHELL_PATH: "C:\\Users\\testuser\\AppData\\Local\\fnm_multishells\\123",@@ -576,11 +576,11 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {),).toEqual({PATH: [+ "C:\\Windows\\System32","C:\\Users\\testuser\\AppData\\Roaming\\npm","C:\\Users\\testuser\\.local\\bin","C:\\Users\\testuser\\.bun\\bin","C:\\Users\\testuser\\scoop\\shims",- "C:\\Windows\\System32",].join(";"),FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm",});diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.tsindex 1fdd35cfd0a..4c86c888631 100644--- a/packages/shared/src/shell.ts+++ b/packages/shared/src/shell.ts@@ -728,7 +728,9 @@ export const resolveWindowsEnvironment = Effect.fn("shell.resolveWindowsEnvironm}).PATH;const mergedPath = mergePathValues(shellPath, inheritedPath, "win32");const knownCliPath = resolveKnownWindowsCliDirs(env).join(WINDOWS_PATH_DELIMITER);- const baselinePath = mergePathValues(knownCliPath, mergedPath, "win32");+ // Preserve the order a user's shell uses. These directories fill gaps when+ // desktop apps launch without the full interactive-shell PATH.+ const baselinePath = mergePathValues(mergedPath, knownCliPath, "win32");const baselinePatch: Partial<NodeJS.ProcessEnv> = baselinePath ? { PATH: baselinePath } : {};const baselineEnv = mergeWindowsEnv(env, baselinePatch);