Skip to content

Commit 2c1d96c

Browse files
committed
wip
1 parent 226d426 commit 2c1d96c

File tree

3 files changed

+52
-1365
lines changed

3 files changed

+52
-1365
lines changed

lib/shadow/npm-injection.cjs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ function findRoot (filepath) {
249249
const npmDir = findRoot(path.dirname(npmEntrypoint))
250250
const arboristLibClassPath = path.join(npmDir, 'node_modules', '@npmcli', 'arborist', 'lib', 'arborist', 'index.js')
251251
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'))
252256

253257
/**
254258
* @type {typeof import('@npmcli/arborist')}
@@ -336,7 +340,7 @@ class SafeArborist extends Arborist {
336340
spinner: oraNS.spinners.dots,
337341
})
338342
}
339-
const risky = await packagesHaveRiskyIssues(this.registry, diff, ora, input, output)
343+
const risky = await packagesHaveRiskyIssues(this, this.registry, diff, ora, input, output)
340344
if (!risky) {
341345
return true
342346
}
@@ -368,8 +372,8 @@ class SafeArborist extends Arborist {
368372
rli.close()
369373
}
370374
} 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')
373377
}
374378
return true
375379
}
@@ -479,14 +483,15 @@ function walk (diff, needInfoOn = []) {
479483
}
480484

481485
/**
486+
* @param {SafeArborist} safeArb
482487
* @param {string} registry
483488
* @param {InstallEffect[]} pkgs
484489
* @param {import('ora')['default'] | null} ora
485490
* @param {Readable | null} [input]
486491
* @param {Writable | null} [output]
487492
* @returns {Promise<boolean>}
488493
*/
489-
async function packagesHaveRiskyIssues (registry, pkgs, ora = null, input, output) {
494+
async function packagesHaveRiskyIssues (safeArb, registry, pkgs, ora = null, input, output) {
490495
let failed = false
491496
if (pkgs.length) {
492497
let remaining = pkgs.length
@@ -511,6 +516,7 @@ async function packagesHaveRiskyIssues (registry, pkgs, ora = null, input, outpu
511516
let displayWarning = false
512517
const name = pkgData.pkg
513518
const version = pkgData.ver
519+
let blocked = false
514520
if (pkgData.type === 'missing') {
515521
failed = true
516522
failures.push({
@@ -524,7 +530,7 @@ async function packagesHaveRiskyIssues (registry, pkgs, ora = null, input, outpu
524530
failures.push({ raw: failure, block: ux.block })
525531
// before we ask about problematic issues, check to see if they already existed in the old version
526532
// 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 + '@'))
528534
if (pkg?.existing) {
529535
for await (const oldPkgData of batchScan([pkg.existing])) {
530536
if (oldPkgData.type === 'success') {
@@ -537,14 +543,23 @@ async function packagesHaveRiskyIssues (registry, pkgs, ora = null, input, outpu
537543
}
538544
if (ux.block) {
539545
failed = true
540-
} else {
541-
// TODO: have pacote/cacache download non-problematic files while waiting
546+
blocked = true
542547
}
543548
if (ux.display) {
544549
displayWarning = true
545550
}
546551
}
547552
}
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+
}
548563
if (displayWarning) {
549564
translations ??= JSON.parse(fs.readFileSync(path.join(__dirname, '/translations.json'), 'utf-8'))
550565
formatter ??= new ((await chalkMarkdownPromise).ChalkOrMarkdown)(false)

0 commit comments

Comments
 (0)