From 0096f69978d2f40b170b28096f269b0b0008a692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Wed, 1 Aug 2018 16:36:03 -0700 Subject: [PATCH] cacache@11.1.0 --- node_modules/cacache/CHANGELOG.md | 22 +++++ node_modules/cacache/lib/content/read.js | 110 +++++++++++++++-------- node_modules/cacache/package.json | 41 ++++----- node_modules/cacache/put.js | 6 +- package-lock.json | 8 +- package.json | 2 +- 6 files changed, 124 insertions(+), 65 deletions(-) diff --git a/node_modules/cacache/CHANGELOG.md b/node_modules/cacache/CHANGELOG.md index f04bdea0c4089..a9aeb3bc1fbe3 100644 --- a/node_modules/cacache/CHANGELOG.md +++ b/node_modules/cacache/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +# [11.1.0](https://github.com/zkat/cacache/compare/v11.0.3...v11.1.0) (2018-08-01) + + +### Features + +* **read:** add sync support for low-level content read ([b43af83](https://github.com/zkat/cacache/commit/b43af83)) + + + + +## [11.0.3](https://github.com/zkat/cacache/compare/v11.0.2...v11.0.3) (2018-08-01) + + +### Bug Fixes + +* **config:** add ssri config options ([#136](https://github.com/zkat/cacache/issues/136)) ([10d5d9a](https://github.com/zkat/cacache/commit/10d5d9a)) +* **perf:** refactor content.read to avoid lstats ([c5ac10e](https://github.com/zkat/cacache/commit/c5ac10e)) +* **test:** oops when removing safe-buffer ([1950490](https://github.com/zkat/cacache/commit/1950490)) + + + ## [11.0.2](https://github.com/zkat/cacache/compare/v11.0.1...v11.0.2) (2018-05-07) diff --git a/node_modules/cacache/lib/content/read.js b/node_modules/cacache/lib/content/read.js index 5c1a6f2f290b4..e308ead92b8b5 100644 --- a/node_modules/cacache/lib/content/read.js +++ b/node_modules/cacache/lib/content/read.js @@ -10,7 +10,8 @@ const pipe = BB.promisify(require('mississippi').pipe) const ssri = require('ssri') const Y = require('../util/y.js') -BB.promisifyAll(fs) +const lstatAsync = BB.promisify(fs.lstat) +const readFileAsync = BB.promisify(fs.readFile) const ReadOpts = figgyPudding({ size: {} @@ -19,10 +20,8 @@ const ReadOpts = figgyPudding({ module.exports = read function read (cache, integrity, opts) { opts = ReadOpts(opts) - return pickContentSri(cache, integrity).then(content => { - const sri = content.sri - const cpath = contentPath(cache, sri) - return fs.readFileAsync(cpath, null).then(data => { + return withContentSri(cache, integrity, (cpath, sri) => { + return readFileAsync(cpath, null).then(data => { if (typeof opts.size === 'number' && opts.size !== data.length) { throw sizeError(opts.size, data.length) } else if (ssri.checkData(data, sri)) { @@ -34,17 +33,31 @@ function read (cache, integrity, opts) { }) } +module.exports.sync = readSync +function readSync (cache, integrity, opts) { + opts = ReadOpts(opts) + return withContentSriSync(cache, integrity, (cpath, sri) => { + const data = fs.readFileSync(cpath) + if (typeof opts.size === 'number' && opts.size !== data.length) { + throw sizeError(opts.size, data.length) + } else if (ssri.checkData(data, sri)) { + return data + } else { + throw integrityError(sri, cpath) + } + }) +} + module.exports.stream = readStream module.exports.readStream = readStream function readStream (cache, integrity, opts) { opts = ReadOpts(opts) const stream = new PassThrough() - pickContentSri( - cache, integrity - ).then(content => { - const sri = content.sri + withContentSri(cache, integrity, (cpath, sri) => { + return lstatAsync(cpath).then(stat => ({cpath, sri, stat})) + }).then(({cpath, sri, stat}) => { return pipe( - fs.createReadStream(contentPath(cache, sri)), + fs.createReadStream(cpath), ssri.integrityStream({ integrity: sri, size: opts.size @@ -57,37 +70,64 @@ function readStream (cache, integrity, opts) { return stream } +let copyFileAsync if (fs.copyFile) { module.exports.copy = copy + copyFileAsync = BB.promisify(fs.copyFile) } function copy (cache, integrity, dest, opts) { opts = ReadOpts(opts) - return pickContentSri(cache, integrity).then(content => { - const sri = content.sri - const cpath = contentPath(cache, sri) - return fs.copyFileAsync(cpath, dest).then(() => content.size) + return withContentSri(cache, integrity, (cpath, sri) => { + return copyFileAsync(cpath, dest) }) } module.exports.hasContent = hasContent function hasContent (cache, integrity) { if (!integrity) { return BB.resolve(false) } - return pickContentSri(cache, integrity) - .catch({code: 'ENOENT'}, () => false) - .catch({code: 'EPERM'}, err => { + return withContentSri(cache, integrity, (cpath, sri) => { + return lstatAsync(cpath).then(stat => ({size: stat.size, sri})) + }).catch(err => { + if (err.code === 'ENOENT') { return false } + if (err.code === 'EPERM') { if (process.platform !== 'win32') { throw err } else { return false } - }).then(content => { - if (!content.sri) return false - return ({ sri: content.sri, size: content.stat.size }) - }) + } + }) } -module.exports._pickContentSri = pickContentSri -function pickContentSri (cache, integrity) { +function withContentSri (cache, integrity, fn) { + return BB.try(() => { + const sri = ssri.parse(integrity) + // If `integrity` has multiple entries, pick the first digest + // with available local data. + const algo = sri.pickAlgorithm() + const digests = sri[algo] + if (digests.length <= 1) { + const cpath = contentPath(cache, digests[0]) + return fn(cpath, digests[0]) + } else { + return BB.any(sri[sri.pickAlgorithm()].map(meta => { + return withContentSri(cache, meta, fn) + }, {concurrency: 1})) + .catch(err => { + if ([].some.call(err, e => e.code === 'ENOENT')) { + throw Object.assign( + new Error('No matching content found for ' + sri.toString()), + {code: 'ENOENT'} + ) + } else { + throw err[0] + } + }) + } + }) +} + +function withContentSriSync (cache, integrity, fn) { const sri = ssri.parse(integrity) // If `integrity` has multiple entries, pick the first digest // with available local data. @@ -95,21 +135,17 @@ function pickContentSri (cache, integrity) { const digests = sri[algo] if (digests.length <= 1) { const cpath = contentPath(cache, digests[0]) - return fs.lstatAsync(cpath).then(stat => ({ sri: digests[0], stat })) + return fn(cpath, digests[0]) } else { - return BB.any(sri[sri.pickAlgorithm()].map(meta => { - return pickContentSri(cache, meta) - })) - .catch(err => { - if ([].some.call(err, e => e.code === 'ENOENT')) { - throw Object.assign( - new Error('No matching content found for ' + sri.toString()), - {code: 'ENOENT'} - ) - } else { - throw err[0] - } - }) + let lastErr = null + for (const meta of sri[sri.pickAlgorithm()]) { + try { + return withContentSriSync(cache, meta, fn) + } catch (err) { + lastErr = err + } + } + if (lastErr) { throw lastErr } } } diff --git a/node_modules/cacache/package.json b/node_modules/cacache/package.json index c9e61596f91c4..01e20c1346d0f 100644 --- a/node_modules/cacache/package.json +++ b/node_modules/cacache/package.json @@ -1,34 +1,30 @@ { - "_args": [ - [ - "cacache@11.0.2", - "/Users/rebecca/code/npm" - ] - ], - "_from": "cacache@11.0.2", - "_id": "cacache@11.0.2", + "_from": "cacache@latest", + "_id": "cacache@11.1.0", "_inBundle": false, - "_integrity": "sha512-hMiz7LN4w8sdfmKsvNs80ao/vf2JCGWWdpu95JyY90AJZRbZJmgE71dCefRiNf8OCqiZQDcUBfYiLlUNu4/j5A==", + "_integrity": "sha512-wFLexxfPdlvoUlpHIaU4y4Vm+Im/otOPCg1ov5g9/HRfUhVA8GpDdQL66SWBgRpgNC+5ebMT1Vr1RyPaFrJVqw==", "_location": "/cacache", "_phantomChildren": {}, "_requested": { - "type": "version", + "type": "tag", "registry": true, - "raw": "cacache@11.0.2", + "raw": "cacache@latest", "name": "cacache", "escapedName": "cacache", - "rawSpec": "11.0.2", + "rawSpec": "latest", "saveSpec": null, - "fetchSpec": "11.0.2" + "fetchSpec": "latest" }, "_requiredBy": [ + "#USER", "/", "/make-fetch-happen", "/pacote" ], - "_resolved": "https://registry.npmjs.org/cacache/-/cacache-11.0.2.tgz", - "_spec": "11.0.2", - "_where": "/Users/rebecca/code/npm", + "_resolved": "https://registry.npmjs.org/cacache/-/cacache-11.1.0.tgz", + "_shasum": "3d76dbc2e9da413acaad2557051960a4dad3e1a4", + "_spec": "cacache@latest", + "_where": "/Users/zkat/Documents/code/work/npm", "author": { "name": "Kat Marchán", "email": "kzm@sykosomatic.org" @@ -36,6 +32,7 @@ "bugs": { "url": "https://github.com/zkat/cacache/issues" }, + "bundleDependencies": false, "cache-version": { "content": "2", "index": "5" @@ -64,7 +61,7 @@ "figgy-pudding": "^3.1.0", "glob": "^7.1.2", "graceful-fs": "^4.1.11", - "lru-cache": "^4.1.2", + "lru-cache": "^4.1.3", "mississippi": "^3.0.0", "mkdirp": "^0.5.1", "move-concurrently": "^1.0.1", @@ -74,17 +71,17 @@ "unique-filename": "^1.1.0", "y18n": "^4.0.0" }, + "deprecated": false, "description": "Fast, fault-tolerant, cross-platform, disk-based, data-agnostic, content-addressable cache.", "devDependencies": { "benchmark": "^2.1.4", "chalk": "^2.3.2", "cross-env": "^5.1.4", "require-inject": "^1.4.2", - "safe-buffer": "^5.1.1", "standard": "^11.0.1", - "standard-version": "^4.3.0", - "tacks": "^1.2.2", - "tap": "^11.1.3", + "standard-version": "^4.4.0", + "tacks": "^1.2.7", + "tap": "^12.0.1", "weallbehave": "^1.2.0", "weallcontribute": "^1.0.8" }, @@ -127,5 +124,5 @@ "update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'", "update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'" }, - "version": "11.0.2" + "version": "11.1.0" } diff --git a/node_modules/cacache/put.js b/node_modules/cacache/put.js index 0b0ee1497813b..01b0dd84fc5ad 100644 --- a/node_modules/cacache/put.js +++ b/node_modules/cacache/put.js @@ -13,10 +13,14 @@ const PutOpts = figgyPudding({ integrity: {}, memoize: {}, metadata: {}, + pickAlgorithm: {}, size: {}, tmpPrefix: {}, uid: {}, - gid: {} + gid: {}, + single: {}, + sep: {}, + strict: {} }) module.exports = putData diff --git a/package-lock.json b/package-lock.json index 1f9107559cdda..a241dc6727923 100644 --- a/package-lock.json +++ b/package-lock.json @@ -355,16 +355,16 @@ "integrity": "sha512-JGC3EV2bCzJH/ENSh3afyJrH4vwxbHTuO5ljLoI5+2iJOcEpMgP8T782jH9b5qGxf2mSUIp1lfGnfKNrRHpvVg==" }, "cacache": { - "version": "11.0.2", - "resolved": "https://registry.npmjs.org/cacache/-/cacache-11.0.2.tgz", - "integrity": "sha512-hMiz7LN4w8sdfmKsvNs80ao/vf2JCGWWdpu95JyY90AJZRbZJmgE71dCefRiNf8OCqiZQDcUBfYiLlUNu4/j5A==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/cacache/-/cacache-11.1.0.tgz", + "integrity": "sha512-wFLexxfPdlvoUlpHIaU4y4Vm+Im/otOPCg1ov5g9/HRfUhVA8GpDdQL66SWBgRpgNC+5ebMT1Vr1RyPaFrJVqw==", "requires": { "bluebird": "^3.5.1", "chownr": "^1.0.1", "figgy-pudding": "^3.1.0", "glob": "^7.1.2", "graceful-fs": "^4.1.11", - "lru-cache": "^4.1.2", + "lru-cache": "^4.1.3", "mississippi": "^3.0.0", "mkdirp": "^0.5.1", "move-concurrently": "^1.0.1", diff --git a/package.json b/package.json index a0eb27d1c93b0..a21f18dd4cbe0 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "bin-links": "^1.1.2", "bluebird": "~3.5.1", "byte-size": "^4.0.3", - "cacache": "^11.0.2", + "cacache": "^11.1.0", "call-limit": "~1.1.0", "chownr": "~1.0.1", "cli-columns": "^3.1.2",