chore: migrate to process.exec for lune v0.9.0

This commit is contained in:
Erica Marigold 2025-04-29 05:55:03 +01:00
parent 690d3ffbf1
commit 4eba797b8d
Signed by: DevComp
SSH key fingerprint: SHA256:jD3oMT4WL3WHPJQbrjC3l5feNCnkv7ndW8nYaHX5wFw
3 changed files with 12 additions and 14 deletions

View file

@ -78,7 +78,7 @@ function CommandBuilder.withStdioStrategy(
return self return self
end end
local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.SpawnOptionsStdioKind local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.ExecStdioKind
if strategy == "pipe" then if strategy == "pipe" then
return "default" return "default"
end end
@ -94,18 +94,18 @@ local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.Spawn
error(`Non-strategy provided: {strategy}`) error(`Non-strategy provided: {strategy}`)
end end
function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult function CommandBuilder.exec(self: CommandBuilder): process.ExecResult
print( print(
stdio.style("bold") .. "$", stdio.style("bold") .. "$",
stdio.style("dim") .. self.program, stdio.style("dim") .. self.program,
table.concat(self.args, " ") .. stdio.style("reset") 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", shell = if process.os == "windows" then "cmd.exe" else "bash",
stdio = self.stdioStrategy stdio = self.stdioStrategy
:orOpt(Option.Some(DEFAULT_STDIO_STRATEGY)) :orOpt(Option.Some(DEFAULT_STDIO_STRATEGY))
:map(function(mappings: IoStrategyMapping) :map(function(mappings: IoStrategyMapping)
local translatedMappings: process.SpawnOptionsStdio = {} local translatedMappings: any = {} -- FIXME: remove this any
for field, value in mappings do for field, value in mappings do
translatedMappings[field] = intoSpawnOptionsStdioKind((value :: Option<StdioStrategy>):unwrap()) translatedMappings[field] = intoSpawnOptionsStdioKind((value :: Option<StdioStrategy>):unwrap())
end end

View file

@ -78,10 +78,8 @@ local function chmod(path: pathfs.Path, mode: number | string)
return return
end end
local result = process.spawn( local result =
"chmod", process.exec("chmod", { if typeof(mode) == "string" then mode else string.format("%o", mode), path:toString() })
{ if typeof(mode) == "string" then mode else string.format("%o", mode), path:toString() }
)
if not result.ok then if not result.ok then
return error(result.stderr) return error(result.stderr)
@ -117,14 +115,14 @@ local bar = ProgressBar.new()
:withStage("install", "Installing") :withStage("install", "Installing")
function runTool(tool: ToolId | pathfs.Path): number 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 -- forward properly
local toolId = tool :: ToolId local toolId = tool :: ToolId
local path = if (toolId :: any).alias ~= nil local path = if (toolId :: any).alias ~= nil
then LINK_INSTALL_DIR:join(toolAliasOrDefault(toolId)) then LINK_INSTALL_DIR:join(toolAliasOrDefault(toolId))
else tool :: pathfs.Path else tool :: pathfs.Path
return process.spawn(path:toString(), process.args, { return process.exec(path:toString(), process.args, {
cwd = process.cwd, cwd = process.cwd,
env = process.env, env = process.env,
stdio = "forward", stdio = "forward",
@ -153,8 +151,8 @@ end
local function getGithubToken(): Option<string> local function getGithubToken(): Option<string>
return Option.from(process.env.GITHUB_TOKEN):orElse(function() return Option.from(process.env.GITHUB_TOKEN):orElse(function()
return ResultExt.ok(Result.try(process.spawn, "gh", { "auth", "token" })) return ResultExt.ok(Result.try(process.exec, "gh", { "auth", "token" }))
:andThen(function(child: process.SpawnResult) :andThen(function(child: process.ExecResult)
if not child.ok then if not child.ok then
return Option.None return Option.None
end end

View file

@ -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 pid = assert(string.match(statFd, "^%S+%s+%S+%s+%S+%s+(%S+)"), "Could not get current process PID")
local stdoutFdMode = ResultExt.ok( 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 if not child.ok then
return Option.None return Option.None
end end