@@ -30,6 +30,7 @@ import { commonFlags } from '../flags'
30
30
import { printFlagList } from '../utils/formatting'
31
31
import { existsSync } from '../utils/fs'
32
32
import { detect } from '../utils/package-manager-detector'
33
+ import { shadowNpmInstall } from '../utils/shadow-npm'
33
34
34
35
import type { CliSubcommand } from '../utils/meow-with-subcommands'
35
36
import type {
@@ -52,9 +53,7 @@ const {
52
53
VLT ,
53
54
YARN_BERRY ,
54
55
YARN_CLASSIC ,
55
- abortSignal,
56
- execPath,
57
- rootBinPath
56
+ abortSignal
58
57
} = constants
59
58
60
59
const COMMAND_TITLE = 'Socket Optimize'
@@ -918,24 +917,20 @@ export const optimize: CliSubcommand = {
918
917
spinner . start ( `Updating ${ lockName } ...` )
919
918
try {
920
919
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 ( {
925
921
env : {
926
- ...process . env ,
927
922
[ SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE ] : '1'
928
923
}
929
- }
930
- await spawn ( execPath , [ wrapperPath , 'install' ] , npmSpawnOptions )
924
+ } )
931
925
// TODO: This is a temporary workaround for a `npm ci` bug where it
932
926
// will error out after Socket Optimize generates a lock file. More
933
927
// 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
+ } )
939
934
} else {
940
935
// All package managers support the "install" command.
941
936
await spawn ( agentExecPath , [ 'install' ] , {
0 commit comments