feat(lib): address type related FIXMEs

This commit is contained in:
Erica Marigold 2024-12-14 06:18:40 +00:00
parent bb6278407d
commit 9a3f3717de
Signed by: DevComp
GPG key ID: 429EF1C337871656
5 changed files with 15 additions and 24 deletions

View file

@ -21,10 +21,9 @@ export type IoStrategyMapping = {
stderr: Option<StdioStrategy>,
}
-- FIXME: remove unknown usage
local DEFAULT_STDIO_STRATEGY: IoStrategyMapping = {
stdout = Option.Some("pipe" :: StdioStrategy) :: Option<unknown>,
stderr = Option.Some("pipe" :: StdioStrategy) :: Option<unknown>,
stdout = Option.Some("pipe" :: StdioStrategy),
stderr = Option.Some("pipe" :: StdioStrategy),
}
function CommandBuilder.new(program: string)
return setmetatable(
@ -70,11 +69,10 @@ function CommandBuilder.withStdioStrategy(
self: CommandBuilder,
strategy: StdioStrategy | IoStrategyMapping
): CommandBuilder
-- FIXME: remove unknown usage
self.stdioStrategy = Option.Some(if typeof(strategy) == "string"
then {
stdout = Option.Some(strategy) :: Option<unknown>,
stderr = Option.Some(strategy) :: Option<unknown>,
stdout = Option.Some(strategy),
stderr = Option.Some(strategy),
}
else strategy) :: Option<IoStrategyMapping>
return self
@ -104,10 +102,8 @@ function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult
)
local child = process.spawn(self.program, self.args, {
shell = if process.os == "windows" then "cmd.exe" else "bash",
stdio = self
.stdioStrategy
-- FIXME: remove unknown usage
:orOpt(Option.Some(DEFAULT_STDIO_STRATEGY) :: Option<unknown>)
stdio = self.stdioStrategy
:orOpt(Option.Some(DEFAULT_STDIO_STRATEGY))
:map(function(mappings: IoStrategyMapping)
local translatedMappings: process.SpawnOptionsStdio = {}
for field, value in mappings do

View file

@ -19,16 +19,16 @@ local function detectFormat(fileName: string): Option<CompressionFormat>
revTable(fileNameParts)
if fileNameParts[1] == "zip" then
return Option.Some("Zip" :: CompressionFormat) :: Option<unknown>
return Option.Some("Zip" :: CompressionFormat)
end
if fileNameParts[2] == "tar" then
if fileNameParts[1] == "gz" then
return Option.Some("TarGz" :: CompressionFormat) :: Option<unknown>
return Option.Some("TarGz" :: CompressionFormat)
end
if fileNameParts[1] == "xz" then
return Option.Some("TarXz" :: CompressionFormat) :: Option<unknown>
return Option.Some("TarXz" :: CompressionFormat)
end
end
@ -38,16 +38,15 @@ end
-- TODO: Use a type function to make all CompressionFormat lowercase
local decompress: { [CompressionFormat]: (compressed: buffer) -> Result<pathfs.AsPath, string> } = {
Zip = function(compressed: buffer)
-- FIXME: remove any usage
return (Option.from(dirs.cacheDir()):map(function(cacheDir)
local progCacheDir = cacheDir:join("pesde-bin")
if not pathfs.isDir(progCacheDir) then
pathfs.writeDir(progCacheDir)
end
return progCacheDir :: pathfs.AsPath
end) :: Option<any>):match({
Some = function(dir)
return progCacheDir :: pathfs.Path
end)):match({
Some = function(dir: pathfs.Path)
-- Generate a unique file name and write the contents to the temporary file
local tmpFile = dir:join(`{serde.hash("blake3", compressed)}.zip`)
local tmpFilePath = tmpFile:toString()
@ -65,19 +64,18 @@ local decompress: { [CompressionFormat]: (compressed: buffer) -> Result<pathfs.A
`-c \`"Import-Module Microsoft.PowerShell.Archive; Expand-Archive -LiteralPath '{tmpFilePath}' -DestinationPath '{decompressedDir:toString()}'\`"`,
})
else CommandBuilder.new("unzip"):withArgs({ tmpFilePath, "-d", decompressedDir:toString() }))
-- FIXME: remove unknown usage
:withStdioStrategy({
-- Powershell on Windows writes errors to stdout. Bruh
stdout = Option.Some(
if process.os == "windows" and process.env.PESDE_LOG == "debug"
then "forward"
else "pipe" :: CommandBuilder.StdioStrategy
) :: Option<unknown>,
),
stderr = Option.Some(
if process.env.PESDE_LOG == "debug"
then "forward"
else "pipe" :: CommandBuilder.StdioStrategy
) :: Option<unknown>,
),
} :: CommandBuilder.IoStrategyMapping)
:intoChildProcess()

View file

@ -69,7 +69,6 @@ function Github.new(repo: string, config: Option<Config>)
)
end
-- FIXME: Remove unknown usage here
function Github.queueTransactions(self: Github, operations: { GithubOperation }): { Result<unknown, string> }
local queue: { (retries: number) -> Result<unknown, string> } = table.create(#operations)

View file

@ -190,7 +190,6 @@ function installTool(tool: ToolId, installPath: pathfs.Path): number
for _, asset in assets do
local desc = PlatformDescriptor.fromString(asset.name)
local descWithArch = desc:map(function(inner: PlatformDescriptor.PlatformDescriptor)
-- FIXME: unknown usage
return inner
end)

View file

@ -8,8 +8,7 @@ return {
detect = function(str: string): Option<Toolchain>
for _, toolchain: Toolchain in TOOLCHAINS do
if string.find(str, toolchain) then
-- FIXME: remove any usage
return Option.Some(toolchain :: any) :: Option<Toolchain>
return Option.Some(toolchain :: Toolchain)
end
end