Comparing version 7.1.1 to 7.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="7.2.0"></a> | ||
# [7.2.0](https://github.com/zkat/pacote/compare/v7.1.1...v7.2.0) (2018-01-19) | ||
### Features | ||
* **resolved:** tarball shortcut when opts.resolved is provided ([46a2f58](https://github.com/zkat/pacote/commit/46a2f58)) | ||
<a name="7.1.1"></a> | ||
@@ -7,0 +17,0 @@ ## [7.1.1](https://github.com/zkat/pacote/compare/v7.1.0...v7.1.1) (2018-01-08) |
@@ -73,2 +73,7 @@ 'use strict' | ||
opts.log.silly('pacote', `${spec} extracted to ${dest} by content address ${Date.now() - start}ms`) | ||
}).catch(err => { | ||
if (err.code === 'EINTEGRITY') { | ||
err.message = `Verification failed while extracting ${spec}:\n${err.message}` | ||
} | ||
throw err | ||
}) | ||
@@ -93,2 +98,7 @@ } | ||
opts.log.silly('pacote', `${spec} extracted in ${Date.now() - start}ms`) | ||
}).catch(err => { | ||
if (err.code === 'EINTEGRITY') { | ||
err.message = `Verification failed while extracting ${spec}:\n${err.message}` | ||
} | ||
throw err | ||
}) | ||
@@ -95,0 +105,0 @@ } |
{ | ||
"name": "pacote", | ||
"version": "7.1.1", | ||
"version": "7.2.0", | ||
"description": "JavaScript package downloader", | ||
@@ -62,3 +62,3 @@ "main": "index.js", | ||
"semver": "^5.4.1", | ||
"ssri": "^5.0.0", | ||
"ssri": "^5.1.0", | ||
"tar": "^4.2.0", | ||
@@ -65,0 +65,0 @@ "unique-filename": "^1.1.0", |
@@ -11,5 +11,12 @@ 'use strict' | ||
const optCheck = require('./lib/util/opt-check') | ||
const PassThrough = require('stream').PassThrough | ||
const path = require('path') | ||
const pipe = BB.promisify(require('mississippi').pipe) | ||
const pipeline = require('mississippi').pipeline | ||
const ssri = require('ssri') | ||
const url = require('url') | ||
const readFileAsync = BB.promisify(fs.readFile) | ||
const statAsync = BB.promisify(fs.stat) | ||
module.exports = tarball | ||
@@ -21,9 +28,35 @@ function tarball (spec, opts) { | ||
if (opts.integrity && !opts.preferOnline) { | ||
opts.log.silly('tarball', 'checking if', opts.integrity, 'is already cached') | ||
return cacache.get.byDigest(opts.cache, opts.integrity).then(data => { | ||
const resolved = ( | ||
opts.resolved && | ||
url.parse(opts.resolved).protocol === 'file:' && | ||
opts.resolved.substr(5) | ||
) | ||
const tryFile = resolved | ||
? readFileAsync(resolved).then( | ||
data => { | ||
if (ssri.checkData(data, opts.integrity)) { | ||
opts.log.silly('tarball', `using local file content for ${spec}, found at ${opts.resolved} (${Date.now() - startTime}ms)`) | ||
return data | ||
} else { | ||
opts.log.silly('tarball', `content for ${spec} found at ${opts.resolved} invalid.`) | ||
} | ||
}, | ||
err => { if (err.code === 'ENOENT') { return null } else { throw err } } | ||
) | ||
: BB.resolve(false) | ||
return tryFile | ||
.then(data => { | ||
if (data) { | ||
opts.log.silly('tarball', `cached content available for ${spec} (${Date.now() - startTime}ms)`) | ||
return data | ||
} else { | ||
return getStream.buffer(tarballByManifest(startTime, spec, opts)) | ||
opts.log.silly('tarball', 'checking if', opts.integrity, 'is already cached') | ||
return cacache.get.byDigest(opts.cache, opts.integrity).then(data => { | ||
if (data) { | ||
opts.log.silly('tarball', `cached content available for ${spec} (${Date.now() - startTime}ms)`) | ||
return data | ||
} else { | ||
return getStream.buffer(tarballByManifest(startTime, spec, opts)) | ||
} | ||
}) | ||
} | ||
@@ -42,16 +75,46 @@ }) | ||
const startTime = Date.now() | ||
const stream = new PassThrough() | ||
if (opts.integrity && !opts.preferOnline) { | ||
opts.log.silly('tarball', 'checking if', opts.integrity, 'is already cached') | ||
return cacache.get.hasContent(opts.cache, opts.integrity).then(info => { | ||
if (info) { | ||
opts.log.silly('tarball', `cached content available for ${spec} (${Date.now() - startTime}ms)`) | ||
return cacache.get.stream.byDigest(opts.cache, opts.integrity, opts) | ||
const resolved = ( | ||
opts.resolved && | ||
url.parse(opts.resolved).protocol === 'file:' && | ||
opts.resolved.substr(5) | ||
) | ||
const hasFile = resolved | ||
? statAsync(resolved).then( | ||
() => true, | ||
err => { if (err.code === 'ENOENT') { return false } else { throw err } } | ||
) | ||
: BB.resolve(false) | ||
hasFile | ||
.then(hasFile => { | ||
if (hasFile) { | ||
opts.log.silly('tarball', `using local file content for ${spec}, found at ${opts.resolved}`) | ||
return pipeline( | ||
fs.createReadStream(resolved), | ||
ssri.integrityStream(opts.integrity) | ||
) | ||
} else { | ||
return tarballByManifest(startTime, spec, opts) | ||
opts.log.silly('tarball', 'checking if', opts.integrity, 'is already cached') | ||
return cacache.get.hasContent(opts.cache, opts.integrity) | ||
.then(info => { | ||
if (info) { | ||
opts.log.silly('tarball', `cached content available for ${spec} (${Date.now() - startTime}ms)`) | ||
return cacache.get.stream.byDigest(opts.cache, opts.integrity, opts) | ||
} else { | ||
return tarballByManifest(startTime, spec, opts) | ||
} | ||
}) | ||
} | ||
}) | ||
.then( | ||
tarStream => pipe(tarStream, stream), | ||
err => stream.emit('error', err) | ||
) | ||
} else { | ||
opts.log.silly('tarball', `no integrity hash provided for ${spec} - fetching by manifest`) | ||
return tarballByManifest(startTime, spec, opts) | ||
pipe(tarballByManifest(startTime, spec, opts), stream) | ||
} | ||
return stream | ||
} | ||
@@ -58,0 +121,0 @@ |
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
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
100169
1765
Updatedssri@^5.1.0