(cwd: PortablePath, argv: Array<string>, withCustomRegistry?: boolean)
| 4 | import {pathToFileURL} from 'url'; |
| 5 | |
| 6 | export async function runCli(cwd: PortablePath, argv: Array<string>, withCustomRegistry?: boolean): Promise<{exitCode: number | null, stdout: string, stderr: string}> { |
| 7 | const out: Array<Buffer> = []; |
| 8 | const err: Array<Buffer> = []; |
| 9 | |
| 10 | return new Promise((resolve, reject) => { |
| 11 | const child = spawn(process.execPath, [`--no-warnings`, ...(withCustomRegistry ? [`--import`, pathToFileURL(path.join(__dirname, `_registryServer.mjs`)) as any as string] : [`-r`, require.resolve(`./recordRequests.js`)]), require.resolve(`../dist/corepack.js`), ...argv], { |
| 12 | cwd: npath.fromPortablePath(cwd), |
| 13 | env: process.env, |
| 14 | stdio: `pipe`, |
| 15 | }); |
| 16 | |
| 17 | child.stdout.on(`data`, chunk => { |
| 18 | out.push(chunk); |
| 19 | }); |
| 20 | |
| 21 | child.stderr.on(`data`, chunk => { |
| 22 | err.push(chunk); |
| 23 | }); |
| 24 | |
| 25 | child.on(`error`, error => { |
| 26 | reject(error); |
| 27 | }); |
| 28 | |
| 29 | child.on(`close`, exitCode => { |
| 30 | resolve({ |
| 31 | exitCode, |
| 32 | stdout: Buffer.concat(out).toString(), |
| 33 | stderr: Buffer.concat(err).toString(), |
| 34 | }); |
| 35 | }); |
| 36 | }); |
| 37 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…