* Promisified wrapper around `child_process.spawn()`. * * In addition to forwarding the `options` to `child_process.spawn()`, it'll also * set the `shell` option to `true`, to ensure that on Windows we can correctly * invoke `.bat` files (necessary for the Python3 wrapper script). * * @param {
(command, args, options = {})
| 48 | * @returns {Promise<{stdout: string, stderr: string}>} |
| 49 | */ |
| 50 | function spawn(command, args, options = {}) { |
| 51 | return new Promise((resolve, reject) => { |
| 52 | let child; |
| 53 | if (os.platform() === 'win32') { |
| 54 | child = childProcess.spawn( |
| 55 | process.env.ComSpec ?? 'cmd.exe', |
| 56 | ['/c', command, ...args], |
| 57 | options, |
| 58 | ); |
| 59 | } else { |
| 60 | child = childProcess.spawn(command, args, options); |
| 61 | } |
| 62 | |
| 63 | let stdout = ''; |
| 64 | let stderr = ''; |
| 65 | |
| 66 | child.stdout.on('data', data => { |
| 67 | stdout += data.toString(); |
| 68 | }); |
| 69 | |
| 70 | child.stderr.on('data', data => { |
| 71 | stderr += data.toString(); |
| 72 | }); |
| 73 | |
| 74 | child.on('exit', (code, signal) => { |
| 75 | if (signal) { |
| 76 | reject( |
| 77 | new SpawnError( |
| 78 | `Process terminated due to signal ${signal}`, |
| 79 | stderr, |
| 80 | stdout, |
| 81 | ), |
| 82 | ); |
| 83 | } else if (code) { |
| 84 | reject( |
| 85 | new SpawnError(`Process exited with code ${code}`, stderr, stdout), |
| 86 | ); |
| 87 | } else { |
| 88 | resolve({ stdout, stderr }); |
| 89 | } |
| 90 | }); |
| 91 | |
| 92 | child.on('error', reject); |
| 93 | }); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Representation of the feature set that is configured for Chrome. This |
no test coverage detected