Skip to content

Commit

Permalink
Cache the tarballs in pacote
Browse files Browse the repository at this point in the history
Tell `fetch` not to cache it's downloaded tarballs, leave that to us

Not sure the implications of changing the return type of _istream /
adding a `cacache` to the end of the pipe, too unfamiliar with streams

Fixes npm#73 & Fixes npm/cli#2160

Also see npm/cli#2976 for my first attempt & some discussions as to how
we got here.
  • Loading branch information
mjsir911 committed Apr 1, 2021
1 parent ad54e6d commit f1ad2d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ class FetcherBase {
}

// private, should be overridden.
// Note that they should *not* calculate or check integrity, but *just*
// return the raw tarball data stream.
// Note that they should *not* calculate or check integrity or cache,
// but *just* return the raw tarball data stream.
[_tarballFromResolved] () {
throw this.notImplementedError
}
Expand Down Expand Up @@ -203,7 +203,12 @@ class FetcherBase {
// gets to the point of re-setting the integrity.
const istream = ssri.integrityStream(this.opts)
istream.on('integrity', i => this.integrity = i)
return stream.on('error', er => istream.emit('error', er)).pipe(istream)
const cstream = cacache.put.stream(
this.opts.cache,
`pacote:tarball:${this.from}`,
this.opts
)
return stream.on('error', er => istream.emit('error', er)).pipe(istream).pipe(cstream)
}

pickIntegrityAlgorithm () {
Expand Down
1 change: 1 addition & 0 deletions lib/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RemoteFetcher extends Fetcher {
spec: this.spec,
integrity: this.integrity,
algorithms: [ this.pickIntegrityAlgorithm() ],
cache: null, // leave the caching of the tarball up to _istream
}
fetch(this.resolved, fetchOpts).then(res => {
const hash = res.headers.get('x-local-cache-hash')
Expand Down

0 comments on commit f1ad2d3

Please sign in to comment.