Skip to content

Commit 1ab1fa5

Browse files
authored
fix(core): forward process execArgv when using the native runner (#23195)
1 parent 0f71685 commit 1ab1fa5

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

packages/nx/src/native/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ export class ChildProcess {
150150
}
151151
export class RustPseudoTerminal {
152152
constructor()
153-
runCommand(command: string, commandDir?: string | undefined | null, jsEnv?: Record<string, string> | undefined | null, quiet?: boolean | undefined | null, tty?: boolean | undefined | null): ChildProcess
153+
runCommand(command: string, commandDir?: string | undefined | null, jsEnv?: Record<string, string> | undefined | null, execArgv?: Array<string> | undefined | null, quiet?: boolean | undefined | null, tty?: boolean | undefined | null): ChildProcess
154154
/**
155155
* This allows us to run a pseudoterminal with a fake node ipc channel
156156
* this makes it possible to be backwards compatible with the old implementation
157157
*/
158-
fork(id: string, forkScript: string, pseudoIpcPath: string, commandDir: string | undefined | null, jsEnv: Record<string, string> | undefined | null, quiet: boolean): ChildProcess
158+
fork(id: string, forkScript: string, pseudoIpcPath: string, commandDir: string | undefined | null, jsEnv: Record<string, string> | undefined | null, execArgv: Array<string> | undefined | null, quiet: boolean): ChildProcess
159159
}
160160
export class HashPlanner {
161161
constructor(nxJson: NxJson, projectGraph: ExternalObject<ProjectGraph>)

packages/nx/src/native/pseudo_terminal/mac.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ impl RustPseudoTerminal {
2424
command: String,
2525
command_dir: Option<String>,
2626
js_env: Option<HashMap<String, String>>,
27+
exec_argv: Option<Vec<String>>,
2728
quiet: Option<bool>,
2829
tty: Option<bool>,
2930
) -> napi::Result<ChildProcess> {
3031
let pseudo_terminal = create_pseudo_terminal()?;
31-
run_command(&pseudo_terminal, command, command_dir, js_env, quiet, tty)
32+
run_command(&pseudo_terminal, command, command_dir, js_env, exec_argv, quiet, tty)
3233
}
3334

3435
/// This allows us to run a pseudoterminal with a fake node ipc channel
@@ -41,6 +42,7 @@ impl RustPseudoTerminal {
4142
pseudo_ipc_path: String,
4243
command_dir: Option<String>,
4344
js_env: Option<HashMap<String, String>>,
45+
exec_argv: Option<Vec<String>>,
4446
quiet: bool,
4547
) -> napi::Result<ChildProcess> {
4648
let command = format!(
@@ -51,6 +53,6 @@ impl RustPseudoTerminal {
5153
);
5254

5355
trace!("nx_fork command: {}", &command);
54-
self.run_command(command, command_dir, js_env, Some(quiet), Some(true))
56+
self.run_command(command, command_dir, js_env, exec_argv, Some(quiet), Some(true))
5557
}
5658
}

packages/nx/src/native/pseudo_terminal/non_mac.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl RustPseudoTerminal {
2929
command: String,
3030
command_dir: Option<String>,
3131
js_env: Option<HashMap<String, String>>,
32+
exec_argv: Option<Vec<String>>,
3233
quiet: Option<bool>,
3334
tty: Option<bool>,
3435
) -> napi::Result<ChildProcess> {
@@ -37,6 +38,7 @@ impl RustPseudoTerminal {
3738
command,
3839
command_dir,
3940
js_env,
41+
exec_argv,
4042
quiet,
4143
tty,
4244
)
@@ -52,6 +54,7 @@ impl RustPseudoTerminal {
5254
pseudo_ipc_path: String,
5355
command_dir: Option<String>,
5456
js_env: Option<HashMap<String, String>>,
57+
exec_argv: Option<Vec<String>>,
5558
quiet: bool,
5659
) -> napi::Result<ChildProcess> {
5760
let command = format!(
@@ -62,6 +65,6 @@ impl RustPseudoTerminal {
6265
);
6366

6467
trace!("nx_fork command: {}", &command);
65-
self.run_command(command, command_dir, js_env, Some(quiet), Some(true))
68+
self.run_command(command, command_dir, js_env, exec_argv, Some(quiet), Some(true))
6669
}
6770
}

packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub fn run_command(
117117
command: String,
118118
command_dir: Option<String>,
119119
js_env: Option<HashMap<String, String>>,
120+
exec_argv: Option<Vec<String>>,
120121
quiet: Option<bool>,
121122
tty: Option<bool>,
122123
) -> napi::Result<ChildProcess> {
@@ -138,6 +139,10 @@ pub fn run_command(
138139
}
139140
}
140141

142+
if let Some(exec_argv) = exec_argv {
143+
cmd.env("NX_PSEUDO_TERMINAL_EXEC_ARGV", exec_argv.join("|"));
144+
}
145+
141146
let (exit_to_process_tx, exit_to_process_rx) = bounded(1);
142147
let mut child = pair.slave.spawn_command(cmd)?;
143148
pseudo_terminal.running.store(true, Ordering::SeqCst);

packages/nx/src/tasks-runner/fork.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ const forkId = process.argv[3];
77

88
const script = join(__dirname, '../../bin/run-executor.js');
99

10+
let execArgv: string[] | undefined;
11+
if (process.env['NX_PSEUDO_TERMINAL_EXEC_ARGV']) {
12+
execArgv = process.env['NX_PSEUDO_TERMINAL_EXEC_ARGV'].split('|');
13+
delete process.env['NX_PSEUDO_TERMINAL_EXEC_ARGV'];
14+
}
15+
1016
const childProcess = fork(script, {
1117
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
18+
env: process.env,
19+
execArgv,
1220
});
1321

1422
const pseudoIPC = new PseudoIPCClient(pseudoIPCPath);

packages/nx/src/tasks-runner/forked-process-task-runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export class ForkedProcessTaskRunner {
220220
const childId = task.id;
221221
const p = await this.pseudoTerminal.fork(childId, forkScript, {
222222
cwd: process.cwd(),
223+
execArgv: process.execArgv,
223224
jsEnv: env,
224225
quiet: !streamOutput,
225226
});

packages/nx/src/tasks-runner/pseudo-terminal.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,27 @@ export class PseudoTerminal {
4141
command: string,
4242
{
4343
cwd,
44+
execArgv,
4445
jsEnv,
4546
quiet,
4647
tty,
4748
}: {
4849
cwd?: string;
50+
execArgv?: string[];
4951
jsEnv?: Record<string, string>;
5052
quiet?: boolean;
5153
tty?: boolean;
5254
} = {}
5355
) {
5456
return new PseudoTtyProcess(
55-
this.rustPseudoTerminal.runCommand(command, cwd, jsEnv, quiet, tty)
57+
this.rustPseudoTerminal.runCommand(
58+
command,
59+
cwd,
60+
jsEnv,
61+
execArgv,
62+
quiet,
63+
tty
64+
)
5665
);
5766
}
5867

@@ -61,10 +70,12 @@ export class PseudoTerminal {
6170
script: string,
6271
{
6372
cwd,
73+
execArgv,
6474
jsEnv,
6575
quiet,
6676
}: {
6777
cwd?: string;
78+
execArgv?: string[];
6879
jsEnv?: Record<string, string>;
6980
quiet?: boolean;
7081
}
@@ -79,6 +90,7 @@ export class PseudoTerminal {
7990
this.pseudoIPCPath,
8091
cwd,
8192
jsEnv,
93+
execArgv,
8294
quiet
8395
),
8496
id,

0 commit comments

Comments
 (0)