mirror of
https://github.com/lune-org/lune.git
synced 2025-04-13 15:00:53 +01:00
fix: stop accepting stdio options for process.spawn
This commit is contained in:
parent
78a3d4db5f
commit
50b1bcbd64
3 changed files with 22 additions and 3 deletions
|
@ -15,6 +15,7 @@ use mlua::prelude::*;
|
||||||
|
|
||||||
use lune_utils::TableBuilder;
|
use lune_utils::TableBuilder;
|
||||||
use mlua_luau_scheduler::{Functions, LuaSpawnExt};
|
use mlua_luau_scheduler::{Functions, LuaSpawnExt};
|
||||||
|
use options::ProcessSpawnOptionsStdio;
|
||||||
use os_str_bytes::RawOsString;
|
use os_str_bytes::RawOsString;
|
||||||
use stream::{ChildProcessReader, ChildProcessWriter};
|
use stream::{ChildProcessReader, ChildProcessWriter};
|
||||||
use tokio::{io::AsyncWriteExt, process::Child};
|
use tokio::{io::AsyncWriteExt, process::Child};
|
||||||
|
@ -183,8 +184,10 @@ async fn process_spawn(
|
||||||
lua: &Lua,
|
lua: &Lua,
|
||||||
(program, args, options): (String, Option<Vec<String>>, ProcessSpawnOptions),
|
(program, args, options): (String, Option<Vec<String>>, ProcessSpawnOptions),
|
||||||
) -> LuaResult<LuaTable> {
|
) -> LuaResult<LuaTable> {
|
||||||
|
// Spawn does not accept stdio options, so we remove them from the options
|
||||||
|
// and use the defaults instead
|
||||||
let mut spawn_options = options.clone();
|
let mut spawn_options = options.clone();
|
||||||
spawn_options.stdio.stdin = None;
|
spawn_options.stdio = ProcessSpawnOptionsStdio::default();
|
||||||
|
|
||||||
let (stdin_tx, stdin_rx) = tokio::sync::oneshot::channel();
|
let (stdin_tx, stdin_rx) = tokio::sync::oneshot::channel();
|
||||||
let (stdout_tx, stdout_rx) = tokio::sync::oneshot::channel();
|
let (stdout_tx, stdout_rx) = tokio::sync::oneshot::channel();
|
||||||
|
@ -221,7 +224,7 @@ async fn process_spawn(
|
||||||
.expect("ExitCode receiver was unexpectedly dropped");
|
.expect("ExitCode receiver was unexpectedly dropped");
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: If not piped, don't return readers and writers instead of panicking
|
// TODO: Remove the lua errors since we no longer accept stdio options for spawn
|
||||||
TableBuilder::new(lua)?
|
TableBuilder::new(lua)?
|
||||||
.with_value(
|
.with_value(
|
||||||
"stdout",
|
"stdout",
|
||||||
|
|
16
test.lua
Normal file
16
test.lua
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
local process = require("@lune/process")
|
||||||
|
local stdio = require("@lune/stdio")
|
||||||
|
|
||||||
|
local child = process.spawn("luau-lsp", { "lsp" })
|
||||||
|
|
||||||
|
while true do
|
||||||
|
child.stdin:write("hello world")
|
||||||
|
local buf = child.stdout:read()
|
||||||
|
|
||||||
|
if buffer.len(buf) == 0 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
stdio.write(buffer.tostring(buf) .. "\n")
|
||||||
|
-- stdio.write(buffer.tostring(child.stderr:read() .. child.stderr:read() .. child.stderr:read() .. child.stderr:read()))
|
||||||
|
end
|
|
@ -26,7 +26,6 @@ export type SpawnOptions = {
|
||||||
cwd: string?,
|
cwd: string?,
|
||||||
env: { [string]: string }?,
|
env: { [string]: string }?,
|
||||||
shell: (boolean | string)?,
|
shell: (boolean | string)?,
|
||||||
stdio: (SpawnOptionsStdio | SpawnOptionsStdioKind)?,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
|
@ -42,6 +41,7 @@ export type SpawnOptions = {
|
||||||
* `stdin` - Optional standard input to pass to executed child process
|
* `stdin` - Optional standard input to pass to executed child process
|
||||||
]=]
|
]=]
|
||||||
export type ExecuteOptions = SpawnOptions & {
|
export type ExecuteOptions = SpawnOptions & {
|
||||||
|
stdio: (SpawnOptionsStdio | SpawnOptionsStdioKind)?,
|
||||||
stdin: string?, -- TODO: Remove this since it is now available in stdio above, breaking change
|
stdin: string?, -- TODO: Remove this since it is now available in stdio above, breaking change
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue