From e9d23cc1ea57c26ef122b393f72adebd9a9f74c6 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 20 Dec 2012 02:29:21 -0500 Subject: [PATCH] Use `child_process.execFile` instead of `child_process.exec` in `post-install.js`. Former-commit-id: 2f6b0827641ceb1c6b418af9de87ef3c70243d5f --- build/post-install.js | 56 +++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/build/post-install.js b/build/post-install.js index 8b59affce..b6c0f61a6 100644 --- a/build/post-install.js +++ b/build/post-install.js @@ -3,7 +3,7 @@ 'use strict'; /** Load Node modules */ - var exec = require('child_process').exec, + var execFile = require('child_process').execFile, fs = require('fs'), https = require('https'), path = require('path'), @@ -20,14 +20,11 @@ var closureId = 'a2787b470c577cee2404d186c562dd9835f779f5'; /** The Git object ID of `uglifyjs.tar.gz` */ - var uglifyId = '7ecae09d413eb48dd5785fe877f24e60ac3bbcef'; + var uglifyId = '505f1be36ef60fd25a992a522f116d5179ab317f'; /** The media type for raw blob data */ var mediaType = 'application/vnd.github.v3.raw'; - /** Reassign `existsSync` for older versions of Node */ - fs.existsSync || (fs.existsSync = path.existsSync); - /** Used to reference parts of the blob href */ var location = (function() { var host = 'api.github.com', @@ -42,6 +39,21 @@ }; }()); + /** The message to display when the install mode is undetectable */ + var oopsMessage = [ + 'Oops! There was a problem detecting the install mode. If you’re installing the', + 'Lo-Dash command-line executable (via `npm install -g lodash`), you’ll need to', + 'manually install UglifyJS and the Closure Compiler by running:', + '', + "curl -H 'Accept: " + mediaType + "' " + location.href + '/' + closureId + " | tar xvz -C '" + vendorPath + "'", + "curl -H 'Accept: " + mediaType + "' " + location.href + '/' + uglifyId + " | tar xvz -C '" + vendorPath + "'", + '', + 'Please submit an issue on the GitHub issue tracker: ' + process.env.npm_package_bugs_url + ].join('\n'); + + /** Reassign `existsSync` for older versions of Node */ + fs.existsSync || (fs.existsSync = path.existsSync); + /*--------------------------------------------------------------------------*/ /** @@ -99,9 +111,14 @@ .on('error', callback); } - /*--------------------------------------------------------------------------*/ - - exec('npm -g root', function(exception, stdout) { + /** + * The `child_process.execFile` callback. + * + * @private + * @param {Object|Undefined} exception The error object. + * @param {String} stdout The stdout buffer. + */ + function onExecFile(exception, stdout) { if (!exception) { try { var root = stdout.trim(), @@ -111,17 +128,7 @@ } } if (exception) { - console.error([ - 'Oops! There was a problem detecting the install mode. If you’re installing the', - 'Lo-Dash command-line executable (via `npm install -g lodash`), you’ll need to', - 'manually install UglifyJS and the Closure Compiler by running:', - '', - "curl -H 'Accept: " + mediaType + "' " + location.href + '/' + closureId + " | tar xvz -C '" + vendorPath + "'", - "curl -H 'Accept: " + mediaType + "' " + location.href + '/' + uglifyId + " | tar xvz -C '" + vendorPath + "'", - '', - 'Please submit an issue on the GitHub issue tracker: ' + process.env.npm_package_bugs_url - ].join('\n')); - + console.error(oopsMessage); console.error(exception); } if (!isGlobal) { @@ -144,5 +151,14 @@ }); } }); - }); + } + + /*--------------------------------------------------------------------------*/ + + try { + execFile('npm', [ '-g', 'root' ], onExecFile); + } catch(e) { + console.error(oopsMessage); + console.error(e); + } }());