node-sass
Advanced tools
Comparing version 3.11.3 to 3.12.0
@@ -8,2 +8,3 @@ /*! | ||
pkg = require('../package.json'), | ||
mkdir = require('mkdirp'), | ||
path = require('path'), | ||
@@ -185,5 +186,7 @@ defaultBinaryPath = path.join(__dirname, '..', 'vendor'); | ||
} else { | ||
binaryName = [process.platform, '-', | ||
process.arch, '-', | ||
process.versions.modules].join(''); | ||
binaryName = [ | ||
process.platform, '-', | ||
process.arch, '-', | ||
process.versions.modules | ||
].join(''); | ||
} | ||
@@ -265,2 +268,75 @@ | ||
/** | ||
* An array of paths suitable for use as a local disk cache of the binding. | ||
* | ||
* @return {[]String} an array of paths | ||
* @api public | ||
*/ | ||
function getCachePathCandidates() { | ||
return [ | ||
process.env.npm_config_sass_binary_cache, | ||
process.env.npm_config_cache, | ||
].filter(function(_) { return _; }); | ||
} | ||
/** | ||
* The most suitable location for caching the binding on disk. | ||
* | ||
* Given the candidates directories provided by `getCachePathCandidates()` this | ||
* returns the first writable directory. By treating the candidate directories | ||
* as a prioritised list this method is deterministic, assuming no change to the | ||
* local environment. | ||
* | ||
* @return {String} directory to cache binding | ||
* @api public | ||
*/ | ||
function getBinaryCachePath() { | ||
var i, | ||
cachePath, | ||
cachePathCandidates = getCachePathCandidates(); | ||
for (i = 0; i < cachePathCandidates.length; i++) { | ||
cachePath = path.join(cachePathCandidates[i], pkg.name, pkg.version); | ||
try { | ||
mkdir.sync(cachePath); | ||
return cachePath; | ||
} catch (e) { | ||
// Directory is not writable, try another | ||
} | ||
} | ||
return ''; | ||
} | ||
/** | ||
* The cached binding | ||
* | ||
* Check the candidates directories provided by `getCachePathCandidates()` for | ||
* the binding file, if it exists. By treating the candidate directories | ||
* as a prioritised list this method is deterministic, assuming no change to the | ||
* local environment. | ||
* | ||
* @return {String} path to cached binary | ||
* @api public | ||
*/ | ||
function getCachedBinary() { | ||
var i, | ||
cachePath, | ||
cacheBinary, | ||
cachePathCandidates = getCachePathCandidates(), | ||
binaryName = getBinaryName(); | ||
for (i = 0; i < cachePathCandidates.length; i++) { | ||
cachePath = path.join(cachePathCandidates[i], pkg.name, pkg.version); | ||
cacheBinary = path.join(cachePath, binaryName); | ||
if (fs.existsSync(cacheBinary)) { | ||
return cacheBinary; | ||
} | ||
} | ||
return ''; | ||
} | ||
/** | ||
* Does the supplied binary path exist | ||
@@ -293,2 +369,5 @@ * | ||
module.exports.getBinaryPath = getBinaryPath; | ||
module.exports.getBinaryCachePath = getBinaryCachePath; | ||
module.exports.getCachedBinary = getCachedBinary; | ||
module.exports.getCachePathCandidates = getCachePathCandidates; | ||
module.exports.getVersionInfo = getVersionInfo; | ||
@@ -295,0 +374,0 @@ module.exports.getHumanEnvironment = getHumanEnvironment; |
{ | ||
"name": "node-sass", | ||
"version": "3.11.3", | ||
"version": "3.12.0", | ||
"libsass": "3.3.6", | ||
@@ -5,0 +5,0 @@ "description": "Wrapper around libsass", |
@@ -5,4 +5,3 @@ /*! | ||
var eol = require('os').EOL, | ||
pkg = require('../package.json'), | ||
var pkg = require('../package.json'), | ||
fs = require('fs'), | ||
@@ -12,2 +11,3 @@ mkdir = require('mkdirp'), | ||
spawn = require('cross-spawn'), | ||
log = require('npmlog'), | ||
sass = require('../lib/extensions'); | ||
@@ -33,3 +33,3 @@ | ||
if (err && err.code !== 'EEXIST') { | ||
console.error(err.message); | ||
log.error('node-sass build', err.message); | ||
return; | ||
@@ -40,3 +40,3 @@ } | ||
if (err) { | ||
console.error('Build succeeded but target not found'); | ||
log.error('node-sass build', 'Build succeeded but target not found'); | ||
return; | ||
@@ -47,7 +47,7 @@ } | ||
if (err) { | ||
console.error(err.message); | ||
log.error('node-sass build', err.message); | ||
return; | ||
} | ||
console.log('Installed in "' + install + '"'); | ||
log.info('node-sass build', 'Installed to %s', install); | ||
}); | ||
@@ -84,4 +84,4 @@ }); | ||
function initSubmodules(cb) { | ||
console.log('Detected a git install'); | ||
console.log('Cloning libSass into src/libsass'); | ||
log.info('node-sass build', 'Detected a git install'); | ||
log.info('node-sass build', 'Cloning LibSass into src/libsass'); | ||
@@ -95,3 +95,3 @@ var clone = spawn('git', ['clone', 'https://github.com/sass/libsass.git', './src/libsass']); | ||
console.log('Checking out libsass to ' + pkg.libsass); | ||
log.info('node-sass build', 'Checking out LibSass to %s', pkg.libsass); | ||
@@ -138,3 +138,3 @@ var checkout = spawn('git', ['checkout', pkg.libsass], { cwd: './src/libsass' }); | ||
if (err) { | ||
console.error(err.message); | ||
log.error('node-sass build', err.message); | ||
process.exit(1); | ||
@@ -148,3 +148,3 @@ } | ||
console.log(['Building:', process.execPath].concat(args).join(' ')); | ||
log.info('node-sass build', [process.execPath].concat(args).join(' ')); | ||
@@ -158,7 +158,11 @@ var proc = spawn(process.execPath, args, { | ||
afterBuild(options); | ||
return; | ||
} | ||
console.error(errorCode === 127 ? 'node-gyp not found!' : 'Build failed'); | ||
if (errorCode === 127 ) { | ||
log.error('node-sass build', 'node-gyp not found!'); | ||
} else { | ||
log.error('node-sass build', 'Build failed with error code: %d', errorCode); | ||
} | ||
process.exit(1); | ||
@@ -216,3 +220,4 @@ }); | ||
console.log('"' + sass.getBinaryPath() + '" exists.', eol, 'testing binary.'); | ||
log.info('node-sass build', 'Binary found at %s', sass.getBinaryPath()); | ||
log.info('node-sass build', 'Testing binary'); | ||
@@ -224,5 +229,6 @@ try { | ||
console.log('Binary is fine; exiting.'); | ||
log.info('node-sass build', 'Binary is fine'); | ||
} catch (e) { | ||
console.log(['Problem with the binary:', e, 'Manual build incoming.'].join(eol)); | ||
log.error('node-sass build', 'Binary has a problem: %s', e); | ||
log.info('node-sass build', 'Building the binary locally'); | ||
@@ -229,0 +235,0 @@ return build(options); |
@@ -51,3 +51,3 @@ /*! | ||
log.http('node-sass install', 'Start downloading binary at' + url); | ||
log.http('node-sass install', 'Downloading binary from %s', url); | ||
@@ -61,2 +61,3 @@ try { | ||
} else { | ||
log.http('node-sass install', 'Download complete'); | ||
cb(); | ||
@@ -67,3 +68,3 @@ } | ||
var length = parseInt(response.headers['content-length'], 10); | ||
var progress = log.newItem(url, length); | ||
var progress = log.newItem('', length); | ||
@@ -77,3 +78,3 @@ if (successful(response)) { | ||
// as far as npm is concerned. | ||
if (process.env.npm_config_progress !== false) { | ||
if (process.env.npm_config_progress === 'true') { | ||
log.enableProgress(); | ||
@@ -99,7 +100,30 @@ | ||
function checkAndDownloadBinary() { | ||
if (sass.hasBinary(sass.getBinaryPath())) { | ||
if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) { | ||
log.info('node-sass install', 'Skipping downloading binaries on CI builds'); | ||
return; | ||
} | ||
mkdir(path.dirname(sass.getBinaryPath()), function(err) { | ||
var cachedBinary = sass.getCachedBinary(), | ||
cachePath = sass.getBinaryCachePath(), | ||
binaryPath = sass.getBinaryPath(); | ||
if (sass.hasBinary(binaryPath)) { | ||
log.info('node-sass build', 'Binary found at %s', binaryPath); | ||
return; | ||
} | ||
try { | ||
mkdir.sync(path.dirname(binaryPath)); | ||
} catch (err) { | ||
log.error('node-sass install', 'Unable to save binary to %s: %s', path.dirname(binaryPath), err); | ||
return; | ||
} | ||
if (cachedBinary) { | ||
log.info('node-sass install', 'Cached binary found at %s', cachedBinary); | ||
fs.createReadStream(cachedBinary).pipe(fs.createWriteStream(binaryPath)); | ||
return; | ||
} | ||
download(sass.getBinaryUrl(), binaryPath, function(err) { | ||
if (err) { | ||
@@ -110,20 +134,17 @@ log.error('node-sass install', err); | ||
download(sass.getBinaryUrl(), sass.getBinaryPath(), function(err) { | ||
if (err) { | ||
log.error('node-sass install', err); | ||
return; | ||
} | ||
log.info('node-sass install', 'Binary saved at %s', binaryPath); | ||
log.info('node-sass install', 'Binary downloaded and installed at' + sass.getBinaryPath()); | ||
}); | ||
}); | ||
} | ||
cachedBinary = path.join(cachePath, sass.getBinaryName()); | ||
/** | ||
* Skip if CI | ||
*/ | ||
if (cachePath) { | ||
log.info('node-sass install', 'Caching binary to %s', cachedBinary); | ||
if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) { | ||
log.info('node-sass install', 'Skipping downloading binaries on CI builds'); | ||
return; | ||
try { | ||
mkdir.sync(path.dirname(cachedBinary)); | ||
fs.createReadStream(binaryPath).pipe(fs.createWriteStream(cachedBinary)); | ||
} catch (err) { | ||
log.error('node-sass install', 'Failed to cache binary: %s', err); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -130,0 +151,0 @@ |
@@ -51,3 +51,3 @@ /*eslint new-cap: ["error", {"capIsNewExceptions": ["Color"]}]*/ | ||
Object.defineProperty(process, 'arch', { | ||
get: function () { return 'foo'; } | ||
value: 'foo', | ||
}); | ||
@@ -57,3 +57,5 @@ }); | ||
afterEach(function() { | ||
process.arch = prevValue; | ||
Object.defineProperty(process, 'arch', { | ||
value: prevValue, | ||
}); | ||
}); | ||
@@ -83,3 +85,3 @@ | ||
Object.defineProperty(process, 'platform', { | ||
get: function () { return 'bar'; } | ||
value: 'bar', | ||
}); | ||
@@ -89,3 +91,5 @@ }); | ||
afterEach(function() { | ||
process.platform = prevValue; | ||
Object.defineProperty(process, 'platform', { | ||
value: prevValue, | ||
}); | ||
}); | ||
@@ -115,3 +119,3 @@ | ||
Object.defineProperty(process.versions, 'modules', { | ||
get: function () { return 'baz'; } | ||
value: 'baz', | ||
}); | ||
@@ -121,3 +125,5 @@ }); | ||
afterEach(function() { | ||
process.versions.modules = prevValue; | ||
Object.defineProperty(process.versions, 'modules', { | ||
value: prevValue, | ||
}); | ||
}); | ||
@@ -124,0 +130,0 @@ |
@@ -118,2 +118,23 @@ var assert = require('assert'), | ||
}); | ||
describe.skip('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; | ||
assert.equal(sass.getCachePath(), overridenCachePath); | ||
}); | ||
it('With no value, falls back to NPM cache', function() { | ||
assert.equal(sass.getCachePath(), npmCacheDir); | ||
}); | ||
}); | ||
}); | ||
@@ -120,0 +141,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1638523
4600
92