Created
March 6, 2012 22:33
-
-
Save trentm/1989462 to your computer and use it in GitHub Desktop.
Patch against node v0.6 branch for https://github.com/joyent/node/issues/2697
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tools/installer.js b/tools/installer.js | |
index 487376d..507731b 100644 | |
--- a/tools/installer.js | |
+++ b/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([ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment