@kiln-js/adapter-vercel 0.1.3 → 0.2.0-hotfix
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.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +68 -28
- package/package.json +12 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zxsty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @kiln-js/adapter-vercel
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@kiln-js/adapter-vercel)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Vercel Edge output for the Kiln framework
|
|
7
|
+
|
|
8
|
+
Part of [Kiln](https://github.com/kiln-js/kiln), a file-based server-side rendering framework for React and Vite.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bun add -d @kiln-js/adapter-vercel
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { adaptVercel } from "@kiln-js/adapter-vercel";
|
|
20
|
+
|
|
21
|
+
await adaptVercel({
|
|
22
|
+
root: process.cwd(),
|
|
23
|
+
clientOut: "dist/client",
|
|
24
|
+
serverOut: "dist/server",
|
|
25
|
+
clientRel: "app/client.tsx",
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
Bun at build time, and the Edge runtime only. Edge functions cannot use Node built-ins such as `node:fs`.
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
34
|
+
|
|
35
|
+
See the [Kiln repository](https://github.com/kiln-js/kiln) for the full API reference and guides.
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
This repository is generated from the Kiln monorepo. Make changes there, then run `scripts/publish-repo.ps1` to publish them here. Report issues in this repository, and send pull requests to the monorepo.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
export type Bundler = "bun" | "esbuild";
|
|
1
2
|
export interface VercelAdapterOptions {
|
|
2
3
|
root: string;
|
|
3
4
|
clientOut: string;
|
|
4
5
|
serverOut: string;
|
|
5
6
|
clientRel: string;
|
|
7
|
+
bundler?: Bundler;
|
|
6
8
|
}
|
|
7
9
|
export declare function adaptVercel(opts: VercelAdapterOptions): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
// packages/adapter-vercel/src/index.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { build as esbuild } from "esbuild";
|
|
5
|
+
function readVercelJson(root) {
|
|
6
|
+
const file = path.join(root, "vercel.json");
|
|
7
|
+
if (!fs.existsSync(file)) return {};
|
|
8
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
9
|
+
}
|
|
10
|
+
async function bundleEdge(entry, bundler) {
|
|
11
|
+
const define = { "process.env.NODE_ENV": JSON.stringify("production") };
|
|
12
|
+
if (bundler === "bun") {
|
|
13
|
+
const Bun = globalThis.Bun;
|
|
14
|
+
if (Bun) {
|
|
15
|
+
const result2 = await Bun.build({
|
|
16
|
+
entrypoints: [entry],
|
|
17
|
+
target: "browser",
|
|
18
|
+
format: "esm",
|
|
19
|
+
minify: true,
|
|
20
|
+
define
|
|
21
|
+
});
|
|
22
|
+
if (!result2.success) {
|
|
23
|
+
throw new Error(`Vercel bundle failed:
|
|
24
|
+
${result2.logs.map((l) => l.message).join("\n")}`);
|
|
25
|
+
}
|
|
26
|
+
return result2.outputs[0].text();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const result = await esbuild({
|
|
30
|
+
entryPoints: [entry],
|
|
31
|
+
bundle: true,
|
|
32
|
+
write: false,
|
|
33
|
+
platform: "browser",
|
|
34
|
+
format: "esm",
|
|
35
|
+
target: "es2022",
|
|
36
|
+
jsx: "automatic",
|
|
37
|
+
minify: true,
|
|
38
|
+
define,
|
|
39
|
+
logLevel: "silent"
|
|
40
|
+
});
|
|
41
|
+
return Buffer.from(result.outputFiles[0].contents).toString("utf8");
|
|
42
|
+
}
|
|
5
43
|
async function adaptVercel(opts) {
|
|
44
|
+
const bundler = opts.bundler ?? "esbuild";
|
|
6
45
|
const outRoot = path.join(opts.root, ".vercel", "output");
|
|
7
46
|
const staticDir = path.join(outRoot, "static");
|
|
8
47
|
const funcDir = path.join(outRoot, "functions", "index.func");
|
|
@@ -12,42 +51,43 @@ async function adaptVercel(opts) {
|
|
|
12
51
|
const manifestPath = path.join(opts.clientOut, ".vite", "manifest.json");
|
|
13
52
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
14
53
|
const entry = manifest[opts.clientRel];
|
|
15
|
-
if (!entry)
|
|
16
|
-
throw new Error(`No manifest entry for ${opts.clientRel}`);
|
|
54
|
+
if (!entry) throw new Error(`No manifest entry for ${opts.clientRel}`);
|
|
17
55
|
const assets = {
|
|
18
|
-
head: (entry.css ?? []).map((href) => `<link rel="stylesheet" href="/${href}">`).join(
|
|
19
|
-
`),
|
|
56
|
+
head: (entry.css ?? []).map((href) => `<link rel="stylesheet" href="/${href}">`).join("\n"),
|
|
20
57
|
entry: `/${entry.file}`
|
|
21
58
|
};
|
|
22
59
|
const entryFile = path.join(opts.root, ".kiln", "vercel-entry.ts");
|
|
23
60
|
fs.mkdirSync(path.dirname(entryFile), { recursive: true });
|
|
24
|
-
fs.writeFileSync(
|
|
61
|
+
fs.writeFileSync(
|
|
62
|
+
entryFile,
|
|
63
|
+
`import { createHandler } from ${JSON.stringify(path.join(opts.serverOut, "server.js"))};
|
|
25
64
|
|
|
26
65
|
const handler = createHandler(${JSON.stringify(assets)});
|
|
27
66
|
|
|
28
67
|
export default function edge(request: Request): Promise<Response> {
|
|
29
68
|
return handler(request);
|
|
30
69
|
}
|
|
31
|
-
`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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({
|
|
70
|
+
`
|
|
71
|
+
);
|
|
72
|
+
fs.writeFileSync(path.join(funcDir, "index.js"), await bundleEdge(entryFile, bundler));
|
|
73
|
+
fs.writeFileSync(
|
|
74
|
+
path.join(funcDir, ".vc-config.json"),
|
|
75
|
+
JSON.stringify({ runtime: "edge", entrypoint: "index.js" }, null, 2)
|
|
76
|
+
);
|
|
77
|
+
const custom = readVercelJson(opts.root);
|
|
78
|
+
const config = {
|
|
48
79
|
version: 3,
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
headers: custom.headers ?? [],
|
|
81
|
+
redirects: custom.redirects ?? [],
|
|
82
|
+
routes: [
|
|
83
|
+
{ handle: "filesystem" },
|
|
84
|
+
...(custom.rewrites ?? []).map((r) => ({ src: r.source, dest: r.destination })),
|
|
85
|
+
{ src: "/(.*)", dest: "/index" }
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
if (custom.cleanUrls !== void 0) config.cleanUrls = custom.cleanUrls;
|
|
89
|
+
if (custom.trailingSlash !== void 0) config.trailingSlash = custom.trailingSlash;
|
|
90
|
+
fs.writeFileSync(path.join(outRoot, "config.json"), JSON.stringify(config, null, 2));
|
|
51
91
|
}
|
|
52
92
|
export {
|
|
53
93
|
adaptVercel
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiln-js/adapter-vercel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-hotfix",
|
|
4
|
+
"description": "Vercel Edge output for the Kiln framework",
|
|
5
|
+
"license": "MIT",
|
|
4
6
|
"type": "module",
|
|
5
7
|
"exports": {
|
|
6
8
|
".": {
|
|
@@ -8,13 +10,21 @@
|
|
|
8
10
|
"import": "./dist/index.js"
|
|
9
11
|
}
|
|
10
12
|
},
|
|
13
|
+
"repository": "github:kiln-js/adapter-vercel",
|
|
14
|
+
"homepage": "https://kiln-js.vercel.app",
|
|
11
15
|
"files": [
|
|
12
16
|
"dist"
|
|
13
17
|
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": "\u003e=18"
|
|
20
|
+
},
|
|
14
21
|
"scripts": {
|
|
15
|
-
"build": "
|
|
22
|
+
"build": "node ../../scripts/build.mjs adapter-vercel",
|
|
16
23
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
17
24
|
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"esbuild": "^0.21.5"
|
|
27
|
+
},
|
|
18
28
|
"devDependencies": {
|
|
19
29
|
"@types/node": "^22.0.0"
|
|
20
30
|
}
|