Skip to content

Commit 18b45bc

Browse files
committed
Remove tty-server
1 parent 6fdb214 commit 18b45bc

File tree

2 files changed

+32
-290
lines changed

2 files changed

+32
-290
lines changed

src/shadow/arborist.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ import {
1515
} from '@socketsecurity/registry/lib/packages'
1616
import { confirm } from '@socketsecurity/registry/lib/prompts'
1717

18-
import isInteractive from 'is-interactive'
1918
import npa from 'npm-package-arg'
2019
import semver from 'semver'
2120

22-
import { createTTYServer } from './tty-server'
2321
import constants from '../constants'
2422
import { ColorOrMarkdown } from '../utils/color-or-markdown'
2523
import { createAlertUXLookup } from '../utils/alert-rules'
@@ -353,8 +351,6 @@ const kRiskyReify = Symbol('riskyReify')
353351
const formatter = new ColorOrMarkdown(false)
354352
const pubToken = getDefaultKey() ?? SOCKET_PUBLIC_API_KEY
355353

356-
const ttyServer = createTTYServer(isInteractive({ stream: process.stdin }), log)
357-
358354
let _uxLookup: AlertUxLookup | undefined
359355

360356
async function uxLookup(
@@ -507,7 +503,6 @@ function maybeReadfileSync(filepath: string): string | undefined {
507503

508504
async function getPackagesAlerts(
509505
safeArb: SafeArborist,
510-
_registry: string,
511506
pkgs: InstallEffect[],
512507
output?: Writable
513508
): Promise<SocketPackageAlert[]> {
@@ -1418,39 +1413,45 @@ export class SafeArborist extends Arborist {
14181413
if (diff.findIndex(c => c.repository_url === NPM_REGISTRY_URL) === -1) {
14191414
return await this[kRiskyReify](...args)
14201415
}
1416+
const input = process.stdin
1417+
const output = process.stderr
14211418
let proceed = ENV[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]
14221419
let alerts: SocketPackageAlert[] | undefined
14231420
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
14481425
}
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+
)
14491437
return true
1450-
})
1438+
})()
14511439
}
14521440
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+
) {
14541455
await updateAdvisoryDependencies(this, alerts)
14551456
}
14561457
return await this[kRiskyReify](...args)

src/shadow/tty-server.ts

Lines changed: 0 additions & 259 deletions
This file was deleted.

0 commit comments

Comments
 (0)