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' )
5
2
const PackageJson = require ( '@npmcli/package-json' )
6
3
const pickManifest = require ( 'npm-pick-manifest' )
7
4
const ssri = require ( 'ssri' )
8
- const crypto = require ( 'crypto' )
9
5
const npa = require ( 'npm-package-arg' )
10
6
const sigstore = require ( 'sigstore' )
11
7
const 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' )
12
12
const _ = require ( './util/protected.js' )
13
13
14
14
// Corgis are cute. 🐕🐶
@@ -20,6 +20,7 @@ const fullDoc = 'application/json'
20
20
const MISSING_TIME_CUTOFF = '2015-01-01T00:00:00.000Z'
21
21
22
22
class RegistryFetcher extends Fetcher {
23
+ #cacheKey
23
24
constructor ( spec , opts ) {
24
25
super ( spec , opts )
25
26
@@ -32,8 +33,8 @@ class RegistryFetcher extends Fetcher {
32
33
this . packumentCache = this . opts . packumentCache || null
33
34
34
35
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 } `
37
38
38
39
const parsed = new URL ( this . registry )
39
40
const regKey = `//${ parsed . host } ${ parsed . pathname } `
@@ -78,8 +79,8 @@ class RegistryFetcher extends Fetcher {
78
79
// note this might be either an in-flight promise for a request,
79
80
// or the actual packument, but we never want to make more than
80
81
// 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 )
83
84
}
84
85
85
86
// npm-registry-fetch the packument
@@ -99,10 +100,10 @@ class RegistryFetcher extends Fetcher {
99
100
if ( contentLength ) {
100
101
packument . _contentLength = Number ( contentLength )
101
102
}
102
- this . packumentCache ?. set ( this . packumentUrl , packument )
103
+ this . packumentCache ?. set ( this . #cacheKey , packument )
103
104
return packument
104
105
} catch ( err ) {
105
- this . packumentCache ?. delete ( this . packumentUrl )
106
+ this . packumentCache ?. delete ( this . #cacheKey )
106
107
if ( err . code !== 'E404' || this . fullMetadata ) {
107
108
throw err
108
109
}
0 commit comments