@kiln-js/adapter-vercel 0.1.4 → 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 +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +36 -14
- package/package.json +3 -1
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
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@kiln-js/adapter-vercel)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Vercel Edge output for the Kiln framework
|
|
7
7
|
|
|
8
8
|
Part of [Kiln](https://github.com/kiln-js/kiln), a file-based server-side rendering framework for React and Vite.
|
|
9
9
|
|
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,13 +1,47 @@
|
|
|
1
1
|
// packages/adapter-vercel/src/index.ts
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { build } from "esbuild";
|
|
4
|
+
import { build as esbuild } from "esbuild";
|
|
5
5
|
function readVercelJson(root) {
|
|
6
6
|
const file = path.join(root, "vercel.json");
|
|
7
7
|
if (!fs.existsSync(file)) return {};
|
|
8
8
|
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
9
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
|
+
}
|
|
10
43
|
async function adaptVercel(opts) {
|
|
44
|
+
const bundler = opts.bundler ?? "esbuild";
|
|
11
45
|
const outRoot = path.join(opts.root, ".vercel", "output");
|
|
12
46
|
const staticDir = path.join(outRoot, "static");
|
|
13
47
|
const funcDir = path.join(outRoot, "functions", "index.func");
|
|
@@ -35,19 +69,7 @@ export default function edge(request: Request): Promise<Response> {
|
|
|
35
69
|
}
|
|
36
70
|
`
|
|
37
71
|
);
|
|
38
|
-
|
|
39
|
-
entryPoints: [entryFile],
|
|
40
|
-
bundle: true,
|
|
41
|
-
write: false,
|
|
42
|
-
platform: "browser",
|
|
43
|
-
format: "esm",
|
|
44
|
-
target: "es2022",
|
|
45
|
-
jsx: "automatic",
|
|
46
|
-
minify: true,
|
|
47
|
-
define: { "process.env.NODE_ENV": '"production"' },
|
|
48
|
-
logLevel: "silent"
|
|
49
|
-
});
|
|
50
|
-
fs.writeFileSync(path.join(funcDir, "index.js"), result.outputFiles[0].contents);
|
|
72
|
+
fs.writeFileSync(path.join(funcDir, "index.js"), await bundleEdge(entryFile, bundler));
|
|
51
73
|
fs.writeFileSync(
|
|
52
74
|
path.join(funcDir, ".vc-config.json"),
|
|
53
75
|
JSON.stringify({ runtime: "edge", entrypoint: "index.js" }, null, 2)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiln-js/adapter-vercel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-hotfix",
|
|
4
4
|
"description": "Vercel Edge output for the Kiln framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"import": "./dist/index.js"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
+
"repository": "github:kiln-js/adapter-vercel",
|
|
14
|
+
"homepage": "https://kiln-js.vercel.app",
|
|
13
15
|
"files": [
|
|
14
16
|
"dist"
|
|
15
17
|
],
|