@@ -5,25 +5,25 @@ import { fork } from './promise-fork'
55import constants from '../constants'
66
77import type { ForkOptions , ForkResult } from './promise-fork'
8+ import type { Serializable } from 'node:child_process'
89
910const { abortSignal } = constants
1011
1112type ShadowNpmInstallOptions = ForkOptions & {
1213 flags ?: string [ ]
14+ ipc ?: Serializable
1315}
1416
1517export function shadowNpmInstall < O extends ShadowNpmInstallOptions > (
1618 opts ?: ShadowNpmInstallOptions
1719) {
18- const { flags = [ ] , ...spawnOptions } = { __proto__ : null , ...opts }
20+ const { flags = [ ] , ipc , ...forkOptions } = { __proto__ : null , ...opts }
1921 // Lazily access constants.ENV.
2022 const { SOCKET_CLI_DEBUG } = constants . ENV
21- return fork (
22- // Lazily access constants.execPath .
23- constants . execPath ,
23+ const promise = fork (
24+ // Lazily access constants.rootBinPath .
25+ path . join ( constants . rootBinPath , 'npm-cli.js' ) ,
2426 [
25- // Lazily access constants.rootBinPath.
26- path . join ( constants . rootBinPath , 'npm-cli.js' ) ,
2727 'install' ,
2828 // Even though the 'silent' flag is passed npm will still run through code
2929 // paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund' flags
@@ -37,11 +37,15 @@ export function shadowNpmInstall<O extends ShadowNpmInstallOptions>(
3737 signal : abortSignal ,
3838 // Lazily access constants.ENV.
3939 stdio : SOCKET_CLI_DEBUG ? 'inherit' : 'ignore' ,
40- ...spawnOptions ,
40+ ...forkOptions ,
4141 env : {
4242 ...process . env ,
43- ...spawnOptions . env
43+ ...forkOptions . env
4444 }
4545 }
4646 ) as ForkResult < O extends { stdioString : false } ? Buffer : string , undefined >
47+ if ( ipc ) {
48+ promise . process . send ( ipc )
49+ }
50+ return promise
4751}
0 commit comments