mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
add: Tanstack Start adapter
This commit is contained in:
41
app/build.ts
41
app/build.ts
@@ -125,7 +125,10 @@ async function buildApi() {
|
||||
|
||||
async function rewriteClient(path: string) {
|
||||
const bundle = await Bun.file(path).text();
|
||||
await Bun.write(path, '"use client";\n' + bundle.replaceAll("ui/client", "bknd/client"));
|
||||
await Bun.write(
|
||||
path,
|
||||
'"use client";\n' + bundle.replaceAll("ui/client", "bknd/client"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,7 +238,10 @@ async function buildUiElements() {
|
||||
/**
|
||||
* Building adapters
|
||||
*/
|
||||
function baseConfig(adapter: string, overrides: Partial<tsup.Options> = {}): tsup.Options {
|
||||
function baseConfig(
|
||||
adapter: string,
|
||||
overrides: Partial<tsup.Options> = {},
|
||||
): tsup.Options {
|
||||
return {
|
||||
minify,
|
||||
sourcemap,
|
||||
@@ -319,6 +325,11 @@ async function buildAdapters() {
|
||||
platform: "node",
|
||||
}),
|
||||
|
||||
tsup.build({
|
||||
...baseConfig("tanstack-start"),
|
||||
platform: "node",
|
||||
}),
|
||||
|
||||
tsup.build({
|
||||
...baseConfig("sveltekit"),
|
||||
platform: "node",
|
||||
@@ -351,11 +362,21 @@ async function buildAdapters() {
|
||||
metafile: false,
|
||||
external: [/^bun\:.*/],
|
||||
}),
|
||||
|
||||
tsup.build({
|
||||
...baseConfig("tanstack-start"),
|
||||
platform: "node",
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
async function buildAll() {
|
||||
await Promise.all([buildApi(), buildUi(), buildUiElements(), buildAdapters()]);
|
||||
await Promise.all([
|
||||
buildApi(),
|
||||
buildUi(),
|
||||
buildUiElements(),
|
||||
buildAdapters(),
|
||||
]);
|
||||
}
|
||||
|
||||
// initial build
|
||||
@@ -387,14 +408,22 @@ if (watch) {
|
||||
};
|
||||
|
||||
// watch src directory recursively
|
||||
fsWatch(join(import.meta.dir, "src"), { recursive: true }, (event, filename) => {
|
||||
fsWatch(
|
||||
join(import.meta.dir, "src"),
|
||||
{ recursive: true },
|
||||
(event, filename) => {
|
||||
if (!filename) return;
|
||||
// ignore non-source files
|
||||
if (!filename.endsWith(".ts") && !filename.endsWith(".tsx") && !filename.endsWith(".css"))
|
||||
if (
|
||||
!filename.endsWith(".ts") &&
|
||||
!filename.endsWith(".tsx") &&
|
||||
!filename.endsWith(".css")
|
||||
)
|
||||
return;
|
||||
oldConsole.log(c.cyan("[Watch]"), c.dim(`${event}: ${filename}`));
|
||||
debouncedRebuild();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// keep process alive
|
||||
await new Promise(() => {});
|
||||
|
||||
@@ -24,6 +24,9 @@ const configs = {
|
||||
bun: {
|
||||
base_path: "",
|
||||
},
|
||||
"tanstack-start": {
|
||||
base_path: "/admin",
|
||||
},
|
||||
};
|
||||
|
||||
export function getAdapterConfig(): typeof default_config {
|
||||
|
||||
@@ -268,6 +268,11 @@
|
||||
"import": "./dist/adapter/browser/index.js",
|
||||
"require": "./dist/adapter/browser/index.js"
|
||||
},
|
||||
"./adapter/tanstack-start": {
|
||||
"types": "./dist/types/adapter/tanstack-start/index.d.ts",
|
||||
"import": "./dist/adapter/tanstack-start/index.js",
|
||||
"require": "./dist/adapter/tanstack-start/index.js"
|
||||
},
|
||||
"./dist/main.css": "./dist/ui/main.css",
|
||||
"./dist/styles.css": "./dist/ui/styles.css",
|
||||
"./dist/manifest.json": "./dist/static/.vite/manifest.json",
|
||||
@@ -286,6 +291,7 @@
|
||||
"adapter/bun": ["./dist/types/adapter/bun/index.d.ts"],
|
||||
"adapter/node": ["./dist/types/adapter/node/index.d.ts"],
|
||||
"adapter/sveltekit": ["./dist/types/adapter/sveltekit/index.d.ts"],
|
||||
"adapter/tanstack-start": ["./dist/types/adapter/tanstack-start/index.d.ts"],
|
||||
"adapter/sqlite": ["./dist/types/adapter/sqlite/edge.d.ts"]
|
||||
}
|
||||
},
|
||||
|
||||
1
app/src/adapter/tanstack-start/index.ts
Normal file
1
app/src/adapter/tanstack-start/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./tanstack-start.adapter";
|
||||
@@ -0,0 +1,16 @@
|
||||
import { afterAll, beforeAll, describe } from "bun:test";
|
||||
import * as tanstackStart from "./tanstack-start.adapter";
|
||||
import { disableConsoleLog, enableConsoleLog } from "core/utils";
|
||||
import { adapterTestSuite } from "adapter/adapter-test-suite";
|
||||
import { bunTestRunner } from "adapter/bun/test";
|
||||
import type { TanstackStartConfig } from "./tanstack-start.adapter";
|
||||
|
||||
beforeAll(disableConsoleLog);
|
||||
afterAll(enableConsoleLog);
|
||||
|
||||
describe("tanstack start adapter", () => {
|
||||
adapterTestSuite<TanstackStartConfig>(bunTestRunner, {
|
||||
makeApp: tanstackStart.getApp,
|
||||
makeHandler: tanstackStart.serve,
|
||||
});
|
||||
});
|
||||
23
app/src/adapter/tanstack-start/tanstack-start.adapter.ts
Normal file
23
app/src/adapter/tanstack-start/tanstack-start.adapter.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createFrameworkApp, type FrameworkBkndConfig } from "bknd/adapter";
|
||||
|
||||
export type TanstackStartEnv = NodeJS.ProcessEnv;
|
||||
|
||||
export type TanstackStartConfig<Env = TanstackStartEnv> =
|
||||
FrameworkBkndConfig<Env>;
|
||||
|
||||
export async function getApp<Env = TanstackStartEnv>(
|
||||
config: TanstackStartConfig<Env>,
|
||||
args: Env = process.env as Env,
|
||||
) {
|
||||
return await createFrameworkApp(config, args);
|
||||
}
|
||||
|
||||
export function serve<Env = TanstackStartEnv>(
|
||||
{ ...config }: TanstackStartConfig<Env> = {},
|
||||
args: Env = process.env as Env,
|
||||
) {
|
||||
return async (request: Request) => {
|
||||
const app = await getApp(config, args);
|
||||
return app.fetch(request);
|
||||
};
|
||||
}
|
||||
4
bun.lock
4
bun.lock
@@ -3846,7 +3846,7 @@
|
||||
|
||||
"@babel/traverse/debug": ["debug@4.4.0", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA=="],
|
||||
|
||||
"@bknd/plasmic/@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
|
||||
"@bknd/plasmic/@types/bun": ["@types/bun@1.3.9", "", { "dependencies": { "bun-types": "1.3.9" } }, "sha512-KQ571yULOdWJiMH+RIWIOZ7B2RXQGpL1YQrBtLIV3FqDcCu6FsbFUBwhdKUlCKUpS3PJDsHlJ1QKlpxoVR+xtw=="],
|
||||
|
||||
"@bundled-es-modules/tough-cookie/tough-cookie": ["tough-cookie@4.1.4", "", { "dependencies": { "psl": "^1.1.33", "punycode": "^2.1.1", "universalify": "^0.2.0", "url-parse": "^1.5.3" } }, "sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag=="],
|
||||
|
||||
@@ -4750,7 +4750,7 @@
|
||||
|
||||
"@babel/preset-env/babel-plugin-polyfill-regenerator/@babel/helper-define-polyfill-provider": ["@babel/helper-define-polyfill-provider@0.6.3", "", { "dependencies": { "@babel/helper-compilation-targets": "^7.22.6", "@babel/helper-plugin-utils": "^7.22.5", "debug": "^4.1.1", "lodash.debounce": "^4.0.8", "resolve": "^1.14.2" }, "peerDependencies": { "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, "sha512-HK7Bi+Hj6H+VTHA3ZvBis7V/6hu9QuTrnMXNybfUf2iiuU/N97I8VjB+KbhFF8Rld/Lx5MzoCwPCpPjfK+n8Cg=="],
|
||||
|
||||
"@bknd/plasmic/@types/bun/bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
|
||||
"@bknd/plasmic/@types/bun/bun-types": ["bun-types@1.3.9", "", { "dependencies": { "@types/node": "*" } }, "sha512-+UBWWOakIP4Tswh0Bt0QD0alpTY8cb5hvgiYeWCMet9YukHbzuruIEeXC2D7nMJPB12kbh8C7XJykSexEqGKJg=="],
|
||||
|
||||
"@bundled-es-modules/tough-cookie/tough-cookie/universalify": ["universalify@0.2.0", "", {}, "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg=="],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user