MCPcopy Index your code
hub / github.com/angular/angular-cli / _exec

Function _exec

tests/e2e/utils/process.ts:30–178  ·  view source on GitHub ↗
(options: ExecOptions, cmd: string, args: string[])

Source from the content-addressed store, hash-verified

28};
29
30function _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

Callers 15

execFunction · 0.85
silentExecFunction · 0.85
execWithEnvFunction · 0.85
execAndCaptureErrorFunction · 0.85
noSilentNgFunction · 0.85
silentNgFunction · 0.85
silentNpmFunction · 0.85
silentYarnFunction · 0.85
silentPnpmFunction · 0.85
silentBunFunction · 0.85
globalNpmFunction · 0.85

Calls 12

getGlobalVariableFunction · 0.90
joinFunction · 0.85
envDumpFunction · 0.85
onMethod · 0.80
toStringMethod · 0.80
logMethod · 0.65
errorMethod · 0.65
writeMethod · 0.65
resolveFunction · 0.50
pushMethod · 0.45
matchMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected