on master help sign in
add check if desired file already exists, skip download if so

@rtfeldman prefers a path that avoids the intermediate invocation of node altogether. I do as well, but I don't know how to do it. So this change restores it to the behavior from before the no-deps tag at least. (I personally think folks should host binaries on their build separate from node to avoid needing npm at all for it, but I am told that people prefer the extra download time and flakiness risk for various reasons.)

commit33e43e87430b6c4abe6ef535bf294cf7d8492c72 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 2 Jul 2019, 17:29 (7 years ago) parent90bf99c
2 files changed+8−6
installers/npm/bin/elm+2−1 installers/npm/download.js+6−5
installers/npm/bin/elm+2−1
@@ -11,7 +11,8 @@ var fs = require('fs');
1111//
1212// This file pretends to be the downloaded binary. It then downloads
1313// the real binary over itself. So in that case, the first run would
14−// also make an HTTPS request to fetch the real binary.
14+// also make an HTTPS request to fetch the real binary. From there,
15+// it calls the binary it downloaded on each run.
1516
1617
1718
installers/npm/download.js+6−5
@@ -17,12 +17,13 @@ module.exports = function(destinationPath, callback)
1717 var version = package.version.replace(/^(\d+\.\d+\.\d+).*$/, '$1'); // turn '1.2.3-alpha' into '1.2.3'
1818 var os = { 'darwin': 'mac', 'win32': 'windows', 'linux': 'linux' }[process.platform];
1919 var arch = { 'x64': '64-bit', 'ia32': '32-bit' }[process.arch];
20+ var path = process.platform === 'win32' ? destinationPath + '.exe' : destinationPath;
21+ var url = 'https://github.com/elm/compiler/releases/download/' + version + '/binary-for-' + os + '-' + arch + '.gz';
2022
21− download(
22− process.platform === 'win32' ? destinationPath + '.exe' : destinationPath,
23− 'https://github.com/elm/compiler/releases/download/' + version + '/binary-for-' + os + '-' + arch + '.gz',
24− callback
25− );
23+ // check if exists for bin/elm running for the Nth time on Windows
24+ fs.existsSync(path)
25+ ? callback()
26+ : download(path, url, callback);
2627};
2728
2829