@qlever-llc/trellis 0.9.0-rc.2 → 0.9.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/npm/src/generate.js +54 -24
- package/package.json +2 -2
- package/script/npm/src/generate.js +54 -57
package/esm/npm/src/generate.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import "./_dnt.polyfills.js";
|
|
2
|
-
import * as dntShim from "./_dnt.shims.js";
|
|
3
2
|
const REPO_OWNER = "qlever-llc";
|
|
4
3
|
const REPO_NAME = "trellis";
|
|
5
4
|
const BIN_NAME = "trellis-generate";
|
|
@@ -12,14 +11,22 @@ const SUPPORTED_TARGETS = new Set([
|
|
|
12
11
|
async function main() {
|
|
13
12
|
const localRepoRoot = await findLocalTrellisRepoRoot();
|
|
14
13
|
if (localRepoRoot) {
|
|
15
|
-
await runLocalGenerator(localRepoRoot,
|
|
14
|
+
await runLocalGenerator(localRepoRoot, denoRuntime().args);
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
17
|
const packageVersion = await readPackageVersion();
|
|
19
|
-
const binary =
|
|
18
|
+
const binary = denoRuntime().env.get("TRELLIS_GENERATE_BIN")?.trim() ||
|
|
20
19
|
await ensureCachedReleaseBinary(packageVersion);
|
|
21
20
|
await verifyBinaryVersion(binary, packageVersion);
|
|
22
|
-
await runBinary(binary,
|
|
21
|
+
await runBinary(binary, denoRuntime().args);
|
|
22
|
+
}
|
|
23
|
+
function denoRuntime() {
|
|
24
|
+
const getGlobalThis = Function("return globalThis");
|
|
25
|
+
const deno = getGlobalThis().Deno;
|
|
26
|
+
if (!deno) {
|
|
27
|
+
throw new Error("@qlever-llc/trellis/generate requires the Deno runtime");
|
|
28
|
+
}
|
|
29
|
+
return deno;
|
|
23
30
|
}
|
|
24
31
|
async function findLocalTrellisRepoRoot() {
|
|
25
32
|
let current = urlDirname(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url);
|
|
@@ -44,13 +51,30 @@ async function runLocalGenerator(repoRoot, args) {
|
|
|
44
51
|
]);
|
|
45
52
|
}
|
|
46
53
|
async function readPackageVersion() {
|
|
47
|
-
const
|
|
48
|
-
|
|
54
|
+
const manifest = await readFirstManifest([
|
|
55
|
+
new URL("./deno.json", globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url),
|
|
56
|
+
new URL("../../../package.json", globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url),
|
|
57
|
+
]);
|
|
49
58
|
if (typeof manifest.version !== "string" || !manifest.version.trim()) {
|
|
50
59
|
throw new Error("@qlever-llc/trellis package manifest does not declare a version");
|
|
51
60
|
}
|
|
52
61
|
return manifest.version.trim();
|
|
53
62
|
}
|
|
63
|
+
async function readFirstManifest(urls) {
|
|
64
|
+
const deno = denoRuntime();
|
|
65
|
+
for (const url of urls) {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(await deno.readTextFile(url));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof deno.errors.NotFound) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw new Error("@qlever-llc/trellis package manifest was not found");
|
|
77
|
+
}
|
|
54
78
|
async function ensureCachedReleaseBinary(version) {
|
|
55
79
|
const target = releaseTarget();
|
|
56
80
|
const cacheDir = joinPath(cacheRoot(), version, target);
|
|
@@ -58,7 +82,8 @@ async function ensureCachedReleaseBinary(version) {
|
|
|
58
82
|
if (await pathExists(binary)) {
|
|
59
83
|
return binary;
|
|
60
84
|
}
|
|
61
|
-
|
|
85
|
+
const deno = denoRuntime();
|
|
86
|
+
await deno.mkdir(cacheDir, { recursive: true });
|
|
62
87
|
const tag = `v${version}`;
|
|
63
88
|
const archiveName = `${BIN_NAME}-${tag}-${target}.tar.gz`;
|
|
64
89
|
const archiveUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${archiveName}`;
|
|
@@ -70,40 +95,42 @@ async function ensureCachedReleaseBinary(version) {
|
|
|
70
95
|
]);
|
|
71
96
|
await verifyChecksum(archive, checksumText, archiveUrl);
|
|
72
97
|
const archivePath = joinPath(cacheDir, archiveName);
|
|
73
|
-
await
|
|
98
|
+
await deno.writeFile(archivePath, archive);
|
|
74
99
|
await runCommandChecked("tar", ["-xzf", archivePath, "-C", cacheDir]);
|
|
75
|
-
await
|
|
100
|
+
await deno.chmod(binary, 0o755);
|
|
76
101
|
return binary;
|
|
77
102
|
}
|
|
78
103
|
function releaseTarget() {
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
const deno = denoRuntime();
|
|
105
|
+
if (SUPPORTED_TARGETS.has(deno.build.target)) {
|
|
106
|
+
return deno.build.target;
|
|
81
107
|
}
|
|
82
|
-
const buildArch =
|
|
108
|
+
const buildArch = deno.build.arch;
|
|
83
109
|
const arch = buildArch === "x86_64" || buildArch === "x64"
|
|
84
110
|
? "x86_64"
|
|
85
111
|
: buildArch;
|
|
86
|
-
const os =
|
|
112
|
+
const os = deno.build.os === "darwin"
|
|
87
113
|
? "apple-darwin"
|
|
88
|
-
:
|
|
114
|
+
: deno.build.os === "linux"
|
|
89
115
|
? "unknown-linux-gnu"
|
|
90
116
|
: undefined;
|
|
91
117
|
const target = os ? `${arch}-${os}` : undefined;
|
|
92
118
|
if (target && SUPPORTED_TARGETS.has(target)) {
|
|
93
119
|
return target;
|
|
94
120
|
}
|
|
95
|
-
throw new Error(`no ${BIN_NAME} release binary is available for ${
|
|
121
|
+
throw new Error(`no ${BIN_NAME} release binary is available for ${deno.build.target}`);
|
|
96
122
|
}
|
|
97
123
|
function cacheRoot() {
|
|
98
|
-
const
|
|
124
|
+
const deno = denoRuntime();
|
|
125
|
+
const explicit = deno.env.get("TRELLIS_GENERATE_CACHE")?.trim();
|
|
99
126
|
if (explicit) {
|
|
100
127
|
return explicit;
|
|
101
128
|
}
|
|
102
|
-
const xdg =
|
|
129
|
+
const xdg = deno.env.get("XDG_CACHE_HOME")?.trim();
|
|
103
130
|
if (xdg) {
|
|
104
131
|
return joinPath(xdg, "trellis", BIN_NAME);
|
|
105
132
|
}
|
|
106
|
-
const home =
|
|
133
|
+
const home = deno.env.get("HOME")?.trim();
|
|
107
134
|
if (!home) {
|
|
108
135
|
throw new Error("HOME or TRELLIS_GENERATE_CACHE must be set to cache trellis-generate");
|
|
109
136
|
}
|
|
@@ -139,7 +166,8 @@ async function verifyChecksum(bytes, checksumText, label) {
|
|
|
139
166
|
}
|
|
140
167
|
}
|
|
141
168
|
async function verifyBinaryVersion(binary, expectedVersion) {
|
|
142
|
-
const
|
|
169
|
+
const Command = denoRuntime().Command;
|
|
170
|
+
const output = await new Command(binary, {
|
|
143
171
|
args: ["--version"],
|
|
144
172
|
stdout: "piped",
|
|
145
173
|
stderr: "piped",
|
|
@@ -162,7 +190,7 @@ async function runBinary(binary, args) {
|
|
|
162
190
|
}
|
|
163
191
|
async function runCommand(command, args, options = {}) {
|
|
164
192
|
const status = await spawnCommand(command, args, options);
|
|
165
|
-
|
|
193
|
+
denoRuntime().exit(status.code);
|
|
166
194
|
}
|
|
167
195
|
async function runCommandChecked(command, args, options = {}) {
|
|
168
196
|
const status = await spawnCommand(command, args, options);
|
|
@@ -171,7 +199,8 @@ async function runCommandChecked(command, args, options = {}) {
|
|
|
171
199
|
}
|
|
172
200
|
}
|
|
173
201
|
async function spawnCommand(command, args, options = {}) {
|
|
174
|
-
const
|
|
202
|
+
const Command = denoRuntime().Command;
|
|
203
|
+
const status = await new Command(command, {
|
|
175
204
|
args,
|
|
176
205
|
cwd: options.cwd,
|
|
177
206
|
stdin: "inherit",
|
|
@@ -181,12 +210,13 @@ async function spawnCommand(command, args, options = {}) {
|
|
|
181
210
|
return status;
|
|
182
211
|
}
|
|
183
212
|
async function pathExists(path) {
|
|
213
|
+
const deno = denoRuntime();
|
|
184
214
|
try {
|
|
185
|
-
await
|
|
215
|
+
await deno.stat(path);
|
|
186
216
|
return true;
|
|
187
217
|
}
|
|
188
218
|
catch (error) {
|
|
189
|
-
if (error instanceof
|
|
219
|
+
if (error instanceof deno.errors.NotFound) {
|
|
190
220
|
return false;
|
|
191
221
|
}
|
|
192
222
|
throw error;
|
|
@@ -212,6 +242,6 @@ function joinPath(...parts) {
|
|
|
212
242
|
if (globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).main) {
|
|
213
243
|
main().catch((error) => {
|
|
214
244
|
console.error(error);
|
|
215
|
-
|
|
245
|
+
denoRuntime().exit(1);
|
|
216
246
|
});
|
|
217
247
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlever-llc/trellis",
|
|
3
|
-
"version": "0.9.0-rc.
|
|
3
|
+
"version": "0.9.0-rc.4",
|
|
4
4
|
"description": "Client-side Trellis runtime, models, and contract helpers for TypeScript applications.",
|
|
5
5
|
"homepage": "https://github.com/Qlever-LLC/trellis#readme",
|
|
6
6
|
"repository": {
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"ts-deepmerge": "^7.0.3",
|
|
123
123
|
"typebox": "^1.0.15",
|
|
124
124
|
"ulid": "^3.0.1",
|
|
125
|
-
"@qlever-llc/result": "0.9.0-rc.
|
|
125
|
+
"@qlever-llc/result": "0.9.0-rc.4"
|
|
126
126
|
},
|
|
127
127
|
"devDependencies": {
|
|
128
128
|
"@types/node": "^20.9.0"
|
|
@@ -1,40 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
require("./_dnt.polyfills.js");
|
|
37
|
-
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
38
4
|
const REPO_OWNER = "qlever-llc";
|
|
39
5
|
const REPO_NAME = "trellis";
|
|
40
6
|
const BIN_NAME = "trellis-generate";
|
|
@@ -47,14 +13,22 @@ const SUPPORTED_TARGETS = new Set([
|
|
|
47
13
|
async function main() {
|
|
48
14
|
const localRepoRoot = await findLocalTrellisRepoRoot();
|
|
49
15
|
if (localRepoRoot) {
|
|
50
|
-
await runLocalGenerator(localRepoRoot,
|
|
16
|
+
await runLocalGenerator(localRepoRoot, denoRuntime().args);
|
|
51
17
|
return;
|
|
52
18
|
}
|
|
53
19
|
const packageVersion = await readPackageVersion();
|
|
54
|
-
const binary =
|
|
20
|
+
const binary = denoRuntime().env.get("TRELLIS_GENERATE_BIN")?.trim() ||
|
|
55
21
|
await ensureCachedReleaseBinary(packageVersion);
|
|
56
22
|
await verifyBinaryVersion(binary, packageVersion);
|
|
57
|
-
await runBinary(binary,
|
|
23
|
+
await runBinary(binary, denoRuntime().args);
|
|
24
|
+
}
|
|
25
|
+
function denoRuntime() {
|
|
26
|
+
const getGlobalThis = Function("return globalThis");
|
|
27
|
+
const deno = getGlobalThis().Deno;
|
|
28
|
+
if (!deno) {
|
|
29
|
+
throw new Error("@qlever-llc/trellis/generate requires the Deno runtime");
|
|
30
|
+
}
|
|
31
|
+
return deno;
|
|
58
32
|
}
|
|
59
33
|
async function findLocalTrellisRepoRoot() {
|
|
60
34
|
let current = urlDirname(globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url);
|
|
@@ -79,13 +53,30 @@ async function runLocalGenerator(repoRoot, args) {
|
|
|
79
53
|
]);
|
|
80
54
|
}
|
|
81
55
|
async function readPackageVersion() {
|
|
82
|
-
const
|
|
83
|
-
|
|
56
|
+
const manifest = await readFirstManifest([
|
|
57
|
+
new URL("./deno.json", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url),
|
|
58
|
+
new URL("../../../package.json", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url),
|
|
59
|
+
]);
|
|
84
60
|
if (typeof manifest.version !== "string" || !manifest.version.trim()) {
|
|
85
61
|
throw new Error("@qlever-llc/trellis package manifest does not declare a version");
|
|
86
62
|
}
|
|
87
63
|
return manifest.version.trim();
|
|
88
64
|
}
|
|
65
|
+
async function readFirstManifest(urls) {
|
|
66
|
+
const deno = denoRuntime();
|
|
67
|
+
for (const url of urls) {
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(await deno.readTextFile(url));
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error instanceof deno.errors.NotFound) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
throw new Error("@qlever-llc/trellis package manifest was not found");
|
|
79
|
+
}
|
|
89
80
|
async function ensureCachedReleaseBinary(version) {
|
|
90
81
|
const target = releaseTarget();
|
|
91
82
|
const cacheDir = joinPath(cacheRoot(), version, target);
|
|
@@ -93,7 +84,8 @@ async function ensureCachedReleaseBinary(version) {
|
|
|
93
84
|
if (await pathExists(binary)) {
|
|
94
85
|
return binary;
|
|
95
86
|
}
|
|
96
|
-
|
|
87
|
+
const deno = denoRuntime();
|
|
88
|
+
await deno.mkdir(cacheDir, { recursive: true });
|
|
97
89
|
const tag = `v${version}`;
|
|
98
90
|
const archiveName = `${BIN_NAME}-${tag}-${target}.tar.gz`;
|
|
99
91
|
const archiveUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${archiveName}`;
|
|
@@ -105,40 +97,42 @@ async function ensureCachedReleaseBinary(version) {
|
|
|
105
97
|
]);
|
|
106
98
|
await verifyChecksum(archive, checksumText, archiveUrl);
|
|
107
99
|
const archivePath = joinPath(cacheDir, archiveName);
|
|
108
|
-
await
|
|
100
|
+
await deno.writeFile(archivePath, archive);
|
|
109
101
|
await runCommandChecked("tar", ["-xzf", archivePath, "-C", cacheDir]);
|
|
110
|
-
await
|
|
102
|
+
await deno.chmod(binary, 0o755);
|
|
111
103
|
return binary;
|
|
112
104
|
}
|
|
113
105
|
function releaseTarget() {
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
const deno = denoRuntime();
|
|
107
|
+
if (SUPPORTED_TARGETS.has(deno.build.target)) {
|
|
108
|
+
return deno.build.target;
|
|
116
109
|
}
|
|
117
|
-
const buildArch =
|
|
110
|
+
const buildArch = deno.build.arch;
|
|
118
111
|
const arch = buildArch === "x86_64" || buildArch === "x64"
|
|
119
112
|
? "x86_64"
|
|
120
113
|
: buildArch;
|
|
121
|
-
const os =
|
|
114
|
+
const os = deno.build.os === "darwin"
|
|
122
115
|
? "apple-darwin"
|
|
123
|
-
:
|
|
116
|
+
: deno.build.os === "linux"
|
|
124
117
|
? "unknown-linux-gnu"
|
|
125
118
|
: undefined;
|
|
126
119
|
const target = os ? `${arch}-${os}` : undefined;
|
|
127
120
|
if (target && SUPPORTED_TARGETS.has(target)) {
|
|
128
121
|
return target;
|
|
129
122
|
}
|
|
130
|
-
throw new Error(`no ${BIN_NAME} release binary is available for ${
|
|
123
|
+
throw new Error(`no ${BIN_NAME} release binary is available for ${deno.build.target}`);
|
|
131
124
|
}
|
|
132
125
|
function cacheRoot() {
|
|
133
|
-
const
|
|
126
|
+
const deno = denoRuntime();
|
|
127
|
+
const explicit = deno.env.get("TRELLIS_GENERATE_CACHE")?.trim();
|
|
134
128
|
if (explicit) {
|
|
135
129
|
return explicit;
|
|
136
130
|
}
|
|
137
|
-
const xdg =
|
|
131
|
+
const xdg = deno.env.get("XDG_CACHE_HOME")?.trim();
|
|
138
132
|
if (xdg) {
|
|
139
133
|
return joinPath(xdg, "trellis", BIN_NAME);
|
|
140
134
|
}
|
|
141
|
-
const home =
|
|
135
|
+
const home = deno.env.get("HOME")?.trim();
|
|
142
136
|
if (!home) {
|
|
143
137
|
throw new Error("HOME or TRELLIS_GENERATE_CACHE must be set to cache trellis-generate");
|
|
144
138
|
}
|
|
@@ -174,7 +168,8 @@ async function verifyChecksum(bytes, checksumText, label) {
|
|
|
174
168
|
}
|
|
175
169
|
}
|
|
176
170
|
async function verifyBinaryVersion(binary, expectedVersion) {
|
|
177
|
-
const
|
|
171
|
+
const Command = denoRuntime().Command;
|
|
172
|
+
const output = await new Command(binary, {
|
|
178
173
|
args: ["--version"],
|
|
179
174
|
stdout: "piped",
|
|
180
175
|
stderr: "piped",
|
|
@@ -197,7 +192,7 @@ async function runBinary(binary, args) {
|
|
|
197
192
|
}
|
|
198
193
|
async function runCommand(command, args, options = {}) {
|
|
199
194
|
const status = await spawnCommand(command, args, options);
|
|
200
|
-
|
|
195
|
+
denoRuntime().exit(status.code);
|
|
201
196
|
}
|
|
202
197
|
async function runCommandChecked(command, args, options = {}) {
|
|
203
198
|
const status = await spawnCommand(command, args, options);
|
|
@@ -206,7 +201,8 @@ async function runCommandChecked(command, args, options = {}) {
|
|
|
206
201
|
}
|
|
207
202
|
}
|
|
208
203
|
async function spawnCommand(command, args, options = {}) {
|
|
209
|
-
const
|
|
204
|
+
const Command = denoRuntime().Command;
|
|
205
|
+
const status = await new Command(command, {
|
|
210
206
|
args,
|
|
211
207
|
cwd: options.cwd,
|
|
212
208
|
stdin: "inherit",
|
|
@@ -216,12 +212,13 @@ async function spawnCommand(command, args, options = {}) {
|
|
|
216
212
|
return status;
|
|
217
213
|
}
|
|
218
214
|
async function pathExists(path) {
|
|
215
|
+
const deno = denoRuntime();
|
|
219
216
|
try {
|
|
220
|
-
await
|
|
217
|
+
await deno.stat(path);
|
|
221
218
|
return true;
|
|
222
219
|
}
|
|
223
220
|
catch (error) {
|
|
224
|
-
if (error instanceof
|
|
221
|
+
if (error instanceof deno.errors.NotFound) {
|
|
225
222
|
return false;
|
|
226
223
|
}
|
|
227
224
|
throw error;
|
|
@@ -247,6 +244,6 @@ function joinPath(...parts) {
|
|
|
247
244
|
if (globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).main) {
|
|
248
245
|
main().catch((error) => {
|
|
249
246
|
console.error(error);
|
|
250
|
-
|
|
247
|
+
denoRuntime().exit(1);
|
|
251
248
|
});
|
|
252
249
|
}
|