(
tempDir: string,
name: string,
options: { exitCode?: number } = {}
)
| 17 | } |
| 18 | |
| 19 | export function createFakeTool( |
| 20 | tempDir: string, |
| 21 | name: string, |
| 22 | options: { exitCode?: number } = {} |
| 23 | ): FakeTool { |
| 24 | const binDir = path.join(tempDir, `fake-${name}-bin`); |
| 25 | const logPath = path.join(tempDir, `${name}-launch.json`); |
| 26 | const recorderPath = path.join(binDir, 'record-launch.cjs'); |
| 27 | const exitCode = options.exitCode ?? 0; |
| 28 | fs.mkdirSync(binDir, { recursive: true }); |
| 29 | fs.writeFileSync( |
| 30 | recorderPath, |
| 31 | "const fs = require('node:fs');\n" + |
| 32 | `fs.writeFileSync(${JSON.stringify(logPath)}, JSON.stringify({ cwd: process.cwd(), args: process.argv.slice(2) }));\n` + |
| 33 | `process.exit(${exitCode});\n` |
| 34 | ); |
| 35 | |
| 36 | const posixExecutable = path.join(binDir, name); |
| 37 | fs.writeFileSync( |
| 38 | posixExecutable, |
| 39 | `#!/bin/sh\nexec node ${JSON.stringify(recorderPath)} "$@"\n` |
| 40 | ); |
| 41 | fs.chmodSync(posixExecutable, 0o755); |
| 42 | fs.writeFileSync( |
| 43 | path.join(binDir, `${name}.cmd`), |
| 44 | `@echo off\r\nnode "${recorderPath}" %*\r\n` |
| 45 | ); |
| 46 | |
| 47 | return { binDir, logPath }; |
| 48 | } |
| 49 | |
| 50 | export function envWithFakeTools( |
| 51 | baseEnv: NodeJS.ProcessEnv, |
no outgoing calls
no test coverage detected