@@ -191,11 +191,7 @@ function writeFakeCrabbox(binDir: string, helpText: string): string {
|
191 | 191 | `require(${JSON.stringify(helperPath)});`, |
192 | 192 | ].join("\n"); |
193 | 193 | writeFileSync(crabboxPath, `${script}\n`, "utf8"); |
194 | | -writeFileSync( |
195 | | -`${crabboxPath}.cmd`, |
196 | | -`@echo off\r\n"${process.execPath}" "%~dp0crabbox" %*\r\n`, |
197 | | -"utf8", |
198 | | -); |
| 194 | +writeFileSync(`${crabboxPath}.cmd`, windowsNodeCmdShim("crabbox"), "utf8"); |
199 | 195 | chmodSync(crabboxPath, 0o755); |
200 | 196 | return crabboxPath; |
201 | 197 | } |
@@ -212,15 +208,34 @@ function makeSlowVersionCrabbox(helpText: string): string {
|
212 | 208 | `else if (args[0] === "run" && args[1] === "--help") { process.stdout.write(${JSON.stringify(helpText)}); }`, |
213 | 209 | ].join("\n"); |
214 | 210 | writeFileSync(crabboxPath, `${script}\n`, "utf8"); |
215 | | -writeFileSync( |
216 | | -`${crabboxPath}.cmd`, |
217 | | -`@echo off\r\n"${process.execPath}" "%~dp0crabbox" %*\r\n`, |
218 | | -"utf8", |
219 | | -); |
| 211 | +writeFileSync(`${crabboxPath}.cmd`, windowsNodeCmdShim("crabbox"), "utf8"); |
220 | 212 | chmodSync(crabboxPath, 0o755); |
221 | 213 | return binDir; |
222 | 214 | } |
223 | 215 | |
| 216 | +function windowsNodeCmdShim(target: string): string { |
| 217 | +return [ |
| 218 | +"@ECHO off", |
| 219 | +"GOTO start", |
| 220 | +":find_dp0", |
| 221 | +"SET dp0=%~dp0", |
| 222 | +"EXIT /b", |
| 223 | +":start", |
| 224 | +"SETLOCAL", |
| 225 | +"CALL :find_dp0", |
| 226 | +'IF EXIST "%dp0%\\node.exe" (', |
| 227 | +' SET "_prog=%dp0%\\node.exe"', |
| 228 | +") ELSE (", |
| 229 | +' SET "_prog=node"', |
| 230 | +")", |
| 231 | +"", |
| 232 | +'endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & set PATHEXT=%PATHEXT:;.JS;=;% & "%_prog%" "%dp0%\\' + |
| 233 | +target + |
| 234 | +'" %*', |
| 235 | +"", |
| 236 | +].join("\r\n"); |
| 237 | +} |
| 238 | + |
224 | 239 | function shellSingleQuote(value: string): string { |
225 | 240 | return `'${value.replaceAll("'", "'\\''")}'`; |
226 | 241 | } |
@@ -282,7 +297,7 @@ function makeFakeGit(
|
282 | 297 | "process.exit(response.status ?? 0);", |
283 | 298 | ].join("\n"); |
284 | 299 | writeFileSync(gitPath, `${script}\n`, "utf8"); |
285 | | -writeFileSync(`${gitPath}.cmd`, `@echo off\r\n"${process.execPath}" "%~dp0git" %*\r\n`, "utf8"); |
| 300 | +writeFileSync(`${gitPath}.cmd`, windowsNodeCmdShim("git"), "utf8"); |
286 | 301 | chmodSync(gitPath, 0o755); |
287 | 302 | return binDir; |
288 | 303 | } |
|