( command: string, platform: NodeJS.Platform, env: NodeJS.ProcessEnv, )
| 94 | ) => string | undefined; |
| 95 | |
| 96 | function resolveSpawnExecutableWithNode( |
| 97 | command: string, |
| 98 | platform: NodeJS.Platform, |
| 99 | env: NodeJS.ProcessEnv, |
| 100 | ): string | undefined { |
| 101 | const path = platform === "win32" ? NodePath.win32 : NodePath.posix; |
| 102 | const windowsPathExtensions = platform === "win32" ? resolveWindowsPathExtensions(env) : []; |
| 103 | const candidates = resolveCommandCandidates( |
| 104 | command, |
| 105 | platform, |
| 106 | windowsPathExtensions, |
| 107 | path.extname, |
| 108 | ); |
| 109 | const isExecutable = (candidate: string) => { |
| 110 | try { |
| 111 | if (!NodeFS.statSync(candidate).isFile()) return false; |
| 112 | if (platform === "win32") { |
| 113 | return windowsPathExtensions.includes(path.extname(candidate).toUpperCase()); |
| 114 | } |
| 115 | return canExecuteFile(candidate); |
| 116 | } catch { |
| 117 | return false; |
| 118 | } |
| 119 | }; |
| 120 | |
| 121 | if (command.includes("/") || command.includes("\\")) { |
| 122 | return candidates.find(isExecutable); |
| 123 | } |
| 124 | |
| 125 | for (const pathEntry of (readEnvPath(env) ?? "").split(pathDelimiterForPlatform(platform))) { |
| 126 | const normalizedPathEntry = stripWrappingQuotes(pathEntry.trim()); |
| 127 | if (normalizedPathEntry.length === 0) continue; |
| 128 | for (const candidate of candidates) { |
| 129 | const candidatePath = path.join(normalizedPathEntry, candidate); |
| 130 | if (isExecutable(candidatePath)) return candidatePath; |
| 131 | } |
| 132 | } |
| 133 | return undefined; |
| 134 | } |
| 135 | |
| 136 | export const SpawnExecutableResolution = Context.Reference<SpawnExecutableResolver>( |
| 137 | "@t3tools/shared/shell/SpawnExecutableResolution", |
nothing calls this directly
no test coverage detected