From 94706f8a9dc3419508364c8e0640d89616556549 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sat, 23 Nov 2024 14:35:23 +0000 Subject: [PATCH] refactor: restructure repo * Restructures monorepo packages * Updated pesde manifests with scope and other metadata * Consolidated all interactive install logic into __call metamethod for one liner bin re-exports * Renamed binlib->toolchainlib * Introduced first real world package - stylua (!!) --- bins/stylua/init.luau | 1 + {lune => bins/stylua}/pesde.lock | 67 +++++++++---------- {lune => bins/stylua}/pesde.toml | 11 ++- lune/init.luau | 37 ---------- pesde.lock | 10 +-- pesde.toml | 6 +- {core => toolchainlib}/README.md | 0 {core => toolchainlib}/pesde.lock | 4 +- {core => toolchainlib}/pesde.toml | 4 +- {core => toolchainlib}/src/compression.luau | 0 {core => toolchainlib}/src/github.luau | 0 {core => toolchainlib}/src/init.luau | 54 ++++++++++++++- {core => toolchainlib}/src/platform/arch.luau | 0 .../src/platform/descriptor.luau | 0 .../src/platform/detection/executable.luau | 0 .../src/platform/detection/init.luau | 0 .../src/platform/detection/pattern.luau | 0 {core => toolchainlib}/src/platform/os.luau | 0 .../src/platform/result.luau | 0 .../src/platform/toolchain.luau | 0 {core => toolchainlib}/src/utils/copy.luau | 0 {core => toolchainlib}/src/utils/eq.luau | 0 {core => toolchainlib}/src/utils/exec.luau | 0 .../src/utils/result_option_conv.luau | 0 .../src/utils/rev_table.luau | 0 {core => toolchainlib}/src/utils/string.luau | 0 26 files changed, 102 insertions(+), 92 deletions(-) create mode 100644 bins/stylua/init.luau rename {lune => bins/stylua}/pesde.lock (89%) rename {lune => bins/stylua}/pesde.toml (54%) delete mode 100644 lune/init.luau rename {core => toolchainlib}/README.md (100%) rename {core => toolchainlib}/pesde.lock (98%) rename {core => toolchainlib}/pesde.toml (91%) rename {core => toolchainlib}/src/compression.luau (100%) rename {core => toolchainlib}/src/github.luau (100%) rename {core => toolchainlib}/src/init.luau (82%) rename {core => toolchainlib}/src/platform/arch.luau (100%) rename {core => toolchainlib}/src/platform/descriptor.luau (100%) rename {core => toolchainlib}/src/platform/detection/executable.luau (100%) rename {core => toolchainlib}/src/platform/detection/init.luau (100%) rename {core => toolchainlib}/src/platform/detection/pattern.luau (100%) rename {core => toolchainlib}/src/platform/os.luau (100%) rename {core => toolchainlib}/src/platform/result.luau (100%) rename {core => toolchainlib}/src/platform/toolchain.luau (100%) rename {core => toolchainlib}/src/utils/copy.luau (100%) rename {core => toolchainlib}/src/utils/eq.luau (100%) rename {core => toolchainlib}/src/utils/exec.luau (100%) rename {core => toolchainlib}/src/utils/result_option_conv.luau (100%) rename {core => toolchainlib}/src/utils/rev_table.luau (100%) rename {core => toolchainlib}/src/utils/string.luau (100%) diff --git a/bins/stylua/init.luau b/bins/stylua/init.luau new file mode 100644 index 0000000..be769a9 --- /dev/null +++ b/bins/stylua/init.luau @@ -0,0 +1 @@ +require("./lune_packages/core")("JohnnyMorganz/stylua", _G.PESDE_ROOT) diff --git a/lune/pesde.lock b/bins/stylua/pesde.lock similarity index 89% rename from lune/pesde.lock rename to bins/stylua/pesde.lock index 4fc19ea..7a44a8f 100644 --- a/lune/pesde.lock +++ b/bins/stylua/pesde.lock @@ -1,10 +1,9 @@ -name = "compeydev/lune" -version = "0.8.9" +name = "pesde/stylua" +version = "2.0.1" target = "lune" [graph."0x5eal/semver"."0.1.1 luau"] -direct = ["semver", { name = "0x5eal/semver", version = "^0.1.1", target = "luau" }, "standard"] -resolved_ty = "standard" +resolved_ty = "peer" [graph."0x5eal/semver"."0.1.1 luau".target] environment = "luau" @@ -29,36 +28,6 @@ result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://gith environment = "luau" lib = "lib/init.luau" -[graph."compeydev/binlib"."0.1.0 lune"] -direct = ["core", { workspace = "compeydev/binlib", version = "^" }, "standard"] -resolved_ty = "standard" - -[graph."compeydev/binlib"."0.1.0 lune".target] -environment = "lune" -lib = "src/init.luau" - -[graph."compeydev/binlib"."0.1.0 lune".dependencies] -"0x5eal/semver" = ["0.1.1 luau", "semver"] -"jiwonz/dirs" = ["0.1.2 lune", "dirs"] -"jiwonz/pathfs" = ["0.1.0 lune", "pathfs"] -"lukadev_0/option" = ["1.2.0 lune", "option"] -"lukadev_0/result" = ["1.2.0 lune", "result"] - -[graph."compeydev/binlib"."0.1.0 lune".pkg_ref] -ref_ty = "workspace" -path = "core" - -[graph."compeydev/binlib"."0.1.0 lune".pkg_ref.dependencies] -dirs = [{ name = "jiwonz/dirs", version = "^0.1.1", index = "https://github.com/daimond113/pesde-index" }, "standard"] -option = [{ name = "lukadev_0/option", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] -pathfs = [{ name = "jiwonz/pathfs", version = "^0.1.0", index = "https://github.com/daimond113/pesde-index" }, "standard"] -result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] -semver = [{ name = "0x5eal/semver", version = "^0.1.1", index = "https://github.com/daimond113/pesde-index", target = "luau" }, "standard"] - -[graph."compeydev/binlib"."0.1.0 lune".pkg_ref.target] -environment = "lune" -lib = "src/init.luau" - [graph."jiwonz/dirs"."0.1.2 lune"] resolved_ty = "standard" @@ -168,3 +137,33 @@ index_url = "https://github.com/daimond113/pesde-index" [graph."lukadev_0/result"."1.2.0 luau".pkg_ref.target] environment = "luau" lib = "lib/init.luau" + +[graph."pesde/toolchainlib"."0.1.0 lune"] +direct = ["core", { workspace = "pesde/toolchainlib", version = "^" }, "standard"] +resolved_ty = "standard" + +[graph."pesde/toolchainlib"."0.1.0 lune".target] +environment = "lune" +lib = "src/init.luau" + +[graph."pesde/toolchainlib"."0.1.0 lune".dependencies] +"0x5eal/semver" = ["0.1.1 luau", "semver"] +"jiwonz/dirs" = ["0.1.2 lune", "dirs"] +"jiwonz/pathfs" = ["0.1.0 lune", "pathfs"] +"lukadev_0/option" = ["1.2.0 lune", "option"] +"lukadev_0/result" = ["1.2.0 lune", "result"] + +[graph."pesde/toolchainlib"."0.1.0 lune".pkg_ref] +ref_ty = "workspace" +path = "toolchainlib" + +[graph."pesde/toolchainlib"."0.1.0 lune".pkg_ref.dependencies] +dirs = [{ name = "jiwonz/dirs", version = "^0.1.1", index = "https://github.com/daimond113/pesde-index" }, "standard"] +option = [{ name = "lukadev_0/option", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] +pathfs = [{ name = "jiwonz/pathfs", version = "^0.1.0", index = "https://github.com/daimond113/pesde-index" }, "standard"] +result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] +semver = [{ name = "0x5eal/semver", version = "^0.1.1", index = "https://github.com/daimond113/pesde-index", target = "luau" }, "peer"] + +[graph."pesde/toolchainlib"."0.1.0 lune".pkg_ref.target] +environment = "lune" +lib = "src/init.luau" diff --git a/lune/pesde.toml b/bins/stylua/pesde.toml similarity index 54% rename from lune/pesde.toml rename to bins/stylua/pesde.toml index 6b0f5a7..4abf400 100644 --- a/lune/pesde.toml +++ b/bins/stylua/pesde.toml @@ -1,11 +1,11 @@ -name = "compeydev/lune" -version = "0.8.9" +name = "pesde/stylua" +version = "2.0.1" description = "A standalone Luau runtime" authors = [ "CompeyDev ", - "Filip Tibell ", + "Johnny Morganz ", ] -repository = "https://github.com/CompeyDev/pesde-tooling/blob/main/lune" +repository = "https://github.com/pesde-dev/tooling" license = "MIT" [target] @@ -15,8 +15,7 @@ bin = "init.luau" [dependencies] result = { name = "lukadev_0/result", version = "^1.2.0" } option = { name = "lukadev_0/option", version = "^1.2.0" } -semver = { name = "0x5eal/semver", version = "^0.1.1", target = "luau" } -core = { workspace = "compeydev/binlib", version = "^" } +core = { workspace = "pesde/toolchainlib", version = "^" } [indices] default = "https://github.com/daimond113/pesde-index" diff --git a/lune/init.luau b/lune/init.luau deleted file mode 100644 index 15b4e26..0000000 --- a/lune/init.luau +++ /dev/null @@ -1,37 +0,0 @@ -local stdio = require("@lune/stdio") -local process = require("@lune/process") -local fs = require("@lune/fs") -local serde = require("@lune/serde") - -local core = require("./lune_packages/core") -local Semver = require("./luau_packages/semver") -local Option = require("./lune_packages/option") -type Option = Option.Option - --- Use _G.PESDE_ROOT to get the install directory, then decode the --- pesde manifest to get the version of the tool dynamically -local PLATFORM_SEP = if process.platform == "windows" then "\\" else "/" -local ERROR_PREFIX = `{stdio.color("red")}{stdio.style("bold")}error{stdio.color("reset")}:` - -local manifestContents = fs.readFile(`{_G.PESDE_ROOT}{PLATFORM_SEP}pesde.toml`) - --- TODO: Create a pesde manifest type in binlib, and use that here -local ok, manifest = pcall(serde.decode, "toml", manifestContents) -if not ok then - stdio.ewrite(`{ERROR_PREFIX} Failed to decode bundled manifest. This is probably a bug.\n\n{manifest}`) - process.exit(1) -end - -local ok, err = pcall( - core.installTool, - { - alias = Option.None, - repo = "lune-org/lune", - version = Option.Some(Semver.parse(manifest.version):unwrap()) :: Option, - } :: core.ToolId -) - -if not ok then - stdio.ewrite(`{ERROR_PREFIX} Failed to install {manifest.name}@{manifest.version}`) - stdio.ewrite(` - {err}`) -end diff --git a/pesde.lock b/pesde.lock index 4ac8b7a..a8ef248 100644 --- a/pesde.lock +++ b/pesde.lock @@ -1,9 +1,9 @@ -name = "compeydev/pesde_bins" +name = "pesde/tooling" version = "0.1.0" target = "lune" -[workspace."compeydev/binlib"] -lune = "core" +[workspace."pesde/stylua"] +lune = "bins/stylua" -[workspace."compeydev/lune"] -lune = "lune" +[workspace."pesde/toolchainlib"] +lune = "toolchainlib" diff --git a/pesde.toml b/pesde.toml index 6e17a6a..91d8f2e 100644 --- a/pesde.toml +++ b/pesde.toml @@ -1,13 +1,11 @@ -name = "compeydev/pesde_bins" +name = "pesde/tooling" version = "0.1.0" private = true -workspace_members = ["lune", "core"] +workspace_members = ["toolchainlib", "bins/*"] [target] environment = "lune" [indices] default = "https://github.com/daimond113/pesde-index" - - diff --git a/core/README.md b/toolchainlib/README.md similarity index 100% rename from core/README.md rename to toolchainlib/README.md diff --git a/core/pesde.lock b/toolchainlib/pesde.lock similarity index 98% rename from core/pesde.lock rename to toolchainlib/pesde.lock index c7214a7..936fb0f 100644 --- a/core/pesde.lock +++ b/toolchainlib/pesde.lock @@ -1,9 +1,9 @@ -name = "compeydev/binlib" +name = "pesde/toolchainlib" version = "0.1.0" target = "lune" [graph."0x5eal/semver"."0.1.1 luau"] -direct = ["semver", { name = "0x5eal/semver", version = "^0.1.1", target = "luau" }, "standard"] +direct = ["semver", { name = "0x5eal/semver", version = "^0.1.1", target = "luau" }, "peer"] resolved_ty = "standard" [graph."0x5eal/semver"."0.1.1 luau".target] diff --git a/core/pesde.toml b/toolchainlib/pesde.toml similarity index 91% rename from core/pesde.toml rename to toolchainlib/pesde.toml index 2132ece..d980a14 100644 --- a/core/pesde.toml +++ b/toolchainlib/pesde.toml @@ -1,4 +1,4 @@ -name = "compeydev/binlib" +name = "pesde/toolchainlib" version = "0.1.0" includes = ["src/", "pesde.toml", "LICENSE", "README.md"] @@ -9,11 +9,11 @@ lib = "src/init.luau" [dependencies] pathfs = { name = "jiwonz/pathfs", version = "^0.1.0" } dirs = { name = "jiwonz/dirs", version = "^0.1.1" } -semver = { name = "0x5eal/semver", version = "^0.1.1", target = "luau" } [peer_dependencies] result = { name = "lukadev_0/result", version = "^1.2.0" } option = { name = "lukadev_0/option", version = "^1.2.0" } +semver = { name = "0x5eal/semver", version = "^0.1.1", target = "luau" } [indices] default = "https://github.com/daimond113/pesde-index" diff --git a/core/src/compression.luau b/toolchainlib/src/compression.luau similarity index 100% rename from core/src/compression.luau rename to toolchainlib/src/compression.luau diff --git a/core/src/github.luau b/toolchainlib/src/github.luau similarity index 100% rename from core/src/github.luau rename to toolchainlib/src/github.luau diff --git a/core/src/init.luau b/toolchainlib/src/init.luau similarity index 82% rename from core/src/init.luau rename to toolchainlib/src/init.luau index 6228f95..e03d954 100644 --- a/core/src/init.luau +++ b/toolchainlib/src/init.luau @@ -9,6 +9,8 @@ local net = require("@lune/net") local process = require("@lune/process") +local stdio = require("@lune/stdio") +local serde = require("@lune/serde") local Semver = require("../luau_packages/semver") local pathfs = require("../lune_packages/pathfs") @@ -254,10 +256,58 @@ function installTool(tool: ToolId) toolInstallPath:toString() ) ) + chmod(linkPath, 0b111101101) + runTool(toolinstallPath) end -return { +return setmetatable({ runTool = runTool, installTool = installTool, -} +}, { + __call = function(lib, tool: string, pesdeRoot: string?) + -- TODO: Progress bar maybe? :D + + local ERROR_PREFIX = `{stdio.color("red")}{stdio.style("bold")}error{stdio.color("reset")}:` + + local repo, version = string.match(tool, "([^@]+)@?(.*)") + if repo == nil then + stdio.ewrite(`{ERROR_PREFIX} Invalid tool provided\n`) + process.exit(1) + end + + local function manifestVersion(): string + if pesdeRoot == nil then + stdio.ewrite(`{ERROR_PREFIX} Failed to discover pesde package root\n`) + process.exit(1) + end + + -- Use _G.PESDE_ROOT to get the install directory, then decode the + -- pesde manifest to get the version of the tool dynamically + local manifestContents = pathfs.readFile(pathfs.Path.from(pesdeRoot):join("pesde.toml")) + -- TODO: Create a pesde manifest type in toolchainlib, and use that here + local ok, manifest = pcall(serde.decode, "toml", manifestContents) + if not ok then + stdio.ewrite(`{ERROR_PREFIX} Failed to decode bundled manifest. This is probably a bug.\n\n{manifest}`) + process.exit(1) + end + + return manifest.version + end + + local ok, err = pcall( + lib.installTool, + { + -- TODO: Use alias within pesde.toml in linker script + alias = Option.None, + repo = repo, + version = Option.Some(Semver.parse(if version ~= "" then version else manifestVersion()):unwrap()) :: Option, + } :: core.ToolId + ) + + if not ok then + stdio.ewrite(`{ERROR_PREFIX} Failed to install {tool}\n`) + stdio.ewrite(` - {err}\n`) + end + end, +}) diff --git a/core/src/platform/arch.luau b/toolchainlib/src/platform/arch.luau similarity index 100% rename from core/src/platform/arch.luau rename to toolchainlib/src/platform/arch.luau diff --git a/core/src/platform/descriptor.luau b/toolchainlib/src/platform/descriptor.luau similarity index 100% rename from core/src/platform/descriptor.luau rename to toolchainlib/src/platform/descriptor.luau diff --git a/core/src/platform/detection/executable.luau b/toolchainlib/src/platform/detection/executable.luau similarity index 100% rename from core/src/platform/detection/executable.luau rename to toolchainlib/src/platform/detection/executable.luau diff --git a/core/src/platform/detection/init.luau b/toolchainlib/src/platform/detection/init.luau similarity index 100% rename from core/src/platform/detection/init.luau rename to toolchainlib/src/platform/detection/init.luau diff --git a/core/src/platform/detection/pattern.luau b/toolchainlib/src/platform/detection/pattern.luau similarity index 100% rename from core/src/platform/detection/pattern.luau rename to toolchainlib/src/platform/detection/pattern.luau diff --git a/core/src/platform/os.luau b/toolchainlib/src/platform/os.luau similarity index 100% rename from core/src/platform/os.luau rename to toolchainlib/src/platform/os.luau diff --git a/core/src/platform/result.luau b/toolchainlib/src/platform/result.luau similarity index 100% rename from core/src/platform/result.luau rename to toolchainlib/src/platform/result.luau diff --git a/core/src/platform/toolchain.luau b/toolchainlib/src/platform/toolchain.luau similarity index 100% rename from core/src/platform/toolchain.luau rename to toolchainlib/src/platform/toolchain.luau diff --git a/core/src/utils/copy.luau b/toolchainlib/src/utils/copy.luau similarity index 100% rename from core/src/utils/copy.luau rename to toolchainlib/src/utils/copy.luau diff --git a/core/src/utils/eq.luau b/toolchainlib/src/utils/eq.luau similarity index 100% rename from core/src/utils/eq.luau rename to toolchainlib/src/utils/eq.luau diff --git a/core/src/utils/exec.luau b/toolchainlib/src/utils/exec.luau similarity index 100% rename from core/src/utils/exec.luau rename to toolchainlib/src/utils/exec.luau diff --git a/core/src/utils/result_option_conv.luau b/toolchainlib/src/utils/result_option_conv.luau similarity index 100% rename from core/src/utils/result_option_conv.luau rename to toolchainlib/src/utils/result_option_conv.luau diff --git a/core/src/utils/rev_table.luau b/toolchainlib/src/utils/rev_table.luau similarity index 100% rename from core/src/utils/rev_table.luau rename to toolchainlib/src/utils/rev_table.luau diff --git a/core/src/utils/string.luau b/toolchainlib/src/utils/string.luau similarity index 100% rename from core/src/utils/string.luau rename to toolchainlib/src/utils/string.luau