cacache 15.2.0 → 15.3.0
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/get.js +112 -128
- package/lib/util/tmp.js +9 -9
- package/package.json +2 -1
package/get.js
CHANGED
|
@@ -1,119 +1,112 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Collect = require('minipass-collect')
|
|
4
|
+
const Minipass = require('minipass')
|
|
5
|
+
const Pipeline = require('minipass-pipeline')
|
|
4
6
|
const fs = require('fs')
|
|
7
|
+
const util = require('util')
|
|
8
|
+
|
|
5
9
|
const index = require('./lib/entry-index')
|
|
6
10
|
const memo = require('./lib/memoization')
|
|
7
11
|
const read = require('./lib/content/read')
|
|
8
12
|
|
|
9
|
-
const Minipass = require('minipass')
|
|
10
|
-
const Collect = require('minipass-collect')
|
|
11
|
-
const Pipeline = require('minipass-pipeline')
|
|
12
|
-
|
|
13
13
|
const writeFile = util.promisify(fs.writeFile)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
return getData(false, cache, key, opts)
|
|
17
|
-
}
|
|
18
|
-
module.exports.byDigest = function getByDigest (cache, digest, opts) {
|
|
19
|
-
return getData(true, cache, digest, opts)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getData (byDigest, cache, key, opts = {}) {
|
|
15
|
+
function getData (cache, key, opts = {}) {
|
|
23
16
|
const { integrity, memoize, size } = opts
|
|
24
|
-
const memoized =
|
|
25
|
-
? memo.get.byDigest(cache, key, opts)
|
|
26
|
-
: memo.get(cache, key, opts)
|
|
17
|
+
const memoized = memo.get(cache, key, opts)
|
|
27
18
|
if (memoized && memoize !== false) {
|
|
28
|
-
return Promise.resolve(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
integrity: memoized.entry.integrity,
|
|
35
|
-
size: memoized.entry.size,
|
|
36
|
-
}
|
|
37
|
-
)
|
|
19
|
+
return Promise.resolve({
|
|
20
|
+
metadata: memoized.entry.metadata,
|
|
21
|
+
data: memoized.data,
|
|
22
|
+
integrity: memoized.entry.integrity,
|
|
23
|
+
size: memoized.entry.size,
|
|
24
|
+
})
|
|
38
25
|
}
|
|
39
|
-
return (byDigest ? Promise.resolve(null) : index.find(cache, key, opts)).then(
|
|
40
|
-
(entry) => {
|
|
41
|
-
if (!entry && !byDigest)
|
|
42
|
-
throw new index.NotFoundError(cache, key)
|
|
43
26
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
: {
|
|
52
|
-
data,
|
|
53
|
-
metadata: entry.metadata,
|
|
54
|
-
size: entry.size,
|
|
55
|
-
integrity: entry.integrity,
|
|
56
|
-
}
|
|
57
|
-
)
|
|
58
|
-
.then((res) => {
|
|
59
|
-
if (memoize && byDigest)
|
|
60
|
-
memo.put.byDigest(cache, key, res, opts)
|
|
61
|
-
else if (memoize)
|
|
62
|
-
memo.put(cache, entry, res.data, opts)
|
|
63
|
-
|
|
64
|
-
return res
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
)
|
|
68
|
-
}
|
|
27
|
+
return index.find(cache, key, opts).then((entry) => {
|
|
28
|
+
if (!entry)
|
|
29
|
+
throw new index.NotFoundError(cache, key)
|
|
30
|
+
|
|
31
|
+
return read(cache, entry.integrity, { integrity, size }).then((data) => {
|
|
32
|
+
if (memoize)
|
|
33
|
+
memo.put(cache, entry, data, opts)
|
|
69
34
|
|
|
70
|
-
|
|
71
|
-
|
|
35
|
+
return {
|
|
36
|
+
data,
|
|
37
|
+
metadata: entry.metadata,
|
|
38
|
+
size: entry.size,
|
|
39
|
+
integrity: entry.integrity,
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
})
|
|
72
43
|
}
|
|
73
|
-
module.exports
|
|
74
|
-
|
|
44
|
+
module.exports = getData
|
|
45
|
+
|
|
46
|
+
function getDataByDigest (cache, key, opts = {}) {
|
|
47
|
+
const { integrity, memoize, size } = opts
|
|
48
|
+
const memoized = memo.get.byDigest(cache, key, opts)
|
|
49
|
+
if (memoized && memoize !== false)
|
|
50
|
+
return Promise.resolve(memoized)
|
|
51
|
+
|
|
52
|
+
return read(cache, key, { integrity, size }).then((res) => {
|
|
53
|
+
if (memoize)
|
|
54
|
+
memo.put.byDigest(cache, key, res, opts)
|
|
55
|
+
return res
|
|
56
|
+
})
|
|
75
57
|
}
|
|
58
|
+
module.exports.byDigest = getDataByDigest
|
|
76
59
|
|
|
77
|
-
function getDataSync (
|
|
60
|
+
function getDataSync (cache, key, opts = {}) {
|
|
78
61
|
const { integrity, memoize, size } = opts
|
|
79
|
-
const memoized =
|
|
80
|
-
|
|
81
|
-
: memo.get(cache, key, opts)
|
|
62
|
+
const memoized = memo.get(cache, key, opts)
|
|
63
|
+
|
|
82
64
|
if (memoized && memoize !== false) {
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
size: memoized.entry.size,
|
|
90
|
-
}
|
|
65
|
+
return {
|
|
66
|
+
metadata: memoized.entry.metadata,
|
|
67
|
+
data: memoized.data,
|
|
68
|
+
integrity: memoized.entry.integrity,
|
|
69
|
+
size: memoized.entry.size,
|
|
70
|
+
}
|
|
91
71
|
}
|
|
92
|
-
const entry =
|
|
93
|
-
if (!entry
|
|
72
|
+
const entry = index.find.sync(cache, key, opts)
|
|
73
|
+
if (!entry)
|
|
94
74
|
throw new index.NotFoundError(cache, key)
|
|
95
|
-
|
|
96
|
-
const data = read.sync(cache, byDigest ? key : entry.integrity, {
|
|
75
|
+
const data = read.sync(cache, entry.integrity, {
|
|
97
76
|
integrity: integrity,
|
|
98
77
|
size: size,
|
|
99
78
|
})
|
|
100
|
-
const res =
|
|
101
|
-
|
|
102
|
-
:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
if (memoize && byDigest)
|
|
109
|
-
memo.put.byDigest(cache, key, res, opts)
|
|
110
|
-
else if (memoize)
|
|
79
|
+
const res = {
|
|
80
|
+
metadata: entry.metadata,
|
|
81
|
+
data: data,
|
|
82
|
+
size: entry.size,
|
|
83
|
+
integrity: entry.integrity,
|
|
84
|
+
}
|
|
85
|
+
if (memoize)
|
|
111
86
|
memo.put(cache, entry, res.data, opts)
|
|
112
87
|
|
|
113
88
|
return res
|
|
114
89
|
}
|
|
115
90
|
|
|
116
|
-
module.exports.
|
|
91
|
+
module.exports.sync = getDataSync
|
|
92
|
+
|
|
93
|
+
function getDataByDigestSync (cache, digest, opts = {}) {
|
|
94
|
+
const { integrity, memoize, size } = opts
|
|
95
|
+
const memoized = memo.get.byDigest(cache, digest, opts)
|
|
96
|
+
|
|
97
|
+
if (memoized && memoize !== false)
|
|
98
|
+
return memoized
|
|
99
|
+
|
|
100
|
+
const res = read.sync(cache, digest, {
|
|
101
|
+
integrity: integrity,
|
|
102
|
+
size: size,
|
|
103
|
+
})
|
|
104
|
+
if (memoize)
|
|
105
|
+
memo.put.byDigest(cache, digest, res, opts)
|
|
106
|
+
|
|
107
|
+
return res
|
|
108
|
+
}
|
|
109
|
+
module.exports.sync.byDigest = getDataByDigestSync
|
|
117
110
|
|
|
118
111
|
const getMemoizedStream = (memoized) => {
|
|
119
112
|
const stream = new Minipass()
|
|
@@ -166,7 +159,7 @@ function getStream (cache, key, opts = {}) {
|
|
|
166
159
|
return stream
|
|
167
160
|
}
|
|
168
161
|
|
|
169
|
-
module.exports.stream
|
|
162
|
+
module.exports.stream = getStream
|
|
170
163
|
|
|
171
164
|
function getStreamDigest (cache, integrity, opts = {}) {
|
|
172
165
|
const { memoize } = opts
|
|
@@ -191,7 +184,7 @@ function getStreamDigest (cache, integrity, opts = {}) {
|
|
|
191
184
|
}
|
|
192
185
|
}
|
|
193
186
|
|
|
194
|
-
module.exports.
|
|
187
|
+
module.exports.stream.byDigest = getStreamDigest
|
|
195
188
|
|
|
196
189
|
function info (cache, key, opts = {}) {
|
|
197
190
|
const { memoize } = opts
|
|
@@ -201,53 +194,44 @@ function info (cache, key, opts = {}) {
|
|
|
201
194
|
else
|
|
202
195
|
return index.find(cache, key)
|
|
203
196
|
}
|
|
197
|
+
module.exports.info = info
|
|
204
198
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
function cp (cache, key, dest, opts) {
|
|
208
|
-
return copy(false, cache, key, dest, opts)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
module.exports.copy = cp
|
|
212
|
-
|
|
213
|
-
function cpDigest (cache, digest, dest, opts) {
|
|
214
|
-
return copy(true, cache, digest, dest, opts)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
module.exports.copy.byDigest = cpDigest
|
|
218
|
-
|
|
219
|
-
function copy (byDigest, cache, key, dest, opts = {}) {
|
|
199
|
+
function copy (cache, key, dest, opts = {}) {
|
|
220
200
|
if (read.copy) {
|
|
221
|
-
return (
|
|
222
|
-
|
|
223
|
-
: index.find(cache, key, opts)
|
|
224
|
-
).then((entry) => {
|
|
225
|
-
if (!entry && !byDigest)
|
|
201
|
+
return index.find(cache, key, opts).then((entry) => {
|
|
202
|
+
if (!entry)
|
|
226
203
|
throw new index.NotFoundError(cache, key)
|
|
227
|
-
|
|
228
|
-
return read
|
|
229
|
-
.copy(cache, byDigest ? key : entry.integrity, dest, opts)
|
|
204
|
+
return read.copy(cache, entry.integrity, dest, opts)
|
|
230
205
|
.then(() => {
|
|
231
|
-
return
|
|
232
|
-
|
|
233
|
-
:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
integrity: entry.integrity,
|
|
237
|
-
}
|
|
206
|
+
return {
|
|
207
|
+
metadata: entry.metadata,
|
|
208
|
+
size: entry.size,
|
|
209
|
+
integrity: entry.integrity,
|
|
210
|
+
}
|
|
238
211
|
})
|
|
239
212
|
})
|
|
240
213
|
}
|
|
241
214
|
|
|
242
|
-
return getData(
|
|
243
|
-
return writeFile(dest,
|
|
244
|
-
return
|
|
245
|
-
|
|
246
|
-
:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
integrity: res.integrity,
|
|
250
|
-
}
|
|
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
|
+
}
|
|
251
222
|
})
|
|
252
223
|
})
|
|
253
224
|
}
|
|
225
|
+
module.exports.copy = copy
|
|
226
|
+
|
|
227
|
+
function copyByDigest (cache, key, dest, opts = {}) {
|
|
228
|
+
if (read.copy)
|
|
229
|
+
return read.copy(cache, key, dest, opts).then(() => key)
|
|
230
|
+
|
|
231
|
+
return getDataByDigest(cache, key, opts).then((res) => {
|
|
232
|
+
return writeFile(dest, res).then(() => key)
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
module.exports.copy.byDigest = copyByDigest
|
|
236
|
+
|
|
237
|
+
module.exports.hasContent = read.hasContent
|
package/lib/util/tmp.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const fs = require('@npmcli/fs')
|
|
4
4
|
|
|
5
5
|
const fixOwner = require('./fix-owner')
|
|
6
6
|
const path = require('path')
|
|
7
|
-
const rimraf = util.promisify(require('rimraf'))
|
|
8
|
-
const uniqueFilename = require('unique-filename')
|
|
9
|
-
const { disposer } = require('./disposer')
|
|
10
7
|
|
|
11
8
|
module.exports.mkdir = mktmpdir
|
|
12
9
|
|
|
13
10
|
function mktmpdir (cache, opts = {}) {
|
|
14
11
|
const { tmpPrefix } = opts
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const tmpDir = path.join(cache, 'tmp')
|
|
13
|
+
return fs.mkdir(tmpDir, { recursive: true, owner: 'inherit' })
|
|
14
|
+
.then(() => {
|
|
15
|
+
// do not use path.join(), it drops the trailing / if tmpPrefix is unset
|
|
16
|
+
const target = `${tmpDir}${path.sep}${tmpPrefix || ''}`
|
|
17
|
+
return fs.mkdtemp(target, { owner: 'inherit' })
|
|
18
|
+
})
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
module.exports.withTmp = withTmp
|
|
@@ -25,7 +25,7 @@ function withTmp (cache, opts, cb) {
|
|
|
25
25
|
cb = opts
|
|
26
26
|
opts = {}
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return fs.withTempDir(path.join(cache, 'tmp'), cb, opts)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
module.exports.fix = fixtmpdir
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cacache",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.3.0",
|
|
4
4
|
"cache-version": {
|
|
5
5
|
"content": "2",
|
|
6
6
|
"index": "5"
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"license": "ISC",
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@npmcli/fs": "^1.0.0",
|
|
46
47
|
"@npmcli/move-file": "^1.0.1",
|
|
47
48
|
"chownr": "^2.0.0",
|
|
48
49
|
"fs-minipass": "^2.0.0",
|