-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmirror.mjs
More file actions
42 lines (34 loc) · 1.01 KB
/
mirror.mjs
File metadata and controls
42 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env node
import module from "node:module";
import process from "node:process";
if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
module.enableCompileCache();
} catch {
// Ignore errors.
}
}
const isModuleNotFoundError = (err) =>
err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND";
const tryImport = async (specifier) => {
try {
return await import(specifier);
} catch (err) {
if (isModuleNotFoundError(err)) {
return undefined;
}
throw err;
}
};
const mod =
(await tryImport("./dist/mirror-entry.js")) ?? (await tryImport("./dist/mirror-entry.mjs"));
if (!mod) {
throw new Error("mirror: missing dist/mirror-entry.(m)js (build output).");
}
if (typeof mod.runMirrorEntry !== "function") {
throw new Error("mirror: dist/mirror-entry does not export runMirrorEntry().");
}
const exitCode = await mod.runMirrorEntry(process.argv);
if (typeof exitCode === "number") {
process.exitCode = exitCode;
}