@@ -5,25 +5,25 @@ import { fork } from './promise-fork'
5
5
import constants from '../constants'
6
6
7
7
import type { ForkOptions , ForkResult } from './promise-fork'
8
+ import type { Serializable } from 'node:child_process'
8
9
9
10
const { abortSignal } = constants
10
11
11
12
type ShadowNpmInstallOptions = ForkOptions & {
12
13
flags ?: string [ ]
14
+ ipc ?: Serializable
13
15
}
14
16
15
17
export function shadowNpmInstall < O extends ShadowNpmInstallOptions > (
16
18
opts ?: ShadowNpmInstallOptions
17
19
) {
18
- const { flags = [ ] , ...spawnOptions } = { __proto__ : null , ...opts }
20
+ const { flags = [ ] , ipc , ...forkOptions } = { __proto__ : null , ...opts }
19
21
// Lazily access constants.ENV.
20
22
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' ) ,
24
26
[
25
- // Lazily access constants.rootBinPath.
26
- path . join ( constants . rootBinPath , 'npm-cli.js' ) ,
27
27
'install' ,
28
28
// Even though the 'silent' flag is passed npm will still run through code
29
29
// paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund' flags
@@ -37,11 +37,15 @@ export function shadowNpmInstall<O extends ShadowNpmInstallOptions>(
37
37
signal : abortSignal ,
38
38
// Lazily access constants.ENV.
39
39
stdio : SOCKET_CLI_DEBUG ? 'inherit' : 'ignore' ,
40
- ...spawnOptions ,
40
+ ...forkOptions ,
41
41
env : {
42
42
...process . env ,
43
- ...spawnOptions . env
43
+ ...forkOptions . env
44
44
}
45
45
}
46
46
) as ForkResult < O extends { stdioString : false } ? Buffer : string , undefined >
47
+ if ( ipc ) {
48
+ promise . process . send ( ipc )
49
+ }
50
+ return promise
47
51
}
0 commit comments