cacache 14.0.0 → 15.0.3
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/CHANGELOG.md +29 -0
- package/README.md +63 -9
- package/get.js +28 -39
- package/lib/content/.write.js.swp +0 -0
- package/lib/content/read.js +15 -23
- package/lib/content/write.js +10 -13
- package/lib/entry-index.js +9 -15
- package/lib/util/.move-file.js.swp +0 -0
- package/lib/util/move-file.js +4 -3
- package/lib/util/tmp.js +4 -11
- package/lib/verify.js +6 -11
- package/package.json +22 -26
- package/put.js +14 -24
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
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.
|
|
4
4
|
|
|
5
|
+
### [15.0.3](https://github.com/npm/cacache/compare/v15.0.2...v15.0.3) (2020-04-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* actually remove move-concurrently dep ([29e6eec](https://github.com/npm/cacache/commit/29e6eec9fee73444ee09daf1c1be06ddd5fe57f6))
|
|
11
|
+
|
|
12
|
+
### [15.0.2](https://github.com/npm/cacache/compare/v15.0.1...v15.0.2) (2020-04-28)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* tacks should be a dev dependency ([93ec158](https://github.com/npm/cacache/commit/93ec15852f0fdf1753ea7f75b4b8926daf8a7565))
|
|
18
|
+
|
|
19
|
+
## [15.0.1](https://github.com/npm/cacache/compare/v15.0.0...v15.0.1) (2020-04-27)
|
|
20
|
+
|
|
21
|
+
* **deps:** Use move-file instead of move-file-concurrently. ([92b125](https://github.com/npm/cacache/commit/92b1251a11b9848878b6c0d101b18bd8845acaa6))
|
|
22
|
+
|
|
23
|
+
## [15.0.0](https://github.com/npm/cacache/compare/v14.0.0...v15.0.0) (2020-02-18)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### ⚠ BREAKING CHANGES
|
|
27
|
+
|
|
28
|
+
* drop figgy-pudding and use canonical option names.
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* remove figgy-pudding ([57d11bc](https://github.com/npm/cacache/commit/57d11bce34f979247d1057d258acc204c4944491))
|
|
33
|
+
|
|
5
34
|
## [14.0.0](https://github.com/npm/cacache/compare/v13.0.1...v14.0.0) (2020-01-28)
|
|
6
35
|
|
|
7
36
|
|
package/README.md
CHANGED
|
@@ -33,7 +33,6 @@ just as easily be used on its own.
|
|
|
33
33
|
* Writing
|
|
34
34
|
* [`put`](#put-data)
|
|
35
35
|
* [`put.stream`](#put-stream)
|
|
36
|
-
* [`put*` opts](#put-options)
|
|
37
36
|
* [`rm.all`](#rm-all)
|
|
38
37
|
* [`rm.entry`](#rm-entry)
|
|
39
38
|
* [`rm.content`](#rm-content)
|
|
@@ -92,7 +91,7 @@ cacache.get.byDigest(cachePath, integrityHash).then(data => {
|
|
|
92
91
|
* Lockless, high-concurrency cache access
|
|
93
92
|
* Streaming support
|
|
94
93
|
* Promise support
|
|
95
|
-
*
|
|
94
|
+
* Fast -- sub-millisecond reads and writes including verification
|
|
96
95
|
* Arbitrary metadata storage
|
|
97
96
|
* Garbage collection and additional offline verification
|
|
98
97
|
* Thorough test coverage
|
|
@@ -201,6 +200,8 @@ A sub-function, `get.byDigest` may be used for identical behavior, except lookup
|
|
|
201
200
|
will happen by integrity hash, bypassing the index entirely. This version of the
|
|
202
201
|
function *only* returns `data` itself, without any wrapper.
|
|
203
202
|
|
|
203
|
+
See: [options](#get-options)
|
|
204
|
+
|
|
204
205
|
##### Note
|
|
205
206
|
|
|
206
207
|
This function loads the entire cache entry into memory before returning it. If
|
|
@@ -242,6 +243,8 @@ A sub-function, `get.stream.byDigest` may be used for identical behavior,
|
|
|
242
243
|
except lookup will happen by integrity hash, bypassing the index entirely. This
|
|
243
244
|
version does not emit the `metadata` and `integrity` events at all.
|
|
244
245
|
|
|
246
|
+
See: [options](#get-options)
|
|
247
|
+
|
|
245
248
|
##### Example
|
|
246
249
|
|
|
247
250
|
```javascript
|
|
@@ -328,12 +331,33 @@ cacache.get.hasContent(cachePath, 'sha521-NOT+IN/CACHE==').then(console.log)
|
|
|
328
331
|
false
|
|
329
332
|
```
|
|
330
333
|
|
|
334
|
+
##### <a name="get-options"></a> Options
|
|
335
|
+
|
|
336
|
+
##### `opts.integrity`
|
|
337
|
+
If present, the pre-calculated digest for the inserted content. If this option
|
|
338
|
+
is provided and does not match the post-insertion digest, insertion will fail
|
|
339
|
+
with an `EINTEGRITY` error.
|
|
340
|
+
|
|
341
|
+
##### `opts.memoize`
|
|
342
|
+
|
|
343
|
+
Default: null
|
|
344
|
+
|
|
345
|
+
If explicitly truthy, cacache will read from memory and memoize data on bulk read. If `false`, cacache will read from disk data. Reader functions by default read from in-memory cache.
|
|
346
|
+
|
|
347
|
+
##### `opts.size`
|
|
348
|
+
If provided, the data stream will be verified to check that enough data was
|
|
349
|
+
passed through. If there's more or less data than expected, insertion will fail
|
|
350
|
+
with an `EBADSIZE` error.
|
|
351
|
+
|
|
352
|
+
|
|
331
353
|
#### <a name="put-data"></a> `> cacache.put(cache, key, data, [opts]) -> Promise`
|
|
332
354
|
|
|
333
355
|
Inserts data passed to it into the cache. The returned Promise resolves with a
|
|
334
356
|
digest (generated according to [`opts.algorithms`](#optsalgorithms)) after the
|
|
335
357
|
cache entry has been successfully written.
|
|
336
358
|
|
|
359
|
+
See: [options](#put-options)
|
|
360
|
+
|
|
337
361
|
##### Example
|
|
338
362
|
|
|
339
363
|
```javascript
|
|
@@ -353,6 +377,8 @@ Stream](https://nodejs.org/api/stream.html#stream_writable_streams) that inserts
|
|
|
353
377
|
data written to it into the cache. Emits an `integrity` event with the digest of
|
|
354
378
|
written contents when it succeeds.
|
|
355
379
|
|
|
380
|
+
See: [options](#put-options)
|
|
381
|
+
|
|
356
382
|
##### Example
|
|
357
383
|
|
|
358
384
|
```javascript
|
|
@@ -365,9 +391,7 @@ request.get(
|
|
|
365
391
|
)
|
|
366
392
|
```
|
|
367
393
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
`cacache.put` functions have a number of options in common.
|
|
394
|
+
##### <a name="put-options"></a> Options
|
|
371
395
|
|
|
372
396
|
##### `opts.metadata`
|
|
373
397
|
|
|
@@ -382,7 +406,7 @@ with an `EBADSIZE` error.
|
|
|
382
406
|
##### `opts.integrity`
|
|
383
407
|
|
|
384
408
|
If present, the pre-calculated digest for the inserted content. If this option
|
|
385
|
-
|
|
409
|
+
is provided and does not match the post-insertion digest, insertion will fail
|
|
386
410
|
with an `EINTEGRITY` error.
|
|
387
411
|
|
|
388
412
|
`algorithms` has no effect if this option is present.
|
|
@@ -415,6 +439,11 @@ cache.
|
|
|
415
439
|
Reading from disk data can be forced by explicitly passing `memoize: false` to
|
|
416
440
|
the reader functions, but their default will be to read from memory.
|
|
417
441
|
|
|
442
|
+
##### `opts.tmpPrefix`
|
|
443
|
+
Default: null
|
|
444
|
+
|
|
445
|
+
Prefix to append on the temporary directory name inside the cache's tmp dir.
|
|
446
|
+
|
|
418
447
|
#### <a name="rm-all"></a> `> cacache.rm.all(cache) -> Promise`
|
|
419
448
|
|
|
420
449
|
Clears the entire cache. Mainly by blowing away the cache directory itself.
|
|
@@ -478,6 +507,8 @@ permissions.
|
|
|
478
507
|
If you want automatic cleanup of this directory, use
|
|
479
508
|
[`tmp.withTmp()`](#with-tpm)
|
|
480
509
|
|
|
510
|
+
See: [options](#tmp-options)
|
|
511
|
+
|
|
481
512
|
##### Example
|
|
482
513
|
|
|
483
514
|
```javascript
|
|
@@ -517,6 +548,8 @@ promise completes.
|
|
|
517
548
|
The same caveats apply when it comes to managing permissions for the tmp dir's
|
|
518
549
|
contents.
|
|
519
550
|
|
|
551
|
+
See: [options](#tmp-options)
|
|
552
|
+
|
|
520
553
|
##### Example
|
|
521
554
|
|
|
522
555
|
```javascript
|
|
@@ -527,6 +560,13 @@ cacache.tmp.withTmp(cache, dir => {
|
|
|
527
560
|
})
|
|
528
561
|
```
|
|
529
562
|
|
|
563
|
+
##### <a name="tmp-options"></a> Options
|
|
564
|
+
|
|
565
|
+
##### `opts.tmpPrefix`
|
|
566
|
+
Default: null
|
|
567
|
+
|
|
568
|
+
Prefix to append on the temporary directory name inside the cache's tmp dir.
|
|
569
|
+
|
|
530
570
|
#### <a name="integrity"></a> Subresource Integrity Digests
|
|
531
571
|
|
|
532
572
|
For content verification and addressing, cacache uses strings following the
|
|
@@ -582,10 +622,24 @@ When it's done, it'll return an object with various stats about the verification
|
|
|
582
622
|
process, including amount of storage reclaimed, number of valid entries, number
|
|
583
623
|
of entries removed, etc.
|
|
584
624
|
|
|
585
|
-
##### Options
|
|
625
|
+
##### <a name="verify-options"></a> Options
|
|
626
|
+
|
|
627
|
+
##### `opts.concurrency`
|
|
628
|
+
|
|
629
|
+
Default: 20
|
|
586
630
|
|
|
587
|
-
|
|
588
|
-
|
|
631
|
+
Number of concurrently read files in the filesystem while doing clean up.
|
|
632
|
+
|
|
633
|
+
##### `opts.filter`
|
|
634
|
+
Receives a formatted entry. Return false to remove it.
|
|
635
|
+
Note: might be called more than once on the same entry.
|
|
636
|
+
|
|
637
|
+
##### `opts.log`
|
|
638
|
+
Custom logger function:
|
|
639
|
+
```
|
|
640
|
+
log: { silly () {} }
|
|
641
|
+
log.silly('verify', 'verifying cache at', cache)
|
|
642
|
+
```
|
|
589
643
|
|
|
590
644
|
##### Example
|
|
591
645
|
|
package/get.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const util = require('util')
|
|
4
|
-
|
|
5
|
-
const figgyPudding = require('figgy-pudding')
|
|
6
4
|
const fs = require('fs')
|
|
7
5
|
const index = require('./lib/entry-index')
|
|
8
6
|
const memo = require('./lib/memoization')
|
|
@@ -14,12 +12,6 @@ const Pipeline = require('minipass-pipeline')
|
|
|
14
12
|
|
|
15
13
|
const writeFile = util.promisify(fs.writeFile)
|
|
16
14
|
|
|
17
|
-
const GetOpts = figgyPudding({
|
|
18
|
-
integrity: {},
|
|
19
|
-
memoize: {},
|
|
20
|
-
size: {}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
15
|
module.exports = function get (cache, key, opts) {
|
|
24
16
|
return getData(false, cache, key, opts)
|
|
25
17
|
}
|
|
@@ -27,12 +19,12 @@ module.exports.byDigest = function getByDigest (cache, digest, opts) {
|
|
|
27
19
|
return getData(true, cache, digest, opts)
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
function getData (byDigest, cache, key, opts) {
|
|
31
|
-
|
|
22
|
+
function getData (byDigest, cache, key, opts = {}) {
|
|
23
|
+
const { integrity, memoize, size } = opts
|
|
32
24
|
const memoized = byDigest
|
|
33
25
|
? memo.get.byDigest(cache, key, opts)
|
|
34
26
|
: memo.get(cache, key, opts)
|
|
35
|
-
if (memoized &&
|
|
27
|
+
if (memoized && memoize !== false) {
|
|
36
28
|
return Promise.resolve(
|
|
37
29
|
byDigest
|
|
38
30
|
? memoized
|
|
@@ -50,23 +42,23 @@ function getData (byDigest, cache, key, opts) {
|
|
|
50
42
|
throw new index.NotFoundError(cache, key)
|
|
51
43
|
}
|
|
52
44
|
return read(cache, byDigest ? key : entry.integrity, {
|
|
53
|
-
integrity
|
|
54
|
-
size
|
|
45
|
+
integrity,
|
|
46
|
+
size
|
|
55
47
|
})
|
|
56
48
|
.then((data) =>
|
|
57
49
|
byDigest
|
|
58
50
|
? data
|
|
59
51
|
: {
|
|
52
|
+
data,
|
|
60
53
|
metadata: entry.metadata,
|
|
61
|
-
data: data,
|
|
62
54
|
size: entry.size,
|
|
63
55
|
integrity: entry.integrity
|
|
64
56
|
}
|
|
65
57
|
)
|
|
66
58
|
.then((res) => {
|
|
67
|
-
if (
|
|
59
|
+
if (memoize && byDigest) {
|
|
68
60
|
memo.put.byDigest(cache, key, res, opts)
|
|
69
|
-
} else if (
|
|
61
|
+
} else if (memoize) {
|
|
70
62
|
memo.put(cache, entry, res.data, opts)
|
|
71
63
|
}
|
|
72
64
|
return res
|
|
@@ -82,12 +74,12 @@ module.exports.sync.byDigest = function getByDigest (cache, digest, opts) {
|
|
|
82
74
|
return getDataSync(true, cache, digest, opts)
|
|
83
75
|
}
|
|
84
76
|
|
|
85
|
-
function getDataSync (byDigest, cache, key, opts) {
|
|
86
|
-
|
|
77
|
+
function getDataSync (byDigest, cache, key, opts = {}) {
|
|
78
|
+
const { integrity, memoize, size } = opts
|
|
87
79
|
const memoized = byDigest
|
|
88
80
|
? memo.get.byDigest(cache, key, opts)
|
|
89
81
|
: memo.get(cache, key, opts)
|
|
90
|
-
if (memoized &&
|
|
82
|
+
if (memoized && memoize !== false) {
|
|
91
83
|
return byDigest
|
|
92
84
|
? memoized
|
|
93
85
|
: {
|
|
@@ -102,8 +94,8 @@ function getDataSync (byDigest, cache, key, opts) {
|
|
|
102
94
|
throw new index.NotFoundError(cache, key)
|
|
103
95
|
}
|
|
104
96
|
const data = read.sync(cache, byDigest ? key : entry.integrity, {
|
|
105
|
-
integrity:
|
|
106
|
-
size:
|
|
97
|
+
integrity: integrity,
|
|
98
|
+
size: size
|
|
107
99
|
})
|
|
108
100
|
const res = byDigest
|
|
109
101
|
? data
|
|
@@ -113,9 +105,9 @@ function getDataSync (byDigest, cache, key, opts) {
|
|
|
113
105
|
size: entry.size,
|
|
114
106
|
integrity: entry.integrity
|
|
115
107
|
}
|
|
116
|
-
if (
|
|
108
|
+
if (memoize && byDigest) {
|
|
117
109
|
memo.put.byDigest(cache, key, res, opts)
|
|
118
|
-
} else if (
|
|
110
|
+
} else if (memoize) {
|
|
119
111
|
memo.put(cache, entry, res.data, opts)
|
|
120
112
|
}
|
|
121
113
|
return res
|
|
@@ -134,10 +126,10 @@ const getMemoizedStream = (memoized) => {
|
|
|
134
126
|
return stream
|
|
135
127
|
}
|
|
136
128
|
|
|
137
|
-
function getStream (cache, key, opts) {
|
|
138
|
-
|
|
129
|
+
function getStream (cache, key, opts = {}) {
|
|
130
|
+
const { memoize, size } = opts
|
|
139
131
|
const memoized = memo.get(cache, key, opts)
|
|
140
|
-
if (memoized &&
|
|
132
|
+
if (memoized && memoize !== false) {
|
|
141
133
|
return getMemoizedStream(memoized)
|
|
142
134
|
}
|
|
143
135
|
|
|
@@ -160,12 +152,10 @@ function getStream (cache, key, opts) {
|
|
|
160
152
|
const src = read.readStream(
|
|
161
153
|
cache,
|
|
162
154
|
entry.integrity,
|
|
163
|
-
opts.
|
|
164
|
-
size: opts.size == null ? entry.size : opts.size
|
|
165
|
-
})
|
|
155
|
+
{ ...opts, size: typeof size !== 'number' ? entry.size : size }
|
|
166
156
|
)
|
|
167
157
|
|
|
168
|
-
if (
|
|
158
|
+
if (memoize) {
|
|
169
159
|
const memoStream = new Collect.PassThrough()
|
|
170
160
|
memoStream.on('collect', data => memo.put(cache, entry, data, opts))
|
|
171
161
|
stream.unshift(memoStream)
|
|
@@ -179,16 +169,16 @@ function getStream (cache, key, opts) {
|
|
|
179
169
|
|
|
180
170
|
module.exports.stream.byDigest = getStreamDigest
|
|
181
171
|
|
|
182
|
-
function getStreamDigest (cache, integrity, opts) {
|
|
183
|
-
|
|
172
|
+
function getStreamDigest (cache, integrity, opts = {}) {
|
|
173
|
+
const { memoize } = opts
|
|
184
174
|
const memoized = memo.get.byDigest(cache, integrity, opts)
|
|
185
|
-
if (memoized &&
|
|
175
|
+
if (memoized && memoize !== false) {
|
|
186
176
|
const stream = new Minipass()
|
|
187
177
|
stream.end(memoized)
|
|
188
178
|
return stream
|
|
189
179
|
} else {
|
|
190
180
|
const stream = read.readStream(cache, integrity, opts)
|
|
191
|
-
if (!
|
|
181
|
+
if (!memoize) {
|
|
192
182
|
return stream
|
|
193
183
|
}
|
|
194
184
|
const memoStream = new Collect.PassThrough()
|
|
@@ -204,10 +194,10 @@ function getStreamDigest (cache, integrity, opts) {
|
|
|
204
194
|
|
|
205
195
|
module.exports.info = info
|
|
206
196
|
|
|
207
|
-
function info (cache, key, opts) {
|
|
208
|
-
|
|
197
|
+
function info (cache, key, opts = {}) {
|
|
198
|
+
const { memoize } = opts
|
|
209
199
|
const memoized = memo.get(cache, key, opts)
|
|
210
|
-
if (memoized &&
|
|
200
|
+
if (memoized && memoize !== false) {
|
|
211
201
|
return Promise.resolve(memoized.entry)
|
|
212
202
|
} else {
|
|
213
203
|
return index.find(cache, key)
|
|
@@ -228,8 +218,7 @@ function cpDigest (cache, digest, dest, opts) {
|
|
|
228
218
|
|
|
229
219
|
module.exports.copy.byDigest = cpDigest
|
|
230
220
|
|
|
231
|
-
function copy (byDigest, cache, key, dest, opts) {
|
|
232
|
-
opts = GetOpts(opts)
|
|
221
|
+
function copy (byDigest, cache, key, dest, opts = {}) {
|
|
233
222
|
if (read.copy) {
|
|
234
223
|
return (byDigest
|
|
235
224
|
? Promise.resolve(null)
|
|
Binary file
|
package/lib/content/read.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const util = require('util')
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const fs = require('graceful-fs')
|
|
5
|
+
const fs = require('fs')
|
|
7
6
|
const fsm = require('fs-minipass')
|
|
8
7
|
const ssri = require('ssri')
|
|
9
8
|
const contentPath = require('./path')
|
|
@@ -12,21 +11,17 @@ const Pipeline = require('minipass-pipeline')
|
|
|
12
11
|
const lstat = util.promisify(fs.lstat)
|
|
13
12
|
const readFile = util.promisify(fs.readFile)
|
|
14
13
|
|
|
15
|
-
const ReadOpts = figgyPudding({
|
|
16
|
-
size: {}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
14
|
module.exports = read
|
|
20
15
|
|
|
21
16
|
const MAX_SINGLE_READ_SIZE = 64 * 1024 * 1024
|
|
22
|
-
function read (cache, integrity, opts) {
|
|
23
|
-
|
|
17
|
+
function read (cache, integrity, opts = {}) {
|
|
18
|
+
const { size } = opts
|
|
24
19
|
return withContentSri(cache, integrity, (cpath, sri) => {
|
|
25
20
|
// get size
|
|
26
21
|
return lstat(cpath).then(stat => ({ stat, cpath, sri }))
|
|
27
22
|
}).then(({ stat, cpath, sri }) => {
|
|
28
|
-
if (typeof
|
|
29
|
-
throw sizeError(
|
|
23
|
+
if (typeof size === 'number' && stat.size !== size) {
|
|
24
|
+
throw sizeError(size, stat.size)
|
|
30
25
|
}
|
|
31
26
|
if (stat.size > MAX_SINGLE_READ_SIZE) {
|
|
32
27
|
return readPipeline(cpath, stat.size, sri, new Pipeline()).concat()
|
|
@@ -57,12 +52,12 @@ const readPipeline = (cpath, size, sri, stream) => {
|
|
|
57
52
|
|
|
58
53
|
module.exports.sync = readSync
|
|
59
54
|
|
|
60
|
-
function readSync (cache, integrity, opts) {
|
|
61
|
-
|
|
55
|
+
function readSync (cache, integrity, opts = {}) {
|
|
56
|
+
const { size } = opts
|
|
62
57
|
return withContentSriSync(cache, integrity, (cpath, sri) => {
|
|
63
58
|
const data = fs.readFileSync(cpath)
|
|
64
|
-
if (typeof
|
|
65
|
-
throw sizeError(
|
|
59
|
+
if (typeof size === 'number' && size !== data.length) {
|
|
60
|
+
throw sizeError(size, data.length)
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
if (ssri.checkData(data, sri)) {
|
|
@@ -76,16 +71,15 @@ function readSync (cache, integrity, opts) {
|
|
|
76
71
|
module.exports.stream = readStream
|
|
77
72
|
module.exports.readStream = readStream
|
|
78
73
|
|
|
79
|
-
function readStream (cache, integrity, opts) {
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
function readStream (cache, integrity, opts = {}) {
|
|
75
|
+
const { size } = opts
|
|
82
76
|
const stream = new Pipeline()
|
|
83
77
|
withContentSri(cache, integrity, (cpath, sri) => {
|
|
84
78
|
// just lstat to ensure it exists
|
|
85
79
|
return lstat(cpath).then((stat) => ({ stat, cpath, sri }))
|
|
86
80
|
}).then(({ stat, cpath, sri }) => {
|
|
87
|
-
if (typeof
|
|
88
|
-
return stream.emit('error', sizeError(
|
|
81
|
+
if (typeof size === 'number' && size !== stat.size) {
|
|
82
|
+
return stream.emit('error', sizeError(size, stat.size))
|
|
89
83
|
}
|
|
90
84
|
readPipeline(cpath, stat.size, sri, stream)
|
|
91
85
|
}, er => stream.emit('error', er))
|
|
@@ -100,15 +94,13 @@ if (fs.copyFile) {
|
|
|
100
94
|
copyFile = util.promisify(fs.copyFile)
|
|
101
95
|
}
|
|
102
96
|
|
|
103
|
-
function copy (cache, integrity, dest
|
|
104
|
-
opts = ReadOpts(opts)
|
|
97
|
+
function copy (cache, integrity, dest) {
|
|
105
98
|
return withContentSri(cache, integrity, (cpath, sri) => {
|
|
106
99
|
return copyFile(cpath, dest)
|
|
107
100
|
})
|
|
108
101
|
}
|
|
109
102
|
|
|
110
|
-
function copySync (cache, integrity, dest
|
|
111
|
-
opts = ReadOpts(opts)
|
|
103
|
+
function copySync (cache, integrity, dest) {
|
|
112
104
|
return withContentSriSync(cache, integrity, (cpath, sri) => {
|
|
113
105
|
return fs.copyFileSync(cpath, dest)
|
|
114
106
|
})
|
package/lib/content/write.js
CHANGED
|
@@ -4,7 +4,7 @@ const util = require('util')
|
|
|
4
4
|
|
|
5
5
|
const contentPath = require('./path')
|
|
6
6
|
const fixOwner = require('../util/fix-owner')
|
|
7
|
-
const fs = require('
|
|
7
|
+
const fs = require('fs')
|
|
8
8
|
const moveFile = require('../util/move-file')
|
|
9
9
|
const Minipass = require('minipass')
|
|
10
10
|
const Pipeline = require('minipass-pipeline')
|
|
@@ -20,19 +20,17 @@ const writeFile = util.promisify(fs.writeFile)
|
|
|
20
20
|
|
|
21
21
|
module.exports = write
|
|
22
22
|
|
|
23
|
-
function write (cache, data, opts) {
|
|
24
|
-
|
|
25
|
-
if (
|
|
23
|
+
function write (cache, data, opts = {}) {
|
|
24
|
+
const { algorithms, size, integrity } = opts
|
|
25
|
+
if (algorithms && algorithms.length > 1) {
|
|
26
26
|
throw new Error('opts.algorithms only supports a single algorithm for now')
|
|
27
27
|
}
|
|
28
|
-
if (typeof
|
|
29
|
-
return Promise.reject(sizeError(
|
|
28
|
+
if (typeof size === 'number' && data.length !== size) {
|
|
29
|
+
return Promise.reject(sizeError(size, data.length))
|
|
30
30
|
}
|
|
31
|
-
const sri = ssri.fromData(data, {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (opts.integrity && !ssri.checkData(data, opts.integrity, opts)) {
|
|
35
|
-
return Promise.reject(checksumError(opts.integrity, sri))
|
|
31
|
+
const sri = ssri.fromData(data, algorithms ? { algorithms } : {})
|
|
32
|
+
if (integrity && !ssri.checkData(data, integrity, opts)) {
|
|
33
|
+
return Promise.reject(checksumError(integrity, sri))
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
return disposer(makeTmp(cache, opts), makeTmpDisposer,
|
|
@@ -90,8 +88,7 @@ class CacacheWriteStream extends Flush {
|
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
function writeStream (cache, opts) {
|
|
94
|
-
opts = opts || {}
|
|
91
|
+
function writeStream (cache, opts = {}) {
|
|
95
92
|
return new CacacheWriteStream(cache, opts)
|
|
96
93
|
}
|
|
97
94
|
|
package/lib/entry-index.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
const util = require('util')
|
|
4
4
|
|
|
5
5
|
const crypto = require('crypto')
|
|
6
|
-
const
|
|
7
|
-
const fs = require('graceful-fs')
|
|
6
|
+
const fs = require('fs')
|
|
8
7
|
const Minipass = require('minipass')
|
|
9
8
|
const path = require('path')
|
|
10
9
|
const ssri = require('ssri')
|
|
@@ -26,22 +25,17 @@ module.exports.NotFoundError = class NotFoundError extends Error {
|
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
const IndexOpts = figgyPudding({
|
|
30
|
-
metadata: {},
|
|
31
|
-
size: {}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
28
|
module.exports.insert = insert
|
|
35
29
|
|
|
36
|
-
function insert (cache, key, integrity, opts) {
|
|
37
|
-
|
|
30
|
+
function insert (cache, key, integrity, opts = {}) {
|
|
31
|
+
const { metadata, size } = opts
|
|
38
32
|
const bucket = bucketPath(cache, key)
|
|
39
33
|
const entry = {
|
|
40
34
|
key,
|
|
41
35
|
integrity: integrity && ssri.stringify(integrity),
|
|
42
36
|
time: Date.now(),
|
|
43
|
-
size
|
|
44
|
-
metadata
|
|
37
|
+
size,
|
|
38
|
+
metadata
|
|
45
39
|
}
|
|
46
40
|
return fixOwner
|
|
47
41
|
.mkdirfix(cache, path.dirname(bucket))
|
|
@@ -75,15 +69,15 @@ function insert (cache, key, integrity, opts) {
|
|
|
75
69
|
|
|
76
70
|
module.exports.insert.sync = insertSync
|
|
77
71
|
|
|
78
|
-
function insertSync (cache, key, integrity, opts) {
|
|
79
|
-
|
|
72
|
+
function insertSync (cache, key, integrity, opts = {}) {
|
|
73
|
+
const { metadata, size } = opts
|
|
80
74
|
const bucket = bucketPath(cache, key)
|
|
81
75
|
const entry = {
|
|
82
76
|
key,
|
|
83
77
|
integrity: integrity && ssri.stringify(integrity),
|
|
84
78
|
time: Date.now(),
|
|
85
|
-
size
|
|
86
|
-
metadata
|
|
79
|
+
size,
|
|
80
|
+
metadata
|
|
87
81
|
}
|
|
88
82
|
fixOwner.mkdirfix.sync(cache, path.dirname(bucket))
|
|
89
83
|
const stringified = JSON.stringify(entry)
|
|
Binary file
|
package/lib/util/move-file.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const fs = require('
|
|
3
|
+
const fs = require('fs')
|
|
4
4
|
const util = require('util')
|
|
5
5
|
const chmod = util.promisify(fs.chmod)
|
|
6
6
|
const unlink = util.promisify(fs.unlink)
|
|
7
7
|
const stat = util.promisify(fs.stat)
|
|
8
|
-
const move = require('move-
|
|
8
|
+
const move = require('move-file')
|
|
9
9
|
const pinflight = require('promise-inflight')
|
|
10
10
|
|
|
11
11
|
module.exports = moveFile
|
|
@@ -61,7 +61,8 @@ function moveFile (src, dest) {
|
|
|
61
61
|
throw err
|
|
62
62
|
}
|
|
63
63
|
// file doesn't already exist! let's try a rename -> copy fallback
|
|
64
|
-
|
|
64
|
+
// only delete if it successfully copies
|
|
65
|
+
return move(src, dest)
|
|
65
66
|
})
|
|
66
67
|
})
|
|
67
68
|
})
|
package/lib/util/tmp.js
CHANGED
|
@@ -2,22 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
const util = require('util')
|
|
4
4
|
|
|
5
|
-
const figgyPudding = require('figgy-pudding')
|
|
6
5
|
const fixOwner = require('./fix-owner')
|
|
7
6
|
const path = require('path')
|
|
8
7
|
const rimraf = util.promisify(require('rimraf'))
|
|
9
8
|
const uniqueFilename = require('unique-filename')
|
|
10
9
|
const { disposer } = require('./disposer')
|
|
11
10
|
|
|
12
|
-
const TmpOpts = figgyPudding({
|
|
13
|
-
tmpPrefix: {}
|
|
14
|
-
})
|
|
15
|
-
|
|
16
11
|
module.exports.mkdir = mktmpdir
|
|
17
12
|
|
|
18
|
-
function mktmpdir (cache, opts) {
|
|
19
|
-
|
|
20
|
-
const tmpTarget = uniqueFilename(path.join(cache, 'tmp'),
|
|
13
|
+
function mktmpdir (cache, opts = {}) {
|
|
14
|
+
const { tmpPrefix } = opts
|
|
15
|
+
const tmpTarget = uniqueFilename(path.join(cache, 'tmp'), tmpPrefix)
|
|
21
16
|
return fixOwner.mkdirfix(cache, tmpTarget).then(() => {
|
|
22
17
|
return tmpTarget
|
|
23
18
|
})
|
|
@@ -28,10 +23,8 @@ module.exports.withTmp = withTmp
|
|
|
28
23
|
function withTmp (cache, opts, cb) {
|
|
29
24
|
if (!cb) {
|
|
30
25
|
cb = opts
|
|
31
|
-
opts =
|
|
26
|
+
opts = {}
|
|
32
27
|
}
|
|
33
|
-
opts = TmpOpts(opts)
|
|
34
|
-
|
|
35
28
|
return disposer(mktmpdir(cache, opts), rimraf, cb)
|
|
36
29
|
}
|
|
37
30
|
|
package/lib/verify.js
CHANGED
|
@@ -4,9 +4,8 @@ const util = require('util')
|
|
|
4
4
|
|
|
5
5
|
const pMap = require('p-map')
|
|
6
6
|
const contentPath = require('./content/path')
|
|
7
|
-
const figgyPudding = require('figgy-pudding')
|
|
8
7
|
const fixOwner = require('./util/fix-owner')
|
|
9
|
-
const fs = require('
|
|
8
|
+
const fs = require('fs')
|
|
10
9
|
const fsm = require('fs-minipass')
|
|
11
10
|
const glob = util.promisify(require('glob'))
|
|
12
11
|
const index = require('./entry-index')
|
|
@@ -22,20 +21,16 @@ const truncate = util.promisify(fs.truncate)
|
|
|
22
21
|
const writeFile = util.promisify(fs.writeFile)
|
|
23
22
|
const readFile = util.promisify(fs.readFile)
|
|
24
23
|
|
|
25
|
-
const
|
|
26
|
-
concurrency:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
filter: {},
|
|
30
|
-
log: {
|
|
31
|
-
default: { silly () {} }
|
|
32
|
-
}
|
|
24
|
+
const verifyOpts = (opts) => ({
|
|
25
|
+
concurrency: 20,
|
|
26
|
+
log: { silly () {} },
|
|
27
|
+
...opts
|
|
33
28
|
})
|
|
34
29
|
|
|
35
30
|
module.exports = verify
|
|
36
31
|
|
|
37
32
|
function verify (cache, opts) {
|
|
38
|
-
opts =
|
|
33
|
+
opts = verifyOpts(opts)
|
|
39
34
|
opts.log.silly('verify', 'verifying cache at', cache)
|
|
40
35
|
|
|
41
36
|
const steps = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cacache",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.3",
|
|
4
4
|
"cache-version": {
|
|
5
5
|
"content": "2",
|
|
6
6
|
"index": "5"
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"files": [
|
|
11
11
|
"*.js",
|
|
12
|
-
"lib"
|
|
13
|
-
"locales"
|
|
12
|
+
"lib"
|
|
14
13
|
],
|
|
15
14
|
"scripts": {
|
|
16
15
|
"benchmarks": "node test/benchmarks",
|
|
16
|
+
"lint": "standard",
|
|
17
|
+
"postrelease": "npm publish",
|
|
18
|
+
"posttest": "npm run lint",
|
|
19
|
+
"prepublishOnly": "git push --follow-tags",
|
|
17
20
|
"prerelease": "npm t",
|
|
18
|
-
"postrelease": "npm publish && git push --follow-tags",
|
|
19
|
-
"pretest": "standard",
|
|
20
21
|
"release": "standard-version -s",
|
|
21
|
-
"test": "tap
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'"
|
|
22
|
+
"test": "tap",
|
|
23
|
+
"coverage": "tap",
|
|
24
|
+
"test-docker": "docker run -it --rm --name pacotest -v \"$PWD\":/tmp -w /tmp node:latest npm test"
|
|
25
25
|
},
|
|
26
26
|
"repository": "https://github.com/npm/cacache",
|
|
27
27
|
"keywords": [
|
|
@@ -58,40 +58,36 @@
|
|
|
58
58
|
],
|
|
59
59
|
"license": "ISC",
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"chownr": "^
|
|
62
|
-
"figgy-pudding": "^3.5.1",
|
|
61
|
+
"chownr": "^2.0.0",
|
|
63
62
|
"fs-minipass": "^2.0.0",
|
|
64
63
|
"glob": "^7.1.4",
|
|
65
|
-
"graceful-fs": "^4.2.2",
|
|
66
64
|
"infer-owner": "^1.0.4",
|
|
67
65
|
"lru-cache": "^5.1.1",
|
|
68
|
-
"minipass": "^3.
|
|
66
|
+
"minipass": "^3.1.1",
|
|
69
67
|
"minipass-collect": "^1.0.2",
|
|
70
68
|
"minipass-flush": "^1.0.5",
|
|
71
69
|
"minipass-pipeline": "^1.2.2",
|
|
72
70
|
"mkdirp": "^1.0.3",
|
|
73
|
-
"move-
|
|
74
|
-
"p-map": "^
|
|
71
|
+
"move-file": "^2.0.0",
|
|
72
|
+
"p-map": "^4.0.0",
|
|
75
73
|
"promise-inflight": "^1.0.1",
|
|
76
|
-
"rimraf": "^
|
|
77
|
-
"ssri": "^
|
|
78
|
-
"tar": "^6.0.
|
|
74
|
+
"rimraf": "^3.0.2",
|
|
75
|
+
"ssri": "^8.0.0",
|
|
76
|
+
"tar": "^6.0.2",
|
|
79
77
|
"unique-filename": "^1.1.1"
|
|
80
78
|
},
|
|
81
79
|
"devDependencies": {
|
|
82
80
|
"benchmark": "^2.1.4",
|
|
83
|
-
"chalk": "^
|
|
84
|
-
"cross-env": "^5.2.1",
|
|
81
|
+
"chalk": "^4.0.0",
|
|
85
82
|
"require-inject": "^1.4.4",
|
|
86
|
-
"standard": "^14.3.
|
|
87
|
-
"standard-version": "^7.
|
|
83
|
+
"standard": "^14.3.1",
|
|
84
|
+
"standard-version": "^7.1.0",
|
|
88
85
|
"tacks": "^1.3.0",
|
|
89
|
-
"tap": "^14.6
|
|
90
|
-
"weallbehave": "^1.2.0",
|
|
91
|
-
"weallcontribute": "^1.0.9"
|
|
86
|
+
"tap": "^14.10.6"
|
|
92
87
|
},
|
|
93
88
|
"tap": {
|
|
94
|
-
"100": true
|
|
89
|
+
"100": true,
|
|
90
|
+
"test-regex": "test/[^/]*.js"
|
|
95
91
|
},
|
|
96
92
|
"engines": {
|
|
97
93
|
"node": ">= 10"
|
package/put.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const figgyPudding = require('figgy-pudding')
|
|
4
3
|
const index = require('./lib/entry-index')
|
|
5
4
|
const memo = require('./lib/memoization')
|
|
6
5
|
const write = require('./lib/content/write')
|
|
@@ -8,31 +7,21 @@ const Flush = require('minipass-flush')
|
|
|
8
7
|
const { PassThrough } = require('minipass-collect')
|
|
9
8
|
const Pipeline = require('minipass-pipeline')
|
|
10
9
|
|
|
11
|
-
const
|
|
12
|
-
algorithms:
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
integrity: {},
|
|
16
|
-
memoize: {},
|
|
17
|
-
metadata: {},
|
|
18
|
-
pickAlgorithm: {},
|
|
19
|
-
size: {},
|
|
20
|
-
tmpPrefix: {},
|
|
21
|
-
single: {},
|
|
22
|
-
sep: {},
|
|
23
|
-
error: {},
|
|
24
|
-
strict: {}
|
|
10
|
+
const putOpts = (opts) => ({
|
|
11
|
+
algorithms: ['sha512'],
|
|
12
|
+
...opts
|
|
25
13
|
})
|
|
26
14
|
|
|
27
15
|
module.exports = putData
|
|
28
16
|
|
|
29
|
-
function putData (cache, key, data, opts) {
|
|
30
|
-
|
|
17
|
+
function putData (cache, key, data, opts = {}) {
|
|
18
|
+
const { memoize } = opts
|
|
19
|
+
opts = putOpts(opts)
|
|
31
20
|
return write(cache, data, opts).then((res) => {
|
|
32
21
|
return index
|
|
33
|
-
.insert(cache, key, res.integrity,
|
|
22
|
+
.insert(cache, key, res.integrity, { ...opts, size: res.size })
|
|
34
23
|
.then((entry) => {
|
|
35
|
-
if (
|
|
24
|
+
if (memoize) {
|
|
36
25
|
memo.put(cache, entry, data, opts)
|
|
37
26
|
}
|
|
38
27
|
return res.integrity
|
|
@@ -42,8 +31,9 @@ function putData (cache, key, data, opts) {
|
|
|
42
31
|
|
|
43
32
|
module.exports.stream = putStream
|
|
44
33
|
|
|
45
|
-
function putStream (cache, key, opts) {
|
|
46
|
-
|
|
34
|
+
function putStream (cache, key, opts = {}) {
|
|
35
|
+
const { memoize } = opts
|
|
36
|
+
opts = putOpts(opts)
|
|
47
37
|
let integrity
|
|
48
38
|
let size
|
|
49
39
|
|
|
@@ -51,7 +41,7 @@ function putStream (cache, key, opts) {
|
|
|
51
41
|
const pipeline = new Pipeline()
|
|
52
42
|
// first item in the pipeline is the memoizer, because we need
|
|
53
43
|
// that to end first and get the collected data.
|
|
54
|
-
if (
|
|
44
|
+
if (memoize) {
|
|
55
45
|
const memoizer = new PassThrough().on('collect', data => {
|
|
56
46
|
memoData = data
|
|
57
47
|
})
|
|
@@ -75,9 +65,9 @@ function putStream (cache, key, opts) {
|
|
|
75
65
|
pipeline.push(new Flush({
|
|
76
66
|
flush () {
|
|
77
67
|
return index
|
|
78
|
-
.insert(cache, key, integrity,
|
|
68
|
+
.insert(cache, key, integrity, { ...opts, size })
|
|
79
69
|
.then((entry) => {
|
|
80
|
-
if (
|
|
70
|
+
if (memoize && memoData) {
|
|
81
71
|
memo.put(cache, entry, memoData, opts)
|
|
82
72
|
}
|
|
83
73
|
if (integrity) {
|