-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add cache for downloaded binary files #1566
Changes from all commits
7d77916
36ac14e
1000858
e244410
1ce1bc1
a07af5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.log | ||
.idea | ||
.DS_Store | ||
.sass-cache | ||
build | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
var fs = require('fs'), | ||
eol = require('os').EOL, | ||
mkdir = require('mkdirp'), | ||
tmpdir = require('os-tmpdir'), | ||
path = require('path'), | ||
sass = require('../lib/extensions'), | ||
request = require('request'), | ||
|
@@ -34,7 +35,7 @@ function download(url, dest, cb) { | |
return response.statusCode >= 200 && response.statusCode < 300; | ||
}; | ||
|
||
var options = { | ||
var options = { | ||
rejectUnauthorized: false, | ||
proxy: getProxy(), | ||
headers: { | ||
|
@@ -109,17 +110,62 @@ function checkAndDownloadBinary() { | |
return; | ||
} | ||
|
||
download(sass.getBinaryUrl(), sass.getBinaryPath(), function(err) { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
var tmpPath = getTempPath(); | ||
if (!(sass.hasBinary(tmpPath))) { // download and install | ||
download(sass.getBinaryUrl(), tmpPath, function(err) { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
console.log('Binary downloaded at', tmpPath); | ||
//copy only, if not already in vendor | ||
if (tmpPath !== sass.getBinaryPath()) { | ||
copyBinary(tmpPath); | ||
} | ||
}); | ||
|
||
console.log('Binary downloaded and installed at', sass.getBinaryPath()); | ||
}); | ||
} else { // install only | ||
copyBinary(tmpPath); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Find a temp folder for file | ||
* | ||
* @returns {string} temp folder including binary file name | ||
* @api private | ||
*/ | ||
|
||
function getTempPath() { | ||
var candidateTmpDir = tmpdir() || process.env.npm_config_tmp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't correct anymore. It's not either or, it's an array of candidates. What you used to have was correct.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please take a look at the whole function. I removed the unnecessary foreach() loop of this list. It's now either Maybe we should (temporary) disable the skip_ci part of this install script to test it on your CI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw the change and IMHO it's incorrect since |
||
var candidatePath = path.join(candidateTmpDir, 'node-sass', 'releases', 'download', 'v' + pkg.version); | ||
|
||
try { | ||
mkdir.sync(candidatePath); | ||
return path.join(candidatePath, sass.getBinaryName()); | ||
} catch (err) { | ||
console.error(candidatePath, 'is not writable:', err.message); | ||
return sass.getBinaryPath(); //fallback to vendor | ||
} | ||
} | ||
|
||
/** | ||
* Copy file | ||
* | ||
* @param from | ||
* @api private | ||
*/ | ||
function copyBinary(from) { | ||
try { | ||
fs.createReadStream(from).pipe(fs.createWriteStream(sass.getBinaryPath())); | ||
|
||
console.log('Binary installed at', sass.getBinaryPath()); | ||
} catch (err) { | ||
console.err('Cannot install binary', err.message); | ||
} | ||
} | ||
|
||
/** | ||
* Skip if CI | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xzyfer this is the part I'm saying will always fall back to the first installed binary file in the temp folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said I've haven't look over the implementation yet. It's entirely likely there are issues that will need to be addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the binary file in the tmp folder based on
sass.getBinaryName()
. E.g.win32-x64-47_binding.node
, not justbinding.node
. If you use another version of node-sass, the name will change too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're both correct. The binaries won't clash on different node/arch/os
combinations. However because we're no longer within node_modules changing
versions of node-sass would be an issue. When changing versions of
node-sass the installer would see a binary for their environment on disk
but it would not the correct binary for their node-sass version.
You'll need to create a folder for the node-sass version for this to work
as intended.