From e35a3b1ab7cc0c5951a6babcb9473d739f5357e2 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 12 Jan 2017 19:28:41 +0100 Subject: [PATCH] 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 --- .gitignore | 1 + scripts/gulp/util.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index dbb9a2e2ad..f1d5c446ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *~ *.sw[mnpcod] *.log +*.lock *.tmp *.tmp.* log.txt diff --git a/scripts/gulp/util.ts b/scripts/gulp/util.ts index 118334ccd2..0e18b2a5bf 100644 --- a/scripts/gulp/util.ts +++ b/scripts/gulp/util.ts @@ -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 }; -} \ No newline at end of file +}