Skip to content

Commit 41a60c8

Browse files
committed
Explicitly add stream to cache
Pacote doesn't do this automatically anymore Closes npm/pacote#73 & Closes #2160
1 parent ffead4a commit 41a60c8

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/cache.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ with --force.`)
105105

106106
log.silly('cache add', 'spec', spec)
107107

108-
// we ask pacote for the thing, and then just throw the data
109-
// away so that it tee-pipes it into the cache like it does
110-
// for a normal request.
111108
await pacote.tarball.stream(spec, stream => {
112109
stream.resume()
113-
return stream.promise()
110+
return cacache.put.stream(this.npm.config.get('cache'), stream)
111+
.pipe(stream).promise()
114112
}, this.npm.flatOptions)
115113
}
116114

test/lib/cache.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ const npmlog = {
2020
},
2121
}
2222

23+
const pipeline = {
24+
pipe: () => pipeline,
25+
promise: () => Promise.resolve(),
26+
resume: () => {},
27+
}
28+
2329
let tarballStreamSpec = ''
2430
let tarballStreamOpts = {}
2531
const pacote = {
2632
tarball: {
2733
stream: (spec, handler, opts) => {
2834
tarballStreamSpec = spec
2935
tarballStreamOpts = opts
30-
return handler({
31-
resume: () => {},
32-
promise: () => Promise.resolve(),
33-
})
36+
return handler(pipeline)
3437
},
3538
},
3639
}
@@ -41,10 +44,16 @@ const cacacheVerifyStats = {
4144
totalEntries: 1,
4245
runTime: { total: 2000 },
4346
}
47+
4448
const cacache = {
4549
verify: (path) => {
4650
return cacacheVerifyStats
4751
},
52+
put: {
53+
stream: (cache, stream) => {
54+
return pipeline
55+
},
56+
},
4857
}
4958

5059
const Cache = requireInject('../../lib/cache.js', {

0 commit comments

Comments
 (0)