Skip to content

Commit

Permalink
Explicitly add stream to cache
Browse files Browse the repository at this point in the history
Pacote doesn't do this automatically anymore

Closes npm/pacote#73 & Closes #2160
  • Loading branch information
mjsir911 committed Mar 27, 2021
1 parent ffead4a commit 41a60c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 2 additions & 4 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,10 @@ with --force.`)

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

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

Expand Down
17 changes: 13 additions & 4 deletions test/lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ const npmlog = {
},
}

const pipeline = {
pipe: () => pipeline,
promise: () => Promise.resolve(),
resume: () => {},
}

let tarballStreamSpec = ''
let tarballStreamOpts = {}
const pacote = {
tarball: {
stream: (spec, handler, opts) => {
tarballStreamSpec = spec
tarballStreamOpts = opts
return handler({
resume: () => {},
promise: () => Promise.resolve(),
})
return handler(pipeline)
},
},
}
Expand All @@ -41,10 +44,16 @@ const cacacheVerifyStats = {
totalEntries: 1,
runTime: { total: 2000 },
}

const cacache = {
verify: (path) => {
return cacacheVerifyStats
},
put: {
stream: (cache, stream) => {
return pipeline
},
},
}

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

0 comments on commit 41a60c8

Please sign in to comment.