Skip to content

Commit 9122fb6

Browse files
authored
fix(cache): add both full and minified packument to cache (#7516)
This will fix the `npm cache add` to cache package with same header as it's used in `npm install` by adding extra manifest call with `fullMetadata: true` while caching to match behaviour with install command which internally request manifest with fullMetadata. ## References Closes #7465
1 parent 9e6686b commit 9122fb6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/commands/cache.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,20 @@ class Cache extends BaseCommand {
152152
throw this.usageError('First argument to `add` is required')
153153
}
154154

155-
return Promise.all(args.map(spec => {
155+
await Promise.all(args.map(async spec => {
156156
log.silly('cache add', 'spec', spec)
157157
// we ask pacote for the thing, and then just throw the data
158158
// away so that it tee-pipes it into the cache like it does
159159
// for a normal request.
160-
return pacote.tarball.stream(spec, stream => {
160+
await pacote.tarball.stream(spec, stream => {
161161
stream.resume()
162162
return stream.promise()
163163
}, { ...this.npm.flatOptions })
164+
165+
await pacote.manifest(spec, {
166+
...this.npm.flatOptions,
167+
fullMetadata: true,
168+
})
164169
}))
165170
}
166171

test/lib/commands/cache.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ t.test('cache add single pkg', async t => {
7171
registry: npm.config.get('registry'),
7272
})
7373
const manifest = registry.manifest({ name: pkg })
74-
await registry.package({ manifest, tarballs: { '1.0.0': path.join(npm.prefix, 'package') } })
74+
await registry.package({
75+
manifest,
76+
times: 2,
77+
tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
78+
})
7579
await npm.exec('cache', ['add', pkg])
7680
t.equal(joinedOutput(), '')
7781
// eslint-disable-next-line max-len
@@ -99,9 +103,13 @@ t.test('cache add multiple pkgs', async t => {
99103
})
100104
const manifest = registry.manifest({ name: pkg })
101105
const manifest2 = registry.manifest({ name: pkg2 })
102-
await registry.package({ manifest, tarballs: { '1.0.0': path.join(npm.prefix, 'package') } })
103106
await registry.package({
104-
manifest: manifest2, tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
107+
manifest,
108+
times: 2,
109+
tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
110+
})
111+
await registry.package({
112+
manifest: manifest2, times: 2, tarballs: { '1.0.0': path.join(npm.prefix, 'package') },
105113
})
106114
await npm.exec('cache', ['add', pkg, pkg2])
107115
t.equal(joinedOutput(), '')

0 commit comments

Comments
 (0)