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

View file

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

View file

@ -69,7 +69,6 @@ function Github.new(repo: string, config: Option<Config>)
) )
end end
-- FIXME: Remove unknown usage here
function Github.queueTransactions(self: Github, operations: { GithubOperation }): { Result<unknown, string> } function Github.queueTransactions(self: Github, operations: { GithubOperation }): { Result<unknown, string> }
local queue: { (retries: number) -> Result<unknown, string> } = table.create(#operations) 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 for _, asset in assets do
local desc = PlatformDescriptor.fromString(asset.name) local desc = PlatformDescriptor.fromString(asset.name)
local descWithArch = desc:map(function(inner: PlatformDescriptor.PlatformDescriptor) local descWithArch = desc:map(function(inner: PlatformDescriptor.PlatformDescriptor)
-- FIXME: unknown usage
return inner return inner
end) end)

View file

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