@@ -18,27 +18,12 @@ const getContents = require('@npmcli/installed-package-contents')
18
18
const PackageJson = require ( '@npmcli/package-json' )
19
19
const { Minipass } = require ( 'minipass' )
20
20
const cacheDir = require ( './util/cache-dir.js' )
21
+ const _ = require ( './util/protected.js' )
21
22
22
23
// Pacote is only concerned with the package.json contents
23
24
const packageJsonPrepare = ( p ) => PackageJson . prepare ( p ) . then ( pkg => pkg . content )
24
25
const packageJsonNormalize = ( p ) => PackageJson . normalize ( p ) . then ( pkg => pkg . content )
25
26
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
-
42
27
class FetcherBase {
43
28
constructor ( spec , opts ) {
44
29
if ( ! opts || typeof opts !== 'object' ) {
@@ -57,7 +42,7 @@ class FetcherBase {
57
42
this . from = this . spec . registry
58
43
? `${ this . spec . name } @${ this . spec . rawSpec } ` : this . spec . saveSpec
59
44
60
- this [ _assertType ] ( )
45
+ this . #assertType ( )
61
46
// clone the opts object so that others aren't upset when we mutate it
62
47
// by adding/modifying the integrity value.
63
48
this . opts = { ...opts }
@@ -93,11 +78,9 @@ class FetcherBase {
93
78
this . before = opts . before
94
79
this . fullMetadata = this . before ? true : ! ! opts . fullMetadata
95
80
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
101
84
102
85
// rrh is a registry hostname or 'never' or 'always'
103
86
// defaults to registry.npmjs.org
@@ -188,7 +171,7 @@ class FetcherBase {
188
171
// private, should be overridden.
189
172
// Note that they should *not* calculate or check integrity or cache,
190
173
// but *just* return the raw tarball data stream.
191
- [ _tarballFromResolved ] ( ) {
174
+ [ _ . tarballFromResolved ] ( ) {
192
175
throw this . notImplementedError
193
176
}
194
177
@@ -204,17 +187,17 @@ class FetcherBase {
204
187
205
188
// private
206
189
// Note: cacache will raise a EINTEGRITY error if the integrity doesn't match
207
- [ _tarballFromCache ] ( ) {
190
+ #tarballFromCache ( ) {
208
191
return cacache . get . stream . byDigest ( this . cache , this . integrity , this . opts )
209
192
}
210
193
211
- get [ _cacheFetches ] ( ) {
194
+ get [ _ . cacheFetches ] ( ) {
212
195
return true
213
196
}
214
197
215
- [ _istream ] ( stream ) {
198
+ #istream ( stream ) {
216
199
// if not caching this, just return it
217
- if ( ! this . opts . cache || ! this [ _cacheFetches ] ) {
200
+ if ( ! this . opts . cache || ! this [ _ . cacheFetches ] ) {
218
201
// instead of creating a new integrity stream, we only piggyback on the
219
202
// provided stream's events
220
203
if ( stream . hasIntegrityEmitter ) {
@@ -267,7 +250,7 @@ class FetcherBase {
267
250
return false
268
251
}
269
252
270
- [ _assertType ] ( ) {
253
+ #assertType ( ) {
271
254
if ( this . types && ! this . types . includes ( this . spec . type ) ) {
272
255
throw new TypeError ( `Wrong spec type (${
273
256
this . spec . type
@@ -306,7 +289,7 @@ class FetcherBase {
306
289
! this . preferOnline &&
307
290
this . integrity &&
308
291
this . resolved
309
- ) ? streamHandler ( this [ _tarballFromCache ] ( ) ) . catch ( er => {
292
+ ) ? streamHandler ( this . #tarballFromCache ( ) ) . catch ( er => {
310
293
if ( this . isDataCorruptionError ( er ) ) {
311
294
log . warn ( 'tarball' , `cached data for ${
312
295
this . spec
@@ -329,7 +312,7 @@ class FetcherBase {
329
312
} . Extracting by manifest.`)
330
313
}
331
314
return this . resolve ( ) . then ( ( ) => retry ( tryAgain =>
332
- streamHandler ( this [ _istream ] ( this [ _tarballFromResolved ] ( ) ) )
315
+ streamHandler ( this . #istream ( this [ _ . tarballFromResolved ] ( ) ) )
333
316
. catch ( streamErr => {
334
317
// Most likely data integrity. A cache ENOENT error is unlikely
335
318
// here, since we're definitely not reading from the cache, but it
@@ -352,24 +335,24 @@ class FetcherBase {
352
335
return cacache . rm . content ( this . cache , this . integrity , this . opts )
353
336
}
354
337
355
- [ _empty ] ( path ) {
338
+ #empty ( path ) {
356
339
return getContents ( { path, depth : 1 } ) . then ( contents => Promise . all (
357
340
contents . map ( entry => fs . rm ( entry , { recursive : true , force : true } ) ) ) )
358
341
}
359
342
360
- async [ _mkdir ] ( dest ) {
361
- await this [ _empty ] ( dest )
343
+ async #mkdir ( dest ) {
344
+ await this . #empty ( dest )
362
345
return await fs . mkdir ( dest , { recursive : true } )
363
346
}
364
347
365
348
// extraction is always the same. the only difference is where
366
349
// the tarball comes from.
367
350
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 ) )
370
353
}
371
354
372
- [ _toFile ] ( dest ) {
355
+ #toFile ( dest ) {
373
356
return this . tarballStream ( str => new Promise ( ( res , rej ) => {
374
357
const writer = new fsm . WriteStream ( dest )
375
358
str . on ( 'error' , er => writer . emit ( 'error' , er ) )
@@ -383,15 +366,15 @@ class FetcherBase {
383
366
} ) )
384
367
}
385
368
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
387
370
async tarballFile ( dest ) {
388
371
const dir = dirname ( dest )
389
372
await fs . mkdir ( dir , { recursive : true } )
390
- return this [ _toFile ] ( dest )
373
+ return this . #toFile ( dest )
391
374
}
392
375
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 } ) )
395
378
const p = new Promise ( ( resolve , reject ) => {
396
379
extractor . on ( 'end' , ( ) => {
397
380
resolve ( {
@@ -416,7 +399,7 @@ class FetcherBase {
416
399
417
400
// always ensure that entries are at least as permissive as our configured
418
401
// dmode/fmode, but never more permissive than the umask allows.
419
- [ _entryMode ] ( path , mode , type ) {
402
+ #entryMode ( path , mode , type ) {
420
403
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
421
404
: / F i l e $ / . test ( type ) ? this . fmode
422
405
: /* istanbul ignore next - should never happen in a pkg */ 0
@@ -427,7 +410,7 @@ class FetcherBase {
427
410
return ( ( mode | m ) & ~ this . umask ) | exe | 0o600
428
411
}
429
412
430
- [ _tarxOptions ] ( { cwd } ) {
413
+ #tarxOptions ( { cwd } ) {
431
414
const sawIgnores = new Set ( )
432
415
return {
433
416
cwd,
@@ -437,7 +420,7 @@ class FetcherBase {
437
420
if ( / L i n k $ / . test ( entry . type ) ) {
438
421
return false
439
422
}
440
- entry . mode = this [ _entryMode ] ( entry . path , entry . mode , entry . type )
423
+ entry . mode = this . #entryMode ( entry . path , entry . mode , entry . type )
441
424
// this replicates the npm pack behavior where .gitignore files
442
425
// are treated like .npmignore files, but only if a .npmignore
443
426
// file is not present.
0 commit comments