Skip to content

Commit 7519e2c

Browse files
authored
chore: Optionally build CLI via build-binaries (#1215)
1 parent 3287c17 commit 7519e2c

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

tasks/build-binaries.ts

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import * as path from "@std/path";
66
interface BuildConfigInitializer {
77
root: string;
88
toolshedFlags: string[];
9+
cliOnly?: boolean;
910
}
1011

1112
class BuildConfig {
1213
readonly root: string;
1314
readonly toolshedFlags: string[];
15+
readonly cliOnly: boolean;
1416
private _manifest: object;
1517

1618
constructor(options: BuildConfigInitializer) {
1719
this.root = options.root;
1820
this.toolshedFlags = options.toolshedFlags;
21+
this.cliOnly = !!options.cliOnly;
1922
this._manifest = JSON.parse(
2023
Deno.readTextFileSync(this.workspaceManifestPath()),
2124
);
@@ -66,7 +69,12 @@ class BuildConfig {
6669
}
6770

6871
bgCharmServiceWorkerPath() {
69-
return this.path("packages", "background-charm-service", "src", "worker.ts");
72+
return this.path(
73+
"packages",
74+
"background-charm-service",
75+
"src",
76+
"worker.ts",
77+
);
7078
}
7179

7280
staticBundleFilePath(filename: string): string[] {
@@ -81,6 +89,14 @@ class BuildConfig {
8189
return this.path("packages", "static", "assets");
8290
}
8391

92+
staticTypesPath() {
93+
return this.path("packages", "static", "assets", "types");
94+
}
95+
96+
cliEntryPath() {
97+
return this.path("packages", "js-runtime", "cli", "mod.ts");
98+
}
99+
84100
distDir() {
85101
return this.path("dist");
86102
}
@@ -98,10 +114,11 @@ async function build(config: BuildConfig): Promise<void> {
98114

99115
// Build jumble first, do not remove deno.lock
100116
// until after this.
101-
await buildJumble(config);
117+
if (!config.cliOnly) await buildJumble(config);
102118
await prepareWorkspace(config);
103-
await buildToolshed(config);
104-
await buildBgCharmService(config);
119+
if (!config.cliOnly) await buildToolshed(config);
120+
if (!config.cliOnly) await buildBgCharmService(config);
121+
if (config.cliOnly) await buildCli(config);
105122
} catch (e: unknown) {
106123
buildError = e as Error;
107124
}
@@ -212,6 +229,53 @@ async function buildBgCharmService(config: BuildConfig): Promise<void> {
212229
console.log("Background charm service binary built successfully");
213230
}
214231

232+
async function buildCli(config: BuildConfig): Promise<void> {
233+
console.log("Building CLI binary...");
234+
const envs = [
235+
"TSC_WATCHFILE",
236+
"TSC_NONPOLLING_WATCHER",
237+
"TSC_WATCHDIRECTORY",
238+
"TSC_WATCH_POLLINGINTERVAL_LOW",
239+
"TSC_WATCH_POLLINGINTERVAL_MEDIUM",
240+
"TSC_WATCH_POLLINGINTERVAL_HIGH",
241+
"TSC_WATCH_POLLINGCHUNKSIZE_LOW",
242+
"TSC_WATCH_POLLINGCHUNKSIZE_MEDIUM",
243+
"TSC_WATCH_POLLINGCHUNKSIZE_HIGH",
244+
"TSC_WATCH_UNCHANGEDPOLLTHRESHOLDS_LOW",
245+
"TSC_WATCH_UNCHANGEDPOLLTHRESHOLDS_MEDIUM",
246+
"TSC_WATCH_UNCHANGEDPOLLTHRESHOLDS_HIGH",
247+
"NODE_INSPECTOR_IPC",
248+
"VSCODE_INSPECTOR_OPTIONS",
249+
"NODE_ENV",
250+
];
251+
const { success } = await new Deno.Command(Deno.execPath(), {
252+
args: [
253+
"compile",
254+
"--output",
255+
config.distPath("ct"),
256+
// Run `--no-check` here, as the `--include`'d
257+
// `es2023.d.ts` file will attempt to be checked
258+
// as a non-static asset. Checking should be done
259+
// prior to building.
260+
"--no-check",
261+
"--allow-read",
262+
// Globs don't work for compile(?)
263+
`--allow-env=${envs.join(",")}`,
264+
"--include",
265+
config.staticTypesPath(),
266+
config.cliEntryPath(),
267+
],
268+
cwd: config.root,
269+
stdout: "inherit",
270+
stderr: "inherit",
271+
}).output();
272+
if (!success) {
273+
console.error("Failed to build background charm service binary");
274+
Deno.exit(1);
275+
}
276+
console.log("CLI binary built successfully");
277+
}
278+
215279
// `deno compile` appears to bundle *all* workspace
216280
// dependencies e.g. dev dependencies. We can sidestep
217281
// this by removing the lock file, and only calling compile
@@ -275,6 +339,7 @@ const config = new BuildConfig({
275339
"--allow-net",
276340
"--allow-write",
277341
],
342+
cliOnly: Deno.args.includes("--cli-only"),
278343
});
279344

280345
Deno.addSignalListener("SIGINT", async () => {

0 commit comments

Comments
 (0)