Skip to content

Commit 10b31c8

Browse files
committed
test: ensure private npm is always on PATH
1 parent b8b1a88 commit 10b31c8

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

tests/legacy-cli/e2e/utils/process.ts

+15-20
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
3333
let stdout = '';
3434
let stderr = '';
3535
const cwd = options.cwd ?? process.cwd();
36-
const env = options.env;
36+
const env = options.env ?? process.env;
3737
console.log(
3838
`==========================================================================================`,
3939
);
4040

41+
// Ensure the custom npm and yarn global bin is on the PATH
42+
// https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables
43+
const paths = [
44+
join(getGlobalVariable('yarn-global'), 'bin'),
45+
join(getGlobalVariable('npm-global'), process.platform.startsWith('win') ? 'bin' : ''),
46+
env.PATH || process.env['PATH'],
47+
].join(delimiter);
48+
4149
args = args.filter((x) => x !== undefined);
4250
const flags = [
4351
options.silent && 'silent',
@@ -52,7 +60,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
5260

5361
const spawnOptions: SpawnOptions = {
5462
cwd,
55-
...(env ? { env } : {}),
63+
env: { ...env, PATH: paths },
5664
};
5765

5866
if (process.platform.startsWith('win')) {
@@ -147,15 +155,10 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
147155
export function extractNpmEnv() {
148156
return Object.keys(process.env)
149157
.filter((v) => NPM_CONFIG_RE.test(v))
150-
.reduce<NodeJS.ProcessEnv>(
151-
(vars, n) => {
152-
vars[n] = process.env[n];
153-
return vars;
154-
},
155-
{
156-
PATH: process.env.PATH,
157-
},
158-
);
158+
.reduce<NodeJS.ProcessEnv>((vars, n) => {
159+
vars[n] = process.env[n];
160+
return vars;
161+
}, {});
159162
}
160163

161164
export function waitForAnyProcessOutputToMatch(
@@ -355,20 +358,12 @@ export async function launchTestProcess(entry: string, ...args: any[]) {
355358
};
356359

357360
// Modify the PATH environment variable...
358-
let paths = process.env.PATH!.split(delimiter);
361+
let paths = (env.PATH || process.env.PATH)!.split(delimiter);
359362

360363
// Only include paths within the sandboxed test environment or external
361364
// non angular-cli paths such as /usr/bin for generic commands.
362365
paths = paths.filter((p) => p.startsWith(tempRoot) || !p.includes('angular-cli'));
363366

364-
// Ensure the custom npm global bin is on the PATH
365-
// https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables
366-
if (process.platform.startsWith('win')) {
367-
paths.unshift(env.NPM_CONFIG_PREFIX!);
368-
} else {
369-
paths.unshift(join(env.NPM_CONFIG_PREFIX!, 'bin'));
370-
}
371-
372367
env.PATH = paths.join(delimiter);
373368

374369
return _exec({ env }, process.execPath, [resolve(__dirname, 'run_test_process'), entry, ...args]);

0 commit comments

Comments
 (0)