MCPcopy Create free account
hub / github.com/pingdotgg/t3code / resolveSpawnExecutableWithNode

Function resolveSpawnExecutableWithNode

packages/shared/src/shell.ts:96–134  ·  view source on GitHub ↗
(
  command: string,
  platform: NodeJS.Platform,
  env: NodeJS.ProcessEnv,
)

Source from the content-addressed store, hash-verified

94) => string | undefined;
95
96function 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
136export const SpawnExecutableResolution = Context.Reference<SpawnExecutableResolver>(
137 "@t3tools/shared/shell/SpawnExecutableResolution",

Callers

nothing calls this directly

Calls 6

resolveCommandCandidatesFunction · 0.85
pathDelimiterForPlatformFunction · 0.85
stripWrappingQuotesFunction · 0.85
isExecutableFunction · 0.85
readEnvPathFunction · 0.70

Tested by

no test coverage detected