|
15 | 15 | // then on, it will run as normal without re-downloading. |
16 | 16 |
|
17 | 17 | var install = require("..").install; |
18 | | -var spawn = require("child_process").spawn; |
| 18 | +var child_process = require("child_process"); |
19 | 19 | var path = require("path"); |
20 | 20 | var fs = require("fs"); |
21 | 21 |
|
22 | 22 | // Make sure we get the right path even if we're executing from the symlinked |
23 | 23 | // node_modules/.bin/ executable |
| 24 | +var interpreter = fs.realpathSync(process.argv[0]); |
24 | 25 | var targetPath = fs.realpathSync(process.argv[1]); |
25 | 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 | + |
26 | 41 | // cd into the directory above bin/ so install() puts bin/ in the right place. |
27 | 42 | process.chdir(path.join(path.dirname(targetPath), "..")); |
28 | 43 |
|
29 | 44 | install(process.platform, process.arch).then(function() { |
30 | | - // we have to do this because the Elm binaries end in `.exe` on |
31 | | - // Windows. Really, we should fix this upstream (in binwrap), but in the |
32 | | - // interests of getting the installers out we're going to do this temporarily |
33 | | - // and ship a fix upstream later. |
34 | | - var replacement = process.argv.slice(2); |
35 | | - if (process.platform === "win32") { |
36 | | - replacement += ".exe"; |
37 | | - |
38 | | - if (fs.existsSync(replacement)) { |
39 | | - // if we replaced the bootstrap script, we should remove it. Otherwise we'd |
40 | | - // have two of them laying around on Windows (elm and elm.exe) |
41 | | - fs.unlinkSync(process.argv.slice(2)); |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - spawn(targetPath, replacement, { |
46 | | - stdio: "inherit" |
47 | | - }).on("exit", process.exit); |
| 45 | + child_process |
| 46 | + .spawn(binaryName, process.argv.slice(2), { stdio: "inherit" }) |
| 47 | + .on("exit", process.exit); |
48 | 48 | }); |
0 commit comments