diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 969b2e807..95059eb86 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -8,6 +8,7 @@ ### Changed +- Changed the bundled Node.js runtime to load jiti's Babel transform only when an extension needs it, reducing CLI startup time and bundle size. - Changed syntax highlighting to initialize only twenty common languages eagerly and defer the remaining grammars until after the initial TUI render, reducing CLI startup time. - Changed the Node.js CLI and RPC entrypoints to load a bundled runtime, reducing startup filesystem reads while keeping the public library and legacy module paths on the modular runtime for normal dependency identity. - Changed session sharing to render clickable terminal links and Radius shares to display only the artifact's canonical URL. diff --git a/packages/coding-agent/src/utils/syntax-highlight.ts b/packages/coding-agent/src/utils/syntax-highlight.ts index e08c4d894..080c128c2 100644 --- a/packages/coding-agent/src/utils/syntax-highlight.ts +++ b/packages/coding-agent/src/utils/syntax-highlight.ts @@ -1,4 +1,3 @@ -import { createRequire } from "node:module"; import hljs from "highlight.js/lib/core.js"; import bash from "highlight.js/lib/languages/bash.js"; import c from "highlight.js/lib/languages/c.js"; @@ -22,11 +21,6 @@ import swift from "highlight.js/lib/languages/swift.js"; import typescript from "highlight.js/lib/languages/typescript.js"; import { decodeHtmlEntityAt } from "./html.ts"; -const moduleRequire = createRequire(import.meta.url); -declare const PI_BUNDLED_NODE: boolean; -declare const Bun: unknown; -declare const require: (specifier: string) => unknown; - const eagerLanguages = { python, java, @@ -60,18 +54,13 @@ export function loadAllHighlightLanguages(): Promise { if (!allLanguagesPromise) { allLanguagesPromise = new Promise((resolve) => { setImmediate(() => { - try { - // Static require lets esbuild and Bun include this deferred module in - // standalone bundles. Source and unbundled Node runtimes need createRequire. - if ((typeof PI_BUNDLED_NODE !== "undefined" && PI_BUNDLED_NODE) || typeof Bun !== "undefined") { - require("highlight.js/lib/index.js"); - } else { - moduleRequire("highlight.js/lib/index.js"); - } - } catch { - // Eager languages and plaintext fallback remain available. - } - resolve(); + void import("highlight.js/lib/index.js").then( + () => resolve(), + () => { + // Eager languages and plaintext fallback remain available. + resolve(); + }, + ); }); }); } diff --git a/scripts/build-coding-agent-bundle.mjs b/scripts/build-coding-agent-bundle.mjs index 5c4fc62c6..d683441ae 100644 --- a/scripts/build-coding-agent-bundle.mjs +++ b/scripts/build-coding-agent-bundle.mjs @@ -17,6 +17,7 @@ const banner = { }; const allowedExternalPackages = new Set([ "@silvia-odwyer/photon-node", + "jiti", // Optional native accelerators. Their callers fall back to JavaScript when absent. "bufferutil", "utf-8-validate", @@ -24,6 +25,13 @@ const allowedExternalPackages = new Set([ "supports-color", ]); +const lazyJitiPlugin = { + name: "lazy-jiti-transform", + setup(build) { + build.onResolve({ filter: /^jiti\/static$/ }, () => ({ external: true, path: "jiti" })); + }, +}; + function commonBuildOptions() { return { absWorkingDir: repoRoot, @@ -38,6 +46,10 @@ function commonBuildOptions() { minifySyntax: true, minifyWhitespace: true, platform: "node", + // The source uses jiti/static so Bun embeds its Babel transform. The Node + // package can use regular jiti from its direct dependency and load Babel + // only when an extension actually needs transformation. + plugins: [lazyJitiPlugin], sourcemap: false, target: "node22.19", // Do not apply the monorepo's source-oriented path aliases while bundling