@@ -249,6 +249,10 @@ function findRoot (filepath) {
249
249
const npmDir = findRoot ( path . dirname ( npmEntrypoint ) )
250
250
const arboristLibClassPath = path . join ( npmDir , 'node_modules' , '@npmcli' , 'arborist' , 'lib' , 'arborist' , 'index.js' )
251
251
const npmlog = require ( path . join ( npmDir , 'node_modules' , 'npmlog' , 'lib' , 'log.js' ) )
252
+ /**
253
+ * @type {import('pacote') }
254
+ */
255
+ const pacote = require ( path . join ( npmDir , 'node_modules' , 'pacote' ) )
252
256
253
257
/**
254
258
* @type {typeof import('@npmcli/arborist') }
@@ -336,7 +340,7 @@ class SafeArborist extends Arborist {
336
340
spinner : oraNS . spinners . dots ,
337
341
} )
338
342
}
339
- const risky = await packagesHaveRiskyIssues ( this . registry , diff , ora , input , output )
343
+ const risky = await packagesHaveRiskyIssues ( this , this . registry , diff , ora , input , output )
340
344
if ( ! risky ) {
341
345
return true
342
346
}
@@ -368,8 +372,8 @@ class SafeArborist extends Arborist {
368
372
rli . close ( )
369
373
}
370
374
} else {
371
- if ( await packagesHaveRiskyIssues ( this . registry , diff , null , null , output ) ) {
372
- throw new Error ( 'Socket npm unable to prompt to accept risk, need TTY to do so' )
375
+ if ( await packagesHaveRiskyIssues ( this , this . registry , diff , null , null , output ) ) {
376
+ throw new Error ( 'Socket npm Unable to prompt to accept risk, need TTY to do so' )
373
377
}
374
378
return true
375
379
}
@@ -479,14 +483,15 @@ function walk (diff, needInfoOn = []) {
479
483
}
480
484
481
485
/**
486
+ * @param {SafeArborist } safeArb
482
487
* @param {string } registry
483
488
* @param {InstallEffect[] } pkgs
484
489
* @param {import('ora')['default'] | null } ora
485
490
* @param {Readable | null } [input]
486
491
* @param {Writable | null } [output]
487
492
* @returns {Promise<boolean> }
488
493
*/
489
- async function packagesHaveRiskyIssues ( registry , pkgs , ora = null , input , output ) {
494
+ async function packagesHaveRiskyIssues ( safeArb , registry , pkgs , ora = null , input , output ) {
490
495
let failed = false
491
496
if ( pkgs . length ) {
492
497
let remaining = pkgs . length
@@ -511,6 +516,7 @@ async function packagesHaveRiskyIssues (registry, pkgs, ora = null, input, outpu
511
516
let displayWarning = false
512
517
const name = pkgData . pkg
513
518
const version = pkgData . ver
519
+ let blocked = false
514
520
if ( pkgData . type === 'missing' ) {
515
521
failed = true
516
522
failures . push ( {
@@ -524,7 +530,7 @@ async function packagesHaveRiskyIssues (registry, pkgs, ora = null, input, outpu
524
530
failures . push ( { raw : failure , block : ux . block } )
525
531
// before we ask about problematic issues, check to see if they already existed in the old version
526
532
// if they did, be quiet
527
- const pkg = pkgs . find ( pkg => pkg . pkgid === `${ pkgData . pkg } @${ pkgData . ver } ` && pkg . existing ?. startsWith ( pkgData . pkg ) )
533
+ const pkg = pkgs . find ( pkg => pkg . pkgid === `${ pkgData . pkg } @${ pkgData . ver } ` && pkg . existing ?. startsWith ( pkgData . pkg + '@' ) )
528
534
if ( pkg ?. existing ) {
529
535
for await ( const oldPkgData of batchScan ( [ pkg . existing ] ) ) {
530
536
if ( oldPkgData . type === 'success' ) {
@@ -537,14 +543,23 @@ async function packagesHaveRiskyIssues (registry, pkgs, ora = null, input, outpu
537
543
}
538
544
if ( ux . block ) {
539
545
failed = true
540
- } else {
541
- // TODO: have pacote/cacache download non-problematic files while waiting
546
+ blocked = true
542
547
}
543
548
if ( ux . display ) {
544
549
displayWarning = true
545
550
}
546
551
}
547
552
}
553
+ if ( ! blocked ) {
554
+ const pkg = pkgs . find ( pkg => pkg . pkgid === `${ pkgData . pkg } @${ pkgData . ver } ` )
555
+ if ( pkg ) {
556
+ pacote . tarball . stream ( pkg . pkgid , ( stream ) => {
557
+ stream . resume ( )
558
+ // @ts -ignore pacote does a naughty
559
+ return stream . promise ( )
560
+ } , { ...safeArb [ kCtorArgs ] [ 0 ] } )
561
+ }
562
+ }
548
563
if ( displayWarning ) {
549
564
translations ??= JSON . parse ( fs . readFileSync ( path . join ( __dirname , '/translations.json' ) , 'utf-8' ) )
550
565
formatter ??= new ( ( await chalkMarkdownPromise ) . ChalkOrMarkdown ) ( false )
0 commit comments