Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cache): add both full and minified packument to cache #7516

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,20 @@ class Cache extends BaseCommand {
throw this.usageError('First argument to `add` is required')
}

return Promise.all(args.map(spec => {
await Promise.all(args.map(async spec => {
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.
return pacote.tarball.stream(spec, stream => {
await pacote.tarball.stream(spec, stream => {
stream.resume()
return stream.promise()
}, { ...this.npm.flatOptions })

await pacote.manifest(spec, {
...this.npm.flatOptions,
fullMetadata: true,
})
}))
}

Expand Down
14 changes: 11 additions & 3 deletions test/lib/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ t.test('cache add single pkg', async t => {
registry: npm.config.get('registry'),
})
const manifest = registry.manifest({ name: pkg })
await registry.package({ manifest, tarballs: { '1.0.0': path.join(npm.prefix, 'package') } })
await registry.package({
manifest,
times: 2,
tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
})
await npm.exec('cache', ['add', pkg])
t.equal(joinedOutput(), '')
// eslint-disable-next-line max-len
Expand Down Expand Up @@ -99,9 +103,13 @@ t.test('cache add multiple pkgs', async t => {
})
const manifest = registry.manifest({ name: pkg })
const manifest2 = registry.manifest({ name: pkg2 })
await registry.package({ manifest, tarballs: { '1.0.0': path.join(npm.prefix, 'package') } })
await registry.package({
manifest: manifest2, tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
manifest,
times: 2,
tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
})
await registry.package({
manifest: manifest2, times: 2, tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
})
await npm.exec('cache', ['add', pkg, pkg2])
t.equal(joinedOutput(), '')
Expand Down
Loading