@qlever-llc/trellis 0.8.0 → 0.8.3

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.
@@ -15,4 +15,103 @@ declare global {
15
15
  }
16
16
  }
17
17
  export {};
18
+ /**
19
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
20
+ * but instead of using npm to install additional dependencies,
21
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
22
+ *
23
+ * Note that this code might be imported multiple times
24
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
25
+ * or Node.js might dynamically clear the cache and then force a require).
26
+ * Therefore, it's important to avoid redundant writes to global objects.
27
+ * Additionally, consider that commonjs is used alongside esm,
28
+ * so the two ponyfill functions are stored independently in two separate global objects.
29
+ */
30
+ import { createRequire } from "node:module";
31
+ import { type URL } from "node:url";
32
+ declare global {
33
+ interface ImportMeta {
34
+ /** A string representation of the fully qualified module URL. When the
35
+ * module is loaded locally, the value will be a file URL (e.g.
36
+ * `file:///path/module.ts`).
37
+ *
38
+ * You can also parse the string as a URL to determine more information about
39
+ * how the current module was loaded. For example to determine if a module was
40
+ * local or not:
41
+ *
42
+ * ```ts
43
+ * const url = new URL(import.meta.url);
44
+ * if (url.protocol === "file:") {
45
+ * console.log("this module was loaded locally");
46
+ * }
47
+ * ```
48
+ */
49
+ url: string;
50
+ /**
51
+ * A function that returns resolved specifier as if it would be imported
52
+ * using `import(specifier)`.
53
+ *
54
+ * ```ts
55
+ * console.log(import.meta.resolve("./foo.js"));
56
+ * // file:///dev/foo.js
57
+ * ```
58
+ *
59
+ * @param specifier The module specifier to resolve relative to `parent`.
60
+ * @param parent The absolute parent module URL to resolve from.
61
+ * @returns The absolute (`file:`) URL string for the resolved module.
62
+ */
63
+ resolve(specifier: string, parent?: string | URL | undefined): string;
64
+ /** A flag that indicates if the current module is the main module that was
65
+ * called when starting the program under Deno.
66
+ *
67
+ * ```ts
68
+ * if (import.meta.main) {
69
+ * // this was loaded as the main module, maybe do some bootstrapping
70
+ * }
71
+ * ```
72
+ */
73
+ main: boolean;
74
+ /** The absolute path of the current module.
75
+ *
76
+ * This property is only provided for local modules (ie. using `file://` URLs).
77
+ *
78
+ * Example:
79
+ * ```
80
+ * // Unix
81
+ * console.log(import.meta.filename); // /home/alice/my_module.ts
82
+ *
83
+ * // Windows
84
+ * console.log(import.meta.filename); // C:\alice\my_module.ts
85
+ * ```
86
+ */
87
+ filename: string;
88
+ /** The absolute path of the directory containing the current module.
89
+ *
90
+ * This property is only provided for local modules (ie. using `file://` URLs).
91
+ *
92
+ * * Example:
93
+ * ```
94
+ * // Unix
95
+ * console.log(import.meta.dirname); // /home/alice
96
+ *
97
+ * // Windows
98
+ * console.log(import.meta.dirname); // C:\alice
99
+ * ```
100
+ */
101
+ dirname: string;
102
+ }
103
+ }
104
+ type NodeRequest = ReturnType<typeof createRequire>;
105
+ type NodeModule = NonNullable<NodeRequest["main"]>;
106
+ interface ImportMetaPonyfillCommonjs {
107
+ (require: NodeRequest, module: NodeModule): ImportMeta;
108
+ }
109
+ interface ImportMetaPonyfillEsmodule {
110
+ (importMeta: ImportMeta): ImportMeta;
111
+ }
112
+ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
113
+ }
114
+ export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
115
+ export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
116
+ export declare let import_meta_ponyfill: ImportMetaPonyfill;
18
117
  //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../../../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../../../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AACV;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
@@ -12,4 +12,130 @@ if (!Object.hasOwn) {
12
12
  writable: true,
13
13
  });
14
14
  }
15
- export {};
15
+ /**
16
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
17
+ * but instead of using npm to install additional dependencies,
18
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
19
+ *
20
+ * Note that this code might be imported multiple times
21
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
22
+ * or Node.js might dynamically clear the cache and then force a require).
23
+ * Therefore, it's important to avoid redundant writes to global objects.
24
+ * Additionally, consider that commonjs is used alongside esm,
25
+ * so the two ponyfill functions are stored independently in two separate global objects.
26
+ */
27
+ //@ts-ignore
28
+ import { createRequire } from "node:module";
29
+ //@ts-ignore
30
+ import { fileURLToPath, pathToFileURL } from "node:url";
31
+ //@ts-ignore
32
+ import { dirname } from "node:path";
33
+ const defineGlobalPonyfill = (symbolFor, fn) => {
34
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
35
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
36
+ configurable: true,
37
+ get() {
38
+ return fn;
39
+ },
40
+ });
41
+ }
42
+ };
43
+ export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
44
+ (() => {
45
+ const moduleImportMetaWM = new WeakMap();
46
+ return (require, module) => {
47
+ let importMetaCache = moduleImportMetaWM.get(module);
48
+ if (importMetaCache == null) {
49
+ const importMeta = Object.assign(Object.create(null), {
50
+ url: pathToFileURL(module.filename).href,
51
+ main: require.main == module,
52
+ resolve: (specifier, parentURL = importMeta.url) => {
53
+ return pathToFileURL((importMeta.url === parentURL
54
+ ? require
55
+ : createRequire(parentURL))
56
+ .resolve(specifier)).href;
57
+ },
58
+ filename: module.filename,
59
+ dirname: module.path,
60
+ });
61
+ moduleImportMetaWM.set(module, importMeta);
62
+ importMetaCache = importMeta;
63
+ }
64
+ return importMetaCache;
65
+ };
66
+ })());
67
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
68
+ export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
69
+ ((importMeta) => {
70
+ const resolveFunStr = String(importMeta.resolve);
71
+ const shimWs = new WeakSet();
72
+ //@ts-ignore
73
+ const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
74
+ .replace(/\/{3,}/, "///");
75
+ const commonShim = (importMeta) => {
76
+ if (typeof importMeta.main !== "boolean") {
77
+ importMeta.main = importMeta.url === mainUrl;
78
+ }
79
+ if (typeof importMeta.filename !== "string") {
80
+ importMeta.filename = fileURLToPath(importMeta.url);
81
+ importMeta.dirname = dirname(importMeta.filename);
82
+ }
83
+ };
84
+ if (
85
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
86
+ resolveFunStr === "undefined" ||
87
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
88
+ resolveFunStr.startsWith("async")
89
+ // enable by --experimental-import-meta-resolve flag
90
+ ) {
91
+ import_meta_ponyfill_esmodule = (importMeta) => {
92
+ if (!shimWs.has(importMeta)) {
93
+ shimWs.add(importMeta);
94
+ const importMetaUrlRequire = {
95
+ url: importMeta.url,
96
+ require: createRequire(importMeta.url),
97
+ };
98
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
99
+ return pathToFileURL((importMetaUrlRequire.url === parentURL
100
+ ? importMetaUrlRequire.require
101
+ : createRequire(parentURL)).resolve(specifier)).href;
102
+ };
103
+ commonShim(importMeta);
104
+ }
105
+ return importMeta;
106
+ };
107
+ }
108
+ else {
109
+ /// native support
110
+ import_meta_ponyfill_esmodule = (importMeta) => {
111
+ if (!shimWs.has(importMeta)) {
112
+ shimWs.add(importMeta);
113
+ commonShim(importMeta);
114
+ }
115
+ return importMeta;
116
+ };
117
+ }
118
+ return import_meta_ponyfill_esmodule(importMeta);
119
+ }));
120
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
121
+ export let import_meta_ponyfill = ((...args) => {
122
+ const _MODULE = (() => {
123
+ if (typeof require === "function" && typeof module === "object") {
124
+ return "commonjs";
125
+ }
126
+ else {
127
+ // eval("typeof import.meta");
128
+ return "esmodule";
129
+ }
130
+ })();
131
+ if (_MODULE === "commonjs") {
132
+ //@ts-ignore
133
+ import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
134
+ }
135
+ else {
136
+ //@ts-ignore
137
+ import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
138
+ }
139
+ //@ts-ignore
140
+ return import_meta_ponyfill(...args);
141
+ });
@@ -0,0 +1,2 @@
1
+ import "./_dnt.polyfills.js";
2
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC"}
@@ -0,0 +1,217 @@
1
+ import "./_dnt.polyfills.js";
2
+ import * as dntShim from "./_dnt.shims.js";
3
+ const REPO_OWNER = "qlever-llc";
4
+ const REPO_NAME = "trellis";
5
+ const BIN_NAME = "trellis-generate";
6
+ const SUPPORTED_TARGETS = new Set([
7
+ "x86_64-unknown-linux-gnu",
8
+ "aarch64-unknown-linux-gnu",
9
+ "x86_64-apple-darwin",
10
+ "aarch64-apple-darwin",
11
+ ]);
12
+ async function main() {
13
+ const localRepoRoot = await findLocalTrellisRepoRoot();
14
+ if (localRepoRoot) {
15
+ await runLocalGenerator(localRepoRoot, dntShim.Deno.args);
16
+ return;
17
+ }
18
+ const packageVersion = await readPackageVersion();
19
+ const binary = dntShim.Deno.env.get("TRELLIS_GENERATE_BIN")?.trim() ||
20
+ await ensureCachedReleaseBinary(packageVersion);
21
+ await verifyBinaryVersion(binary, packageVersion);
22
+ await runBinary(binary, dntShim.Deno.args);
23
+ }
24
+ async function findLocalTrellisRepoRoot() {
25
+ let current = urlDirname(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url);
26
+ while (current !== dirname(current)) {
27
+ if (await pathExists(joinPath(current, "rust/tools/generate/Cargo.toml")) &&
28
+ await pathExists(joinPath(current, "js/deno.json"))) {
29
+ return current;
30
+ }
31
+ current = dirname(current);
32
+ }
33
+ return undefined;
34
+ }
35
+ async function runLocalGenerator(repoRoot, args) {
36
+ return await runCommand("cargo", [
37
+ "run",
38
+ "--manifest-path",
39
+ joinPath(repoRoot, "rust/tools/generate/Cargo.toml"),
40
+ "--bin",
41
+ BIN_NAME,
42
+ "--",
43
+ ...args,
44
+ ]);
45
+ }
46
+ async function readPackageVersion() {
47
+ const manifestUrl = new URL("./deno.json", globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url);
48
+ const manifest = JSON.parse(await dntShim.Deno.readTextFile(manifestUrl));
49
+ if (typeof manifest.version !== "string" || !manifest.version.trim()) {
50
+ throw new Error("@qlever-llc/trellis package manifest does not declare a version");
51
+ }
52
+ return manifest.version.trim();
53
+ }
54
+ async function ensureCachedReleaseBinary(version) {
55
+ const target = releaseTarget();
56
+ const cacheDir = joinPath(cacheRoot(), version, target);
57
+ const binary = joinPath(cacheDir, BIN_NAME);
58
+ if (await pathExists(binary)) {
59
+ return binary;
60
+ }
61
+ await dntShim.Deno.mkdir(cacheDir, { recursive: true });
62
+ const tag = `v${version}`;
63
+ const archiveName = `${BIN_NAME}-${tag}-${target}.tar.gz`;
64
+ const archiveUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${archiveName}`;
65
+ const checksumName = `checksum-${tag}-${target}-${BIN_NAME}.sha256`;
66
+ const checksumUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${checksumName}`;
67
+ const [archive, checksumText] = await Promise.all([
68
+ downloadBytes(archiveUrl),
69
+ downloadText(checksumUrl),
70
+ ]);
71
+ await verifyChecksum(archive, checksumText, archiveUrl);
72
+ const archivePath = joinPath(cacheDir, archiveName);
73
+ await dntShim.Deno.writeFile(archivePath, archive);
74
+ await runCommandChecked("tar", ["-xzf", archivePath, "-C", cacheDir]);
75
+ await dntShim.Deno.chmod(binary, 0o755);
76
+ return binary;
77
+ }
78
+ function releaseTarget() {
79
+ if (SUPPORTED_TARGETS.has(dntShim.Deno.build.target)) {
80
+ return dntShim.Deno.build.target;
81
+ }
82
+ const buildArch = dntShim.Deno.build.arch;
83
+ const arch = buildArch === "x86_64" || buildArch === "x64"
84
+ ? "x86_64"
85
+ : buildArch;
86
+ const os = dntShim.Deno.build.os === "darwin"
87
+ ? "apple-darwin"
88
+ : dntShim.Deno.build.os === "linux"
89
+ ? "unknown-linux-gnu"
90
+ : undefined;
91
+ const target = os ? `${arch}-${os}` : undefined;
92
+ if (target && SUPPORTED_TARGETS.has(target)) {
93
+ return target;
94
+ }
95
+ throw new Error(`no ${BIN_NAME} release binary is available for ${dntShim.Deno.build.target}`);
96
+ }
97
+ function cacheRoot() {
98
+ const explicit = dntShim.Deno.env.get("TRELLIS_GENERATE_CACHE")?.trim();
99
+ if (explicit) {
100
+ return explicit;
101
+ }
102
+ const xdg = dntShim.Deno.env.get("XDG_CACHE_HOME")?.trim();
103
+ if (xdg) {
104
+ return joinPath(xdg, "trellis", BIN_NAME);
105
+ }
106
+ const home = dntShim.Deno.env.get("HOME")?.trim();
107
+ if (!home) {
108
+ throw new Error("HOME or TRELLIS_GENERATE_CACHE must be set to cache trellis-generate");
109
+ }
110
+ return joinPath(home, ".cache", "trellis", BIN_NAME);
111
+ }
112
+ async function downloadBytes(url) {
113
+ const response = await fetch(url);
114
+ if (!response.ok) {
115
+ throw new Error(`failed to download ${url}: HTTP ${response.status}`);
116
+ }
117
+ return new Uint8Array(await response.arrayBuffer());
118
+ }
119
+ async function downloadText(url) {
120
+ const response = await fetch(url);
121
+ if (!response.ok) {
122
+ throw new Error(`failed to download ${url}: HTTP ${response.status}`);
123
+ }
124
+ return await response.text();
125
+ }
126
+ async function verifyChecksum(bytes, checksumText, label) {
127
+ const expected = checksumText.trim().split(/\s+/)[0]?.toLowerCase();
128
+ if (!expected || !/^[0-9a-f]{64}$/.test(expected)) {
129
+ throw new Error("release checksum asset did not contain a SHA-256 digest");
130
+ }
131
+ const buffer = new ArrayBuffer(bytes.byteLength);
132
+ new Uint8Array(buffer).set(bytes);
133
+ const digest = await crypto.subtle.digest("SHA-256", buffer);
134
+ const actual = Array.from(new Uint8Array(digest))
135
+ .map((byte) => byte.toString(16).padStart(2, "0"))
136
+ .join("");
137
+ if (actual !== expected) {
138
+ throw new Error(`checksum mismatch for ${label}: expected ${expected}, got ${actual}`);
139
+ }
140
+ }
141
+ async function verifyBinaryVersion(binary, expectedVersion) {
142
+ const output = await new dntShim.Deno.Command(binary, {
143
+ args: ["--version"],
144
+ stdout: "piped",
145
+ stderr: "piped",
146
+ }).output();
147
+ if (!output.success) {
148
+ throw new Error(`failed to run ${binary} --version`);
149
+ }
150
+ const text = new TextDecoder().decode(output.stdout).trim();
151
+ const actualVersion = text.split(/\s+/).find((part) => /^v?\d+\.\d+\.\d+/.test(part));
152
+ if (!actualVersion ||
153
+ normalizeVersion(actualVersion) !== normalizeVersion(expectedVersion)) {
154
+ throw new Error(`${binary} is ${text || "unknown version"}; expected ${BIN_NAME} ${expectedVersion}`);
155
+ }
156
+ }
157
+ function normalizeVersion(version) {
158
+ return version.trim().replace(/^v/, "").split("+")[0];
159
+ }
160
+ async function runBinary(binary, args) {
161
+ return await runCommand(binary, args);
162
+ }
163
+ async function runCommand(command, args, options = {}) {
164
+ const status = await spawnCommand(command, args, options);
165
+ dntShim.Deno.exit(status.code);
166
+ }
167
+ async function runCommandChecked(command, args, options = {}) {
168
+ const status = await spawnCommand(command, args, options);
169
+ if (!status.success) {
170
+ throw new Error(`${command} failed with exit code ${status.code}`);
171
+ }
172
+ }
173
+ async function spawnCommand(command, args, options = {}) {
174
+ const status = await new dntShim.Deno.Command(command, {
175
+ args,
176
+ cwd: options.cwd,
177
+ stdin: "inherit",
178
+ stdout: "inherit",
179
+ stderr: "inherit",
180
+ }).spawn().status;
181
+ return status;
182
+ }
183
+ async function pathExists(path) {
184
+ try {
185
+ await dntShim.Deno.stat(path);
186
+ return true;
187
+ }
188
+ catch (error) {
189
+ if (error instanceof dntShim.Deno.errors.NotFound) {
190
+ return false;
191
+ }
192
+ throw error;
193
+ }
194
+ }
195
+ function urlDirname(url) {
196
+ return dirname(decodeURIComponent(new URL(url).pathname));
197
+ }
198
+ function dirname(path) {
199
+ const normalized = path.replace(/\/+$/, "");
200
+ const index = normalized.lastIndexOf("/");
201
+ if (index <= 0) {
202
+ return "/";
203
+ }
204
+ return normalized.slice(0, index);
205
+ }
206
+ function joinPath(...parts) {
207
+ return parts
208
+ .filter((part) => part.length > 0)
209
+ .join("/")
210
+ .replace(/\/+/g, "/");
211
+ }
212
+ if (globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).main) {
213
+ main().catch((error) => {
214
+ console.error(error);
215
+ dntShim.Deno.exit(1);
216
+ });
217
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlever-llc/trellis",
3
- "version": "0.8.0",
3
+ "version": "0.8.3",
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": {
@@ -42,6 +42,10 @@
42
42
  "import": "./esm/npm/src/device/deno.js",
43
43
  "require": "./script/npm/src/device/deno.js"
44
44
  },
45
+ "./generate": {
46
+ "import": "./esm/npm/src/generate.js",
47
+ "require": "./script/npm/src/generate.js"
48
+ },
45
49
  "./health": {
46
50
  "import": "./esm/health.js",
47
51
  "require": "./script/health.js"
@@ -119,7 +123,7 @@
119
123
  "ts-deepmerge": "^7.0.3",
120
124
  "typebox": "^1.0.15",
121
125
  "ulid": "^3.0.1",
122
- "@qlever-llc/result": "^0.8.0"
126
+ "@qlever-llc/result": "^0.8.3"
123
127
  },
124
128
  "devDependencies": {
125
129
  "@types/node": "^20.9.0"
@@ -15,4 +15,103 @@ declare global {
15
15
  }
16
16
  }
17
17
  export {};
18
+ /**
19
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
20
+ * but instead of using npm to install additional dependencies,
21
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
22
+ *
23
+ * Note that this code might be imported multiple times
24
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
25
+ * or Node.js might dynamically clear the cache and then force a require).
26
+ * Therefore, it's important to avoid redundant writes to global objects.
27
+ * Additionally, consider that commonjs is used alongside esm,
28
+ * so the two ponyfill functions are stored independently in two separate global objects.
29
+ */
30
+ import { createRequire } from "node:module";
31
+ import { type URL } from "node:url";
32
+ declare global {
33
+ interface ImportMeta {
34
+ /** A string representation of the fully qualified module URL. When the
35
+ * module is loaded locally, the value will be a file URL (e.g.
36
+ * `file:///path/module.ts`).
37
+ *
38
+ * You can also parse the string as a URL to determine more information about
39
+ * how the current module was loaded. For example to determine if a module was
40
+ * local or not:
41
+ *
42
+ * ```ts
43
+ * const url = new URL(import.meta.url);
44
+ * if (url.protocol === "file:") {
45
+ * console.log("this module was loaded locally");
46
+ * }
47
+ * ```
48
+ */
49
+ url: string;
50
+ /**
51
+ * A function that returns resolved specifier as if it would be imported
52
+ * using `import(specifier)`.
53
+ *
54
+ * ```ts
55
+ * console.log(import.meta.resolve("./foo.js"));
56
+ * // file:///dev/foo.js
57
+ * ```
58
+ *
59
+ * @param specifier The module specifier to resolve relative to `parent`.
60
+ * @param parent The absolute parent module URL to resolve from.
61
+ * @returns The absolute (`file:`) URL string for the resolved module.
62
+ */
63
+ resolve(specifier: string, parent?: string | URL | undefined): string;
64
+ /** A flag that indicates if the current module is the main module that was
65
+ * called when starting the program under Deno.
66
+ *
67
+ * ```ts
68
+ * if (import.meta.main) {
69
+ * // this was loaded as the main module, maybe do some bootstrapping
70
+ * }
71
+ * ```
72
+ */
73
+ main: boolean;
74
+ /** The absolute path of the current module.
75
+ *
76
+ * This property is only provided for local modules (ie. using `file://` URLs).
77
+ *
78
+ * Example:
79
+ * ```
80
+ * // Unix
81
+ * console.log(import.meta.filename); // /home/alice/my_module.ts
82
+ *
83
+ * // Windows
84
+ * console.log(import.meta.filename); // C:\alice\my_module.ts
85
+ * ```
86
+ */
87
+ filename: string;
88
+ /** The absolute path of the directory containing the current module.
89
+ *
90
+ * This property is only provided for local modules (ie. using `file://` URLs).
91
+ *
92
+ * * Example:
93
+ * ```
94
+ * // Unix
95
+ * console.log(import.meta.dirname); // /home/alice
96
+ *
97
+ * // Windows
98
+ * console.log(import.meta.dirname); // C:\alice
99
+ * ```
100
+ */
101
+ dirname: string;
102
+ }
103
+ }
104
+ type NodeRequest = ReturnType<typeof createRequire>;
105
+ type NodeModule = NonNullable<NodeRequest["main"]>;
106
+ interface ImportMetaPonyfillCommonjs {
107
+ (require: NodeRequest, module: NodeModule): ImportMeta;
108
+ }
109
+ interface ImportMetaPonyfillEsmodule {
110
+ (importMeta: ImportMeta): ImportMeta;
111
+ }
112
+ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
113
+ }
114
+ export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
115
+ export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
116
+ export declare let import_meta_ponyfill: ImportMetaPonyfill;
18
117
  //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../../../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../../../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AACV;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.import_meta_ponyfill = exports.import_meta_ponyfill_esmodule = exports.import_meta_ponyfill_commonjs = void 0;
3
4
  // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
4
5
  if (!Object.hasOwn) {
5
6
  Object.defineProperty(Object, "hasOwn", {
@@ -14,3 +15,130 @@ if (!Object.hasOwn) {
14
15
  writable: true,
15
16
  });
16
17
  }
18
+ /**
19
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
20
+ * but instead of using npm to install additional dependencies,
21
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
22
+ *
23
+ * Note that this code might be imported multiple times
24
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
25
+ * or Node.js might dynamically clear the cache and then force a require).
26
+ * Therefore, it's important to avoid redundant writes to global objects.
27
+ * Additionally, consider that commonjs is used alongside esm,
28
+ * so the two ponyfill functions are stored independently in two separate global objects.
29
+ */
30
+ //@ts-ignore
31
+ const node_module_1 = require("node:module");
32
+ //@ts-ignore
33
+ const node_url_1 = require("node:url");
34
+ //@ts-ignore
35
+ const node_path_1 = require("node:path");
36
+ const defineGlobalPonyfill = (symbolFor, fn) => {
37
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
38
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
39
+ configurable: true,
40
+ get() {
41
+ return fn;
42
+ },
43
+ });
44
+ }
45
+ };
46
+ exports.import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
47
+ (() => {
48
+ const moduleImportMetaWM = new WeakMap();
49
+ return (require, module) => {
50
+ let importMetaCache = moduleImportMetaWM.get(module);
51
+ if (importMetaCache == null) {
52
+ const importMeta = Object.assign(Object.create(null), {
53
+ url: (0, node_url_1.pathToFileURL)(module.filename).href,
54
+ main: require.main == module,
55
+ resolve: (specifier, parentURL = importMeta.url) => {
56
+ return (0, node_url_1.pathToFileURL)((importMeta.url === parentURL
57
+ ? require
58
+ : (0, node_module_1.createRequire)(parentURL))
59
+ .resolve(specifier)).href;
60
+ },
61
+ filename: module.filename,
62
+ dirname: module.path,
63
+ });
64
+ moduleImportMetaWM.set(module, importMeta);
65
+ importMetaCache = importMeta;
66
+ }
67
+ return importMetaCache;
68
+ };
69
+ })());
70
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", exports.import_meta_ponyfill_commonjs);
71
+ exports.import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
72
+ ((importMeta) => {
73
+ const resolveFunStr = String(importMeta.resolve);
74
+ const shimWs = new WeakSet();
75
+ //@ts-ignore
76
+ const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
77
+ .replace(/\/{3,}/, "///");
78
+ const commonShim = (importMeta) => {
79
+ if (typeof importMeta.main !== "boolean") {
80
+ importMeta.main = importMeta.url === mainUrl;
81
+ }
82
+ if (typeof importMeta.filename !== "string") {
83
+ importMeta.filename = (0, node_url_1.fileURLToPath)(importMeta.url);
84
+ importMeta.dirname = (0, node_path_1.dirname)(importMeta.filename);
85
+ }
86
+ };
87
+ if (
88
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
89
+ resolveFunStr === "undefined" ||
90
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
91
+ resolveFunStr.startsWith("async")
92
+ // enable by --experimental-import-meta-resolve flag
93
+ ) {
94
+ exports.import_meta_ponyfill_esmodule = (importMeta) => {
95
+ if (!shimWs.has(importMeta)) {
96
+ shimWs.add(importMeta);
97
+ const importMetaUrlRequire = {
98
+ url: importMeta.url,
99
+ require: (0, node_module_1.createRequire)(importMeta.url),
100
+ };
101
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
102
+ return (0, node_url_1.pathToFileURL)((importMetaUrlRequire.url === parentURL
103
+ ? importMetaUrlRequire.require
104
+ : (0, node_module_1.createRequire)(parentURL)).resolve(specifier)).href;
105
+ };
106
+ commonShim(importMeta);
107
+ }
108
+ return importMeta;
109
+ };
110
+ }
111
+ else {
112
+ /// native support
113
+ exports.import_meta_ponyfill_esmodule = (importMeta) => {
114
+ if (!shimWs.has(importMeta)) {
115
+ shimWs.add(importMeta);
116
+ commonShim(importMeta);
117
+ }
118
+ return importMeta;
119
+ };
120
+ }
121
+ return (0, exports.import_meta_ponyfill_esmodule)(importMeta);
122
+ }));
123
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", exports.import_meta_ponyfill_esmodule);
124
+ exports.import_meta_ponyfill = ((...args) => {
125
+ const _MODULE = (() => {
126
+ if (typeof require === "function" && typeof module === "object") {
127
+ return "commonjs";
128
+ }
129
+ else {
130
+ // eval("typeof import.meta");
131
+ return "esmodule";
132
+ }
133
+ })();
134
+ if (_MODULE === "commonjs") {
135
+ //@ts-ignore
136
+ exports.import_meta_ponyfill = (r, m) => (0, exports.import_meta_ponyfill_commonjs)(r, m);
137
+ }
138
+ else {
139
+ //@ts-ignore
140
+ exports.import_meta_ponyfill = (im) => (0, exports.import_meta_ponyfill_esmodule)(im);
141
+ }
142
+ //@ts-ignore
143
+ return (0, exports.import_meta_ponyfill)(...args);
144
+ });
@@ -0,0 +1,2 @@
1
+ import "./_dnt.polyfills.js";
2
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC"}
@@ -0,0 +1,252 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ require("./_dnt.polyfills.js");
37
+ const dntShim = __importStar(require("./_dnt.shims.js"));
38
+ const REPO_OWNER = "qlever-llc";
39
+ const REPO_NAME = "trellis";
40
+ const BIN_NAME = "trellis-generate";
41
+ const SUPPORTED_TARGETS = new Set([
42
+ "x86_64-unknown-linux-gnu",
43
+ "aarch64-unknown-linux-gnu",
44
+ "x86_64-apple-darwin",
45
+ "aarch64-apple-darwin",
46
+ ]);
47
+ async function main() {
48
+ const localRepoRoot = await findLocalTrellisRepoRoot();
49
+ if (localRepoRoot) {
50
+ await runLocalGenerator(localRepoRoot, dntShim.Deno.args);
51
+ return;
52
+ }
53
+ const packageVersion = await readPackageVersion();
54
+ const binary = dntShim.Deno.env.get("TRELLIS_GENERATE_BIN")?.trim() ||
55
+ await ensureCachedReleaseBinary(packageVersion);
56
+ await verifyBinaryVersion(binary, packageVersion);
57
+ await runBinary(binary, dntShim.Deno.args);
58
+ }
59
+ async function findLocalTrellisRepoRoot() {
60
+ let current = urlDirname(globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url);
61
+ while (current !== dirname(current)) {
62
+ if (await pathExists(joinPath(current, "rust/tools/generate/Cargo.toml")) &&
63
+ await pathExists(joinPath(current, "js/deno.json"))) {
64
+ return current;
65
+ }
66
+ current = dirname(current);
67
+ }
68
+ return undefined;
69
+ }
70
+ async function runLocalGenerator(repoRoot, args) {
71
+ return await runCommand("cargo", [
72
+ "run",
73
+ "--manifest-path",
74
+ joinPath(repoRoot, "rust/tools/generate/Cargo.toml"),
75
+ "--bin",
76
+ BIN_NAME,
77
+ "--",
78
+ ...args,
79
+ ]);
80
+ }
81
+ async function readPackageVersion() {
82
+ const manifestUrl = new URL("./deno.json", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url);
83
+ const manifest = JSON.parse(await dntShim.Deno.readTextFile(manifestUrl));
84
+ if (typeof manifest.version !== "string" || !manifest.version.trim()) {
85
+ throw new Error("@qlever-llc/trellis package manifest does not declare a version");
86
+ }
87
+ return manifest.version.trim();
88
+ }
89
+ async function ensureCachedReleaseBinary(version) {
90
+ const target = releaseTarget();
91
+ const cacheDir = joinPath(cacheRoot(), version, target);
92
+ const binary = joinPath(cacheDir, BIN_NAME);
93
+ if (await pathExists(binary)) {
94
+ return binary;
95
+ }
96
+ await dntShim.Deno.mkdir(cacheDir, { recursive: true });
97
+ const tag = `v${version}`;
98
+ const archiveName = `${BIN_NAME}-${tag}-${target}.tar.gz`;
99
+ const archiveUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${archiveName}`;
100
+ const checksumName = `checksum-${tag}-${target}-${BIN_NAME}.sha256`;
101
+ const checksumUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${checksumName}`;
102
+ const [archive, checksumText] = await Promise.all([
103
+ downloadBytes(archiveUrl),
104
+ downloadText(checksumUrl),
105
+ ]);
106
+ await verifyChecksum(archive, checksumText, archiveUrl);
107
+ const archivePath = joinPath(cacheDir, archiveName);
108
+ await dntShim.Deno.writeFile(archivePath, archive);
109
+ await runCommandChecked("tar", ["-xzf", archivePath, "-C", cacheDir]);
110
+ await dntShim.Deno.chmod(binary, 0o755);
111
+ return binary;
112
+ }
113
+ function releaseTarget() {
114
+ if (SUPPORTED_TARGETS.has(dntShim.Deno.build.target)) {
115
+ return dntShim.Deno.build.target;
116
+ }
117
+ const buildArch = dntShim.Deno.build.arch;
118
+ const arch = buildArch === "x86_64" || buildArch === "x64"
119
+ ? "x86_64"
120
+ : buildArch;
121
+ const os = dntShim.Deno.build.os === "darwin"
122
+ ? "apple-darwin"
123
+ : dntShim.Deno.build.os === "linux"
124
+ ? "unknown-linux-gnu"
125
+ : undefined;
126
+ const target = os ? `${arch}-${os}` : undefined;
127
+ if (target && SUPPORTED_TARGETS.has(target)) {
128
+ return target;
129
+ }
130
+ throw new Error(`no ${BIN_NAME} release binary is available for ${dntShim.Deno.build.target}`);
131
+ }
132
+ function cacheRoot() {
133
+ const explicit = dntShim.Deno.env.get("TRELLIS_GENERATE_CACHE")?.trim();
134
+ if (explicit) {
135
+ return explicit;
136
+ }
137
+ const xdg = dntShim.Deno.env.get("XDG_CACHE_HOME")?.trim();
138
+ if (xdg) {
139
+ return joinPath(xdg, "trellis", BIN_NAME);
140
+ }
141
+ const home = dntShim.Deno.env.get("HOME")?.trim();
142
+ if (!home) {
143
+ throw new Error("HOME or TRELLIS_GENERATE_CACHE must be set to cache trellis-generate");
144
+ }
145
+ return joinPath(home, ".cache", "trellis", BIN_NAME);
146
+ }
147
+ async function downloadBytes(url) {
148
+ const response = await fetch(url);
149
+ if (!response.ok) {
150
+ throw new Error(`failed to download ${url}: HTTP ${response.status}`);
151
+ }
152
+ return new Uint8Array(await response.arrayBuffer());
153
+ }
154
+ async function downloadText(url) {
155
+ const response = await fetch(url);
156
+ if (!response.ok) {
157
+ throw new Error(`failed to download ${url}: HTTP ${response.status}`);
158
+ }
159
+ return await response.text();
160
+ }
161
+ async function verifyChecksum(bytes, checksumText, label) {
162
+ const expected = checksumText.trim().split(/\s+/)[0]?.toLowerCase();
163
+ if (!expected || !/^[0-9a-f]{64}$/.test(expected)) {
164
+ throw new Error("release checksum asset did not contain a SHA-256 digest");
165
+ }
166
+ const buffer = new ArrayBuffer(bytes.byteLength);
167
+ new Uint8Array(buffer).set(bytes);
168
+ const digest = await crypto.subtle.digest("SHA-256", buffer);
169
+ const actual = Array.from(new Uint8Array(digest))
170
+ .map((byte) => byte.toString(16).padStart(2, "0"))
171
+ .join("");
172
+ if (actual !== expected) {
173
+ throw new Error(`checksum mismatch for ${label}: expected ${expected}, got ${actual}`);
174
+ }
175
+ }
176
+ async function verifyBinaryVersion(binary, expectedVersion) {
177
+ const output = await new dntShim.Deno.Command(binary, {
178
+ args: ["--version"],
179
+ stdout: "piped",
180
+ stderr: "piped",
181
+ }).output();
182
+ if (!output.success) {
183
+ throw new Error(`failed to run ${binary} --version`);
184
+ }
185
+ const text = new TextDecoder().decode(output.stdout).trim();
186
+ const actualVersion = text.split(/\s+/).find((part) => /^v?\d+\.\d+\.\d+/.test(part));
187
+ if (!actualVersion ||
188
+ normalizeVersion(actualVersion) !== normalizeVersion(expectedVersion)) {
189
+ throw new Error(`${binary} is ${text || "unknown version"}; expected ${BIN_NAME} ${expectedVersion}`);
190
+ }
191
+ }
192
+ function normalizeVersion(version) {
193
+ return version.trim().replace(/^v/, "").split("+")[0];
194
+ }
195
+ async function runBinary(binary, args) {
196
+ return await runCommand(binary, args);
197
+ }
198
+ async function runCommand(command, args, options = {}) {
199
+ const status = await spawnCommand(command, args, options);
200
+ dntShim.Deno.exit(status.code);
201
+ }
202
+ async function runCommandChecked(command, args, options = {}) {
203
+ const status = await spawnCommand(command, args, options);
204
+ if (!status.success) {
205
+ throw new Error(`${command} failed with exit code ${status.code}`);
206
+ }
207
+ }
208
+ async function spawnCommand(command, args, options = {}) {
209
+ const status = await new dntShim.Deno.Command(command, {
210
+ args,
211
+ cwd: options.cwd,
212
+ stdin: "inherit",
213
+ stdout: "inherit",
214
+ stderr: "inherit",
215
+ }).spawn().status;
216
+ return status;
217
+ }
218
+ async function pathExists(path) {
219
+ try {
220
+ await dntShim.Deno.stat(path);
221
+ return true;
222
+ }
223
+ catch (error) {
224
+ if (error instanceof dntShim.Deno.errors.NotFound) {
225
+ return false;
226
+ }
227
+ throw error;
228
+ }
229
+ }
230
+ function urlDirname(url) {
231
+ return dirname(decodeURIComponent(new URL(url).pathname));
232
+ }
233
+ function dirname(path) {
234
+ const normalized = path.replace(/\/+$/, "");
235
+ const index = normalized.lastIndexOf("/");
236
+ if (index <= 0) {
237
+ return "/";
238
+ }
239
+ return normalized.slice(0, index);
240
+ }
241
+ function joinPath(...parts) {
242
+ return parts
243
+ .filter((part) => part.length > 0)
244
+ .join("/")
245
+ .replace(/\/+/g, "/");
246
+ }
247
+ if (globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).main) {
248
+ main().catch((error) => {
249
+ console.error(error);
250
+ dntShim.Deno.exit(1);
251
+ });
252
+ }