chore: fix incorrect execution of node binaries (#9962)

* chore: fix incorrect execution of node binaries

* Currently gulp runs the `ngc` by manually calling the `./node_modules/.bin/ngc` file (by assuming it's a node script)
  This is not always correct, because often package managers like (npm or yarn) create bash files for the package binaries.

* Using `resolve-bin` to properly determine the path to the *real* node script and then we can assume it's a node file.

Fixes #8341

* Remove extra newline
This commit is contained in:
Paul Gschwendtner
2017-01-12 19:28:41 +01:00
committed by Brandy Carney
parent 2d26edb679
commit e35a3b1ab7
2 changed files with 16 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*~
*.sw[mnpcod]
*.log
*.lock
*.tmp
*.tmp.*
log.txt

View File

@ -11,6 +11,9 @@ import * as through from 'through2';
import * as uglifyPlugin from 'rollup-plugin-uglify';
import { argv } from 'yargs';
// These packages lack of types.
const resolveBin = require('resolve-bin');
export function mergeObjects(obj1: any, obj2: any ) {
if (! obj1) {
obj1 = {};
@ -140,7 +143,8 @@ export function copyFile(srcPath: string, destPath: string) {
export function runNgc(pathToConfigFile: string, done: Function) {
let exec = require('child_process').exec;
var shellCommand = `node --max_old_space_size=8096 ${PROJECT_ROOT}/node_modules/.bin/ngc -p ${pathToConfigFile}`;
let ngcPath = getBinaryPath('@angular/compiler-cli', 'ngc');
let shellCommand = `node --max_old_space_size=8096 ${ngcPath} -p ${pathToConfigFile}`;
exec(shellCommand, function(err, stdout, stderr) {
console.log(stdout);
@ -151,7 +155,8 @@ export function runNgc(pathToConfigFile: string, done: Function) {
export function runTsc(pathToConfigFile: string, done: Function) {
let exec = require('child_process').exec;
var shellCommand = `node --max_old_space_size=8096 ${PROJECT_ROOT}/node_modules/.bin/tsc -p ${pathToConfigFile}`;
let tscPath = getBinaryPath('typescript', 'tsc');
let shellCommand = `node --max_old_space_size=8096 ${tscPath} -p ${pathToConfigFile}`;
exec(shellCommand, function(err, stdout, stderr) {
console.log(stdout);
@ -162,7 +167,8 @@ export function runTsc(pathToConfigFile: string, done: Function) {
export function runWebpack(pathToWebpackConfig: string, done: Function) {
let exec = require('child_process').exec;
let shellCommand = `node --max_old_space_size=8096 ./node_modules/.bin/webpack --config ${pathToWebpackConfig} --display-error-details`;
let webpackPath = getBinaryPath('webpack');
let shellCommand = `node --max_old_space_size=8096 ${webpackPath} --config ${pathToWebpackConfig} --display-error-details`;
exec(shellCommand, function(err, stdout, stderr) {
console.log(stdout);
@ -171,6 +177,11 @@ export function runWebpack(pathToWebpackConfig: string, done: Function) {
});
}
/** Resolves the path for a node package executable. */
export function getBinaryPath(packageName: string, executable = packageName): string {
return resolveBin.sync(packageName, {executable});
}
export function deleteFiles(glob: string[], done: Function) {
let del = require('del');
del.sync(glob);
@ -276,4 +287,4 @@ export function getFolderInfo() {
componentName: componentName,
componentTest: componentTest
};
}
}