diff --git a/pesde.lock b/pesde.lock index 8c3339e..4bd2fbf 100644 --- a/pesde.lock +++ b/pesde.lock @@ -18,120 +18,120 @@ luau_lsp = [{ name = "pesde/luau_lsp", version = "^1.38.0", index = "https://git selene = [{ name = "pesde/selene", version = "^0.27.1", index = "https://github.com/pesde-pkg/index" }, "dev"] stylua = [{ name = "pesde/stylua", version = "^2.0.2", index = "https://github.com/pesde-pkg/index" }, "dev"] -[graph."caveful_games/table_helper@0.2.0-rc.1 luau"] -direct = ["table_helper", { name = "caveful_games/table_helper", version = "^0.2.0-rc.1", index = "default", target = "luau" }, "standard"] +[graph."jiwonz/darklua_lune@0.3.0 lune"] +direct = ["darklua_lune", { name = "jiwonz/darklua_lune", version = "^0.3.0", index = "default" }, "standard"] -[graph."caveful_games/table_helper@0.2.0-rc.1 luau".pkg_ref] -ref_ty = "pesde" -index_url = "https://github.com/pesde-pkg/index" - -[graph."corecii/greentea@0.4.11 lune"] -direct = ["greentea", { name = "corecii/greentea", version = "^0.4.11", index = "default" }, "standard"] +[graph."jiwonz/darklua_lune@0.3.0 lune".dependencies] +dirs = ["jiwonz/dirs@0.6.0 lune", "standard"] +greentea = ["jiwonz/greentea_luau@0.2.0 luau", "standard"] -[graph."corecii/greentea@0.4.11 lune".pkg_ref] +[graph."jiwonz/darklua_lune@0.3.0 lune".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/darklua_lune@0.2.0 lune"] -direct = ["darklua_lune", { name = "jiwonz/darklua_lune", version = "^0.2.0", index = "default" }, "standard"] +[graph."jiwonz/darklua_lune@0.3.0 lune".pkg_ref.dependencies] +dirs = [{ name = "jiwonz/dirs", version = "^0.6.0", index = "https://github.com/pesde-pkg/index" }, "standard"] +greentea = [{ name = "jiwonz/greentea_luau", version = "^0.2.0", index = "https://github.com/pesde-pkg/index", target = "luau" }, "standard"] -[graph."jiwonz/darklua_lune@0.2.0 lune".dependencies] -dirs = ["jiwonz/dirs@0.5.1 lune", "standard"] -greentea = ["corecii/greentea@0.4.11 lune", "standard"] +[graph."jiwonz/dirs@0.6.0 lune".dependencies] +greentea = ["jiwonz/greentea_luau@0.2.0 luau", "standard"] +pathfs = ["jiwonz/pathfs@0.6.0 lune", "standard"] -[graph."jiwonz/darklua_lune@0.2.0 lune".pkg_ref] +[graph."jiwonz/dirs@0.6.0 lune".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/darklua_lune@0.2.0 lune".pkg_ref.dependencies] -dirs = [{ name = "jiwonz/dirs", version = "^0.5.1", index = "https://github.com/pesde-pkg/index" }, "standard"] -greentea = [{ name = "corecii/greentea", version = "^0.4.11", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/dirs@0.6.0 lune".pkg_ref.dependencies] +greentea = [{ name = "jiwonz/greentea_luau", version = "^0.2.0", index = "https://github.com/pesde-pkg/index", target = "luau" }, "standard"] +pathfs = [{ name = "jiwonz/pathfs", version = "^0.6.0", index = "https://github.com/pesde-pkg/index" }, "standard"] -[graph."jiwonz/dirs@0.5.1 lune".dependencies] -greentea = ["corecii/greentea@0.4.11 lune", "standard"] -pathfs = ["jiwonz/pathfs@0.6.0-rc.8 lune", "standard"] +[graph."jiwonz/glob@0.2.0 lune"] +direct = ["glob", { name = "jiwonz/glob", version = "^0.2.0", index = "default" }, "standard"] -[graph."jiwonz/dirs@0.5.1 lune".pkg_ref] +[graph."jiwonz/glob@0.2.0 lune".dependencies] +globrex_lune = ["kimpure/globrex_lune@0.2.9 lune", "standard"] +pathfs = ["jiwonz/pathfs@0.6.0 lune", "standard"] + +[graph."jiwonz/glob@0.2.0 lune".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/dirs@0.5.1 lune".pkg_ref.dependencies] -greentea = [{ name = "corecii/greentea", version = "^0.4.10", index = "https://github.com/daimond113/pesde-index" }, "standard"] -pathfs = [{ name = "jiwonz/pathfs", version = "^0.6.0-rc.6", index = "https://github.com/daimond113/pesde-index" }, "standard"] - -[graph."jiwonz/glob@0.1.2 lune"] -direct = ["glob", { name = "jiwonz/glob", version = "^0.1.1", index = "default" }, "standard"] +[graph."jiwonz/glob@0.2.0 lune".pkg_ref.dependencies] +globrex_lune = [{ name = "kimpure/globrex_lune", version = "^0.2.9", index = "https://github.com/pesde-pkg/index" }, "standard"] +pathfs = [{ name = "jiwonz/pathfs", version = "^0.6.0", index = "https://github.com/pesde-pkg/index" }, "standard"] -[graph."jiwonz/glob@0.1.2 lune".dependencies] -globrex_lune = ["kimpure/globrex_lune@0.2.4 lune", "standard"] -pathfs = ["jiwonz/pathfs@0.6.0-rc.8 lune", "standard"] +[graph."jiwonz/greentea_luau@0.2.0 luau"] +direct = ["greentea", { name = "jiwonz/greentea_luau", version = "^0.2.0", index = "default", target = "luau" }, "standard"] -[graph."jiwonz/glob@0.1.2 lune".pkg_ref] +[graph."jiwonz/greentea_luau@0.2.0 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/glob@0.1.2 lune".pkg_ref.dependencies] -globrex_lune = [{ name = "kimpure/globrex_lune", version = "^0.2.4", index = "https://github.com/pesde-pkg/index" }, "standard"] -pathfs = [{ name = "jiwonz/pathfs", version = "^0.6.0-rc.3", index = "https://github.com/pesde-pkg/index" }, "standard"] - -[graph."jiwonz/luau_disk@0.1.4 luau".pkg_ref] +[graph."jiwonz/luau_disk@0.2.0 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/luau_path@0.1.4 luau".dependencies] -luau_disk = ["jiwonz/luau_disk@0.1.4 luau", "standard"] +[graph."jiwonz/luau_path@0.2.0 luau"] +direct = ["luau_path", { name = "jiwonz/luau_path", version = "^0.2.0", index = "default", target = "luau" }, "standard"] + +[graph."jiwonz/luau_path@0.2.0 luau".dependencies] +luau_disk = ["jiwonz/luau_disk@0.2.0 luau", "standard"] -[graph."jiwonz/luau_path@0.1.4 luau".pkg_ref] +[graph."jiwonz/luau_path@0.2.0 luau".pkg_ref] ref_ty = "pesde" -index_url = "https://github.com/daimond113/pesde-index" +index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/luau_path@0.1.4 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.2.0 luau".pkg_ref.dependencies] +luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.2.0", index = "https://github.com/pesde-pkg/index" }, "standard"] [graph."jiwonz/luau_regexp@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/pathfs@0.6.0-rc.8 lune"] -direct = ["pathfs", { name = "jiwonz/pathfs", version = "^0.6.0-rc.8", index = "default" }, "standard"] +[graph."jiwonz/pathfs@0.6.0 lune"] +direct = ["pathfs", { name = "jiwonz/pathfs", version = "^0.6.0", index = "default" }, "standard"] -[graph."jiwonz/pathfs@0.6.0-rc.8 lune".dependencies] -greentea = ["corecii/greentea@0.4.11 lune", "standard"] -luau_path = ["jiwonz/luau_path@0.1.4 luau", "standard"] +[graph."jiwonz/pathfs@0.6.0 lune".dependencies] +greentea = ["jiwonz/greentea_luau@0.2.0 luau", "standard"] +luau_path = ["jiwonz/luau_path@0.2.0 luau", "standard"] -[graph."jiwonz/pathfs@0.6.0-rc.8 lune".pkg_ref] +[graph."jiwonz/pathfs@0.6.0 lune".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."jiwonz/pathfs@0.6.0-rc.8 lune".pkg_ref.dependencies] -frktest = [{ name = "itsfrank/frktest", version = "^0.0.2", index = "https://github.com/daimond113/pesde-index" }, "dev"] -greentea = [{ name = "corecii/greentea", version = "^0.4.11", index = "https://github.com/daimond113/pesde-index" }, "standard"] -luau_path = [{ name = "jiwonz/luau_path", version = "^0.1.4", index = "https://github.com/daimond113/pesde-index", target = "luau" }, "standard"] +[graph."jiwonz/pathfs@0.6.0 lune".pkg_ref.dependencies] +frktest = [{ name = "itsfrank/frktest", version = "^0.0.4", index = "https://github.com/pesde-pkg/index", target = "luau" }, "dev"] +greentea = [{ name = "jiwonz/greentea_luau", version = "^0.2.0", index = "https://github.com/pesde-pkg/index", target = "luau" }, "standard"] +luau_path = [{ name = "jiwonz/luau_path", version = "^0.2.0", index = "https://github.com/pesde-pkg/index", target = "luau" }, "standard"] -[graph."kimpure/chalk_luau@0.1.7 luau"] -direct = ["chalk_luau", { name = "kimpure/chalk_luau", version = "^0.1.7", index = "default", target = "luau" }, "standard"] +[graph."kimpure/chalk_luau@0.1.8 luau"] +direct = ["chalk_luau", { name = "kimpure/chalk_luau", version = "^0.1.8", index = "default", target = "luau" }, "standard"] -[graph."kimpure/chalk_luau@0.1.7 luau".pkg_ref] +[graph."kimpure/chalk_luau@0.1.8 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."kimpure/globrex_lune@0.2.4 lune".dependencies] +[graph."kimpure/chalk_luau@0.1.8 luau".pkg_ref.dependencies] +darklua = [{ name = "pesde/darklua", version = "^0.16.0", index = "https://github.com/pesde-pkg/index", target = "lune" }, "dev"] +multitarget = [{ name = "jiwonz/multitarget", version = "^0.4.0-rc.28", index = "https://github.com/pesde-pkg/index", target = "lune" }, "dev"] + +[graph."kimpure/globrex_lune@0.2.9 lune".dependencies] luau_regexp = ["jiwonz/luau_regexp@0.1.3 luau", "standard"] -[graph."kimpure/globrex_lune@0.2.4 lune".pkg_ref] +[graph."kimpure/globrex_lune@0.2.9 lune".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" -[graph."kimpure/globrex_lune@0.2.4 lune".pkg_ref.dependencies] +[graph."kimpure/globrex_lune@0.2.9 lune".pkg_ref.dependencies] luau_check = [{ name = "jiwonz/luau_check", version = "^0.2.2", index = "https://github.com/pesde-pkg/index" }, "dev"] luau_lsp = [{ name = "pesde/luau_lsp", version = "^1.38.1", index = "https://github.com/pesde-pkg/index" }, "dev"] luau_regexp = [{ name = "jiwonz/luau_regexp", version = "^0.1.0", index = "https://github.com/pesde-pkg/index", target = "luau" }, "standard"] selene = [{ name = "pesde/selene", version = "^0.27.1", index = "https://github.com/pesde-pkg/index" }, "dev"] stylua = [{ name = "pesde/stylua", version = "^2.0.2", index = "https://github.com/pesde-pkg/index" }, "dev"] -[graph."lukadev_0/result@1.2.0 lune"] -direct = ["result", { name = "lukadev_0/result", version = "^1.2.0", index = "default" }, "standard"] +[graph."lukadev_0/result@1.2.1 lune"] +direct = ["result", { name = "lukadev_0/result", version = "^1.2.1", index = "default" }, "standard"] -[graph."lukadev_0/result@1.2.0 lune".pkg_ref] +[graph."lukadev_0/result@1.2.1 lune".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/pesde-pkg/index" diff --git a/pesde.toml b/pesde.toml index 09b7ee1..f93a544 100644 --- a/pesde.toml +++ b/pesde.toml @@ -18,15 +18,15 @@ default = "https://github.com/pesde-pkg/index" example = "scripts/example.luau" [engines] -lune = "^0.9.4" -pesde = "^0.7.0-rc.1" +lune = "^0.10.3" +pesde = "^0.7.1" [dependencies] -pathfs = { name = "jiwonz/pathfs", version = "^0.6.0-rc.8" } -greentea = { name = "corecii/greentea", version = "^0.4.11" } +pathfs = { name = "jiwonz/pathfs", version = "^0.6.0" } +greentea = { name = "jiwonz/greentea_luau", version = "^0.2.0", target = "luau" } argparse = { name = "caveful_games/argparse", version = "^0.1.2" } -glob = { name = "jiwonz/glob", version = "^0.1.1" } -darklua_lune = { name = "jiwonz/darklua_lune", version = "^0.2.0" } -result = { name = "lukadev_0/result", version = "^1.2.0" } -chalk_luau = { name = "kimpure/chalk_luau", version = "^0.1.7", target = "luau" } -table_helper = { name = "caveful_games/table_helper", version = "^0.2.0-rc.1", target = "luau" } +glob = { name = "jiwonz/glob", version = "^0.2.0" } +darklua_lune = { name = "jiwonz/darklua_lune", version = "^0.3.0" } +result = { name = "lukadev_0/result", version = "^1.2.1" } +chalk_luau = { name = "kimpure/chalk_luau", version = "^0.1.8", target = "luau" } +luau_path = { name = "jiwonz/luau_path", version = "^0.2.0", target = "luau" } diff --git a/scripts/example.luau b/scripts/example.luau index 8460b64..4e7ac8a 100644 --- a/scripts/example.luau +++ b/scripts/example.luau @@ -9,7 +9,7 @@ lib.build( }, "dist", { - "src", + "src", }, "LUA_ENV", "pkg" diff --git a/src/bin.luau b/src/bin.luau index 187dfc9..26beca9 100644 --- a/src/bin.luau +++ b/src/bin.luau @@ -6,7 +6,8 @@ local stdio = require("@lune/stdio") local serde = require("@lune/serde") local process = require("@lune/process") local chalk = require("../luau_packages/chalk_luau") -local tableHelper = require("../luau_packages/table_helper") + +local set = require("./tableUtils/set") local DEFAULT_OUTPUT_DIR = multitarget.DEFAULT_OUTPUT_DIR local DEFAULT_LUA_ENV_GLOBAL = multitarget.DEFAULT_LUA_ENV_GLOBAL @@ -125,7 +126,7 @@ end local setup = cli:command("setup", "Setup your project before building") setup:action(function() do - local pesdeToml = pathfs.File.new("pesde.toml") + local pesdeToml = pathfs.FilePath.new("pesde.toml") if not pesdeToml:isFile() then stdio.ewrite(`{ERROR_PREFIX} pesde.toml is not found. Are you in the right directory?\n`) process.exit(1) @@ -145,7 +146,7 @@ setup:action(function() `{WARN_PREFIX} It is recommended to set 'private = true' in pesde.toml to prevent accidental publishing the root project.` ) end - local luaurcFile = pathfs.File.new(".luaurc") + local luaurcFile = pathfs.FilePath.new(".luaurc") local luaurc: { aliases: { [string]: string? }?, } = if luaurcFile:isFile() @@ -175,8 +176,8 @@ setup:action(function() `Found dependencies in pesde.toml. Would you like to add default aliases '@{DEFAULT_PKG_ALIAS}' and '@{DEFAULT_LUAU_PKG_ALIAS}' in .luaurc for each target's dependencies?` ) then - tableHelper.set(luaurc, { "aliases", DEFAULT_PKG_ALIAS }, pkgPath) - tableHelper.set(luaurc, { "aliases", DEFAULT_LUAU_PKG_ALIAS }, "./luau_packages/") + set(luaurc, { "aliases", DEFAULT_PKG_ALIAS }, pkgPath) + set(luaurc, { "aliases", DEFAULT_LUAU_PKG_ALIAS }, "./luau_packages/") luaurcFile:writeFile(serde.encode("json", luaurc, true)) end end @@ -226,7 +227,7 @@ setup:action(function() `Found a selene.toml file. Would you like to add the default lua environment global variable name('{DEFAULT_LUA_ENV_GLOBAL}') to the ignore pattern?` ) then - tableHelper.set(seleneToml, path, DEFAULT_LUA_ENV_GLOBAL) + set(seleneToml, path, DEFAULT_LUA_ENV_GLOBAL) seleneFile:writeFile(serde.encode("toml", seleneToml, true)) end end @@ -242,7 +243,7 @@ setup:action(function() end end do - local declarationFile = pathfs.File.new(".d.luau") + local declarationFile = pathfs.FilePath.new(".d.luau") if not declarationFile:isFile() then if stdio.prompt( @@ -255,8 +256,8 @@ setup:action(function() end end do - local vscodeDir = pathfs.Directory.new(".vscode") - local vscodeSettings = pathfs.File.new(vscodeDir.path:join("settings.json")) + local vscodeDir = pathfs.DirectoryPath.new(".vscode") + local vscodeSettings = pathfs.FilePath.new(vscodeDir.path:join("settings.json")) local settings: { ["luau-lsp.types.definitionFiles"]: { string }?, } = if vscodeSettings:isFile() @@ -292,7 +293,7 @@ end) local version = cli:command("version", "Show the version of multitarget") version:action(function() - local multitargetPesdeToml = pathfs.File.fromExisting(pathfs.Path.from(_G.PESDE_ROOT):join("pesde.toml")) + local multitargetPesdeToml = pathfs.FilePath.fromExisting(pathfs.Path.from(_G.PESDE_ROOT):join("pesde.toml")) local pesdeManifest: { version: string, } = serde.decode("toml", multitargetPesdeToml:readFile()) diff --git a/src/lib.luau b/src/lib.luau index f2e412e..99bafaf 100644 --- a/src/lib.luau +++ b/src/lib.luau @@ -2,12 +2,15 @@ local stdio = require("@lune/stdio") local serde = require("@lune/serde") local pathfs = require("../lune_packages/pathfs") local fs = pathfs.fs -local gt = require("../lune_packages/greentea") +local gt = require("../luau_packages/greentea") local glob = require("../lune_packages/glob") local process = require("@lune/process") local darklua = require("../lune_packages/darklua_lune") local Result = require("../lune_packages/result") -local tableHelper = require("../luau_packages/table_helper") +local pathfsTypes = require("./pathfsTypes") + +local set = require("./tableUtils/set") +local copy = require("./tableUtils/copy") local DEFAULT_DARKLUA_RULES = { "remove_unused_if_branch", @@ -56,7 +59,7 @@ local targetsType = gt.build(gt.table({ local environmentType = gt.build(gt.union(gt.literal("luau"), gt.literal("lune"), gt.literal("roblox"))) local optionalStringType = gt.build(gt.opt(gt.string())) local optionalStringArrayType = gt.build(gt.opt(gt.array(gt.string()))) -local optionalAsPathType = gt.build(gt.opt(pathfs.types.AsPath:type())) +local optionalAsPathType = gt.build(gt.opt(pathfsTypes.AsPathType:type())) local optionalBooleanType = gt.build(gt.opt(gt.boolean())) local requireModeName = gt.union(gt.literal("path"), gt.literal("luau")) @@ -108,12 +111,12 @@ function multitarget.build( luauPkgAlias: typeof(optionalStringType:type()), strict: typeof(optionalBooleanType:type()), requireMode: typeof(optionalRequireModeType:type()) -): Result.Result - pathfs.types.AsPath:assert(pesdeTomlPath) - pathfs.types.AsPath:assert(outputPath) + pathfsTypes.AsPathType:assert(pesdeTomlPath) + pathfsTypes.AsPathType:assert(outputPath) targetsType:assert(targets) optionalStringArrayType:assert(buildFiles) optionalStringType:assert(luaEnvGlobal) @@ -135,7 +138,7 @@ function multitarget.build( -- selene: allow(shadowing) local pkgAlias = pkgAlias or DEFAULT_PKG_ALIAS -- selene: allow(shadowing) - local pesdeTomlFile = pathfs.File.fromExisting(pesdeTomlPath) + local pesdeTomlFile = pathfs.FilePath.fromExisting(pesdeTomlPath) local outputDir = pathfs.findDir(outputPath) if outputDir then return Result.Err({ @@ -143,7 +146,7 @@ function multitarget.build( }) end -- selene: allow(shadowing) - local outputDir = pathfs.Directory.create(outputPath) + local outputDir = pathfs.DirectoryPath.new(outputPath):withDirWritten() local workingDirPath = pathfs.canonicalize(pesdeTomlFile.path):parent() or pathfs.cwd() local pesdeToml: { @@ -236,11 +239,11 @@ function multitarget.build( end environmentType:assert(target) - local targetDir = pathfs.Directory.new(outputDir.path:join(target)) + local targetDir = pathfs.DirectoryPath.new(outputDir.path:join(target)) targetDir:writeDir() -- assure it exists (may not exist later if the user uses "includes" incorrectly, which would throw an undescriptive error later when trying to access this directory) -- selene: allow(shadowing) - local newPesdeToml = tableHelper.copy(pesdeToml, true) + local newPesdeToml = copy(pesdeToml, true) if newPesdeToml.includes then for _, include in newPesdeToml.includes do for _, path in @@ -284,18 +287,18 @@ function multitarget.build( newPesdeToml.private = nil if #pesdeAddParams > 0 then -- there are dependencies - local luaurcFile = pathfs.File.new(targetDir.path:join(".luaurc")) + local luaurcFile = pathfs.FilePath.new(targetDir.path:join(".luaurc")) local luaurc: { aliases: { [string]: string? }?, } = if luaurcFile:isFile() then serde.decode("json", luaurcFile:readFile()) else {} - tableHelper.set(luaurc, { "aliases", pkgAlias }, `./{target}_packages/`) + set(luaurc, { "aliases", pkgAlias }, `./{target}_packages/`) if targets.lune then if target == "lune" then - tableHelper.set(luaurc, { "aliases", luauPkgAlias }, `./luau_packages/`) + set(luaurc, { "aliases", luauPkgAlias }, `./luau_packages/`) elseif target == "roblox" then - tableHelper.set(luaurc, { "aliases", luauPkgAlias }, `./roblox_packages/`) + set(luaurc, { "aliases", luauPkgAlias }, `./roblox_packages/`) end end luaurcFile:writeFile(serde.encode("json", luaurc, true)) @@ -367,7 +370,7 @@ function multitarget.build( continue end - local targetDir = pathfs.Directory.new(outputDir.path:join(target)) + local targetDir = pathfs.DirectoryPath.new(outputDir.path:join(target)) local injectGlobalValueRule = { rule = "inject_global_value", identifier = luaEnvGlobal, diff --git a/src/pathfsTypes.luau b/src/pathfsTypes.luau new file mode 100644 index 0000000..198758a --- /dev/null +++ b/src/pathfsTypes.luau @@ -0,0 +1,23 @@ +-- This file only exists because pathfs doesn't re-export it's internal types +-- So this is just a stripped down version of https://github.com/jiwonz/lune-pathfs/blob/main/src/types.luau + +local luauPath = require("../luau_packages/luau_path") +local Path = luauPath.Path +local gt = require("../luau_packages/greentea") + +export type Components = typeof(Path.new(""):components()) + +local PathType = gt.build(gt.custom(luauPath.Path.is, "Path") :: luauPath.Path) +local Components = getmetatable(Path.from("a"):components() :: any).__index :: Components & { + new: (path: string, prefix: any?, hasPhysicalRoot: boolean) -> Components, + is: (value: unknown) -> boolean, +} +local ComponentsType = gt.build(gt.custom(Components.is, "Components") :: Components) +local AsPathType = gt.build(gt.union(gt.string(), PathType:type(), ComponentsType:type())) + +return { + PathType = PathType, + Components = Components, + ComponentsType = ComponentsType, + AsPathType = AsPathType, +} diff --git a/src/tableUtils/copy.luau b/src/tableUtils/copy.luau new file mode 100644 index 0000000..ea48765 --- /dev/null +++ b/src/tableUtils/copy.luau @@ -0,0 +1,20 @@ +-- From: https://github.com/CavefulGames/luau-table-helper/blob/main/src/lib/init.luau +-- TODO: Remove when https://github.com/CavefulGames/luau-table-helper/pull/6 gets merged & released + +local function copy(t: T, deep: boolean?): T + if not deep then + return (table.clone(t :: any) :: any) :: T + end + local function deepCopy(tbl: { any }) + local tCopy = table.clone(tbl) + for k, v in tCopy do + if type(v) == "table" then + tCopy[k] = deepCopy(v) + end + end + return tCopy + end + return deepCopy(t :: any) :: T +end + +return copy diff --git a/src/tableUtils/set.luau b/src/tableUtils/set.luau new file mode 100644 index 0000000..b3814a3 --- /dev/null +++ b/src/tableUtils/set.luau @@ -0,0 +1,16 @@ +-- From: https://github.com/CavefulGames/luau-table-helper/blob/main/src/lib/init.luau +-- TODO: Remove when https://github.com/CavefulGames/luau-table-helper/pull/6 gets merged & released + +local function set(t: {}, path: { any }, value: any) + local current = t + for i = 1, #path - 1 do + local key = path[i] + if not current[key] then + current[key] = {} + end + current = current[key] + end + current[path[#path]] = value +end + +return set