@@ -1,48 +1,26 @@
11#!/usr/bin/env node
22
3−// This file exists for the benefit of npm users who have --ignore-scripts
4−// enabled. (Enabling this flag globally is a good security measure.)
5−// Since they won't run the post-install hook, the binaries won't be downloaded
6−// and installed.
3+var child_process = require('child_process');
4+var download = require('../download.js');
5+var fs = require('fs');
6+
7+
8+// Some npm users enable --ignore-scripts (a good security measure)
79//
8−// Since this file is included in "bin" in package.json, npm will install
9−// it automatically in a place that should be on the PATH. All the file does
10−// is to download the appropriate binary (just like the post-install hook would
11−// have), replace this file with that binary, and run the binary.
10+// They do not run the post-install hook, so install.js does not run.
1211//
13−// In this way, the first time a user with --ignore-scripts enabled runs this
14−// binary, it will download and install itself, and then run as normal. From
15−// then on, it will run as normal without re-downloading.
12+// This file pretends to be the downloaded binary. It then downloads
13+// the real binary over itself. So in that case, the first run would
14+// also make an HTTPS request to fetch the real binary.
15+
1616
17−var install = require("..").install;
18−var child_process = require("child_process");
19−var path = require("path");
20−var fs = require("fs");
2117
2218// Make sure we get the right path even if we're executing from the symlinked
2319// node_modules/.bin/ executable
24−var interpreter = fs.realpathSync(process.argv[0]);
25−var targetPath = fs.realpathSync(process.argv[1]);
26−
27−// Figure out the binary name as we'll eventually want to execute
28−// this. Re-executing this script doesn't always work because of varying
29−// permissions and modes of operation across platforms (for example, Windows has
30−// some interesting edge cases here.)
31−var binaryName = path.join(
32− __dirname,
33− "..",
34− "unpacked_bin",
35− path.basename(targetPath)
36−);
37−if (process.platform === "win") {
38− binaryName += ".exe";
39−}
40−
41−// cd into the directory above bin/ so install() puts bin/ in the right place.
42−process.chdir(path.join(path.dirname(targetPath), ".."));
20+var pathToThisFile = fs.realpathSync(process.argv[1]);
4321
44−install(process.platform, process.arch).then(function() {
22+download(pathToThisFile, function() {
4523 child_process
46− .spawn(binaryName, process.argv.slice(2), { stdio: "inherit" })
47− .on("exit", process.exit);
24+ .spawn(pathToThisFile, process.argv.slice(2), { stdio: 'inherit' })
25+ .on('exit', process.exit);
4826});