Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
abce8c1a
Commit
abce8c1a
authored
Oct 03, 2016
by
Michael Mifsud
Committed by
GitHub
Oct 03, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1714 from nschonni/npm-download-cache
User configurable cache folder for binary download
parents
63d103fa
b6558523
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
13 deletions
+61
-13
extensions.js
lib/extensions.js
+12
-0
install.js
scripts/install.js
+26
-13
runtime.js
test/runtime.js
+23
-0
No files found.
lib/extensions.js
View file @
abce8c1a
...
...
@@ -259,6 +259,17 @@ function getBinaryPath() {
}
/**
* Looks for the configured cache path. If none is found, fall back to the NPM
* cache folder
*
* @api public
*/
function
getCachePath
()
{
return
process
.
env
.
npm_config_sass_binary_cache
||
process
.
env
.
npm_config_cache
;
}
/**
* Does the supplied binary path exist
*
* @param {String} binaryPath
...
...
@@ -286,6 +297,7 @@ module.exports.hasBinary = hasBinary;
module
.
exports
.
getBinaryUrl
=
getBinaryUrl
;
module
.
exports
.
getBinaryName
=
getBinaryName
;
module
.
exports
.
getBinaryPath
=
getBinaryPath
;
module
.
exports
.
getCachePath
=
getCachePath
;
module
.
exports
.
getVersionInfo
=
getVersionInfo
;
module
.
exports
.
getHumanEnvironment
=
getHumanEnvironment
;
module
.
exports
.
getInstalledBinaries
=
getInstalledBinaries
;
...
...
scripts/install.js
View file @
abce8c1a
...
...
@@ -119,34 +119,47 @@ function getProxy() {
*/
function
checkAndDownloadBinary
()
{
if
(
sass
.
hasBinary
(
sass
.
getBinaryPath
()))
{
if
(
process
.
env
.
SKIP_SASS_BINARY_DOWNLOAD_FOR_CI
)
{
console
.
log
(
'Skipping downloading binaries on CI builds'
);
return
;
}
var
binaryPath
=
sass
.
getBinaryPath
();
if
(
sass
.
hasBinary
(
binaryPath
))
{
return
;
}
mkdir
(
path
.
dirname
(
binaryPath
),
function
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
return
;
}
mkdir
(
path
.
dirname
(
sass
.
getBinaryPath
()),
function
(
err
)
{
var
cachePath
=
path
.
join
(
sass
.
getCachePath
(),
pkg
.
name
,
pkg
.
version
);
var
cacheBinary
=
path
.
join
(
cachePath
,
sass
.
getBinaryName
());
if
(
fs
.
existsSync
(
cacheBinary
))
{
console
.
log
(
'Found existing binary in '
+
cacheBinary
);
fs
.
createReadStream
(
cacheBinary
).
pipe
(
fs
.
createWriteStream
(
binaryPath
));
}
else
{
// In case the cache path doesn't exist
mkdir
(
cachePath
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
return
;
}
download
(
sass
.
getBinaryUrl
(),
sass
.
getBinaryPath
()
,
function
(
err
)
{
download
(
sass
.
getBinaryUrl
(),
cacheBinary
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
return
;
}
console
.
log
(
'Binary downloaded and installed at'
,
sass
.
getBinaryPath
());
console
.
log
(
'Binary downloaded to '
+
cacheBinary
);
fs
.
createReadStream
(
cacheBinary
).
pipe
(
fs
.
createWriteStream
(
binaryPath
));
});
});
}
/**
* Skip if CI
*/
if
(
process
.
env
.
SKIP_SASS_BINARY_DOWNLOAD_FOR_CI
)
{
console
.
log
(
'Skipping downloading binaries on CI builds'
);
return
;
}
});
}
/**
...
...
test/runtime.js
View file @
abce8c1a
...
...
@@ -134,6 +134,29 @@ describe('runtime parameters', function() {
});
});
describe
(
'Sass Binary Cache'
,
function
()
{
var
npmCacheDir
;
before
(
function
()
{
npmCacheDir
=
process
.
env
.
npm_config_cache
;
});
beforeEach
(
function
()
{
delete
process
.
env
.
npm_config_sass_binary_cache
;
});
it
(
'npm config variable'
,
function
()
{
var
overridenCachePath
=
'/foo/bar/'
;
process
.
env
.
npm_config_sass_binary_cache
=
overridenCachePath
;
var
sass
=
require
(
extensionsPath
);
assert
.
equal
(
sass
.
getCachePath
(),
overridenCachePath
);
});
it
(
'With no value, falls back to NPM cache'
,
function
()
{
var
sass
=
require
(
extensionsPath
);
assert
.
equal
(
sass
.
getCachePath
(),
npmCacheDir
);
});
});
});
// describe('library detection', function() {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment