Remove legacy stdin option in favor of full stdio options on process exec + adjust tests accordingly

This commit is contained in:
Filip Tibell 2025-04-24 22:14:03 +02:00
parent 551120fba1
commit 1119f0d46b
No known key found for this signature in database
4 changed files with 49 additions and 34 deletions

View file

@ -118,21 +118,11 @@ impl FromLua for ProcessSpawnOptions {
} }
/* /*
If we got options for stdio handling, parse those as well - note that If we got options for stdio handling, parse those as well
we accept a separate "stdin" value here for compatibility with older
scripts, but the user should preferrably pass it in the stdio table This may optionally contain configuration for any or all of: stdin, stdout, stderr
*/ */
this.stdio = value.get("stdio")?; this.stdio = value.get("stdio")?;
match value.get("stdin")? {
LuaValue::Nil => {}
LuaValue::String(s) => this.stdio.stdin = Some(s.as_bytes().to_vec()),
value => {
return Err(LuaError::RuntimeError(format!(
"Invalid type for option 'stdin' - expected 'string', got '{}'",
value.type_name()
)))
}
}
Ok(this) Ok(this)
} }

View file

@ -1,3 +1,4 @@
use bstr::BString;
use mlua::prelude::*; use mlua::prelude::*;
use super::kind::ProcessSpawnOptionsStdioKind; use super::kind::ProcessSpawnOptionsStdioKind;
@ -29,8 +30,8 @@ impl FromLua for ProcessSpawnOptionsStdio {
LuaValue::Table(t) => { LuaValue::Table(t) => {
let mut this = Self::default(); let mut this = Self::default();
if let Some(stdin) = t.get("stdin")? { if let Some(stdin) = t.get::<Option<BString>>("stdin")? {
this.stdin = stdin; this.stdin = Some(stdin.to_vec());
} }
if let Some(stdout) = t.get("stdout")? { if let Some(stdout) = t.get("stdout")? {

View file

@ -2,27 +2,35 @@ export type OS = "linux" | "macos" | "windows"
export type Arch = "x86_64" | "aarch64" export type Arch = "x86_64" | "aarch64"
export type Endianness = "big" | "little" export type Endianness = "big" | "little"
export type StdioKind = "default" | "inherit" | "forward" | "none"
export type StdioOptions = {
stdin: StdioKind?,
stdout: StdioKind?,
stderr: StdioKind?,
}
--[=[ --[=[
@interface CreateOptions @interface ExecStdioKind
@within Process @within Process
A dictionary of options for `process.create`, with the following available values: Enum determining how to treat a standard input/output stream for `process.exec`.
* `cwd` - The current working directory for the process Can be one of the following values:
* `env` - Extra environment variables to give to the process
* `shell` - Whether to run in a shell or not - set to `true` to run using the default shell, or a string to run using a specific shell * `default` - The default behavior, writing to the final result table only
* `inherit` - Inherit the stream from the parent process, writing to both the result table and the respective stream for the parent process
* `forward` - Forward the stream to the parent process, without writing to the result table, only respective stream for the parent process
* `none` - Do not create any input/output stream
]=] ]=]
export type CreateOptions = { export type ExecStdioKind = "default" | "inherit" | "forward" | "none"
cwd: string?,
env: { [string]: string }?, --[=[
shell: (boolean | string)?, @interface ExecStdioOptions
@within Process
A dictionary of stdio-specific options for `process.exec`, with the following available values:
* `stdin` - A buffer or string to write to the stdin of the process
* `stdout` - How to treat the stdout stream from the child process - see `ExecStdioKind` for more info
* `stderr` - How to treat the stderr stream from the child process - see `ExecStdioKind` for more info
]=]
export type ExecStdioOptions = {
stdin: (buffer | string)?,
stdout: ExecStdioKind?,
stderr: ExecStdioKind?,
} }
--[=[ --[=[
@ -40,7 +48,23 @@ export type ExecOptions = {
cwd: string?, cwd: string?,
env: { [string]: string }?, env: { [string]: string }?,
shell: (boolean | string)?, shell: (boolean | string)?,
stdio: (StdioKind | StdioOptions)?, stdio: (ExecStdioKind | ExecStdioOptions)?,
}
--[=[
@interface CreateOptions
@within Process
A dictionary of options for `process.create`, with the following available values:
* `cwd` - The current working directory for the process
* `env` - Extra environment variables to give to the process
* `shell` - Whether to run in a shell or not - set to `true` to run using the default shell, or a string to run using a specific shell
]=]
export type CreateOptions = {
cwd: string?,
env: { [string]: string }?,
shell: (boolean | string)?,
} }
--[=[ --[=[

View file

@ -10,8 +10,8 @@ local echoMessage = "Hello from child process!"
-- When passing stdin to powershell on windows we must "accept" using the double newline -- When passing stdin to powershell on windows we must "accept" using the double newline
local result = if IS_WINDOWS local result = if IS_WINDOWS
then process.exec("powershell", { "echo" }, { stdin = echoMessage .. "\n\n" }) then process.exec("powershell", { "echo" }, { stdio = { stdin = echoMessage .. "\n\n" } })
else process.exec("xargs", { "echo" }, { stdin = echoMessage }) else process.exec("xargs", { "echo" }, { stdio = { stdin = echoMessage } })
local resultStdout = if IS_WINDOWS local resultStdout = if IS_WINDOWS
then string.sub(result.stdout, #result.stdout - #echoMessage - 1) then string.sub(result.stdout, #result.stdout - #echoMessage - 1)