@@ -15,11 +15,9 @@ import {
15
15
} from '@socketsecurity/registry/lib/packages'
16
16
import { confirm } from '@socketsecurity/registry/lib/prompts'
17
17
18
- import isInteractive from 'is-interactive'
19
18
import npa from 'npm-package-arg'
20
19
import semver from 'semver'
21
20
22
- import { createTTYServer } from './tty-server'
23
21
import constants from '../constants'
24
22
import { ColorOrMarkdown } from '../utils/color-or-markdown'
25
23
import { createAlertUXLookup } from '../utils/alert-rules'
@@ -353,8 +351,6 @@ const kRiskyReify = Symbol('riskyReify')
353
351
const formatter = new ColorOrMarkdown ( false )
354
352
const pubToken = getDefaultKey ( ) ?? SOCKET_PUBLIC_API_KEY
355
353
356
- const ttyServer = createTTYServer ( isInteractive ( { stream : process . stdin } ) , log )
357
-
358
354
let _uxLookup : AlertUxLookup | undefined
359
355
360
356
async function uxLookup (
@@ -507,7 +503,6 @@ function maybeReadfileSync(filepath: string): string | undefined {
507
503
508
504
async function getPackagesAlerts (
509
505
safeArb : SafeArborist ,
510
- _registry : string ,
511
506
pkgs : InstallEffect [ ] ,
512
507
output ?: Writable
513
508
) : Promise < SocketPackageAlert [ ] > {
@@ -1418,39 +1413,45 @@ export class SafeArborist extends Arborist {
1418
1413
if ( diff . findIndex ( c => c . repository_url === NPM_REGISTRY_URL ) === - 1 ) {
1419
1414
return await this [ kRiskyReify ] ( ...args )
1420
1415
}
1416
+ const input = process . stdin
1417
+ const output = process . stderr
1421
1418
let proceed = ENV [ UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE ]
1422
1419
let alerts : SocketPackageAlert [ ] | undefined
1423
1420
if ( ! proceed ) {
1424
- proceed = await ttyServer . captureTTY ( async ( input , output ) => {
1425
- if ( input && output ) {
1426
- alerts = await getPackagesAlerts ( this , this [ 'registry' ] , diff , output )
1427
- if ( ! alerts . length ) {
1428
- return true
1429
- }
1430
- return await confirm (
1431
- {
1432
- message : 'Accept risks of installing these packages?' ,
1433
- default : false
1434
- } ,
1435
- {
1436
- input,
1437
- output,
1438
- signal : abortSignal
1439
- }
1440
- )
1441
- } else if (
1442
- ( await getPackagesAlerts ( this , this [ 'registry' ] , diff , output ) )
1443
- . length > 0
1444
- ) {
1445
- throw new Error (
1446
- 'Socket npm Unable to prompt to accept risk, need TTY to do so'
1447
- )
1421
+ proceed = await ( async ( ) => {
1422
+ alerts = await getPackagesAlerts ( this , diff , output )
1423
+ if ( ! alerts . length ) {
1424
+ return true
1448
1425
}
1426
+ return await confirm (
1427
+ {
1428
+ message : 'Accept risks of installing these packages?' ,
1429
+ default : false
1430
+ } ,
1431
+ {
1432
+ input,
1433
+ output,
1434
+ signal : abortSignal
1435
+ }
1436
+ )
1449
1437
return true
1450
- } )
1438
+ } ) ( )
1451
1439
}
1452
1440
if ( proceed ) {
1453
- if ( options [ 'fix' ] && alerts ?. length ) {
1441
+ if (
1442
+ alerts ?. length &&
1443
+ ( await confirm (
1444
+ {
1445
+ message : 'Try to fix alerts?' ,
1446
+ default : true
1447
+ } ,
1448
+ {
1449
+ input,
1450
+ output,
1451
+ signal : abortSignal
1452
+ }
1453
+ ) )
1454
+ ) {
1454
1455
await updateAdvisoryDependencies ( this , alerts )
1455
1456
}
1456
1457
return await this [ kRiskyReify ] ( ...args )
0 commit comments