1- const Fetcher = require ( './fetcher.js' )
2- const RemoteFetcher = require ( './remote.js' )
3- const pacoteVersion = require ( '../package.json' ) . version
4- const removeTrailingSlashes = require ( './util/trailing-slashes.js' )
1+ const crypto = require ( 'node:crypto' )
52const PackageJson = require ( '@npmcli/package-json' )
63const pickManifest = require ( 'npm-pick-manifest' )
74const ssri = require ( 'ssri' )
8- const crypto = require ( 'crypto' )
95const npa = require ( 'npm-package-arg' )
106const sigstore = require ( 'sigstore' )
117const fetch = require ( 'npm-registry-fetch' )
8+ const Fetcher = require ( './fetcher.js' )
9+ const RemoteFetcher = require ( './remote.js' )
10+ const pacoteVersion = require ( '../package.json' ) . version
11+ const removeTrailingSlashes = require ( './util/trailing-slashes.js' )
1212const _ = require ( './util/protected.js' )
1313
1414// Corgis are cute. 🐕🐶
@@ -20,6 +20,7 @@ const fullDoc = 'application/json'
2020const MISSING_TIME_CUTOFF = '2015-01-01T00:00:00.000Z'
2121
2222class RegistryFetcher extends Fetcher {
23+ #cacheKey
2324 constructor ( spec , opts ) {
2425 super ( spec , opts )
2526
@@ -32,8 +33,8 @@ class RegistryFetcher extends Fetcher {
3233 this . packumentCache = this . opts . packumentCache || null
3334
3435 this . registry = fetch . pickRegistry ( spec , opts )
35- this . packumentUrl = removeTrailingSlashes ( this . registry ) + '/' +
36- this . spec . escapedName
36+ this . packumentUrl = ` ${ removeTrailingSlashes ( this . registry ) } / ${ this . spec . escapedName } `
37+ this . #cacheKey = ` ${ this . fullMetadata ? 'full' : 'corgi' } : ${ this . packumentUrl } `
3738
3839 const parsed = new URL ( this . registry )
3940 const regKey = `//${ parsed . host } ${ parsed . pathname } `
@@ -78,8 +79,8 @@ class RegistryFetcher extends Fetcher {
7879 // note this might be either an in-flight promise for a request,
7980 // or the actual packument, but we never want to make more than
8081 // one request at a time for the same thing regardless.
81- if ( this . packumentCache ?. has ( this . packumentUrl ) ) {
82- return this . packumentCache . get ( this . packumentUrl )
82+ if ( this . packumentCache ?. has ( this . #cacheKey ) ) {
83+ return this . packumentCache . get ( this . #cacheKey )
8384 }
8485
8586 // npm-registry-fetch the packument
@@ -99,10 +100,10 @@ class RegistryFetcher extends Fetcher {
99100 if ( contentLength ) {
100101 packument . _contentLength = Number ( contentLength )
101102 }
102- this . packumentCache ?. set ( this . packumentUrl , packument )
103+ this . packumentCache ?. set ( this . #cacheKey , packument )
103104 return packument
104105 } catch ( err ) {
105- this . packumentCache ?. delete ( this . packumentUrl )
106+ this . packumentCache ?. delete ( this . #cacheKey )
106107 if ( err . code !== 'E404' || this . fullMetadata ) {
107108 throw err
108109 }
0 commit comments