Skip to content

Commit

Permalink
feat: support binary mirror replaceHostFiles config (#285)
Browse files Browse the repository at this point in the history
like sharp package

detail see cnpm/binary-mirror-config#10
  • Loading branch information
fengmk2 authored Dec 13, 2018
1 parent 0c233cf commit 45bdbc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/download/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function* download(pkg, options) {
const binaryMirror = options.binaryMirrors[pkg.name];
if (binaryMirror) {
// node-pre-gyp
if (pkg.scripts && pkg.scripts.install) {
if (pkg.scripts && pkg.scripts.install && !binaryMirror.replaceHostFiles) {
// leveldown and sqlite3
// nodegit
if (/prebuild --install/.test(pkg.scripts.install) ||
Expand Down Expand Up @@ -244,10 +244,15 @@ function* download(pkg, options) {
} else if ((binaryMirror.replaceHost && binaryMirror.host) || binaryMirror.replaceHostMap) {
// use mirror url instead
// e.g.: pngquant-bin
const indexFilepath = path.join(ungzipDir, 'lib/index.js');
yield replaceHostInFile(pkg, indexFilepath, binaryMirror, options);
const installFilepath = path.join(ungzipDir, 'lib/install.js');
yield replaceHostInFile(pkg, installFilepath, binaryMirror, options);
// https://github.com/lovell/sharp/blob/master/install/libvips.js#L19
const replaceHostFiles = binaryMirror.replaceHostFiles || [
'lib/index.js',
'lib/install.js',
];
for (const replaceHostFile of replaceHostFiles) {
const replaceHostFilePath = path.join(ungzipDir, replaceHostFile);
yield replaceHostInFile(pkg, replaceHostFilePath, binaryMirror, options);
}
}

// replace cypress download url
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"agentkeepalive": "^3.1.0",
"await-event": "^2.1.0",
"binary-mirror-config": "^1.6.0",
"binary-mirror-config": "^1.19.0",
"bytes": "^2.5.0",
"chalk": "^1.1.3",
"cmd-shim": "^2.0.2",
Expand Down

0 comments on commit 45bdbc0

Please sign in to comment.