pacote 11.3.1 → 11.3.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/lib/fetcher.js +40 -15
- package/lib/remote.js +7 -0
- package/package.json +4 -7
package/lib/fetcher.js
CHANGED
|
@@ -40,6 +40,7 @@ const _istream = Symbol('_istream')
|
|
|
40
40
|
const _assertType = Symbol('_assertType')
|
|
41
41
|
const _tarballFromCache = Symbol('_tarballFromCache')
|
|
42
42
|
const _tarballFromResolved = Symbol.for('pacote.Fetcher._tarballFromResolved')
|
|
43
|
+
const _cacheFetches = Symbol.for('pacote.Fetcher._cacheFetches')
|
|
43
44
|
|
|
44
45
|
class FetcherBase {
|
|
45
46
|
constructor (spec, opts) {
|
|
@@ -166,25 +167,19 @@ class FetcherBase {
|
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
// private, should be overridden.
|
|
169
|
-
// Note that they should *not* calculate or check integrity
|
|
170
|
-
// return the raw tarball data stream.
|
|
170
|
+
// Note that they should *not* calculate or check integrity or cache,
|
|
171
|
+
// but *just* return the raw tarball data stream.
|
|
171
172
|
[_tarballFromResolved] () {
|
|
172
173
|
throw this.notImplementedError
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
// public, should not be overridden
|
|
176
177
|
tarball () {
|
|
177
|
-
return this.tarballStream(stream =>
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
data.integrity = this.integrity && String(this.integrity)
|
|
183
|
-
data.resolved = this.resolved
|
|
184
|
-
data.from = this.from
|
|
185
|
-
return res(data)
|
|
186
|
-
})
|
|
187
|
-
stream.on('data', d => buf.push(d))
|
|
178
|
+
return this.tarballStream(stream => stream.concat().then(data => {
|
|
179
|
+
data.integrity = this.integrity && String(this.integrity)
|
|
180
|
+
data.resolved = this.resolved
|
|
181
|
+
data.from = this.from
|
|
182
|
+
return data
|
|
188
183
|
}))
|
|
189
184
|
}
|
|
190
185
|
|
|
@@ -194,6 +189,10 @@ class FetcherBase {
|
|
|
194
189
|
return cacache.get.stream.byDigest(this.cache, this.integrity, this.opts)
|
|
195
190
|
}
|
|
196
191
|
|
|
192
|
+
get [_cacheFetches] () {
|
|
193
|
+
return true
|
|
194
|
+
}
|
|
195
|
+
|
|
197
196
|
[_istream] (stream) {
|
|
198
197
|
// everyone will need one of these, either for verifying or calculating
|
|
199
198
|
// We always set it, because we have might only have a weak legacy hex
|
|
@@ -203,7 +202,31 @@ class FetcherBase {
|
|
|
203
202
|
// gets to the point of re-setting the integrity.
|
|
204
203
|
const istream = ssri.integrityStream(this.opts)
|
|
205
204
|
istream.on('integrity', i => this.integrity = i)
|
|
206
|
-
|
|
205
|
+
stream.on('error', er => istream.emit('error', er))
|
|
206
|
+
|
|
207
|
+
// if not caching this, just pipe through to the istream and return it
|
|
208
|
+
if (!this.opts.cache || !this[_cacheFetches])
|
|
209
|
+
return stream.pipe(istream)
|
|
210
|
+
|
|
211
|
+
// we have to return a stream that gets ALL the data, and proxies errors,
|
|
212
|
+
// but then pipe from the original tarball stream into the cache as well.
|
|
213
|
+
// To do this without losing any data, and since the cacache put stream
|
|
214
|
+
// is not a passthrough, we have to pipe from the original stream into
|
|
215
|
+
// the cache AFTER we pipe into the istream. Since the cache stream
|
|
216
|
+
// has an asynchronous flush to write its contents to disk, we need to
|
|
217
|
+
// defer the istream end until the cache stream ends.
|
|
218
|
+
stream.pipe(istream, { end: false })
|
|
219
|
+
const cstream = cacache.put.stream(
|
|
220
|
+
this.opts.cache,
|
|
221
|
+
`pacote:tarball:${this.from}`,
|
|
222
|
+
this.opts
|
|
223
|
+
)
|
|
224
|
+
stream.pipe(cstream)
|
|
225
|
+
// defer istream end until after cstream
|
|
226
|
+
// cache write errors should not crash the fetch, this is best-effort.
|
|
227
|
+
cstream.promise().catch(() => {}).then(() => istream.end())
|
|
228
|
+
|
|
229
|
+
return istream
|
|
207
230
|
}
|
|
208
231
|
|
|
209
232
|
pickIntegrityAlgorithm () {
|
|
@@ -232,7 +255,9 @@ class FetcherBase {
|
|
|
232
255
|
// An ENOENT trying to read a tgz file, for example, is Right Out.
|
|
233
256
|
isRetriableError (er) {
|
|
234
257
|
// TODO: check error class, once those are rolled out to our deps
|
|
235
|
-
return this.isDataCorruptionError(er) ||
|
|
258
|
+
return this.isDataCorruptionError(er) ||
|
|
259
|
+
er.code === 'ENOENT' ||
|
|
260
|
+
er.code === 'EISDIR'
|
|
236
261
|
}
|
|
237
262
|
|
|
238
263
|
// Mostly internal, but has some uses
|
package/lib/remote.js
CHANGED
|
@@ -8,6 +8,7 @@ const Minipass = require('minipass')
|
|
|
8
8
|
// The default registry URL is a string of great magic.
|
|
9
9
|
const magic = /^https?:\/\/registry\.npmjs\.org\//
|
|
10
10
|
|
|
11
|
+
const _cacheFetches = Symbol.for('pacote.Fetcher._cacheFetches')
|
|
11
12
|
const _headers = Symbol('_headers')
|
|
12
13
|
class RemoteFetcher extends Fetcher {
|
|
13
14
|
constructor (spec, opts) {
|
|
@@ -21,6 +22,12 @@ class RemoteFetcher extends Fetcher {
|
|
|
21
22
|
this.pkgid = opts.pkgid ? opts.pkgid : `remote:${nameat}${this.resolved}`
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
// Don't need to cache tarball fetches in pacote, because make-fetch-happen
|
|
26
|
+
// will write into cacache anyway.
|
|
27
|
+
get [_cacheFetches] () {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
[_tarballFromResolved] () {
|
|
25
32
|
const stream = new Minipass()
|
|
26
33
|
const fetchOpts = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pacote",
|
|
3
|
-
"version": "11.3.
|
|
3
|
+
"version": "11.3.2",
|
|
4
4
|
"description": "JavaScript package downloader",
|
|
5
5
|
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
|
|
6
6
|
"bin": {
|
|
@@ -17,15 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"tap": {
|
|
19
19
|
"timeout": 300,
|
|
20
|
-
"
|
|
21
|
-
"coverage-map": "map.js",
|
|
22
|
-
"esm": false
|
|
20
|
+
"coverage-map": "map.js"
|
|
23
21
|
},
|
|
24
22
|
"devDependencies": {
|
|
25
23
|
"mutate-fs": "^2.1.1",
|
|
26
24
|
"npm-registry-mock": "^1.3.1",
|
|
27
|
-
"
|
|
28
|
-
"tap": "^14.11.0"
|
|
25
|
+
"tap": "^15.0.4"
|
|
29
26
|
},
|
|
30
27
|
"files": [
|
|
31
28
|
"lib/**/*.js"
|
|
@@ -49,7 +46,7 @@
|
|
|
49
46
|
"npm-package-arg": "^8.0.1",
|
|
50
47
|
"npm-packlist": "^2.1.4",
|
|
51
48
|
"npm-pick-manifest": "^6.0.0",
|
|
52
|
-
"npm-registry-fetch": "^
|
|
49
|
+
"npm-registry-fetch": "^10.0.0",
|
|
53
50
|
"promise-retry": "^2.0.1",
|
|
54
51
|
"read-package-json-fast": "^2.0.1",
|
|
55
52
|
"rimraf": "^3.0.2",
|