Repository navigation
Expand file tree
/
Copy pathbin.ts
More file actions
49 lines (45 loc) · 1.77 KB
/
Copy pathbin.ts
File metadata and controls
49 lines (45 loc) · 1.77 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
43
44
45
46
47
48
49
// @effect-diagnostics nodeBuiltinImport:off -- The service launcher starts before the CLI runtime.
import * as NodeModule from "node:module";
import * as NodeSea from "node:sea";
import * as NodeURL from "node:url";
import { isEntrypoint } from "./entrypoint.ts";
// Loads the CLI outside the launcher's module graph. Packaged builds embed it as a raw asset.
async function loadCliMain(): Promise<typeof import("./binMain.ts")> {
if (!NodeSea.isSea()) return import("./binMain.ts");
// Keep the executable's module URL so the CLI finds the web client and native packages beside it.
const require = NodeModule.createRequire(import.meta.url);
// require() resolves links in the executable path, such as a Windows junction.
const cliUrl = NodeURL.pathToFileURL(require.resolve(process.execPath)).href;
const hook = NodeModule.registerHooks({
load(url, context, next) {
if (url !== cliUrl) return next(url, context);
return {
format: "module",
source: new Uint8Array(NodeSea.getRawAsset("binMain.mjs")),
shortCircuit: true,
};
},
});
try {
return require(process.execPath) as typeof import("./binMain.ts");
} finally {
hook.deregister();
}
}
if (
isEntrypoint({
moduleUrl: import.meta.url,
entryPath: process.argv[1],
runtimeMain: import.meta.main,
})
) {
// The launcher owns shutdown until its child exits, so it bypasses the Effect CLI runtime.
// The service unit passes no arguments; flags and help go through the full CLI.
if (process.argv[2] === "__service-launcher" && process.argv.length === 3) {
const { runServiceLauncherCli } = await import("./cli/serviceLauncher.ts");
await runServiceLauncherCli();
} else {
const { runCliCommand } = await loadCliMain();
await runCliCommand();
}
}