fix(cli): replace jiti with Node native type-stripping for TS configs

Drop jiti dependency. Node >=22.18 imports .ts natively; 22.13–22.17 re-execs with --experimental-strip-types. Bun re-exec unchanged.
This commit is contained in:
Cameron Pak
2026-03-07 09:50:56 -06:00
parent 48d432ddb2
commit db961b5447
3 changed files with 35 additions and 7 deletions
+1 -2
View File
@@ -63,8 +63,7 @@
"dayjs": "^1.11.19", "dayjs": "^1.11.19",
"fast-xml-parser": "^5.3.1", "fast-xml-parser": "^5.3.1",
"hono": "4.10.4", "hono": "4.10.4",
"jiti": "^2.4.2", "json-schema-library": "10.0.0-rc7",
"json-schema-library": "10.0.0-rc7",
"json-schema-to-ts": "^3.1.1", "json-schema-to-ts": "^3.1.1",
"jsonv-ts": "^0.10.1", "jsonv-ts": "^0.10.1",
"kysely": "0.28.8", "kysely": "0.28.8",
+34 -4
View File
@@ -56,11 +56,41 @@ if (!registries.media.has(local)) {
registries.media.register(local, StorageLocalAdapter); registries.media.register(local, StorageLocalAdapter);
} }
function needsTypeStripping(configFilePath: string): boolean {
if (!/\.[mc]?ts$/.test(configFilePath)) return false;
const [major, minor] = process.versions.node.split(".").map(Number);
return major === 22 && minor! < 18;
}
function reexecWithTypeStripping(): never {
if (process.env.__BKND_REEXEC) {
console.error(c.red("TS config still failed after re-exec with --experimental-strip-types."));
process.exit(1);
}
const cliPath = path.resolve(process.argv[1]!);
const args = ["--experimental-strip-types", cliPath, ...process.argv.slice(2)];
console.info(
c.yellow("Node <22.18 detected, re-executing with --experimental-strip-types"),
);
try {
execFileSync(process.execPath, args, {
stdio: "inherit",
env: { ...process.env, __BKND_REEXEC: "1" },
});
process.exit(0);
} catch (e: any) {
if (e.status != null) process.exit(e.status);
console.error(c.red("Failed to re-exec with --experimental-strip-types."));
process.exit(1);
}
}
async function loadConfigFile(configFilePath: string): Promise<CliBkndConfig> { async function loadConfigFile(configFilePath: string): Promise<CliBkndConfig> {
if (/\.[mc]?ts$/.test(configFilePath)) { if (needsTypeStripping(configFilePath) && !process.execArgv.includes("--experimental-strip-types")) {
const { createJiti } = await import("jiti"); reexecWithTypeStripping();
const jiti = createJiti(import.meta.url);
return (await jiti.import(configFilePath, { default: true })) as CliBkndConfig;
} }
return (await import(configFilePath).then((m) => m.default)) as CliBkndConfig; return (await import(configFilePath).then((m) => m.default)) as CliBkndConfig;
} }
-1
View File
@@ -34,7 +34,6 @@
"dayjs": "^1.11.19", "dayjs": "^1.11.19",
"fast-xml-parser": "^5.3.1", "fast-xml-parser": "^5.3.1",
"hono": "4.10.4", "hono": "4.10.4",
"jiti": "^2.4.2",
"json-schema-library": "10.0.0-rc7", "json-schema-library": "10.0.0-rc7",
"json-schema-to-ts": "^3.1.1", "json-schema-to-ts": "^3.1.1",
"jsonv-ts": "^0.10.1", "jsonv-ts": "^0.10.1",