Use child_process.execFile instead of child_process.exec in post-install.js.

Former-commit-id: 2f6b0827641ceb1c6b418af9de87ef3c70243d5f
This commit is contained in:
John-David Dalton
2012-12-20 02:29:21 -05:00
parent 34173fd60f
commit e9d23cc1ea

View File

@@ -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 youre installing the',
'Lo-Dash command-line executable (via `npm install -g lodash`), youll 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 youre installing the',
'Lo-Dash command-line executable (via `npm install -g lodash`), youll 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);
}
}());