Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

issue #2697: have 'make install' set npm shebang to use its node

  • Loading branch information...
commit 1cdadb1e3b6108bb636213debacf2f93166fbf83 1 parent 1cecfee
@trentm trentm authored isaacs committed
Showing with 31 additions and 6 deletions.
  1. +31 −6 tools/installer.js
View
37 tools/installer.js
@@ -53,18 +53,41 @@ function remove(files) {
});
}
+// Add/update shebang (#!) line
+function shebang(line, file) {
+ var content = fs.readFileSync(file, 'utf8');
+ var firstLine = content.split(/\n/, 1)[0];
+ var newContent;
+ if (firstLine.slice(0, 2) === '#!') {
+ newContent = line + content.slice(firstLine.length);
+ } else {
+ newContent = line + '\n' + content;
+ }
+ if (content !== newContent) {
+ fs.writeFileSync(file, newContent, 'utf8');
+ }
+}
+
// Run every command in queue, one-by-one
function run() {
var cmd = queue.shift();
if (!cmd) return;
- console.log(cmd);
- exec(cmd, function(err, stdout, stderr) {
- if (stderr) console.error(stderr);
- if (err) process.exit(1);
-
+ if (Array.isArray(cmd) && cmd[0] instanceof Function) {
+ var func = cmd[0];
+ var args = cmd.slice(1);
+ console.log.apply(null, [func.name].concat(args));
+ func.apply(null, args);
run();
- });
+ } else {
+ console.log(cmd);
+ exec(cmd, function(err, stdout, stderr) {
+ if (stderr) console.error(stderr);
+ if (err) process.exit(1);
+
+ run();
+ });
+ }
}
if (cmd === 'install') {
@@ -109,6 +132,8 @@ if (cmd === 'install') {
copy('deps/npm', 'lib/node_modules/npm');
queue.push('ln -sf ../lib/node_modules/npm/bin/npm-cli.js ' +
path.join(node_prefix, 'bin/npm'));
+ queue.push([shebang, '#!' + path.join(node_prefix, 'bin/node'),
+ path.join(node_prefix, 'lib/node_modules/npm/bin/npm-cli.js')]);
}
} else {
remove([
Please sign in to comment.
Something went wrong with that request. Please try again.