diff --git a/app/package.json b/app/package.json index 82197388..002d3709 100644 --- a/app/package.json +++ b/app/package.json @@ -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", diff --git a/app/src/cli/commands/run/run.ts b/app/src/cli/commands/run/run.ts index 8a507b64..6e997f86 100644 --- a/app/src/cli/commands/run/run.ts +++ b/app/src/cli/commands/run/run.ts @@ -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 { - 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; } diff --git a/bun.lock b/bun.lock index ff094edf..5e3bbf4b 100644 --- a/bun.lock +++ b/bun.lock @@ -34,7 +34,6 @@ "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-to-ts": "^3.1.1", "jsonv-ts": "^0.10.1",