Skip to content

Commit c9a2742

Browse files
committed
Use shadow-npm util
1 parent e7dc42a commit c9a2742

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/commands/fix.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@ import spawn from '@npmcli/promise-spawn'
55
import { Spinner } from '@socketsecurity/registry/lib/spinner'
66

77
import constants from '../constants'
8+
import { shadowNpmInstall } from '../utils/shadow-npm'
89

910
import type { CliSubcommand } from '../utils/meow-with-subcommands'
1011

11-
const { SOCKET_CLI_FIX_PACKAGE_LOCK_FILE, abortSignal, execPath, rootBinPath } =
12-
constants
12+
const { SOCKET_CLI_FIX_PACKAGE_LOCK_FILE } = constants
1313

1414
export const fix: CliSubcommand = {
1515
description: 'Fix "fixable" Socket alerts',
1616
async run() {
17-
const wrapperPath = path.join(rootBinPath, 'npm-cli.js')
1817
const spinner = new Spinner().start()
1918
try {
20-
await spawn(execPath, [wrapperPath, 'install'], {
21-
signal: abortSignal,
22-
stdio: 'inherit',
19+
await shadowNpmInstall({
2320
env: {
24-
...process.env,
2521
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: '1'
2622
}
2723
})

src/commands/optimize.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { commonFlags } from '../flags'
3030
import { printFlagList } from '../utils/formatting'
3131
import { existsSync } from '../utils/fs'
3232
import { detect } from '../utils/package-manager-detector'
33+
import { shadowNpmInstall } from '../utils/shadow-npm'
3334

3435
import type { CliSubcommand } from '../utils/meow-with-subcommands'
3536
import type {
@@ -52,9 +53,7 @@ const {
5253
VLT,
5354
YARN_BERRY,
5455
YARN_CLASSIC,
55-
abortSignal,
56-
execPath,
57-
rootBinPath
56+
abortSignal
5857
} = constants
5958

6059
const COMMAND_TITLE = 'Socket Optimize'
@@ -918,24 +917,20 @@ export const optimize: CliSubcommand = {
918917
spinner.start(`Updating ${lockName}...`)
919918
try {
920919
if (isNpm) {
921-
const wrapperPath = path.join(rootBinPath, 'npm-cli.js')
922-
const npmSpawnOptions: Parameters<typeof spawn>[2] = {
923-
signal: abortSignal,
924-
stdio: 'inherit',
920+
await shadowNpmInstall({
925921
env: {
926-
...process.env,
927922
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
928923
}
929-
}
930-
await spawn(execPath, [wrapperPath, 'install'], npmSpawnOptions)
924+
})
931925
// TODO: This is a temporary workaround for a `npm ci` bug where it
932926
// will error out after Socket Optimize generates a lock file. More
933927
// investigation is needed.
934-
await spawn(
935-
execPath,
936-
[wrapperPath, 'install', '--ignore-scripts', '--package-lock-only'],
937-
npmSpawnOptions
938-
)
928+
await shadowNpmInstall({
929+
flags: ['--ignore-scripts', '--package-lock-only'],
930+
env: {
931+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
932+
}
933+
})
939934
} else {
940935
// All package managers support the "install" command.
941936
await spawn(agentExecPath, ['install'], {

0 commit comments

Comments
 (0)