GeezerVison is showing github.com — fix(shared): share the cwd snapshot with PATH searches and launch the… · pingdotgg/t3code@81e9154
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/shell.test.ts +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -894,13 +894,17 @@ console.log(JSON.stringify({ resolved, resolvedGit })); | 894 | 894 | ]; | 895 | 895 | const gitEntries = ["", "."].flatMap((entry) => { | 896 | 896 | const PATH = `${entry}:${listed}`; | | 897 | + // An empty entry launches the local git it found; "." keeps its relative spelling. | | 898 | + const localGit = entry === "" ? path.join(cwd, "git") : "git"; | 897 | 899 | return [ | 898 | 900 | { PATH, cwd: empty, cacheGroup: `xcode-first-${entry}`, expected: xcodeGit }, | 899 | | - { PATH, cwd, cacheGroup: `xcode-first-${entry}`, expected: "git" }, | 900 | | - { PATH, cwd, cacheGroup: `local-first-${entry}`, expected: "git" }, | | 901 | + { PATH, cwd, cacheGroup: `xcode-first-${entry}`, expected: localGit }, | | 902 | + { PATH, cwd, cacheGroup: `local-first-${entry}`, expected: localGit }, | 901 | 903 | { PATH, cwd: empty, cacheGroup: `local-first-${entry}`, expected: xcodeGit }, | 902 | 904 | ]; | 903 | 905 | }); | | 906 | + // A match from an absolute entry stays bare `git`, even when PATH also has a relative entry. | | 907 | + gitEntries.push({ PATH: `.:${cwd}`, cwd: empty, cacheGroup: "absolute", expected: "git" }); | 904 | 908 | const stdout = NodeChildProcess.execFileSync( | 905 | 909 | process.execPath, | 906 | 910 | [ | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/shell.ts +15-6Lines changed: 15 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -801,10 +801,11 @@ const findOnPath = Effect.fnUntraced(function* ( | 801 | 801 | platform: NodeJS.Platform, | 802 | 802 | windowsPathExtensions: ReadonlyArray<string>, | 803 | 803 | isLast: (match: string) => boolean, | | 804 | + // The caller's snapshot, so a cache key and the search it stores agree on the directory. | | 805 | + cwd: string | null | undefined, | 804 | 806 | ): Effect.fn.Return<ReadonlyArray<string>, never, FileSystem.FileSystem | Path.Path> { | 805 | 807 | const path = yield* Path.Path; | 806 | 808 | const pathEntries = pathEntriesForPlatform(pathValue, platform); | 807 | | - const cwd = pathSearchCwd(pathValue, platform); | 808 | 809 |
| 809 | 810 | // A match through an empty component is anchored: callers may launch it from another cwd or | 810 | 811 | // through a wrapper. A literal "." keeps its relative spelling; the first of the two wins, as | @@ -894,6 +895,7 @@ const resolveCommandPathForPlatform = Effect.fn("shell.resolveCommandPathForPlat | 894 | 895 | platform, | 895 | 896 | windowsPathExtensions, | 896 | 897 | () => true, | | 898 | + cwd, | 897 | 899 | ); | 898 | 900 | if (cwd !== null) cacheCommandResolution(cache, cacheKey, resolvedPath, nowNanos); | 899 | 901 | return resolvedPath; | @@ -918,12 +920,14 @@ export const resolveCommandPaths = Effect.fn("shell.resolveCommandPaths")(functi | 918 | 920 | const platform = yield* HostProcess.Platform; | 919 | 921 | const env = options.env ?? (yield* HostProcess.Environment); | 920 | 922 | const windowsPathExtensions = platform === "win32" ? resolveWindowsPathExtensions(env) : []; | | 923 | + const pathValue = resolvePathEnvironmentVariable(env); | 921 | 924 | return yield* findOnPath( | 922 | | - resolvePathEnvironmentVariable(env), | | 925 | + pathValue, | 923 | 926 | resolveCommandCandidates(command, platform, windowsPathExtensions, path.extname), | 924 | 927 | platform, | 925 | 928 | windowsPathExtensions, | 926 | 929 | options.until, | | 930 | + pathSearchCwd(pathValue, platform), | 927 | 931 | ); | 928 | 932 | }); | 929 | 933 |
| @@ -1050,6 +1054,8 @@ const resolveMacosGit = Effect.fnUntraced(function* ( | 1050 | 1054 | const locateXcodeGit = yield* XcodeGitLocation; | 1051 | 1055 | const cache = yield* CommandResolutionCache; | 1052 | 1056 | const pathValue = resolvePathEnvironmentVariable(env); | | 1057 | + const nowNanos = yield* Clock.currentTimeNanos; | | 1058 | + // Read after the clock, so the synchronous lookup below searches the directory the key names. | 1053 | 1059 | const cwd = pathSearchCwd(pathValue, "darwin"); | 1054 | 1060 | const cacheKey = [ | 1055 | 1061 | "xcode-git", | @@ -1059,7 +1065,6 @@ const resolveMacosGit = Effect.fnUntraced(function* ( | 1059 | 1065 | env.DEVELOPER_DIR ?? "", | 1060 | 1066 | ...(cwd === undefined ? [] : [cwd]), | 1061 | 1067 | ].join(COMMAND_RESOLUTION_CACHE_KEY_SEPARATOR); | 1062 | | - const nowNanos = yield* Clock.currentTimeNanos; | 1063 | 1068 | const cached = cwd === null ? undefined : cache.get(cacheKey); | 1064 | 1069 | // An Xcode update or removal deletes the binary; look again instead of failing the spawn. | 1065 | 1070 | if ( | @@ -1070,12 +1075,16 @@ const resolveMacosGit = Effect.fnUntraced(function* ( | 1070 | 1075 | ) { | 1071 | 1076 | return cached.resolvedPath ?? "git"; | 1072 | 1077 | } | 1073 | | - const located = | 1074 | | - resolveExecutable("git", "darwin", env) === MACOS_GIT_SHIM ? locateXcodeGit(env) : undefined; | | 1078 | + const pathGit = resolveExecutable("git", "darwin", env); | | 1079 | + const located = pathGit === MACOS_GIT_SHIM ? locateXcodeGit(env) : undefined; | 1075 | 1080 | const realGit = | 1076 | 1081 | located !== undefined && resolveExecutable(located, "darwin", env) !== undefined | 1077 | 1082 | ? located | 1078 | | - : null; | | 1083 | + : // A match anchored to the cwd came through an empty PATH entry, which a child would search | | 1084 | + // again from its own cwd; launch the file that was checked instead of bare `git`. | | 1085 | + typeof cwd === "string" && pathGit === NodePath.posix.join(cwd, "git") | | 1086 | + ? pathGit | | 1087 | + : null; | 1079 | 1088 | if (cwd !== null) cacheCommandResolution(cache, cacheKey, realGit, nowNanos); | 1080 | 1089 | return realGit ?? "git"; | 1081 | 1090 | }); | |
|