Skip to content

Commit

Permalink
deps: cacache@16.0.7 (#4816)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored May 3, 2022
1 parent 62faf8a commit 4ff7d3d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 136 deletions.
9 changes: 3 additions & 6 deletions node_modules/cacache/lib/content/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Pipeline = require('minipass-pipeline')

const lstat = util.promisify(fs.lstat)
const readFile = util.promisify(fs.readFile)
const copyFile = util.promisify(fs.copyFile)

module.exports = read

Expand Down Expand Up @@ -90,12 +91,8 @@ function readStream (cache, integrity, opts = {}) {
return stream
}

let copyFile
if (fs.copyFile) {
module.exports.copy = copy
module.exports.copy.sync = copySync
copyFile = util.promisify(fs.copyFile)
}
module.exports.copy = copy
module.exports.copy.sync = copySync

function copy (cache, integrity, dest) {
return withContentSri(cache, integrity, (cpath, sri) => {
Expand Down
65 changes: 30 additions & 35 deletions node_modules/cacache/lib/content/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,37 @@ const path = require('path')
const rimraf = util.promisify(require('rimraf'))
const ssri = require('ssri')
const uniqueFilename = require('unique-filename')
const { disposer } = require('./../util/disposer')
const fsm = require('fs-minipass')

const writeFile = util.promisify(fs.writeFile)

module.exports = write

function write (cache, data, opts = {}) {
async function write (cache, data, opts = {}) {
const { algorithms, size, integrity } = opts
if (algorithms && algorithms.length > 1) {
throw new Error('opts.algorithms only supports a single algorithm for now')
}

if (typeof size === 'number' && data.length !== size) {
return Promise.reject(sizeError(size, data.length))
throw sizeError(size, data.length)
}

const sri = ssri.fromData(data, algorithms ? { algorithms } : {})
if (integrity && !ssri.checkData(data, integrity, opts)) {
return Promise.reject(checksumError(integrity, sri))
throw checksumError(integrity, sri)
}

return disposer(makeTmp(cache, opts), makeTmpDisposer,
(tmp) => {
return writeFile(tmp.target, data, { flag: 'wx' })
.then(() => moveToDestination(tmp, cache, sri, opts))
})
.then(() => ({ integrity: sri, size: data.length }))
const tmp = await makeTmp(cache, opts)
try {
await writeFile(tmp.target, data, { flag: 'wx' })
await moveToDestination(tmp, cache, sri, opts)
return { integrity: sri, size: data.length }
} finally {
if (!tmp.moved) {
await rimraf(tmp.target)
}
}
}

module.exports.stream = writeStream
Expand Down Expand Up @@ -94,18 +97,22 @@ function writeStream (cache, opts = {}) {
return new CacacheWriteStream(cache, opts)
}

function handleContent (inputStream, cache, opts) {
return disposer(makeTmp(cache, opts), makeTmpDisposer, (tmp) => {
return pipeToTmp(inputStream, cache, tmp.target, opts)
.then((res) => {
return moveToDestination(
tmp,
cache,
res.integrity,
opts
).then(() => res)
})
})
async function handleContent (inputStream, cache, opts) {
const tmp = await makeTmp(cache, opts)
try {
const res = await pipeToTmp(inputStream, cache, tmp.target, opts)
await moveToDestination(
tmp,
cache,
res.integrity,
opts
)
return res
} finally {
if (!tmp.moved) {
await rimraf(tmp.target)
}
}
}

function pipeToTmp (inputStream, cache, tmpTarget, opts) {
Expand Down Expand Up @@ -136,11 +143,7 @@ function pipeToTmp (inputStream, cache, tmpTarget, opts) {
outStream
)

return pipeline.promise()
.then(() => ({ integrity, size }))
.catch(er => rimraf(tmpTarget).then(() => {
throw er
}))
return pipeline.promise().then(() => ({ integrity, size }))
}

function makeTmp (cache, opts) {
Expand All @@ -151,14 +154,6 @@ function makeTmp (cache, opts) {
}))
}

function makeTmpDisposer (tmp) {
if (tmp.moved) {
return Promise.resolve()
}

return rimraf(tmp.target)
}

function moveToDestination (tmp, cache, sri, opts) {
const destination = contentPath(cache, sri)
const destDir = path.dirname(destination)
Expand Down
8 changes: 6 additions & 2 deletions node_modules/cacache/lib/entry-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const path = require('path')
const ssri = require('ssri')
const uniqueFilename = require('unique-filename')

const { disposer } = require('./util/disposer')
const contentPath = require('./content/path')
const fixOwner = require('./util/fix-owner')
const hashToSegments = require('./util/hash-to-segments')
Expand Down Expand Up @@ -102,7 +101,12 @@ async function compact (cache, key, matchFn, opts = {}) {
}

// write the file atomically
await disposer(setup(), teardown, write)
const tmp = await setup()
try {
await write(tmp)
} finally {
await teardown(tmp)
}

// we reverse the list we generated such that the newest
// entries come first in order to make looping through them easier
Expand Down
49 changes: 14 additions & 35 deletions node_modules/cacache/lib/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
const Collect = require('minipass-collect')
const Minipass = require('minipass')
const Pipeline = require('minipass-pipeline')
const fs = require('fs')
const util = require('util')

const index = require('./entry-index')
const memo = require('./memoization')
const read = require('./content/read')

const writeFile = util.promisify(fs.writeFile)

function getData (cache, key, opts = {}) {
const { integrity, memoize, size } = opts
const memoized = memo.get(cache, key, opts)
Expand Down Expand Up @@ -209,42 +205,25 @@ function info (cache, key, opts = {}) {
module.exports.info = info

function copy (cache, key, dest, opts = {}) {
if (read.copy) {
return index.find(cache, key, opts).then((entry) => {
if (!entry) {
throw new index.NotFoundError(cache, key)
}
return read.copy(cache, entry.integrity, dest, opts)
.then(() => {
return {
metadata: entry.metadata,
size: entry.size,
integrity: entry.integrity,
}
})
})
}

return getData(cache, key, opts).then((res) => {
return writeFile(dest, res.data).then(() => {
return {
metadata: res.metadata,
size: res.size,
integrity: res.integrity,
}
})
return index.find(cache, key, opts).then((entry) => {
if (!entry) {
throw new index.NotFoundError(cache, key)
}
return read.copy(cache, entry.integrity, dest, opts)
.then(() => {
return {
metadata: entry.metadata,
size: entry.size,
integrity: entry.integrity,
}
})
})
}

module.exports.copy = copy

function copyByDigest (cache, key, dest, opts = {}) {
if (read.copy) {
return read.copy(cache, key, dest, opts).then(() => key)
}

return getDataByDigest(cache, key, opts).then((res) => {
return writeFile(dest, res).then(() => key)
})
return read.copy(cache, key, dest, opts).then(() => key)
}
module.exports.copy.byDigest = copyByDigest

Expand Down
26 changes: 13 additions & 13 deletions node_modules/cacache/lib/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function putStream (cache, key, opts = {}) {
opts = putOpts(opts)
let integrity
let size
let error

let memoData
const pipeline = new Pipeline()
Expand All @@ -58,28 +59,27 @@ function putStream (cache, key, opts = {}) {
.on('size', (s) => {
size = s
})
.on('error', (err) => {
error = err
})

pipeline.push(contentStream)

// last but not least, we write the index and emit hash and size,
// and memoize if we're doing that
pipeline.push(new Flush({
flush () {
return index
.insert(cache, key, integrity, { ...opts, size })
.then((entry) => {
if (memoize && memoData) {
memo.put(cache, entry, memoData, opts)
}

if (integrity) {
if (!error) {
return index
.insert(cache, key, integrity, { ...opts, size })
.then((entry) => {
if (memoize && memoData) {
memo.put(cache, entry, memoData, opts)
}
pipeline.emit('integrity', integrity)
}

if (size) {
pipeline.emit('size', size)
}
})
})
}
},
}))

Expand Down
31 changes: 0 additions & 31 deletions node_modules/cacache/lib/util/disposer.js

This file was deleted.

7 changes: 1 addition & 6 deletions node_modules/cacache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cacache",
"version": "16.0.6",
"version": "16.0.7",
"cache-version": {
"content": "2",
"index": "5"
Expand All @@ -12,7 +12,6 @@
"lib/"
],
"scripts": {
"benchmarks": "node test/benchmarks",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
Expand Down Expand Up @@ -71,10 +70,6 @@
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "3.4.1",
"benchmark": "^2.1.4",
"chalk": "^4.1.2",
"require-inject": "^1.4.4",
"tacks": "^1.3.0",
"tap": "^16.0.0"
},
"tap": {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"@npmcli/run-script": "^3.0.1",
"abbrev": "~1.1.1",
"archy": "~1.0.0",
"cacache": "^16.0.6",
"cacache": "^16.0.7",
"chalk": "^4.1.2",
"chownr": "^2.0.0",
"cli-columns": "^4.0.0",
Expand Down Expand Up @@ -1597,9 +1597,9 @@
}
},
"node_modules/cacache": {
"version": "16.0.6",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-16.0.6.tgz",
"integrity": "sha512-9a/MLxGaw3LEGes0HaPez2RgZWDV6X0jrgChsuxfEh8xoDoYGxaGrkMe7Dlyjrb655tA/b8fX0qlUg6Ii5MBvw==",
"version": "16.0.7",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-16.0.7.tgz",
"integrity": "sha512-a4zfQpp5vm4Ipdvbj+ZrPonikRhm6WBEd4zT1Yc1DXsmAxrPgDwWBLF/u/wTVXSFPIgOJ1U3ghSa2Xm4s3h28w==",
"inBundle": true,
"dependencies": {
"@npmcli/fs": "^2.1.0",
Expand Down Expand Up @@ -11253,9 +11253,9 @@
}
},
"cacache": {
"version": "16.0.6",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-16.0.6.tgz",
"integrity": "sha512-9a/MLxGaw3LEGes0HaPez2RgZWDV6X0jrgChsuxfEh8xoDoYGxaGrkMe7Dlyjrb655tA/b8fX0qlUg6Ii5MBvw==",
"version": "16.0.7",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-16.0.7.tgz",
"integrity": "sha512-a4zfQpp5vm4Ipdvbj+ZrPonikRhm6WBEd4zT1Yc1DXsmAxrPgDwWBLF/u/wTVXSFPIgOJ1U3ghSa2Xm4s3h28w==",
"requires": {
"@npmcli/fs": "^2.1.0",
"@npmcli/move-file": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@npmcli/run-script": "^3.0.1",
"abbrev": "~1.1.1",
"archy": "~1.0.0",
"cacache": "^16.0.6",
"cacache": "^16.0.7",
"chalk": "^4.1.2",
"chownr": "^2.0.0",
"cli-columns": "^4.0.0",
Expand Down

0 comments on commit 4ff7d3d

Please sign in to comment.