From 9aae6e78d606235d973fd41a3e9a74e9434091e4 Mon Sep 17 00:00:00 2001 From: dswbx Date: Tue, 16 Sep 2025 16:41:16 +0200 Subject: [PATCH] config: allow full property usage in `app` function and improve type consistency Added support for all properties in the `app` function configuration and ensured consistent type definitions for `BkndConfig`. Updated `makeConfig` function to reflect these changes and added relevant unit tests. --- app/__test__/adapter/adapter.test.ts | 27 ++++++++++++++++++++++++++- app/src/adapter/index.ts | 8 ++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/__test__/adapter/adapter.test.ts b/app/__test__/adapter/adapter.test.ts index 1644c89..8527b5d 100644 --- a/app/__test__/adapter/adapter.test.ts +++ b/app/__test__/adapter/adapter.test.ts @@ -1,4 +1,4 @@ -import { expect, describe, it, beforeAll, afterAll } from "bun:test"; +import { expect, describe, it, beforeAll, afterAll, mock } from "bun:test"; import * as adapter from "adapter"; import { disableConsoleLog, enableConsoleLog } from "core/utils"; import { adapterTestSuite } from "adapter/adapter-test-suite"; @@ -29,6 +29,31 @@ describe("adapter", () => { }); }); + it("allows all properties in app function", async () => { + const called = mock(() => null); + const config = await adapter.makeConfig( + { + app: (env) => ({ + connection: { url: "test" }, + config: { server: { cors: { origin: "test" } } }, + options: { + mode: "db", + }, + onBuilt: () => { + called(); + expect(env).toEqual({ foo: "bar" }); + }, + }), + }, + { foo: "bar" }, + ); + expect(config.connection).toEqual({ url: "test" }); + expect(config.config).toEqual({ server: { cors: { origin: "test" } } }); + expect(config.options).toEqual({ mode: "db" }); + await config.onBuilt?.(null as any); + expect(called).toHaveBeenCalled(); + }); + adapterTestSuite(bunTestRunner, { makeApp: adapter.createFrameworkApp, label: "framework app", diff --git a/app/src/adapter/index.ts b/app/src/adapter/index.ts index f496253..0ee5e0c 100644 --- a/app/src/adapter/index.ts +++ b/app/src/adapter/index.ts @@ -13,9 +13,9 @@ import type { AdminControllerOptions } from "modules/server/AdminController"; import type { Manifest } from "vite"; export type BkndConfig = CreateAppConfig & { - app?: CreateAppConfig | ((args: Args) => MaybePromise); - onBuilt?: (app: App) => Promise; - beforeBuild?: (app: App, registries?: typeof $registries) => Promise; + app?: Omit | ((args: Args) => MaybePromise, "app">>); + onBuilt?: (app: App) => MaybePromise; + beforeBuild?: (app: App, registries?: typeof $registries) => MaybePromise; buildConfig?: Parameters[0]; }; @@ -34,7 +34,7 @@ export type DefaultArgs = { export async function makeConfig( config: BkndConfig, args?: Args, -): Promise { +): Promise, "app">> { let additionalConfig: CreateAppConfig = {}; const { app, ...rest } = config; if (app) {