From 4eba797b8d4086ace7c8c7d6fcabac7e37060727 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Tue, 29 Apr 2025 05:55:03 +0100 Subject: [PATCH] chore: migrate to `process.exec` for lune v0.9.0 --- .lune/exec.luau | 8 ++++---- toolchainlib/src/init.luau | 14 ++++++-------- toolchainlib/src/utils/sys.luau | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.lune/exec.luau b/.lune/exec.luau index d87f8f6..482dbd1 100644 --- a/.lune/exec.luau +++ b/.lune/exec.luau @@ -78,7 +78,7 @@ function CommandBuilder.withStdioStrategy( return self end -local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.SpawnOptionsStdioKind +local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.ExecStdioKind if strategy == "pipe" then return "default" end @@ -94,18 +94,18 @@ local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.Spawn error(`Non-strategy provided: {strategy}`) end -function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult +function CommandBuilder.exec(self: CommandBuilder): process.ExecResult print( stdio.style("bold") .. "$", stdio.style("dim") .. self.program, table.concat(self.args, " ") .. stdio.style("reset") ) - local child = process.spawn(self.program, self.args, { + local child = process.exec(self.program, self.args, { shell = if process.os == "windows" then "cmd.exe" else "bash", stdio = self.stdioStrategy :orOpt(Option.Some(DEFAULT_STDIO_STRATEGY)) :map(function(mappings: IoStrategyMapping) - local translatedMappings: process.SpawnOptionsStdio = {} + local translatedMappings: any = {} -- FIXME: remove this any for field, value in mappings do translatedMappings[field] = intoSpawnOptionsStdioKind((value :: Option):unwrap()) end diff --git a/toolchainlib/src/init.luau b/toolchainlib/src/init.luau index bbbcd6e..43b85d2 100644 --- a/toolchainlib/src/init.luau +++ b/toolchainlib/src/init.luau @@ -78,10 +78,8 @@ local function chmod(path: pathfs.Path, mode: number | string) return end - local result = process.spawn( - "chmod", - { if typeof(mode) == "string" then mode else string.format("%o", mode), path:toString() } - ) + local result = + process.exec("chmod", { if typeof(mode) == "string" then mode else string.format("%o", mode), path:toString() }) if not result.ok then return error(result.stderr) @@ -117,14 +115,14 @@ local bar = ProgressBar.new() :withStage("install", "Installing") function runTool(tool: ToolId | pathfs.Path): number - -- FIXME: `process.spawn` has a bug where interactive features don't + -- FIXME: `process.exec` has a bug where interactive features don't -- forward properly local toolId = tool :: ToolId local path = if (toolId :: any).alias ~= nil then LINK_INSTALL_DIR:join(toolAliasOrDefault(toolId)) else tool :: pathfs.Path - return process.spawn(path:toString(), process.args, { + return process.exec(path:toString(), process.args, { cwd = process.cwd, env = process.env, stdio = "forward", @@ -153,8 +151,8 @@ end local function getGithubToken(): Option return Option.from(process.env.GITHUB_TOKEN):orElse(function() - return ResultExt.ok(Result.try(process.spawn, "gh", { "auth", "token" })) - :andThen(function(child: process.SpawnResult) + return ResultExt.ok(Result.try(process.exec, "gh", { "auth", "token" })) + :andThen(function(child: process.ExecResult) if not child.ok then return Option.None end diff --git a/toolchainlib/src/utils/sys.luau b/toolchainlib/src/utils/sys.luau index 9fbc839..141a5d0 100644 --- a/toolchainlib/src/utils/sys.luau +++ b/toolchainlib/src/utils/sys.luau @@ -36,9 +36,9 @@ function sys.isTTY(fd: number | StdioFd): boolean local pid = assert(string.match(statFd, "^%S+%s+%S+%s+%S+%s+(%S+)"), "Could not get current process PID") local stdoutFdMode = ResultExt.ok( - Result.try(process.spawn, "stat", { "-L", "-c", "%f", `/proc/{pid}/fd/{inputFd}` }) + Result.try(process.exec, "stat", { "-L", "-c", "%f", `/proc/{pid}/fd/{inputFd}` }) ) - :andThen(function(child: process.SpawnResult) + :andThen(function(child: process.ExecResult) if not child.ok then return Option.None end