(options: ExecOptions, cmd: string, args: string[])
| 28 | }; |
| 29 | |
| 30 | function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<ProcessOutput> { |
| 31 | const cwd = options.cwd ?? process.cwd(); |
| 32 | const env = options.env ?? process.env; |
| 33 | |
| 34 | console.log( |
| 35 | `==========================================================================================`, |
| 36 | ); |
| 37 | |
| 38 | // Ensure the custom npm and yarn global bin is on the PATH |
| 39 | // https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables |
| 40 | const paths = [ |
| 41 | join(getGlobalVariable('yarn-global'), 'bin'), |
| 42 | join(getGlobalVariable('npm-global'), process.platform.startsWith('win') ? '' : 'bin'), |
| 43 | env.PATH || process.env['PATH'], |
| 44 | ].join(delimiter); |
| 45 | |
| 46 | args = args.filter((x) => x !== undefined); |
| 47 | const flags = [ |
| 48 | options.silent && 'silent', |
| 49 | options.waitForMatch && `matching(${options.waitForMatch})`, |
| 50 | ] |
| 51 | .filter((x) => !!x) // Remove false and undefined. |
| 52 | .join(', ') |
| 53 | .replace(/^(.+)$/, ' [$1]'); // Proper formatting. |
| 54 | |
| 55 | console.log( |
| 56 | styleText(['blue'], `Running \`${cmd} ${args.map((x) => `"${x}"`).join(' ')}\`${flags}...`), |
| 57 | ); |
| 58 | console.log(styleText(['blue'], `CWD: ${cwd}`)); |
| 59 | |
| 60 | const spawnOptions: SpawnOptions = { |
| 61 | cwd, |
| 62 | env: { ...env, PATH: paths }, |
| 63 | }; |
| 64 | |
| 65 | if (process.platform.startsWith('win')) { |
| 66 | args.unshift('/c', cmd); |
| 67 | cmd = 'cmd.exe'; |
| 68 | spawnOptions['stdio'] = 'pipe'; |
| 69 | } |
| 70 | |
| 71 | const childProcess = child_process.spawn(cmd, args, spawnOptions); |
| 72 | |
| 73 | _processes.push(childProcess); |
| 74 | |
| 75 | // Create the error here so the stack shows who called this function. |
| 76 | const error = new Error(); |
| 77 | |
| 78 | const processPromise = new Promise<ProcessOutput>((resolve, reject) => { |
| 79 | let stdout = ''; |
| 80 | let stderr = ''; |
| 81 | let matched = false; |
| 82 | |
| 83 | // Return log info about the current process status |
| 84 | function envDump() { |
| 85 | return `STDOUT:\n${stdout}\n\nSTDERR:\n${stderr}`; |
| 86 | } |
| 87 |
no test coverage detected