From 9122fb65ac05d793a69f4fdcbd03b59595adf937 Mon Sep 17 00:00:00 2001 From: milaninfy <111582375+milaninfy@users.noreply.github.com> Date: Wed, 22 May 2024 10:07:17 -0400 Subject: [PATCH] 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 --- lib/commands/cache.js | 9 +++++++-- test/lib/commands/cache.js | 14 +++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/commands/cache.js b/lib/commands/cache.js index d23c51c390287..b8bef966aef1e 100644 --- a/lib/commands/cache.js +++ b/lib/commands/cache.js @@ -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, + }) })) } diff --git a/test/lib/commands/cache.js b/test/lib/commands/cache.js index 15ee4dc80aa1a..b962fa63f82a5 100644 --- a/test/lib/commands/cache.js +++ b/test/lib/commands/cache.js @@ -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 @@ -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(), '')