@@ -18,27 +18,12 @@ const getContents = require('@npmcli/installed-package-contents')
1818const PackageJson = require ( '@npmcli/package-json' )
1919const { Minipass } = require ( 'minipass' )
2020const cacheDir = require ( './util/cache-dir.js' )
21+ const _ = require ( './util/protected.js' )
2122
2223// Pacote is only concerned with the package.json contents
2324const packageJsonPrepare = ( p ) => PackageJson . prepare ( p ) . then ( pkg => pkg . content )
2425const packageJsonNormalize = ( p ) => PackageJson . normalize ( p ) . then ( pkg => pkg . content )
2526
26- // Private methods.
27- // Child classes should not have to override these.
28- // Users should never call them.
29- const _extract = Symbol ( '_extract' )
30- const _mkdir = Symbol ( '_mkdir' )
31- const _empty = Symbol ( '_empty' )
32- const _toFile = Symbol ( '_toFile' )
33- const _tarxOptions = Symbol ( '_tarxOptions' )
34- const _entryMode = Symbol ( '_entryMode' )
35- const _istream = Symbol ( '_istream' )
36- const _assertType = Symbol ( '_assertType' )
37- const _tarballFromCache = Symbol ( '_tarballFromCache' )
38- const _tarballFromResolved = Symbol . for ( 'pacote.Fetcher._tarballFromResolved' )
39- const _cacheFetches = Symbol . for ( 'pacote.Fetcher._cacheFetches' )
40- const _readPackageJson = Symbol . for ( 'package.Fetcher._readPackageJson' )
41-
4227class FetcherBase {
4328 constructor ( spec , opts ) {
4429 if ( ! opts || typeof opts !== 'object' ) {
@@ -57,7 +42,7 @@ class FetcherBase {
5742 this . from = this . spec . registry
5843 ? `${ this . spec . name } @${ this . spec . rawSpec } ` : this . spec . saveSpec
5944
60- this [ _assertType ] ( )
45+ this . #assertType ( )
6146 // clone the opts object so that others aren't upset when we mutate it
6247 // by adding/modifying the integrity value.
6348 this . opts = { ...opts }
@@ -93,11 +78,9 @@ class FetcherBase {
9378 this . before = opts . before
9479 this . fullMetadata = this . before ? true : ! ! opts . fullMetadata
9580 this . fullReadJson = ! ! opts . fullReadJson
96- if ( this . fullReadJson ) {
97- this [ _readPackageJson ] = packageJsonPrepare
98- } else {
99- this [ _readPackageJson ] = packageJsonNormalize
100- }
81+ this [ _ . readPackageJson ] = this . fullReadJson
82+ ? packageJsonPrepare
83+ : packageJsonNormalize
10184
10285 // rrh is a registry hostname or 'never' or 'always'
10386 // defaults to registry.npmjs.org
@@ -188,7 +171,7 @@ class FetcherBase {
188171 // private, should be overridden.
189172 // Note that they should *not* calculate or check integrity or cache,
190173 // but *just* return the raw tarball data stream.
191- [ _tarballFromResolved ] ( ) {
174+ [ _ . tarballFromResolved ] ( ) {
192175 throw this . notImplementedError
193176 }
194177
@@ -204,17 +187,17 @@ class FetcherBase {
204187
205188 // private
206189 // Note: cacache will raise a EINTEGRITY error if the integrity doesn't match
207- [ _tarballFromCache ] ( ) {
190+ #tarballFromCache ( ) {
208191 return cacache . get . stream . byDigest ( this . cache , this . integrity , this . opts )
209192 }
210193
211- get [ _cacheFetches ] ( ) {
194+ get [ _ . cacheFetches ] ( ) {
212195 return true
213196 }
214197
215- [ _istream ] ( stream ) {
198+ #istream ( stream ) {
216199 // if not caching this, just return it
217- if ( ! this . opts . cache || ! this [ _cacheFetches ] ) {
200+ if ( ! this . opts . cache || ! this [ _ . cacheFetches ] ) {
218201 // instead of creating a new integrity stream, we only piggyback on the
219202 // provided stream's events
220203 if ( stream . hasIntegrityEmitter ) {
@@ -267,7 +250,7 @@ class FetcherBase {
267250 return false
268251 }
269252
270- [ _assertType ] ( ) {
253+ #assertType ( ) {
271254 if ( this . types && ! this . types . includes ( this . spec . type ) ) {
272255 throw new TypeError ( `Wrong spec type (${
273256 this . spec . type
@@ -306,7 +289,7 @@ class FetcherBase {
306289 ! this . preferOnline &&
307290 this . integrity &&
308291 this . resolved
309- ) ? streamHandler ( this [ _tarballFromCache ] ( ) ) . catch ( er => {
292+ ) ? streamHandler ( this . #tarballFromCache ( ) ) . catch ( er => {
310293 if ( this . isDataCorruptionError ( er ) ) {
311294 log . warn ( 'tarball' , `cached data for ${
312295 this . spec
@@ -329,7 +312,7 @@ class FetcherBase {
329312 } . Extracting by manifest.`)
330313 }
331314 return this . resolve ( ) . then ( ( ) => retry ( tryAgain =>
332- streamHandler ( this [ _istream ] ( this [ _tarballFromResolved ] ( ) ) )
315+ streamHandler ( this . #istream ( this [ _ . tarballFromResolved ] ( ) ) )
333316 . catch ( streamErr => {
334317 // Most likely data integrity. A cache ENOENT error is unlikely
335318 // here, since we're definitely not reading from the cache, but it
@@ -352,24 +335,24 @@ class FetcherBase {
352335 return cacache . rm . content ( this . cache , this . integrity , this . opts )
353336 }
354337
355- [ _empty ] ( path ) {
338+ #empty ( path ) {
356339 return getContents ( { path, depth : 1 } ) . then ( contents => Promise . all (
357340 contents . map ( entry => fs . rm ( entry , { recursive : true , force : true } ) ) ) )
358341 }
359342
360- async [ _mkdir ] ( dest ) {
361- await this [ _empty ] ( dest )
343+ async #mkdir ( dest ) {
344+ await this . #empty ( dest )
362345 return await fs . mkdir ( dest , { recursive : true } )
363346 }
364347
365348 // extraction is always the same. the only difference is where
366349 // the tarball comes from.
367350 async extract ( dest ) {
368- await this [ _mkdir ] ( dest )
369- return this . tarballStream ( ( tarball ) => this [ _extract ] ( dest , tarball ) )
351+ await this . #mkdir ( dest )
352+ return this . tarballStream ( ( tarball ) => this . #extract ( dest , tarball ) )
370353 }
371354
372- [ _toFile ] ( dest ) {
355+ #toFile ( dest ) {
373356 return this . tarballStream ( str => new Promise ( ( res , rej ) => {
374357 const writer = new fsm . WriteStream ( dest )
375358 str . on ( 'error' , er => writer . emit ( 'error' , er ) )
@@ -383,15 +366,15 @@ class FetcherBase {
383366 } ) )
384367 }
385368
386- // don't use this[_mkdir] because we don't want to rimraf anything
369+ // don't use this.#mkdir because we don't want to rimraf anything
387370 async tarballFile ( dest ) {
388371 const dir = dirname ( dest )
389372 await fs . mkdir ( dir , { recursive : true } )
390- return this [ _toFile ] ( dest )
373+ return this . #toFile ( dest )
391374 }
392375
393- [ _extract ] ( dest , tarball ) {
394- const extractor = tar . x ( this [ _tarxOptions ] ( { cwd : dest } ) )
376+ #extract ( dest , tarball ) {
377+ const extractor = tar . x ( this . #tarxOptions ( { cwd : dest } ) )
395378 const p = new Promise ( ( resolve , reject ) => {
396379 extractor . on ( 'end' , ( ) => {
397380 resolve ( {
@@ -416,7 +399,7 @@ class FetcherBase {
416399
417400 // always ensure that entries are at least as permissive as our configured
418401 // dmode/fmode, but never more permissive than the umask allows.
419- [ _entryMode ] ( path , mode , type ) {
402+ #entryMode ( path , mode , type ) {
420403 const m = / D i r e c t o r y | G N U D u m p D i r / . test ( type ) ? this . dmode
421404 : / F i l e $ / . test ( type ) ? this . fmode
422405 : /* istanbul ignore next - should never happen in a pkg */ 0
@@ -427,7 +410,7 @@ class FetcherBase {
427410 return ( ( mode | m ) & ~ this . umask ) | exe | 0o600
428411 }
429412
430- [ _tarxOptions ] ( { cwd } ) {
413+ #tarxOptions ( { cwd } ) {
431414 const sawIgnores = new Set ( )
432415 return {
433416 cwd,
@@ -437,7 +420,7 @@ class FetcherBase {
437420 if ( / L i n k $ / . test ( entry . type ) ) {
438421 return false
439422 }
440- entry . mode = this [ _entryMode ] ( entry . path , entry . mode , entry . type )
423+ entry . mode = this . #entryMode ( entry . path , entry . mode , entry . type )
441424 // this replicates the npm pack behavior where .gitignore files
442425 // are treated like .npmignore files, but only if a .npmignore
443426 // file is not present.
0 commit comments