()
| 56 | } |
| 57 | |
| 58 | function spawnScript() { |
| 59 | // get all the arguments of the script and find the position of our script commands |
| 60 | const args = process.argv.slice(2) |
| 61 | const scriptIndex = args.findIndex(x => |
| 62 | [ |
| 63 | 'build', |
| 64 | 'format', |
| 65 | 'lint', |
| 66 | 'pre-commit', |
| 67 | 'test', |
| 68 | 'validate', |
| 69 | 'typecheck', |
| 70 | ].includes(x), |
| 71 | ) |
| 72 | |
| 73 | // Extract the node arguments so we can pass them to node later on |
| 74 | const buildCommand = scriptIndex === -1 ? args[0] : args[scriptIndex] |
| 75 | const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [] |
| 76 | |
| 77 | if (!buildCommand) { |
| 78 | throw new Error(`Unknown script "${script}".`) |
| 79 | } |
| 80 | |
| 81 | const relativeScriptPath = path.join(__dirname, './scripts', buildCommand) |
| 82 | const scriptPath = attemptResolve(relativeScriptPath) |
| 83 | if (!scriptPath) { |
| 84 | throw new Error(`Unknown script "${script}".`) |
| 85 | } |
| 86 | |
| 87 | // Attempt to strt the script with the passed node arguments |
| 88 | const result = spawn.sync( |
| 89 | executor, |
| 90 | nodeArgs.concat(scriptPath).concat(args.slice(scriptIndex + 1)), |
| 91 | { |
| 92 | stdio: 'inherit', |
| 93 | env: getEnv(), |
| 94 | }, |
| 95 | ) |
| 96 | |
| 97 | if (result.signal) { |
| 98 | handleSignal(result) |
| 99 | } else { |
| 100 | process.exit(result.status) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | function handleSignal(result) { |
| 105 | if (result.signal === 'SIGKILL') { |
no test coverage detected
searching dependent graphs…