fix(cli): support loading bknd.config.ts without tsx workaround

Add jiti as a dependency to handle TypeScript config imports natively in the CLI, removing the need for npx tsx or --experimental-strip-types workarounds.

Closes #360
This commit is contained in:
Cameron Pak
2026-03-07 08:06:51 -06:00
parent 7832328a50
commit e6b17f6424
4 changed files with 16 additions and 28 deletions
+1
View File
@@ -63,6 +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-to-ts": "^3.1.1",
"jsonv-ts": "^0.10.1",
+10 -1
View File
@@ -55,6 +55,15 @@ if (!registries.media.has(local)) {
registries.media.register(local, StorageLocalAdapter);
}
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;
}
return (await import(configFilePath).then((m) => m.default)) as CliBkndConfig;
}
type MakeAppConfig = {
connection?: CreateAppConfig["connection"];
server?: { platform?: Platform };
@@ -100,7 +109,7 @@ export async function makeAppFromEnv(options: Partial<RunOptions> = {}) {
} else if (configFilePath) {
console.info("Using config from", c.cyan(configFilePath));
try {
const config = (await import(configFilePath).then((m) => m.default)) as CliBkndConfig;
const config = await loadConfigFile(configFilePath);
app = await makeConfigApp(config, options.server);
} catch (e) {
console.error("Failed to load config:", e);