@qlever-llc/trellis 0.8.2 → 0.8.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/bin/trellis-generate.js +132 -0
- package/esm/npm/src/_dnt.polyfills.d.ts +99 -0
- package/esm/npm/src/_dnt.polyfills.d.ts.map +1 -1
- package/esm/npm/src/_dnt.polyfills.js +127 -1
- package/esm/npm/src/generate.d.ts +2 -0
- package/esm/npm/src/generate.d.ts.map +1 -0
- package/esm/npm/src/generate.js +234 -0
- package/package.json +6 -3
- package/script/npm/src/_dnt.polyfills.d.ts +99 -0
- package/script/npm/src/_dnt.polyfills.d.ts.map +1 -1
- package/script/npm/src/_dnt.polyfills.js +128 -0
- package/script/npm/src/generate.d.ts +2 -0
- package/script/npm/src/generate.d.ts.map +1 -0
- package/script/npm/src/generate.js +269 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { createHash } = require("node:crypto");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const https = require("node:https");
|
|
5
|
+
const os = require("node:os");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
const { spawnSync } = require("node:child_process");
|
|
8
|
+
|
|
9
|
+
const REPO_OWNER = "qlever-llc";
|
|
10
|
+
const REPO_NAME = "trellis";
|
|
11
|
+
const BIN_NAME = "trellis-generate";
|
|
12
|
+
const SUPPORTED_TARGETS = new Set([
|
|
13
|
+
"x86_64-unknown-linux-gnu",
|
|
14
|
+
"aarch64-unknown-linux-gnu",
|
|
15
|
+
"x86_64-apple-darwin",
|
|
16
|
+
"aarch64-apple-darwin",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
main().catch((error) => {
|
|
20
|
+
console.error(error);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
const packageVersion = readPackageVersion();
|
|
26
|
+
const binary = (process.env.TRELLIS_GENERATE_BIN || "").trim() ||
|
|
27
|
+
await ensureCachedReleaseBinary(packageVersion);
|
|
28
|
+
verifyBinaryVersion(binary, packageVersion);
|
|
29
|
+
const status = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
30
|
+
if (status.error) throw status.error;
|
|
31
|
+
process.exit(status.status ?? 1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readPackageVersion() {
|
|
35
|
+
const manifestPath = path.resolve(__dirname, "../package.json");
|
|
36
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
37
|
+
if (typeof manifest.version !== "string" || !manifest.version.trim()) {
|
|
38
|
+
throw new Error("@qlever-llc/trellis package manifest does not declare a version");
|
|
39
|
+
}
|
|
40
|
+
return manifest.version.trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function ensureCachedReleaseBinary(version) {
|
|
44
|
+
const target = releaseTarget();
|
|
45
|
+
const cacheDir = path.join(cacheRoot(), version, target);
|
|
46
|
+
const binary = path.join(cacheDir, BIN_NAME);
|
|
47
|
+
if (fs.existsSync(binary)) return binary;
|
|
48
|
+
|
|
49
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
50
|
+
const tag = "v" + version;
|
|
51
|
+
const archiveName = BIN_NAME + "-" + tag + "-" + target + ".tar.gz";
|
|
52
|
+
const checksumName = "checksum-" + tag + "-" + target + "-" + BIN_NAME + ".sha256";
|
|
53
|
+
const releaseBase = "https://github.com/" + REPO_OWNER + "/" + REPO_NAME + "/releases/download/" + tag;
|
|
54
|
+
const [archive, checksumText] = await Promise.all([
|
|
55
|
+
downloadBytes(releaseBase + "/" + archiveName),
|
|
56
|
+
downloadText(releaseBase + "/" + checksumName),
|
|
57
|
+
]);
|
|
58
|
+
verifyChecksum(archive, checksumText, archiveName);
|
|
59
|
+
|
|
60
|
+
const archivePath = path.join(cacheDir, archiveName);
|
|
61
|
+
fs.writeFileSync(archivePath, archive);
|
|
62
|
+
const extract = spawnSync("tar", ["-xzf", archivePath, "-C", cacheDir], { stdio: "inherit" });
|
|
63
|
+
if (extract.error) throw extract.error;
|
|
64
|
+
if (extract.status !== 0) throw new Error("tar failed with exit code " + extract.status);
|
|
65
|
+
fs.chmodSync(binary, 0o755);
|
|
66
|
+
return binary;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function releaseTarget() {
|
|
70
|
+
const arch = os.arch() === "x64" ? "x86_64" : os.arch() === "arm64" ? "aarch64" : os.arch();
|
|
71
|
+
const platform = os.platform() === "darwin" ? "apple-darwin" : os.platform() === "linux" ? "unknown-linux-gnu" : undefined;
|
|
72
|
+
const target = platform ? arch + "-" + platform : undefined;
|
|
73
|
+
if (target && SUPPORTED_TARGETS.has(target)) return target;
|
|
74
|
+
throw new Error("no " + BIN_NAME + " release binary is available for " + os.platform() + " " + os.arch());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function cacheRoot() {
|
|
78
|
+
if ((process.env.TRELLIS_GENERATE_CACHE || "").trim()) return process.env.TRELLIS_GENERATE_CACHE.trim();
|
|
79
|
+
if ((process.env.XDG_CACHE_HOME || "").trim()) return path.join(process.env.XDG_CACHE_HOME.trim(), "trellis", BIN_NAME);
|
|
80
|
+
if ((process.env.LOCALAPPDATA || "").trim()) return path.join(process.env.LOCALAPPDATA.trim(), "trellis", BIN_NAME);
|
|
81
|
+
if ((process.env.HOME || "").trim()) return path.join(process.env.HOME.trim(), ".cache", "trellis", BIN_NAME);
|
|
82
|
+
throw new Error("HOME, LOCALAPPDATA, or TRELLIS_GENERATE_CACHE must be set to cache trellis-generate");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function downloadBytes(url) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
https.get(url, (response) => {
|
|
88
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
89
|
+
resolve(downloadBytes(response.headers.location));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (response.statusCode !== 200) {
|
|
93
|
+
reject(new Error("failed to download " + url + ": HTTP " + response.statusCode));
|
|
94
|
+
response.resume();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const chunks = [];
|
|
98
|
+
response.on("data", (chunk) => chunks.push(chunk));
|
|
99
|
+
response.on("end", () => resolve(Buffer.concat(chunks)));
|
|
100
|
+
}).on("error", reject);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function downloadText(url) {
|
|
105
|
+
return (await downloadBytes(url)).toString("utf8");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function verifyChecksum(bytes, checksumText, label) {
|
|
109
|
+
const expected = checksumText.trim().split(/\s+/)[0]?.toLowerCase();
|
|
110
|
+
if (!expected || !/^[0-9a-f]{64}$/.test(expected)) {
|
|
111
|
+
throw new Error("release checksum asset did not contain a SHA-256 digest");
|
|
112
|
+
}
|
|
113
|
+
const actual = createHash("sha256").update(bytes).digest("hex");
|
|
114
|
+
if (actual !== expected) {
|
|
115
|
+
throw new Error("checksum mismatch for " + label + ": expected " + expected + ", got " + actual);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function verifyBinaryVersion(binary, expectedVersion) {
|
|
120
|
+
const output = spawnSync(binary, ["--version"], { encoding: "utf8" });
|
|
121
|
+
if (output.error) throw output.error;
|
|
122
|
+
if (output.status !== 0) throw new Error("failed to run " + binary + " --version");
|
|
123
|
+
const text = (output.stdout || "").trim();
|
|
124
|
+
const actualVersion = text.split(/\s+/).find((part) => /^v?\d+\.\d+\.\d+/.test(part));
|
|
125
|
+
if (!actualVersion || normalizeVersion(actualVersion) !== normalizeVersion(expectedVersion)) {
|
|
126
|
+
throw new Error(binary + " is " + (text || "unknown version") + "; expected " + BIN_NAME + " " + expectedVersion);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function normalizeVersion(version) {
|
|
131
|
+
return version.trim().replace(/^v/, "").split("+")[0];
|
|
132
|
+
}
|
|
@@ -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
|
-
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,234 @@
|
|
|
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 manifest = await readFirstManifest([
|
|
48
|
+
new URL("./deno.json", globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url),
|
|
49
|
+
new URL("../package.json", globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url),
|
|
50
|
+
new URL("../../../package.json", globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url),
|
|
51
|
+
]);
|
|
52
|
+
if (typeof manifest.version !== "string" || !manifest.version.trim()) {
|
|
53
|
+
throw new Error("@qlever-llc/trellis package manifest does not declare a version");
|
|
54
|
+
}
|
|
55
|
+
return manifest.version.trim();
|
|
56
|
+
}
|
|
57
|
+
async function readFirstManifest(urls) {
|
|
58
|
+
for (const url of urls) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(await dntShim.Deno.readTextFile(url));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof dntShim.Deno.errors.NotFound) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
throw new Error("could not find @qlever-llc/trellis package manifest");
|
|
70
|
+
}
|
|
71
|
+
async function ensureCachedReleaseBinary(version) {
|
|
72
|
+
const target = releaseTarget();
|
|
73
|
+
const cacheDir = joinPath(cacheRoot(), version, target);
|
|
74
|
+
const binary = joinPath(cacheDir, BIN_NAME);
|
|
75
|
+
if (await pathExists(binary)) {
|
|
76
|
+
return binary;
|
|
77
|
+
}
|
|
78
|
+
await dntShim.Deno.mkdir(cacheDir, { recursive: true });
|
|
79
|
+
const tag = `v${version}`;
|
|
80
|
+
const archiveName = `${BIN_NAME}-${tag}-${target}.tar.gz`;
|
|
81
|
+
const archiveUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${archiveName}`;
|
|
82
|
+
const checksumName = `checksum-${tag}-${target}-${BIN_NAME}.sha256`;
|
|
83
|
+
const checksumUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${checksumName}`;
|
|
84
|
+
const [archive, checksumText] = await Promise.all([
|
|
85
|
+
downloadBytes(archiveUrl),
|
|
86
|
+
downloadText(checksumUrl),
|
|
87
|
+
]);
|
|
88
|
+
await verifyChecksum(archive, checksumText, archiveUrl);
|
|
89
|
+
const archivePath = joinPath(cacheDir, archiveName);
|
|
90
|
+
await dntShim.Deno.writeFile(archivePath, archive);
|
|
91
|
+
await runCommandChecked("tar", ["-xzf", archivePath, "-C", cacheDir]);
|
|
92
|
+
await dntShim.Deno.chmod(binary, 0o755);
|
|
93
|
+
return binary;
|
|
94
|
+
}
|
|
95
|
+
function releaseTarget() {
|
|
96
|
+
if (SUPPORTED_TARGETS.has(dntShim.Deno.build.target)) {
|
|
97
|
+
return dntShim.Deno.build.target;
|
|
98
|
+
}
|
|
99
|
+
const buildArch = dntShim.Deno.build.arch;
|
|
100
|
+
const arch = buildArch === "x86_64" || buildArch === "x64"
|
|
101
|
+
? "x86_64"
|
|
102
|
+
: buildArch;
|
|
103
|
+
const os = dntShim.Deno.build.os === "darwin"
|
|
104
|
+
? "apple-darwin"
|
|
105
|
+
: dntShim.Deno.build.os === "linux"
|
|
106
|
+
? "unknown-linux-gnu"
|
|
107
|
+
: undefined;
|
|
108
|
+
const target = os ? `${arch}-${os}` : undefined;
|
|
109
|
+
if (target && SUPPORTED_TARGETS.has(target)) {
|
|
110
|
+
return target;
|
|
111
|
+
}
|
|
112
|
+
throw new Error(`no ${BIN_NAME} release binary is available for ${dntShim.Deno.build.target}`);
|
|
113
|
+
}
|
|
114
|
+
function cacheRoot() {
|
|
115
|
+
const explicit = dntShim.Deno.env.get("TRELLIS_GENERATE_CACHE")?.trim();
|
|
116
|
+
if (explicit) {
|
|
117
|
+
return explicit;
|
|
118
|
+
}
|
|
119
|
+
const xdg = dntShim.Deno.env.get("XDG_CACHE_HOME")?.trim();
|
|
120
|
+
if (xdg) {
|
|
121
|
+
return joinPath(xdg, "trellis", BIN_NAME);
|
|
122
|
+
}
|
|
123
|
+
const home = dntShim.Deno.env.get("HOME")?.trim();
|
|
124
|
+
if (!home) {
|
|
125
|
+
throw new Error("HOME or TRELLIS_GENERATE_CACHE must be set to cache trellis-generate");
|
|
126
|
+
}
|
|
127
|
+
return joinPath(home, ".cache", "trellis", BIN_NAME);
|
|
128
|
+
}
|
|
129
|
+
async function downloadBytes(url) {
|
|
130
|
+
const response = await fetch(url);
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
throw new Error(`failed to download ${url}: HTTP ${response.status}`);
|
|
133
|
+
}
|
|
134
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
135
|
+
}
|
|
136
|
+
async function downloadText(url) {
|
|
137
|
+
const response = await fetch(url);
|
|
138
|
+
if (!response.ok) {
|
|
139
|
+
throw new Error(`failed to download ${url}: HTTP ${response.status}`);
|
|
140
|
+
}
|
|
141
|
+
return await response.text();
|
|
142
|
+
}
|
|
143
|
+
async function verifyChecksum(bytes, checksumText, label) {
|
|
144
|
+
const expected = checksumText.trim().split(/\s+/)[0]?.toLowerCase();
|
|
145
|
+
if (!expected || !/^[0-9a-f]{64}$/.test(expected)) {
|
|
146
|
+
throw new Error("release checksum asset did not contain a SHA-256 digest");
|
|
147
|
+
}
|
|
148
|
+
const buffer = new ArrayBuffer(bytes.byteLength);
|
|
149
|
+
new Uint8Array(buffer).set(bytes);
|
|
150
|
+
const digest = await crypto.subtle.digest("SHA-256", buffer);
|
|
151
|
+
const actual = Array.from(new Uint8Array(digest))
|
|
152
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
153
|
+
.join("");
|
|
154
|
+
if (actual !== expected) {
|
|
155
|
+
throw new Error(`checksum mismatch for ${label}: expected ${expected}, got ${actual}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async function verifyBinaryVersion(binary, expectedVersion) {
|
|
159
|
+
const output = await new dntShim.Deno.Command(binary, {
|
|
160
|
+
args: ["--version"],
|
|
161
|
+
stdout: "piped",
|
|
162
|
+
stderr: "piped",
|
|
163
|
+
}).output();
|
|
164
|
+
if (!output.success) {
|
|
165
|
+
throw new Error(`failed to run ${binary} --version`);
|
|
166
|
+
}
|
|
167
|
+
const text = new TextDecoder().decode(output.stdout).trim();
|
|
168
|
+
const actualVersion = text.split(/\s+/).find((part) => /^v?\d+\.\d+\.\d+/.test(part));
|
|
169
|
+
if (!actualVersion ||
|
|
170
|
+
normalizeVersion(actualVersion) !== normalizeVersion(expectedVersion)) {
|
|
171
|
+
throw new Error(`${binary} is ${text || "unknown version"}; expected ${BIN_NAME} ${expectedVersion}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function normalizeVersion(version) {
|
|
175
|
+
return version.trim().replace(/^v/, "").split("+")[0];
|
|
176
|
+
}
|
|
177
|
+
async function runBinary(binary, args) {
|
|
178
|
+
return await runCommand(binary, args);
|
|
179
|
+
}
|
|
180
|
+
async function runCommand(command, args, options = {}) {
|
|
181
|
+
const status = await spawnCommand(command, args, options);
|
|
182
|
+
dntShim.Deno.exit(status.code);
|
|
183
|
+
}
|
|
184
|
+
async function runCommandChecked(command, args, options = {}) {
|
|
185
|
+
const status = await spawnCommand(command, args, options);
|
|
186
|
+
if (!status.success) {
|
|
187
|
+
throw new Error(`${command} failed with exit code ${status.code}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function spawnCommand(command, args, options = {}) {
|
|
191
|
+
const status = await new dntShim.Deno.Command(command, {
|
|
192
|
+
args,
|
|
193
|
+
cwd: options.cwd,
|
|
194
|
+
stdin: "inherit",
|
|
195
|
+
stdout: "inherit",
|
|
196
|
+
stderr: "inherit",
|
|
197
|
+
}).spawn().status;
|
|
198
|
+
return status;
|
|
199
|
+
}
|
|
200
|
+
async function pathExists(path) {
|
|
201
|
+
try {
|
|
202
|
+
await dntShim.Deno.stat(path);
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (error instanceof dntShim.Deno.errors.NotFound) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function urlDirname(url) {
|
|
213
|
+
return dirname(decodeURIComponent(new URL(url).pathname));
|
|
214
|
+
}
|
|
215
|
+
function dirname(path) {
|
|
216
|
+
const normalized = path.replace(/\/+$/, "");
|
|
217
|
+
const index = normalized.lastIndexOf("/");
|
|
218
|
+
if (index <= 0) {
|
|
219
|
+
return "/";
|
|
220
|
+
}
|
|
221
|
+
return normalized.slice(0, index);
|
|
222
|
+
}
|
|
223
|
+
function joinPath(...parts) {
|
|
224
|
+
return parts
|
|
225
|
+
.filter((part) => part.length > 0)
|
|
226
|
+
.join("/")
|
|
227
|
+
.replace(/\/+/g, "/");
|
|
228
|
+
}
|
|
229
|
+
if (globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).main) {
|
|
230
|
+
main().catch((error) => {
|
|
231
|
+
console.error(error);
|
|
232
|
+
dntShim.Deno.exit(1);
|
|
233
|
+
});
|
|
234
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlever-llc/trellis",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.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": {
|
|
@@ -119,10 +119,13 @@
|
|
|
119
119
|
"ts-deepmerge": "^7.0.3",
|
|
120
120
|
"typebox": "^1.0.15",
|
|
121
121
|
"ulid": "^3.0.1",
|
|
122
|
-
"@qlever-llc/result": "^0.8.
|
|
122
|
+
"@qlever-llc/result": "^0.8.4"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
125
|
"@types/node": "^20.9.0"
|
|
126
126
|
},
|
|
127
|
-
"_generatedBy": "dnt@dev"
|
|
127
|
+
"_generatedBy": "dnt@dev",
|
|
128
|
+
"bin": {
|
|
129
|
+
"trellis-generate": "./bin/trellis-generate.js"
|
|
130
|
+
}
|
|
128
131
|
}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,269 @@
|
|
|
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 manifest = await readFirstManifest([
|
|
83
|
+
new URL("./deno.json", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url),
|
|
84
|
+
new URL("../package.json", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url),
|
|
85
|
+
new URL("../../../package.json", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url),
|
|
86
|
+
]);
|
|
87
|
+
if (typeof manifest.version !== "string" || !manifest.version.trim()) {
|
|
88
|
+
throw new Error("@qlever-llc/trellis package manifest does not declare a version");
|
|
89
|
+
}
|
|
90
|
+
return manifest.version.trim();
|
|
91
|
+
}
|
|
92
|
+
async function readFirstManifest(urls) {
|
|
93
|
+
for (const url of urls) {
|
|
94
|
+
try {
|
|
95
|
+
return JSON.parse(await dntShim.Deno.readTextFile(url));
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error instanceof dntShim.Deno.errors.NotFound) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw new Error("could not find @qlever-llc/trellis package manifest");
|
|
105
|
+
}
|
|
106
|
+
async function ensureCachedReleaseBinary(version) {
|
|
107
|
+
const target = releaseTarget();
|
|
108
|
+
const cacheDir = joinPath(cacheRoot(), version, target);
|
|
109
|
+
const binary = joinPath(cacheDir, BIN_NAME);
|
|
110
|
+
if (await pathExists(binary)) {
|
|
111
|
+
return binary;
|
|
112
|
+
}
|
|
113
|
+
await dntShim.Deno.mkdir(cacheDir, { recursive: true });
|
|
114
|
+
const tag = `v${version}`;
|
|
115
|
+
const archiveName = `${BIN_NAME}-${tag}-${target}.tar.gz`;
|
|
116
|
+
const archiveUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${archiveName}`;
|
|
117
|
+
const checksumName = `checksum-${tag}-${target}-${BIN_NAME}.sha256`;
|
|
118
|
+
const checksumUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${checksumName}`;
|
|
119
|
+
const [archive, checksumText] = await Promise.all([
|
|
120
|
+
downloadBytes(archiveUrl),
|
|
121
|
+
downloadText(checksumUrl),
|
|
122
|
+
]);
|
|
123
|
+
await verifyChecksum(archive, checksumText, archiveUrl);
|
|
124
|
+
const archivePath = joinPath(cacheDir, archiveName);
|
|
125
|
+
await dntShim.Deno.writeFile(archivePath, archive);
|
|
126
|
+
await runCommandChecked("tar", ["-xzf", archivePath, "-C", cacheDir]);
|
|
127
|
+
await dntShim.Deno.chmod(binary, 0o755);
|
|
128
|
+
return binary;
|
|
129
|
+
}
|
|
130
|
+
function releaseTarget() {
|
|
131
|
+
if (SUPPORTED_TARGETS.has(dntShim.Deno.build.target)) {
|
|
132
|
+
return dntShim.Deno.build.target;
|
|
133
|
+
}
|
|
134
|
+
const buildArch = dntShim.Deno.build.arch;
|
|
135
|
+
const arch = buildArch === "x86_64" || buildArch === "x64"
|
|
136
|
+
? "x86_64"
|
|
137
|
+
: buildArch;
|
|
138
|
+
const os = dntShim.Deno.build.os === "darwin"
|
|
139
|
+
? "apple-darwin"
|
|
140
|
+
: dntShim.Deno.build.os === "linux"
|
|
141
|
+
? "unknown-linux-gnu"
|
|
142
|
+
: undefined;
|
|
143
|
+
const target = os ? `${arch}-${os}` : undefined;
|
|
144
|
+
if (target && SUPPORTED_TARGETS.has(target)) {
|
|
145
|
+
return target;
|
|
146
|
+
}
|
|
147
|
+
throw new Error(`no ${BIN_NAME} release binary is available for ${dntShim.Deno.build.target}`);
|
|
148
|
+
}
|
|
149
|
+
function cacheRoot() {
|
|
150
|
+
const explicit = dntShim.Deno.env.get("TRELLIS_GENERATE_CACHE")?.trim();
|
|
151
|
+
if (explicit) {
|
|
152
|
+
return explicit;
|
|
153
|
+
}
|
|
154
|
+
const xdg = dntShim.Deno.env.get("XDG_CACHE_HOME")?.trim();
|
|
155
|
+
if (xdg) {
|
|
156
|
+
return joinPath(xdg, "trellis", BIN_NAME);
|
|
157
|
+
}
|
|
158
|
+
const home = dntShim.Deno.env.get("HOME")?.trim();
|
|
159
|
+
if (!home) {
|
|
160
|
+
throw new Error("HOME or TRELLIS_GENERATE_CACHE must be set to cache trellis-generate");
|
|
161
|
+
}
|
|
162
|
+
return joinPath(home, ".cache", "trellis", BIN_NAME);
|
|
163
|
+
}
|
|
164
|
+
async function downloadBytes(url) {
|
|
165
|
+
const response = await fetch(url);
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
throw new Error(`failed to download ${url}: HTTP ${response.status}`);
|
|
168
|
+
}
|
|
169
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
170
|
+
}
|
|
171
|
+
async function downloadText(url) {
|
|
172
|
+
const response = await fetch(url);
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
throw new Error(`failed to download ${url}: HTTP ${response.status}`);
|
|
175
|
+
}
|
|
176
|
+
return await response.text();
|
|
177
|
+
}
|
|
178
|
+
async function verifyChecksum(bytes, checksumText, label) {
|
|
179
|
+
const expected = checksumText.trim().split(/\s+/)[0]?.toLowerCase();
|
|
180
|
+
if (!expected || !/^[0-9a-f]{64}$/.test(expected)) {
|
|
181
|
+
throw new Error("release checksum asset did not contain a SHA-256 digest");
|
|
182
|
+
}
|
|
183
|
+
const buffer = new ArrayBuffer(bytes.byteLength);
|
|
184
|
+
new Uint8Array(buffer).set(bytes);
|
|
185
|
+
const digest = await crypto.subtle.digest("SHA-256", buffer);
|
|
186
|
+
const actual = Array.from(new Uint8Array(digest))
|
|
187
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
188
|
+
.join("");
|
|
189
|
+
if (actual !== expected) {
|
|
190
|
+
throw new Error(`checksum mismatch for ${label}: expected ${expected}, got ${actual}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async function verifyBinaryVersion(binary, expectedVersion) {
|
|
194
|
+
const output = await new dntShim.Deno.Command(binary, {
|
|
195
|
+
args: ["--version"],
|
|
196
|
+
stdout: "piped",
|
|
197
|
+
stderr: "piped",
|
|
198
|
+
}).output();
|
|
199
|
+
if (!output.success) {
|
|
200
|
+
throw new Error(`failed to run ${binary} --version`);
|
|
201
|
+
}
|
|
202
|
+
const text = new TextDecoder().decode(output.stdout).trim();
|
|
203
|
+
const actualVersion = text.split(/\s+/).find((part) => /^v?\d+\.\d+\.\d+/.test(part));
|
|
204
|
+
if (!actualVersion ||
|
|
205
|
+
normalizeVersion(actualVersion) !== normalizeVersion(expectedVersion)) {
|
|
206
|
+
throw new Error(`${binary} is ${text || "unknown version"}; expected ${BIN_NAME} ${expectedVersion}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function normalizeVersion(version) {
|
|
210
|
+
return version.trim().replace(/^v/, "").split("+")[0];
|
|
211
|
+
}
|
|
212
|
+
async function runBinary(binary, args) {
|
|
213
|
+
return await runCommand(binary, args);
|
|
214
|
+
}
|
|
215
|
+
async function runCommand(command, args, options = {}) {
|
|
216
|
+
const status = await spawnCommand(command, args, options);
|
|
217
|
+
dntShim.Deno.exit(status.code);
|
|
218
|
+
}
|
|
219
|
+
async function runCommandChecked(command, args, options = {}) {
|
|
220
|
+
const status = await spawnCommand(command, args, options);
|
|
221
|
+
if (!status.success) {
|
|
222
|
+
throw new Error(`${command} failed with exit code ${status.code}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function spawnCommand(command, args, options = {}) {
|
|
226
|
+
const status = await new dntShim.Deno.Command(command, {
|
|
227
|
+
args,
|
|
228
|
+
cwd: options.cwd,
|
|
229
|
+
stdin: "inherit",
|
|
230
|
+
stdout: "inherit",
|
|
231
|
+
stderr: "inherit",
|
|
232
|
+
}).spawn().status;
|
|
233
|
+
return status;
|
|
234
|
+
}
|
|
235
|
+
async function pathExists(path) {
|
|
236
|
+
try {
|
|
237
|
+
await dntShim.Deno.stat(path);
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
if (error instanceof dntShim.Deno.errors.NotFound) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function urlDirname(url) {
|
|
248
|
+
return dirname(decodeURIComponent(new URL(url).pathname));
|
|
249
|
+
}
|
|
250
|
+
function dirname(path) {
|
|
251
|
+
const normalized = path.replace(/\/+$/, "");
|
|
252
|
+
const index = normalized.lastIndexOf("/");
|
|
253
|
+
if (index <= 0) {
|
|
254
|
+
return "/";
|
|
255
|
+
}
|
|
256
|
+
return normalized.slice(0, index);
|
|
257
|
+
}
|
|
258
|
+
function joinPath(...parts) {
|
|
259
|
+
return parts
|
|
260
|
+
.filter((part) => part.length > 0)
|
|
261
|
+
.join("/")
|
|
262
|
+
.replace(/\/+/g, "/");
|
|
263
|
+
}
|
|
264
|
+
if (globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).main) {
|
|
265
|
+
main().catch((error) => {
|
|
266
|
+
console.error(error);
|
|
267
|
+
dntShim.Deno.exit(1);
|
|
268
|
+
});
|
|
269
|
+
}
|