Skip to content

Commit b9ea729

Browse files
committed
fix: exclude local node_modules from PATH when launch 'npm install'
1 parent 93da512 commit b9ea729

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/angular-cli/tasks/npm-install.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,33 @@ const Task = require('ember-cli/lib/models/task');
22
import * as chalk from 'chalk';
33
import {exec} from 'child_process';
44

5+
const RElocalNodeModulesFolder = /node_modules\/\.bin/;
6+
function isLocalNodeModulesFolder(name: string) {
7+
return RElocalNodeModulesFolder.test(name);
8+
}
9+
10+
function getPath() {
11+
const pathArr = process.env.PATH.split(':');
12+
const newPathArr = [];
13+
for (let pathItem of pathArr) {
14+
if (!isLocalNodeModulesFolder(pathItem)) {
15+
newPathArr.push(pathItem);
16+
}
17+
}
18+
return newPathArr.join(':');
19+
}
520

621
export default Task.extend({
722
run: function() {
823
const ui = this.ui;
924

1025
return new Promise(function(resolve, reject) {
1126
ui.writeLine(chalk.green('Installing packages for tooling via npm.'));
27+
const options = {
28+
env: {
29+
PATH: getPath()
30+
}
31+
}
1232
exec('npm install',
1333
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
1434
if (err) {

0 commit comments

Comments
 (0)