Skip to content

Commit 5013860

Browse files
committed
overhaul/simplify infra
1 parent d1096c5 commit 5013860

File tree

13 files changed

+172
-448
lines changed

13 files changed

+172
-448
lines changed

lute/cli/commands/pkg/loom-core/extern/pp.luau

Lines changed: 0 additions & 187 deletions
This file was deleted.

lute/cli/commands/pkg/loom-core/src/authentication/authenticationstore.luau renamed to lute/cli/commands/pkg/loom-core/src/authenticationstore.luau

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local fs = require("@std/fs")
22
local luau = require("@std/luau")
33
local path = require("@std/path")
44
local process = require("@std/process")
5-
local pp = require("../../extern/pp")
5+
local pp = require("@batteries/pp")
66

77
export type AuthenticationEntry = {
88
token: string,
@@ -20,23 +20,8 @@ end
2020
local function loadAuthenticationStore(): AuthenticationStore
2121
local authPath = getAuthenticationFilePath()
2222

23-
local ok, content = pcall(fs.readFileToString, authPath)
24-
if not ok then
25-
return {}
26-
end
27-
28-
local compileOk, bytecode = pcall(luau.compile, content)
29-
if not compileOk then
30-
return {}
31-
end
32-
33-
local loadOk, func = pcall(luau.load, bytecode, authPath, nil)
34-
if not loadOk then
35-
return {}
36-
end
37-
38-
local execOk, result = pcall(func)
39-
if not execOk or type(result) ~= "table" then
23+
local ok, result = pcall(luau.loadModule, authPath, nil)
24+
if not ok or type(result) ~= "table" then
4025
return {}
4126
end
4227

lute/cli/commands/pkg/loom-core/src/commands/authenticate.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local cli = require("@batteries/cli")
2-
local authStore = require("../authentication/authenticationstore")
2+
local authStore = require("../authenticationstore")
33

44
local function authenticate(...: string)
55
local args = cli.parser()
Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
local git = require("../packagesource/git")
2-
local resolution = require("../resolver/resolution")
3-
local projectManifest = require("../manifest/projectmanifest")
4-
local pp = require("../../extern/pp")
1+
local packageresolution = require("../packageresolution")
2+
local path = require("@std/path")
3+
local process = require("@std/process")
54

6-
local fsUtils = require("../utils/fsutils")
7-
local luau = require("@std/luau")
5+
local function printDiagnostics(graph: packageresolution.ResolvedGraph)
6+
local depCount = 0
7+
for _ in graph.dependencies do
8+
depCount += 1
9+
end
10+
print(`Resolved {depCount} package(s).`)
811

9-
local function executeLuauSource(source: string): any
10-
local bytecode = luau.compile(source)
11-
local func = luau.load(bytecode, "loom.config.luau", {})
12-
return func()
12+
for key, pkg in graph.dependencies do
13+
local transitive = 0
14+
local deps = graph.graph[key]
15+
if deps then
16+
for _ in deps do
17+
transitive += 1
18+
end
19+
end
20+
print(` {key} ({pkg.sourceKind}, {transitive} dep(s))`)
21+
end
1322
end
1423

1524
local function install()
16-
local manifestPath = "loom.config.luau"
17-
local manifestContent = fsUtils.readfiletostring(manifestPath)
18-
local manifestTable = executeLuauSource(manifestContent)
19-
local manifest = projectManifest.fromTable(manifestTable)
20-
21-
local projectResolution = resolution.fromManifest(manifest)
22-
23-
local lockfile = resolution.toLockFile(projectResolution)
24-
fsUtils.writestringtofile("loom.lock.luau", "return " .. pp(lockfile))
25-
26-
for _, pkg in projectResolution.packages do
27-
print(`package: {pkg.name}, Rev: {pkg.rev}, Source: {pkg.sourceKind} - {pkg.source}`)
28-
if pkg.sourceKind == "github" then
29-
local zipArchive = git:downloadFromGitHubArchive(pkg.source)
30-
git:installZipArchive(pkg.name, pkg.rev, zipArchive)
31-
end
32-
end
25+
local rootDirectory = path.format(process.cwd())
26+
local graph = packageresolution.resolve(rootDirectory)
27+
printDiagnostics(graph)
3328
end
3429

3530
return install

lute/cli/commands/pkg/loom-core/src/packagesource/git.luau renamed to lute/cli/commands/pkg/loom-core/src/git.luau

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
local authenticationStore = require("../authentication/authenticationstore")
2-
local fsUtils = require("../utils/fsutils")
1+
local authenticationStore = require("./authenticationstore.luau")
2+
local fs = require("@std/fs")
33
local net = require("@std/net")
44
local process = require("@std/process")
5-
local unzip = require("../../extern/unzip")
6-
7-
export type Git = {
8-
installZipArchive: (self: Git, name: string, version: string, content: string) -> (),
9-
downloadFromGitHubArchive: (self: Git, url: string) -> string,
10-
}
11-
12-
local Git = {} :: Git
5+
local projectmanifest = require("./projectmanifest")
6+
local unzip = require("../extern/unzip")
137

148
local function sanitizePath(path: string): string
159
-- Input validation
@@ -60,7 +54,7 @@ local function getGithubAuthenticationToken(): string?
6054
return nil
6155
end
6256

63-
function Git:installZipArchive(name: string, _version: string, content: string)
57+
local function installZipArchive(content: string, installPath: string)
6458
local reader = unzip.load(buffer.fromstring(content))
6559

6660
reader:walk(function(entry, _depth)
@@ -74,12 +68,12 @@ function Git:installZipArchive(name: string, _version: string, content: string)
7468
local slash = string.find(sanitized, "/")
7569
assert(slash, `Expected entry name to contain a slash: {sanitized}`)
7670

77-
local outputPath = `Packages/{name}/{string.sub(sanitized, slash)}`
78-
fsUtils.writestringtofile(outputPath, content)
71+
local outputPath = `{installPath}/{string.sub(sanitized, slash)}`
72+
fs.writeStringToFile(outputPath, content)
7973
end)
8074
end
8175

82-
function Git:downloadFromGitHubArchive(url: string): string
76+
local function downloadFromGitHubArchive(url: string): string
8377
local headers = {}
8478

8579
local token = getGithubAuthenticationToken()
@@ -94,4 +88,12 @@ function Git:downloadFromGitHubArchive(url: string): string
9488
return response.body
9589
end
9690

97-
return Git
91+
local function installPackage(pkg: projectmanifest.DependencySpec, installPath: string): ()
92+
local url = `{pkg.source}/archive/{pkg.rev}.zip`
93+
local zipArchive = downloadFromGitHubArchive(url)
94+
installZipArchive(zipArchive, installPath)
95+
end
96+
97+
return {
98+
installPackage = installPackage,
99+
}

0 commit comments

Comments
 (0)