@guren/plugin-vercel 0.2.0 → 0.2.1
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/README.md +44 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -44
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @guren/plugin-vercel
|
|
2
|
+
|
|
3
|
+
Deploy a [Guren](https://guren.dev/) SSR application to Vercel. The plugin assembles a [Build Output API v3](https://vercel.com/docs/build-output-api/v3) directory that runs on Vercel's Bun runtime.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bunx guren plugin @guren/plugin-vercel
|
|
7
|
+
bun add @guren/plugin-vercel
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Installing scaffolds `src/vercel.ts`, `scripts/vercel-build.ts`, and `vercel.json`.
|
|
11
|
+
|
|
12
|
+
## Build and deploy
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
bun run vercel:build
|
|
16
|
+
vercel deploy --prebuilt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## API
|
|
20
|
+
|
|
21
|
+
- **`createVercelHandler(app)`** — boots a Guren `Application` and returns a `fetch` handler for the serverless function.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// src/vercel.ts
|
|
25
|
+
import app from './app.js'
|
|
26
|
+
import { createVercelHandler } from '@guren/plugin-vercel'
|
|
27
|
+
|
|
28
|
+
export default await createVercelHandler(app)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- **`buildVercelOutput(options)`** — assembles `.vercel/output`: the bundled function, static assets, and the routing config. Reads the Vite manifests to inject the correct `GUREN_INERTIA_*` environment variables into the function.
|
|
32
|
+
- **`vercelPlugin()`** — the service provider factory, registered automatically by `guren plugin`.
|
|
33
|
+
|
|
34
|
+
## Notes
|
|
35
|
+
|
|
36
|
+
- **SSR apps only.** The plugin reads Vite manifests to wire the Inertia SSR bundle. API-only apps should use Docker or Lambda instead.
|
|
37
|
+
- **SSR bundles must be self-contained.** Function directories ship without `node_modules`, so externalized `react`/`@inertiajs/react` imports fail at runtime and Inertia silently falls back to client-side rendering. The Guren Vite plugin defaults `ssr.noExternal: true` for SSR builds — leave it alone unless you know the target has those packages installed.
|
|
38
|
+
- **`NODE_ENV` is inlined at bundle time.** `bun build` bakes in `"development"` unless told otherwise, and a runtime `NODE_ENV=production` cannot override it. This plugin passes the right `--define` for you.
|
|
39
|
+
|
|
40
|
+
See the [deployment guide](https://guren.dev/docs/guides/deployment) for the full setup.
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { cpSync, existsSync, mkdirSync,
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
3
|
import { basename, extname, resolve } from "path";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
4
|
import { definePlugin } from "@guren/core";
|
|
5
|
+
import {
|
|
6
|
+
assertOutputDirOutsideRoot,
|
|
7
|
+
resetOutputDir,
|
|
8
|
+
resolveClientAssetEnv,
|
|
9
|
+
resolvePathLike,
|
|
10
|
+
resolveSsrEntryFile,
|
|
11
|
+
ssrRuntimePaths
|
|
12
|
+
} from "@guren/core/internal/deploy-build";
|
|
13
|
+
var LABEL = "Vercel build";
|
|
6
14
|
var factory = definePlugin({
|
|
7
15
|
name: "vercel",
|
|
8
16
|
register() {
|
|
@@ -29,12 +37,16 @@ function buildVercelOutput(options = {}) {
|
|
|
29
37
|
const docsDir = resolvePathLike(options.docsDir ?? resolveNearestDocsDir(root) ?? resolve(root, "docs"));
|
|
30
38
|
const ssrDir = resolvePathLike(options.ssrDir ?? resolve(root, ".guren/ssr"));
|
|
31
39
|
const migrationsDir = resolvePathLike(options.migrationsDir ?? resolve(root, "db/migrations"));
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
assertOutputDirOutsideRoot(out, root, LABEL);
|
|
41
|
+
if (!existsSync(entrypoint)) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`${LABEL}: entrypoint not found at ${entrypoint}. Run \`bunx guren plugin @guren/plugin-vercel\` to scaffold src/vercel.ts, or pass "entrypoint".`
|
|
44
|
+
);
|
|
34
45
|
}
|
|
46
|
+
const env = buildVercelEnvironment(publicDir, ssrDir);
|
|
47
|
+
resetOutputDir(out, root, LABEL);
|
|
35
48
|
mkdirSync(funcDir, { recursive: true });
|
|
36
49
|
mkdirSync(resolve(out, "static"), { recursive: true });
|
|
37
|
-
const env = buildVercelEnvironment(root);
|
|
38
50
|
writeFileSync(
|
|
39
51
|
resolve(out, "config.json"),
|
|
40
52
|
JSON.stringify(
|
|
@@ -76,6 +88,16 @@ function buildVercelOutput(options = {}) {
|
|
|
76
88
|
const result = Bun.spawnSync({
|
|
77
89
|
// `bun build` inlines `process.env.NODE_ENV` at bundle time (defaulting to
|
|
78
90
|
// "development"), so pin it to "production" for the deployed function.
|
|
91
|
+
//
|
|
92
|
+
// Whitespace and syntax only — never plain `--minify`, which also mangles
|
|
93
|
+
// identifiers. Guren keys durable records on class names: the queue
|
|
94
|
+
// registry stores each job's wire name (its class name unless it declares a
|
|
95
|
+
// jobName) in every queued message, and notifications persist
|
|
96
|
+
// `constructor.name` as their `type`. Mangled, a job dispatched by one
|
|
97
|
+
// deploy resolves to nothing after the next.
|
|
98
|
+
//
|
|
99
|
+
// Not `--keep-names`: as of Bun 1.3.14 it is accepted and silently leaves
|
|
100
|
+
// class names mangled, so it cannot replace this.
|
|
79
101
|
cmd: [
|
|
80
102
|
"bun",
|
|
81
103
|
"build",
|
|
@@ -84,7 +106,8 @@ function buildVercelOutput(options = {}) {
|
|
|
84
106
|
funcDir,
|
|
85
107
|
"--target",
|
|
86
108
|
"bun",
|
|
87
|
-
"--minify",
|
|
109
|
+
"--minify-whitespace",
|
|
110
|
+
"--minify-syntax",
|
|
88
111
|
"--define",
|
|
89
112
|
'process.env.NODE_ENV="production"'
|
|
90
113
|
],
|
|
@@ -108,45 +131,33 @@ function buildVercelOutput(options = {}) {
|
|
|
108
131
|
cpSync(publicDir, resolve(out, "static"), { recursive: true });
|
|
109
132
|
}
|
|
110
133
|
}
|
|
111
|
-
function buildVercelEnvironment(
|
|
134
|
+
function buildVercelEnvironment(publicDir, ssrDir) {
|
|
112
135
|
const env = {
|
|
113
136
|
NODE_ENV: "production",
|
|
114
137
|
BUN_RUNTIME_TRANSPILER_CACHE_PATH: "/tmp/.bun-cache",
|
|
115
138
|
BUN_INSTALL_CACHE_DIR: "/tmp/.bun-install-cache",
|
|
116
139
|
TMPDIR: "/tmp"
|
|
117
140
|
};
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
);
|
|
122
|
-
if (clientManifest) {
|
|
123
|
-
const entry = clientManifest["resources/js/app.tsx"];
|
|
124
|
-
if (entry?.file) {
|
|
125
|
-
env.GUREN_INERTIA_ENTRY = `/assets/${entry.file}`;
|
|
126
|
-
}
|
|
127
|
-
if (entry?.css?.length) {
|
|
128
|
-
env.GUREN_INERTIA_STYLES = entry.css.map((file) => `/assets/${file}`).join(",");
|
|
129
|
-
}
|
|
141
|
+
const assetEnv = resolveClientAssetEnv(publicDir, "resources/js/app.tsx", LABEL);
|
|
142
|
+
if (assetEnv.entry) {
|
|
143
|
+
env.GUREN_INERTIA_ENTRY = assetEnv.entry;
|
|
130
144
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
);
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
if (assetEnv.styles) {
|
|
146
|
+
env.GUREN_INERTIA_STYLES = assetEnv.styles;
|
|
147
|
+
}
|
|
148
|
+
const ssrFile = resolveSsrEntryFile(ssrDir, "resources/js/ssr.tsx", LABEL);
|
|
149
|
+
if (ssrFile) {
|
|
150
|
+
const ssrPaths = ssrRuntimePaths(ssrDir, ssrFile, "./.guren/ssr");
|
|
151
|
+
env.GUREN_INERTIA_SSR_ENTRY = ssrPaths.entry;
|
|
152
|
+
if (ssrPaths.manifest) {
|
|
153
|
+
env.GUREN_INERTIA_SSR_MANIFEST = ssrPaths.manifest;
|
|
139
154
|
}
|
|
140
|
-
env.GUREN_INERTIA_SSR_MANIFEST = "./.guren/ssr/.vite/manifest.json";
|
|
141
155
|
}
|
|
142
156
|
env.GUREN_INERTIA_IMPORT_MAP = JSON.stringify({
|
|
143
157
|
"@guren/inertia-client": "/vendor/inertia-client.tsx"
|
|
144
158
|
});
|
|
145
159
|
return env;
|
|
146
160
|
}
|
|
147
|
-
function resolvePathLike(value) {
|
|
148
|
-
return value instanceof URL ? fileURLToPath(value) : resolve(String(value));
|
|
149
|
-
}
|
|
150
161
|
function resolveNearestDocsDir(startDir, maxDepth = 6) {
|
|
151
162
|
let currentDir = startDir;
|
|
152
163
|
for (let depth = 0; depth < maxDepth; depth += 1) {
|
|
@@ -162,19 +173,6 @@ function resolveNearestDocsDir(startDir, maxDepth = 6) {
|
|
|
162
173
|
}
|
|
163
174
|
return void 0;
|
|
164
175
|
}
|
|
165
|
-
function loadManifest(...paths) {
|
|
166
|
-
for (const path of paths) {
|
|
167
|
-
if (!existsSync(path)) {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
try {
|
|
171
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
172
|
-
} catch {
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return void 0;
|
|
177
|
-
}
|
|
178
176
|
export {
|
|
179
177
|
buildVercelOutput,
|
|
180
178
|
createVercelHandler,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-vercel",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"typecheck": "tsc --noEmit"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@guren/core": "^1.
|
|
38
|
+
"@guren/core": "^1.4.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^20.14.10",
|