mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 08:06:00 +00:00
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:
+1
-2
@@ -63,8 +63,7 @@
|
||||
"dayjs": "^1.11.19",
|
||||
"fast-xml-parser": "^5.3.1",
|
||||
"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",
|
||||
"jsonv-ts": "^0.10.1",
|
||||
"kysely": "0.28.8",
|
||||
|
||||
@@ -56,11 +56,41 @@ if (!registries.media.has(local)) {
|
||||
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> {
|
||||
if (/\.[mc]?ts$/.test(configFilePath)) {
|
||||
const { createJiti } = await import("jiti");
|
||||
const jiti = createJiti(import.meta.url);
|
||||
return (await jiti.import(configFilePath, { default: true })) as CliBkndConfig;
|
||||
if (needsTypeStripping(configFilePath) && !process.execArgv.includes("--experimental-strip-types")) {
|
||||
reexecWithTypeStripping();
|
||||
}
|
||||
return (await import(configFilePath).then((m) => m.default)) as CliBkndConfig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user