@kiln-js/adapter-vercel 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ export interface VercelAdapterOptions {
2
+ root: string;
3
+ clientOut: string;
4
+ serverOut: string;
5
+ clientRel: string;
6
+ }
7
+ export declare function adaptVercel(opts: VercelAdapterOptions): Promise<void>;
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ // @bun
2
+ // src/index.ts
3
+ import fs from "fs";
4
+ import path from "path";
5
+ async function adaptVercel(opts) {
6
+ const outRoot = path.join(opts.root, ".vercel", "output");
7
+ const staticDir = path.join(outRoot, "static");
8
+ const funcDir = path.join(outRoot, "functions", "index.func");
9
+ fs.rmSync(outRoot, { recursive: true, force: true });
10
+ fs.mkdirSync(funcDir, { recursive: true });
11
+ fs.cpSync(opts.clientOut, staticDir, { recursive: true });
12
+ const manifestPath = path.join(opts.clientOut, ".vite", "manifest.json");
13
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
14
+ const entry = manifest[opts.clientRel];
15
+ if (!entry)
16
+ throw new Error(`No manifest entry for ${opts.clientRel}`);
17
+ const assets = {
18
+ head: (entry.css ?? []).map((href) => `<link rel="stylesheet" href="/${href}">`).join(`
19
+ `),
20
+ entry: `/${entry.file}`
21
+ };
22
+ const entryFile = path.join(opts.root, ".kiln", "vercel-entry.ts");
23
+ fs.mkdirSync(path.dirname(entryFile), { recursive: true });
24
+ fs.writeFileSync(entryFile, `import { createHandler } from ${JSON.stringify(path.join(opts.serverOut, "server.js"))};
25
+
26
+ const handler = createHandler(${JSON.stringify(assets)});
27
+
28
+ export default function edge(request: Request): Promise<Response> {
29
+ return handler(request);
30
+ }
31
+ `);
32
+ const result = await Bun.build({
33
+ entrypoints: [entryFile],
34
+ target: "browser",
35
+ format: "esm",
36
+ minify: true,
37
+ define: { "process.env.NODE_ENV": JSON.stringify("production") }
38
+ });
39
+ if (!result.success) {
40
+ const msg = result.logs.map((l) => l.message).join(`
41
+ `);
42
+ throw new Error(`Vercel bundle failed:
43
+ ${msg}`);
44
+ }
45
+ fs.writeFileSync(path.join(funcDir, "index.js"), await result.outputs[0].text());
46
+ fs.writeFileSync(path.join(funcDir, ".vc-config.json"), JSON.stringify({ runtime: "edge", entrypoint: "index.js" }, null, 2));
47
+ fs.writeFileSync(path.join(outRoot, "config.json"), JSON.stringify({
48
+ version: 3,
49
+ routes: [{ handle: "filesystem" }, { src: "/(.*)", dest: "/index" }]
50
+ }, null, 2));
51
+ }
52
+ export {
53
+ adaptVercel
54
+ };
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
- {
2
- "name": "@kiln-js/adapter-vercel",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
1
+ {
2
+ "name": "@kiln-js/adapter-vercel",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ }
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "scripts": {
15
+ "build": "bun build ./src/index.ts --outdir ./dist --target bun --packages external \u0026\u0026 tsc -p tsconfig.json --emitDeclarationOnly",
16
+ "typecheck": "tsc -p tsconfig.json --noEmit"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^22.0.0"
20
+ }
6
21
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.