Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
issue #2697: have 'make install' set npm shebang to use its node
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm authored and isaacs committed Mar 13, 2012
1 parent 1cecfee commit 1cdadb1
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions tools/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 1cdadb1

Please sign in to comment.