Skip to content

fix: using local npm 2 from ember-cli dependency while ng init #2301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions packages/angular-cli/tasks/npm-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,59 @@ const Task = require('ember-cli/lib/models/task');
import * as chalk from 'chalk';
import {exec} from 'child_process';

function removeFromArray(array: any[], item: any) {
const itemIndex = array.indexOf(item);
if (itemIndex !== -1) {
array.splice(itemIndex, 1);
}
}

export default Task.extend({
run: function() {
const ui = this.ui;
let PATH: string;

return new Promise(function(resolve, reject) {
ui.writeLine(chalk.green('Installing packages for tooling via npm.'));
exec('npm install',
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
if (err) {
ui.writeLine(stderr);
ui.writeLine(chalk.red('Package install failed, see above.'));
reject();
} else {
ui.writeLine(chalk.green('Installed packages for tooling via npm.'));
resolve();
}
// remove from PATH:
// - absolute path to projet's node_modules
// - relative path to projet's node_modules (linux and windows)
exec('npm bin', (err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
if (err) {
ui.writeLine(stderr);
ui.writeLine(chalk.red('Package install failed, see above.'));
reject();
} else {
const absoluteProjectNodeModulesPath = stdout.replace(/(\r|\n)/, '');
const pathArr = process.env.PATH.split(':');
removeFromArray(pathArr, absoluteProjectNodeModulesPath);
removeFromArray(pathArr, 'node_modules/.bin');
removeFromArray(pathArr, 'node_modules\.bin');
PATH = pathArr.join(':');
resolve();
}
});
})
.then(() => {
return new Promise(function(resolve, reject) {
const options = {
env: {
PATH: PATH
}
};
exec(
'npm install',
options,
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
if (err) {
ui.writeLine(stderr);
ui.writeLine(chalk.red('Package install failed, see above.'));
reject();
} else {
ui.writeLine(chalk.green('Installed packages for tooling via npm.'));
resolve();
}
});
});
});
}
Expand Down