(cmd, args, options = {})
| 1 | const { spawnSync } = require("child_process"); |
| 2 | |
| 3 | const runSync = (cmd, args, options = {}) => { |
| 4 | const result = spawnSync(cmd, args, { |
| 5 | stdio: ["inherit", "inherit", "inherit"], |
| 6 | windowsHide: true, |
| 7 | ...options, |
| 8 | env: { |
| 9 | ...process.env, |
| 10 | YARN_SILENT: "1", |
| 11 | npm_config_loglevel: "silent", |
| 12 | ...options.env, |
| 13 | }, |
| 14 | }); |
| 15 | |
| 16 | const { error, status, signal, stderr, stdout } = result; |
| 17 | |
| 18 | if (error) { |
| 19 | throw error; |
| 20 | } |
| 21 | |
| 22 | if (status || signal) { |
| 23 | if (stdout) { |
| 24 | console.log(stdout.toString("utf8")); |
| 25 | } |
| 26 | if (stderr) { |
| 27 | console.error(stderr.toString("utf8")); |
| 28 | } |
| 29 | if (status) { |
| 30 | process.exitCode = status; |
| 31 | throw new Error( |
| 32 | `Process exited with status '${status}' (running '${cmd} ${ |
| 33 | args ? args.join(" ") : "" |
| 34 | }')` |
| 35 | ); |
| 36 | } else { |
| 37 | throw new Error( |
| 38 | `Process exited due to signal '${signal}' (running '${cmd} ${ |
| 39 | args ? args.join(" ") : null |
| 40 | }')` |
| 41 | ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return result; |
| 46 | }; |
| 47 | |
| 48 | exports.runSync = runSync; |
no test coverage detected