pnpm 7.9.1 → 7.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -7
- package/bin/pnpm.cjs +3 -0
- package/bin/pnpx.cjs +1 -15
- package/dist/node_modules/.modules.yaml +3 -3
- package/dist/node_modules/.pnpm/lock.yaml +76 -42
- package/dist/node_modules/@npmcli/fs/lib/common/owner-sync.js +96 -0
- package/dist/node_modules/@npmcli/fs/lib/common/owner.js +8 -4
- package/dist/node_modules/@npmcli/fs/lib/copy-file.js +3 -9
- package/dist/node_modules/@npmcli/fs/lib/fs.js +9 -3
- package/dist/node_modules/@npmcli/fs/lib/index.js +3 -1
- package/dist/node_modules/@npmcli/fs/lib/mkdir.js +19 -0
- package/dist/node_modules/@npmcli/fs/lib/mkdtemp.js +3 -8
- package/dist/node_modules/@npmcli/fs/lib/with-owner-sync.js +21 -0
- package/dist/node_modules/@npmcli/fs/lib/with-owner.js +21 -0
- package/dist/node_modules/@npmcli/fs/lib/with-temp-dir.js +4 -2
- package/dist/node_modules/@npmcli/fs/lib/write-file.js +3 -8
- package/dist/node_modules/@npmcli/fs/package.json +21 -9
- package/dist/node_modules/@npmcli/move-file/{index.js → lib/index.js} +50 -27
- package/dist/node_modules/@npmcli/move-file/package.json +20 -7
- package/dist/node_modules/@tootallnate/once/LICENSE +21 -0
- package/dist/node_modules/@tootallnate/once/dist/index.js +21 -36
- package/dist/node_modules/@tootallnate/once/dist/index.js.map +1 -1
- package/dist/node_modules/@tootallnate/once/dist/overloaded-parameters.js +3 -0
- package/dist/node_modules/@tootallnate/once/dist/overloaded-parameters.js.map +1 -0
- package/dist/node_modules/@tootallnate/once/dist/types.js +3 -0
- package/dist/node_modules/@tootallnate/once/dist/types.js.map +1 -0
- package/dist/node_modules/@tootallnate/once/package.json +22 -15
- package/dist/node_modules/cacache/lib/content/read.js +99 -102
- package/dist/node_modules/cacache/lib/content/rm.js +9 -8
- package/dist/node_modules/cacache/lib/content/write.js +67 -67
- package/dist/node_modules/cacache/lib/entry-index.js +128 -118
- package/dist/node_modules/cacache/{get.js → lib/get.js} +88 -100
- package/dist/node_modules/cacache/{index.js → lib/index.js} +5 -6
- package/dist/node_modules/cacache/lib/memoization.js +10 -11
- package/dist/node_modules/cacache/{put.js → lib/put.js} +23 -26
- package/dist/node_modules/cacache/{rm.js → lib/rm.js} +3 -3
- package/dist/node_modules/cacache/lib/util/fix-owner.js +41 -38
- package/dist/node_modules/cacache/lib/util/move-file.js +36 -47
- package/dist/node_modules/cacache/lib/util/tmp.js +5 -7
- package/dist/node_modules/cacache/lib/verify.js +160 -190
- package/dist/node_modules/cacache/node_modules/brace-expansion/.github/FUNDING.yml +2 -0
- package/dist/node_modules/cacache/node_modules/brace-expansion/LICENSE +21 -0
- package/dist/node_modules/cacache/node_modules/brace-expansion/index.js +203 -0
- package/dist/node_modules/cacache/node_modules/brace-expansion/package.json +46 -0
- package/dist/node_modules/cacache/node_modules/glob/LICENSE +15 -0
- package/dist/node_modules/cacache/node_modules/glob/common.js +240 -0
- package/dist/node_modules/cacache/node_modules/glob/glob.js +790 -0
- package/dist/node_modules/cacache/node_modules/glob/package.json +55 -0
- package/dist/node_modules/cacache/node_modules/glob/sync.js +486 -0
- package/dist/node_modules/cacache/node_modules/minimatch/LICENSE +15 -0
- package/dist/node_modules/cacache/node_modules/minimatch/lib/path.js +4 -0
- package/dist/node_modules/cacache/node_modules/minimatch/minimatch.js +906 -0
- package/dist/node_modules/cacache/node_modules/minimatch/package.json +32 -0
- package/dist/node_modules/cacache/package.json +34 -30
- package/dist/node_modules/http-proxy-agent/dist/agent.js +3 -3
- package/dist/node_modules/http-proxy-agent/dist/agent.js.map +1 -1
- package/dist/node_modules/http-proxy-agent/package.json +4 -4
- package/dist/node_modules/lru-cache/LICENSE +1 -1
- package/dist/node_modules/lru-cache/index.js +921 -247
- package/dist/node_modules/lru-cache/package.json +49 -9
- package/dist/node_modules/make-fetch-happen/LICENSE +1 -1
- package/dist/node_modules/make-fetch-happen/lib/agent.js +34 -14
- package/dist/node_modules/make-fetch-happen/lib/cache/entry.js +90 -106
- package/dist/node_modules/make-fetch-happen/lib/cache/errors.js +1 -0
- package/dist/node_modules/make-fetch-happen/lib/cache/index.js +10 -6
- package/dist/node_modules/make-fetch-happen/lib/cache/policy.js +21 -21
- package/dist/node_modules/make-fetch-happen/lib/dns.js +49 -0
- package/dist/node_modules/make-fetch-happen/lib/fetch.js +40 -22
- package/dist/node_modules/make-fetch-happen/lib/index.js +4 -3
- package/dist/node_modules/make-fetch-happen/lib/options.js +17 -9
- package/dist/node_modules/make-fetch-happen/lib/pipeline.js +41 -0
- package/dist/node_modules/make-fetch-happen/lib/remote.js +28 -9
- package/dist/node_modules/make-fetch-happen/package.json +36 -33
- package/dist/node_modules/minipass-fetch/lib/blob.js +4 -4
- package/dist/node_modules/minipass-fetch/lib/body.js +63 -49
- package/dist/node_modules/minipass-fetch/lib/fetch-error.js +2 -1
- package/dist/node_modules/minipass-fetch/lib/headers.js +38 -21
- package/dist/node_modules/minipass-fetch/lib/index.js +130 -106
- package/dist/node_modules/minipass-fetch/lib/request.js +46 -28
- package/dist/node_modules/minipass-fetch/lib/response.js +3 -2
- package/dist/node_modules/minipass-fetch/package.json +27 -14
- package/dist/node_modules/node-gyp/.github/workflows/release-please.yml +1 -1
- package/dist/node_modules/node-gyp/.github/workflows/tests.yml +16 -9
- package/dist/node_modules/node-gyp/.github/workflows/visual-studio.yml +16 -8
- package/dist/node_modules/node-gyp/lib/build.js +7 -0
- package/dist/node_modules/node-gyp/lib/configure.js +26 -1
- package/dist/node_modules/node-gyp/lib/create-config-gypi.js +2 -1
- package/dist/node_modules/node-gyp/lib/find-visualstudio.js +9 -8
- package/dist/node_modules/node-gyp/lib/node-gyp.js +4 -0
- package/dist/node_modules/node-gyp/package.json +4 -4
- package/dist/node_modules/semver/node_modules/lru-cache/LICENSE +15 -0
- package/dist/node_modules/semver/node_modules/lru-cache/index.js +334 -0
- package/dist/node_modules/semver/node_modules/lru-cache/package.json +34 -0
- package/dist/node_modules/socks-proxy-agent/dist/index.js +3 -3
- package/dist/node_modules/socks-proxy-agent/dist/index.js.map +1 -1
- package/dist/node_modules/socks-proxy-agent/package.json +2 -2
- package/dist/node_modules/ssri/{index.js → lib/index.js} +78 -24
- package/dist/node_modules/ssri/package.json +27 -16
- package/dist/pnpm.cjs +67042 -65886
- package/package.json +6 -6
- package/dist/node_modules/@npmcli/fs/lib/common/file-url-to-path/index.js +0 -17
- package/dist/node_modules/@npmcli/fs/lib/common/file-url-to-path/polyfill.js +0 -121
- package/dist/node_modules/@npmcli/fs/lib/mkdir/index.js +0 -32
- package/dist/node_modules/@npmcli/fs/lib/mkdir/polyfill.js +0 -81
- package/dist/node_modules/cacache/lib/util/disposer.js +0 -30
- package/dist/node_modules/cacache/ls.js +0 -6
- package/dist/node_modules/cacache/verify.js +0 -3
- package/dist/node_modules/minipass-fetch/index.js +0 -1
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const util = require('util')
|
|
4
4
|
const crypto = require('crypto')
|
|
5
|
-
const fs = require('fs')
|
|
5
|
+
const fs = require('@npmcli/fs')
|
|
6
6
|
const Minipass = require('minipass')
|
|
7
7
|
const path = require('path')
|
|
8
8
|
const ssri = require('ssri')
|
|
9
9
|
const uniqueFilename = require('unique-filename')
|
|
10
10
|
|
|
11
|
-
const { disposer } = require('./util/disposer')
|
|
12
11
|
const contentPath = require('./content/path')
|
|
13
12
|
const fixOwner = require('./util/fix-owner')
|
|
14
13
|
const hashToSegments = require('./util/hash-to-segments')
|
|
@@ -18,11 +17,6 @@ const _rimraf = require('rimraf')
|
|
|
18
17
|
const rimraf = util.promisify(_rimraf)
|
|
19
18
|
rimraf.sync = _rimraf.sync
|
|
20
19
|
|
|
21
|
-
const appendFile = util.promisify(fs.appendFile)
|
|
22
|
-
const readFile = util.promisify(fs.readFile)
|
|
23
|
-
const readdir = util.promisify(fs.readdir)
|
|
24
|
-
const writeFile = util.promisify(fs.writeFile)
|
|
25
|
-
|
|
26
20
|
module.exports.NotFoundError = class NotFoundError extends Error {
|
|
27
21
|
constructor (cache, key) {
|
|
28
22
|
super(`No cache entry for ${key} found in ${cache}`)
|
|
@@ -49,8 +43,9 @@ async function compact (cache, key, matchFn, opts = {}) {
|
|
|
49
43
|
// if the integrity is null and no validateEntry is provided, we break
|
|
50
44
|
// as we consider the null integrity to be a deletion of everything
|
|
51
45
|
// that came before it.
|
|
52
|
-
if (entry.integrity === null && !opts.validateEntry)
|
|
46
|
+
if (entry.integrity === null && !opts.validateEntry) {
|
|
53
47
|
break
|
|
48
|
+
}
|
|
54
49
|
|
|
55
50
|
// if this entry is valid, and it is either the first entry or
|
|
56
51
|
// the newEntries array doesn't already include an entry that
|
|
@@ -58,8 +53,9 @@ async function compact (cache, key, matchFn, opts = {}) {
|
|
|
58
53
|
// it to the beginning of our list
|
|
59
54
|
if ((!opts.validateEntry || opts.validateEntry(entry) === true) &&
|
|
60
55
|
(newEntries.length === 0 ||
|
|
61
|
-
!newEntries.find((oldEntry) => matchFn(oldEntry, entry))))
|
|
56
|
+
!newEntries.find((oldEntry) => matchFn(oldEntry, entry)))) {
|
|
62
57
|
newEntries.unshift(entry)
|
|
58
|
+
}
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
const newIndex = '\n' + newEntries.map((entry) => {
|
|
@@ -78,12 +74,13 @@ async function compact (cache, key, matchFn, opts = {}) {
|
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
const teardown = async (tmp) => {
|
|
81
|
-
if (!tmp.moved)
|
|
77
|
+
if (!tmp.moved) {
|
|
82
78
|
return rimraf(tmp.target)
|
|
79
|
+
}
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
const write = async (tmp) => {
|
|
86
|
-
await writeFile(tmp.target, newIndex, { flag: 'wx' })
|
|
83
|
+
await fs.writeFile(tmp.target, newIndex, { flag: 'wx' })
|
|
87
84
|
await fixOwner.mkdirfix(cache, path.dirname(bucket))
|
|
88
85
|
// we use @npmcli/move-file directly here because we
|
|
89
86
|
// want to overwrite the existing file
|
|
@@ -92,13 +89,19 @@ async function compact (cache, key, matchFn, opts = {}) {
|
|
|
92
89
|
try {
|
|
93
90
|
await fixOwner.chownr(cache, bucket)
|
|
94
91
|
} catch (err) {
|
|
95
|
-
if (err.code !== 'ENOENT')
|
|
92
|
+
if (err.code !== 'ENOENT') {
|
|
96
93
|
throw err
|
|
94
|
+
}
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
// write the file atomically
|
|
101
|
-
await
|
|
99
|
+
const tmp = await setup()
|
|
100
|
+
try {
|
|
101
|
+
await write(tmp)
|
|
102
|
+
} finally {
|
|
103
|
+
await teardown(tmp)
|
|
104
|
+
}
|
|
102
105
|
|
|
103
106
|
// we reverse the list we generated such that the newest
|
|
104
107
|
// entries come first in order to make looping through them easier
|
|
@@ -110,7 +113,7 @@ async function compact (cache, key, matchFn, opts = {}) {
|
|
|
110
113
|
|
|
111
114
|
module.exports.insert = insert
|
|
112
115
|
|
|
113
|
-
function insert (cache, key, integrity, opts = {}) {
|
|
116
|
+
async function insert (cache, key, integrity, opts = {}) {
|
|
114
117
|
const { metadata, size } = opts
|
|
115
118
|
const bucket = bucketPath(cache, key)
|
|
116
119
|
const entry = {
|
|
@@ -120,35 +123,32 @@ function insert (cache, key, integrity, opts = {}) {
|
|
|
120
123
|
size,
|
|
121
124
|
metadata,
|
|
122
125
|
}
|
|
123
|
-
|
|
124
|
-
.mkdirfix(cache, path.dirname(bucket))
|
|
125
|
-
.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return undefined
|
|
126
|
+
try {
|
|
127
|
+
await fixOwner.mkdirfix(cache, path.dirname(bucket))
|
|
128
|
+
const stringified = JSON.stringify(entry)
|
|
129
|
+
// NOTE - Cleverness ahoy!
|
|
130
|
+
//
|
|
131
|
+
// This works because it's tremendously unlikely for an entry to corrupt
|
|
132
|
+
// another while still preserving the string length of the JSON in
|
|
133
|
+
// question. So, we just slap the length in there and verify it on read.
|
|
134
|
+
//
|
|
135
|
+
// Thanks to @isaacs for the whiteboarding session that ended up with
|
|
136
|
+
// this.
|
|
137
|
+
await fs.appendFile(bucket, `\n${hashEntry(stringified)}\t${stringified}`)
|
|
138
|
+
await fixOwner.chownr(cache, bucket)
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err.code === 'ENOENT') {
|
|
141
|
+
return undefined
|
|
142
|
+
}
|
|
141
143
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return formatEntry(cache, entry)
|
|
151
|
-
})
|
|
144
|
+
throw err
|
|
145
|
+
// There's a class of race conditions that happen when things get deleted
|
|
146
|
+
// during fixOwner, or between the two mkdirfix/chownr calls.
|
|
147
|
+
//
|
|
148
|
+
// It's perfectly fine to just not bother in those cases and lie
|
|
149
|
+
// that the index entry was written. Because it's a cache.
|
|
150
|
+
}
|
|
151
|
+
return formatEntry(cache, entry)
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
module.exports.insert.sync = insertSync
|
|
@@ -169,31 +169,33 @@ function insertSync (cache, key, integrity, opts = {}) {
|
|
|
169
169
|
try {
|
|
170
170
|
fixOwner.chownr.sync(cache, bucket)
|
|
171
171
|
} catch (err) {
|
|
172
|
-
if (err.code !== 'ENOENT')
|
|
172
|
+
if (err.code !== 'ENOENT') {
|
|
173
173
|
throw err
|
|
174
|
+
}
|
|
174
175
|
}
|
|
175
176
|
return formatEntry(cache, entry)
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
module.exports.find = find
|
|
179
180
|
|
|
180
|
-
function find (cache, key) {
|
|
181
|
+
async function find (cache, key) {
|
|
181
182
|
const bucket = bucketPath(cache, key)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
183
|
+
try {
|
|
184
|
+
const entries = await bucketEntries(bucket)
|
|
185
|
+
return entries.reduce((latest, next) => {
|
|
186
|
+
if (next && next.key === key) {
|
|
187
|
+
return formatEntry(cache, next)
|
|
188
|
+
} else {
|
|
189
|
+
return latest
|
|
190
|
+
}
|
|
191
|
+
}, null)
|
|
192
|
+
} catch (err) {
|
|
193
|
+
if (err.code === 'ENOENT') {
|
|
194
|
+
return null
|
|
195
|
+
} else {
|
|
196
|
+
throw err
|
|
197
|
+
}
|
|
198
|
+
}
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
module.exports.find.sync = findSync
|
|
@@ -202,24 +204,27 @@ function findSync (cache, key) {
|
|
|
202
204
|
const bucket = bucketPath(cache, key)
|
|
203
205
|
try {
|
|
204
206
|
return bucketEntriesSync(bucket).reduce((latest, next) => {
|
|
205
|
-
if (next && next.key === key)
|
|
207
|
+
if (next && next.key === key) {
|
|
206
208
|
return formatEntry(cache, next)
|
|
207
|
-
else
|
|
209
|
+
} else {
|
|
208
210
|
return latest
|
|
211
|
+
}
|
|
209
212
|
}, null)
|
|
210
213
|
} catch (err) {
|
|
211
|
-
if (err.code === 'ENOENT')
|
|
214
|
+
if (err.code === 'ENOENT') {
|
|
212
215
|
return null
|
|
213
|
-
else
|
|
216
|
+
} else {
|
|
214
217
|
throw err
|
|
218
|
+
}
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
|
|
218
222
|
module.exports.delete = del
|
|
219
223
|
|
|
220
224
|
function del (cache, key, opts = {}) {
|
|
221
|
-
if (!opts.removeFully)
|
|
225
|
+
if (!opts.removeFully) {
|
|
222
226
|
return insert(cache, key, null, opts)
|
|
227
|
+
}
|
|
223
228
|
|
|
224
229
|
const bucket = bucketPath(cache, key)
|
|
225
230
|
return rimraf(bucket)
|
|
@@ -228,8 +233,9 @@ function del (cache, key, opts = {}) {
|
|
|
228
233
|
module.exports.delete.sync = delSync
|
|
229
234
|
|
|
230
235
|
function delSync (cache, key, opts = {}) {
|
|
231
|
-
if (!opts.removeFully)
|
|
236
|
+
if (!opts.removeFully) {
|
|
232
237
|
return insertSync(cache, key, null, opts)
|
|
238
|
+
}
|
|
233
239
|
|
|
234
240
|
const bucket = bucketPath(cache, key)
|
|
235
241
|
return rimraf.sync(bucket)
|
|
@@ -241,65 +247,65 @@ function lsStream (cache) {
|
|
|
241
247
|
const indexDir = bucketDir(cache)
|
|
242
248
|
const stream = new Minipass({ objectMode: true })
|
|
243
249
|
|
|
244
|
-
|
|
245
|
-
|
|
250
|
+
// Set all this up to run on the stream and then just return the stream
|
|
251
|
+
Promise.resolve().then(async () => {
|
|
252
|
+
const buckets = await readdirOrEmpty(indexDir)
|
|
253
|
+
await Promise.all(buckets.map(async (bucket) => {
|
|
246
254
|
const bucketPath = path.join(indexDir, bucket)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
})
|
|
277
|
-
))
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
err => stream.emit('error', err)
|
|
283
|
-
)
|
|
255
|
+
const subbuckets = await readdirOrEmpty(bucketPath)
|
|
256
|
+
await Promise.all(subbuckets.map(async (subbucket) => {
|
|
257
|
+
const subbucketPath = path.join(bucketPath, subbucket)
|
|
258
|
+
|
|
259
|
+
// "/cachename/<bucket 0xFF>/<bucket 0xFF>./*"
|
|
260
|
+
const subbucketEntries = await readdirOrEmpty(subbucketPath)
|
|
261
|
+
await Promise.all(subbucketEntries.map(async (entry) => {
|
|
262
|
+
const entryPath = path.join(subbucketPath, entry)
|
|
263
|
+
try {
|
|
264
|
+
const entries = await bucketEntries(entryPath)
|
|
265
|
+
// using a Map here prevents duplicate keys from showing up
|
|
266
|
+
// twice, I guess?
|
|
267
|
+
const reduced = entries.reduce((acc, entry) => {
|
|
268
|
+
acc.set(entry.key, entry)
|
|
269
|
+
return acc
|
|
270
|
+
}, new Map())
|
|
271
|
+
// reduced is a map of key => entry
|
|
272
|
+
for (const entry of reduced.values()) {
|
|
273
|
+
const formatted = formatEntry(cache, entry)
|
|
274
|
+
if (formatted) {
|
|
275
|
+
stream.write(formatted)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} catch (err) {
|
|
279
|
+
if (err.code === 'ENOENT') {
|
|
280
|
+
return undefined
|
|
281
|
+
}
|
|
282
|
+
throw err
|
|
283
|
+
}
|
|
284
|
+
}))
|
|
285
|
+
}))
|
|
286
|
+
}))
|
|
287
|
+
stream.end()
|
|
288
|
+
return stream
|
|
289
|
+
}).catch(err => stream.emit('error', err))
|
|
284
290
|
|
|
285
291
|
return stream
|
|
286
292
|
}
|
|
287
293
|
|
|
288
294
|
module.exports.ls = ls
|
|
289
295
|
|
|
290
|
-
function ls (cache) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
)
|
|
296
|
+
async function ls (cache) {
|
|
297
|
+
const entries = await lsStream(cache).collect()
|
|
298
|
+
return entries.reduce((acc, xs) => {
|
|
299
|
+
acc[xs.key] = xs
|
|
300
|
+
return acc
|
|
301
|
+
}, {})
|
|
297
302
|
}
|
|
298
303
|
|
|
299
304
|
module.exports.bucketEntries = bucketEntries
|
|
300
305
|
|
|
301
|
-
function bucketEntries (bucket, filter) {
|
|
302
|
-
|
|
306
|
+
async function bucketEntries (bucket, filter) {
|
|
307
|
+
const data = await fs.readFile(bucket, 'utf8')
|
|
308
|
+
return _bucketEntries(data, filter)
|
|
303
309
|
}
|
|
304
310
|
|
|
305
311
|
module.exports.bucketEntries.sync = bucketEntriesSync
|
|
@@ -312,8 +318,9 @@ function bucketEntriesSync (bucket, filter) {
|
|
|
312
318
|
function _bucketEntries (data, filter) {
|
|
313
319
|
const entries = []
|
|
314
320
|
data.split('\n').forEach((entry) => {
|
|
315
|
-
if (!entry)
|
|
321
|
+
if (!entry) {
|
|
316
322
|
return
|
|
323
|
+
}
|
|
317
324
|
|
|
318
325
|
const pieces = entry.split('\t')
|
|
319
326
|
if (!pieces[1] || hashEntry(pieces[1]) !== pieces[0]) {
|
|
@@ -328,8 +335,9 @@ function _bucketEntries (data, filter) {
|
|
|
328
335
|
// Entry is corrupted!
|
|
329
336
|
return
|
|
330
337
|
}
|
|
331
|
-
if (obj)
|
|
338
|
+
if (obj) {
|
|
332
339
|
entries.push(obj)
|
|
340
|
+
}
|
|
333
341
|
})
|
|
334
342
|
return entries
|
|
335
343
|
}
|
|
@@ -371,8 +379,9 @@ function hash (str, digest) {
|
|
|
371
379
|
|
|
372
380
|
function formatEntry (cache, entry, keepAll) {
|
|
373
381
|
// Treat null digests as deletions. They'll shadow any previous entries.
|
|
374
|
-
if (!entry.integrity && !keepAll)
|
|
382
|
+
if (!entry.integrity && !keepAll) {
|
|
375
383
|
return null
|
|
384
|
+
}
|
|
376
385
|
|
|
377
386
|
return {
|
|
378
387
|
key: entry.key,
|
|
@@ -385,9 +394,10 @@ function formatEntry (cache, entry, keepAll) {
|
|
|
385
394
|
}
|
|
386
395
|
|
|
387
396
|
function readdirOrEmpty (dir) {
|
|
388
|
-
return readdir(dir).catch((err) => {
|
|
389
|
-
if (err.code === 'ENOENT' || err.code === 'ENOTDIR')
|
|
397
|
+
return fs.readdir(dir).catch((err) => {
|
|
398
|
+
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
|
|
390
399
|
return []
|
|
400
|
+
}
|
|
391
401
|
|
|
392
402
|
throw err
|
|
393
403
|
})
|
|
@@ -3,57 +3,53 @@
|
|
|
3
3
|
const Collect = require('minipass-collect')
|
|
4
4
|
const Minipass = require('minipass')
|
|
5
5
|
const Pipeline = require('minipass-pipeline')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const util = require('util')
|
|
8
6
|
|
|
9
|
-
const index = require('./
|
|
10
|
-
const memo = require('./
|
|
11
|
-
const read = require('./
|
|
7
|
+
const index = require('./entry-index')
|
|
8
|
+
const memo = require('./memoization')
|
|
9
|
+
const read = require('./content/read')
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function getData (cache, key, opts = {}) {
|
|
11
|
+
async function getData (cache, key, opts = {}) {
|
|
16
12
|
const { integrity, memoize, size } = opts
|
|
17
13
|
const memoized = memo.get(cache, key, opts)
|
|
18
14
|
if (memoized && memoize !== false) {
|
|
19
|
-
return
|
|
15
|
+
return {
|
|
20
16
|
metadata: memoized.entry.metadata,
|
|
21
17
|
data: memoized.data,
|
|
22
18
|
integrity: memoized.entry.integrity,
|
|
23
19
|
size: memoized.entry.size,
|
|
24
|
-
}
|
|
20
|
+
}
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
const entry = await index.find(cache, key, opts)
|
|
24
|
+
if (!entry) {
|
|
25
|
+
throw new index.NotFoundError(cache, key)
|
|
26
|
+
}
|
|
27
|
+
const data = await read(cache, entry.integrity, { integrity, size })
|
|
28
|
+
if (memoize) {
|
|
29
|
+
memo.put(cache, entry, data, opts)
|
|
30
|
+
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
-
})
|
|
32
|
+
return {
|
|
33
|
+
data,
|
|
34
|
+
metadata: entry.metadata,
|
|
35
|
+
size: entry.size,
|
|
36
|
+
integrity: entry.integrity,
|
|
37
|
+
}
|
|
43
38
|
}
|
|
44
39
|
module.exports = getData
|
|
45
40
|
|
|
46
|
-
function getDataByDigest (cache, key, opts = {}) {
|
|
41
|
+
async function getDataByDigest (cache, key, opts = {}) {
|
|
47
42
|
const { integrity, memoize, size } = opts
|
|
48
43
|
const memoized = memo.get.byDigest(cache, key, opts)
|
|
49
|
-
if (memoized && memoize !== false)
|
|
50
|
-
return
|
|
44
|
+
if (memoized && memoize !== false) {
|
|
45
|
+
return memoized
|
|
46
|
+
}
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
const res = await read(cache, key, { integrity, size })
|
|
49
|
+
if (memoize) {
|
|
50
|
+
memo.put.byDigest(cache, key, res, opts)
|
|
51
|
+
}
|
|
52
|
+
return res
|
|
57
53
|
}
|
|
58
54
|
module.exports.byDigest = getDataByDigest
|
|
59
55
|
|
|
@@ -70,8 +66,9 @@ function getDataSync (cache, key, opts = {}) {
|
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
68
|
const entry = index.find.sync(cache, key, opts)
|
|
73
|
-
if (!entry)
|
|
69
|
+
if (!entry) {
|
|
74
70
|
throw new index.NotFoundError(cache, key)
|
|
71
|
+
}
|
|
75
72
|
const data = read.sync(cache, entry.integrity, {
|
|
76
73
|
integrity: integrity,
|
|
77
74
|
size: size,
|
|
@@ -82,8 +79,9 @@ function getDataSync (cache, key, opts = {}) {
|
|
|
82
79
|
size: entry.size,
|
|
83
80
|
integrity: entry.integrity,
|
|
84
81
|
}
|
|
85
|
-
if (memoize)
|
|
82
|
+
if (memoize) {
|
|
86
83
|
memo.put(cache, entry, res.data, opts)
|
|
84
|
+
}
|
|
87
85
|
|
|
88
86
|
return res
|
|
89
87
|
}
|
|
@@ -94,15 +92,17 @@ function getDataByDigestSync (cache, digest, opts = {}) {
|
|
|
94
92
|
const { integrity, memoize, size } = opts
|
|
95
93
|
const memoized = memo.get.byDigest(cache, digest, opts)
|
|
96
94
|
|
|
97
|
-
if (memoized && memoize !== false)
|
|
95
|
+
if (memoized && memoize !== false) {
|
|
98
96
|
return memoized
|
|
97
|
+
}
|
|
99
98
|
|
|
100
99
|
const res = read.sync(cache, digest, {
|
|
101
100
|
integrity: integrity,
|
|
102
101
|
size: size,
|
|
103
102
|
})
|
|
104
|
-
if (memoize)
|
|
103
|
+
if (memoize) {
|
|
105
104
|
memo.put.byDigest(cache, digest, res, opts)
|
|
105
|
+
}
|
|
106
106
|
|
|
107
107
|
return res
|
|
108
108
|
}
|
|
@@ -122,39 +122,41 @@ const getMemoizedStream = (memoized) => {
|
|
|
122
122
|
function getStream (cache, key, opts = {}) {
|
|
123
123
|
const { memoize, size } = opts
|
|
124
124
|
const memoized = memo.get(cache, key, opts)
|
|
125
|
-
if (memoized && memoize !== false)
|
|
125
|
+
if (memoized && memoize !== false) {
|
|
126
126
|
return getMemoizedStream(memoized)
|
|
127
|
+
}
|
|
127
128
|
|
|
128
129
|
const stream = new Pipeline()
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const src = read.readStream(
|
|
145
|
-
cache,
|
|
146
|
-
entry.integrity,
|
|
147
|
-
{ ...opts, size: typeof size !== 'number' ? entry.size : size }
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
if (memoize) {
|
|
151
|
-
const memoStream = new Collect.PassThrough()
|
|
152
|
-
memoStream.on('collect', data => memo.put(cache, entry, data, opts))
|
|
153
|
-
stream.unshift(memoStream)
|
|
154
|
-
}
|
|
155
|
-
stream.unshift(src)
|
|
130
|
+
// Set all this up to run on the stream and then just return the stream
|
|
131
|
+
Promise.resolve().then(async () => {
|
|
132
|
+
const entry = await index.find(cache, key)
|
|
133
|
+
if (!entry) {
|
|
134
|
+
throw new index.NotFoundError(cache, key)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
stream.emit('metadata', entry.metadata)
|
|
138
|
+
stream.emit('integrity', entry.integrity)
|
|
139
|
+
stream.emit('size', entry.size)
|
|
140
|
+
stream.on('newListener', function (ev, cb) {
|
|
141
|
+
ev === 'metadata' && cb(entry.metadata)
|
|
142
|
+
ev === 'integrity' && cb(entry.integrity)
|
|
143
|
+
ev === 'size' && cb(entry.size)
|
|
156
144
|
})
|
|
157
|
-
|
|
145
|
+
|
|
146
|
+
const src = read.readStream(
|
|
147
|
+
cache,
|
|
148
|
+
entry.integrity,
|
|
149
|
+
{ ...opts, size: typeof size !== 'number' ? entry.size : size }
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
if (memoize) {
|
|
153
|
+
const memoStream = new Collect.PassThrough()
|
|
154
|
+
memoStream.on('collect', data => memo.put(cache, entry, data, opts))
|
|
155
|
+
stream.unshift(memoStream)
|
|
156
|
+
}
|
|
157
|
+
stream.unshift(src)
|
|
158
|
+
return stream
|
|
159
|
+
}).catch((err) => stream.emit('error', err))
|
|
158
160
|
|
|
159
161
|
return stream
|
|
160
162
|
}
|
|
@@ -170,8 +172,9 @@ function getStreamDigest (cache, integrity, opts = {}) {
|
|
|
170
172
|
return stream
|
|
171
173
|
} else {
|
|
172
174
|
const stream = read.readStream(cache, integrity, opts)
|
|
173
|
-
if (!memoize)
|
|
175
|
+
if (!memoize) {
|
|
174
176
|
return stream
|
|
177
|
+
}
|
|
175
178
|
|
|
176
179
|
const memoStream = new Collect.PassThrough()
|
|
177
180
|
memoStream.on('collect', data => memo.put.byDigest(
|
|
@@ -189,49 +192,34 @@ module.exports.stream.byDigest = getStreamDigest
|
|
|
189
192
|
function info (cache, key, opts = {}) {
|
|
190
193
|
const { memoize } = opts
|
|
191
194
|
const memoized = memo.get(cache, key, opts)
|
|
192
|
-
if (memoized && memoize !== false)
|
|
195
|
+
if (memoized && memoize !== false) {
|
|
193
196
|
return Promise.resolve(memoized.entry)
|
|
194
|
-
else
|
|
197
|
+
} else {
|
|
195
198
|
return index.find(cache, key)
|
|
199
|
+
}
|
|
196
200
|
}
|
|
197
201
|
module.exports.info = info
|
|
198
202
|
|
|
199
|
-
function copy (cache, key, dest, opts = {}) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
integrity: entry.integrity,
|
|
210
|
-
}
|
|
211
|
-
})
|
|
212
|
-
})
|
|
203
|
+
async function copy (cache, key, dest, opts = {}) {
|
|
204
|
+
const entry = await index.find(cache, key, opts)
|
|
205
|
+
if (!entry) {
|
|
206
|
+
throw new index.NotFoundError(cache, key)
|
|
207
|
+
}
|
|
208
|
+
await read.copy(cache, entry.integrity, dest, opts)
|
|
209
|
+
return {
|
|
210
|
+
metadata: entry.metadata,
|
|
211
|
+
size: entry.size,
|
|
212
|
+
integrity: entry.integrity,
|
|
213
213
|
}
|
|
214
|
-
|
|
215
|
-
return getData(cache, key, opts).then((res) => {
|
|
216
|
-
return writeFile(dest, res.data).then(() => {
|
|
217
|
-
return {
|
|
218
|
-
metadata: res.metadata,
|
|
219
|
-
size: res.size,
|
|
220
|
-
integrity: res.integrity,
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
})
|
|
224
214
|
}
|
|
225
|
-
module.exports.copy = copy
|
|
226
215
|
|
|
227
|
-
|
|
228
|
-
if (read.copy)
|
|
229
|
-
return read.copy(cache, key, dest, opts).then(() => key)
|
|
216
|
+
module.exports.copy = copy
|
|
230
217
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
218
|
+
async function copyByDigest (cache, key, dest, opts = {}) {
|
|
219
|
+
await read.copy(cache, key, dest, opts)
|
|
220
|
+
return key
|
|
234
221
|
}
|
|
222
|
+
|
|
235
223
|
module.exports.copy.byDigest = copyByDigest
|
|
236
224
|
|
|
237
225
|
module.exports.hasContent = read.hasContent
|