@guren/plugin-vercel 0.3.1 → 0.5.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.
- package/dist/index.js +54 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cpSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { basename, extname, resolve } from "node:path";
|
|
3
3
|
import { definePlugin } from "@guren/core";
|
|
4
|
-
import {
|
|
4
|
+
import { DOCUMENT_ASSET_EXTENSIONS, DOCUMENT_ASSET_HEADERS, MCP_SDK_SUBPATH_PREFIX, appUsesMcpPlugin, assertOutputDirOutsideRoot, clientManifestJson, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stubbableDevOnlyModules, unusedSqlClients } from "@guren/core/internal/deploy-build";
|
|
5
5
|
//#region src/index.ts
|
|
6
6
|
/** Prefixes every diagnostic this build emits. */
|
|
7
7
|
const LABEL = "Vercel build";
|
|
@@ -53,6 +53,12 @@ async function buildVercelOutput(options = {}) {
|
|
|
53
53
|
{
|
|
54
54
|
src: "/(.*)",
|
|
55
55
|
dest: "/index"
|
|
56
|
+
},
|
|
57
|
+
{ handle: "hit" },
|
|
58
|
+
{
|
|
59
|
+
src: documentAssetPattern(),
|
|
60
|
+
headers: { ...DOCUMENT_ASSET_HEADERS },
|
|
61
|
+
continue: true
|
|
56
62
|
}
|
|
57
63
|
]
|
|
58
64
|
}, null, 2));
|
|
@@ -67,13 +73,30 @@ async function buildVercelOutput(options = {}) {
|
|
|
67
73
|
entrypoint,
|
|
68
74
|
funcDir,
|
|
69
75
|
root,
|
|
70
|
-
dialects: options.databaseDialects
|
|
76
|
+
dialects: options.databaseDialects,
|
|
77
|
+
viteManifest: clientManifestJson(publicDir)
|
|
71
78
|
});
|
|
72
79
|
if (existsSync(ssrDir)) cpSync(ssrDir, resolve(funcDir, ".guren/ssr"), { recursive: true });
|
|
73
80
|
if (existsSync(migrationsDir)) cpSync(migrationsDir, resolve(funcDir, "db/migrations"), { recursive: true });
|
|
74
81
|
if (existsSync(docsDir)) cpSync(docsDir, resolve(funcDir, "docs"), { recursive: true });
|
|
75
82
|
if (existsSync(publicDir)) cpSync(publicDir, resolve(out, "static"), { recursive: true });
|
|
76
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Matches a staged path whose extension a browser would render as a document.
|
|
86
|
+
*
|
|
87
|
+
* The CDN serves `.vercel/output/static` ahead of the function, so the
|
|
88
|
+
* framework's own guard never sees these files. This is the same policy
|
|
89
|
+
* expressed in the one place that still reaches them.
|
|
90
|
+
*
|
|
91
|
+
* Spelled with a character class per letter because Vercel compiles `src`
|
|
92
|
+
* case-sensitively: a plain extension would leave logo.SVG inline, while the
|
|
93
|
+
* framework guard lowercases before its mime lookup and catches it. An inline
|
|
94
|
+
* case-insensitive flag is not an option, because `src` is validated by
|
|
95
|
+
* constructing a JavaScript `RegExp` from it.
|
|
96
|
+
*/
|
|
97
|
+
function documentAssetPattern() {
|
|
98
|
+
return `^/.*\\.(?:${DOCUMENT_ASSET_EXTENSIONS.map((extension) => [...extension].map((character) => `[${character}${character.toUpperCase()}]`).join("")).join("|")})$`;
|
|
99
|
+
}
|
|
77
100
|
const MCP_UNAVAILABLE = "The MCP endpoint is unavailable on Vercel — it generates files on disk, and the function filesystem is read-only.";
|
|
78
101
|
/**
|
|
79
102
|
* Why each dev-only module cannot run here, or `null` for one that can and is
|
|
@@ -108,9 +131,15 @@ const UNAVAILABLE_ON_VERCEL = {
|
|
|
108
131
|
* - The database clients for dialects the app does not use, decided per app
|
|
109
132
|
* rather than per platform — the ones it *does* use are load-bearing here,
|
|
110
133
|
* unlike on Workers where D1 is the only database.
|
|
134
|
+
*
|
|
135
|
+
* The dev-only set is per app in one respect too: an app declaring
|
|
136
|
+
* `@guren/plugin-mcp` serves the App MCP endpoint from this function, so its
|
|
137
|
+
* transport must reach the bundle (RFC 0016 §7). The *Dev* MCP's `McpServer`
|
|
138
|
+
* and the CLI behind it stay stubbed regardless — see
|
|
139
|
+
* `stubbableDevOnlyModules`.
|
|
111
140
|
*/
|
|
112
|
-
function stubbedModules(root, dialects) {
|
|
113
|
-
const devOnly =
|
|
141
|
+
function stubbedModules(root, dialects, mcpPlugin) {
|
|
142
|
+
const devOnly = stubbableDevOnlyModules({ mcpPlugin }).flatMap((module) => {
|
|
114
143
|
const message = UNAVAILABLE_ON_VERCEL[module.kind];
|
|
115
144
|
return message === null ? [] : [[module.specifier, renderDevOnlyStub(module, message)]];
|
|
116
145
|
});
|
|
@@ -127,8 +156,22 @@ function stubbedModules(root, dialects) {
|
|
|
127
156
|
* rather than resolving to an empty module: a subpath reached from app code
|
|
128
157
|
* (not Guren's disabled MCP endpoint) must fail loudly at build or cold start,
|
|
129
158
|
* never silently hand back missing exports.
|
|
159
|
+
*
|
|
160
|
+
* Reachable only for an app that does *not* declare `@guren/plugin-mcp`. For
|
|
161
|
+
* one that does, the SDK is a dependency it deliberately ships, and this
|
|
162
|
+
* fallback would stub `server/index.js` and `types.js` — which
|
|
163
|
+
* `@guren/plugin-mcp` imports statically — leaving the endpoint just as
|
|
164
|
+
* compiled shut as the transport stub did.
|
|
130
165
|
*/
|
|
131
166
|
const unlistedMcpStub = `throw new Error(${JSON.stringify(MCP_UNAVAILABLE)})\n`;
|
|
167
|
+
function escapeRegExp(value) {
|
|
168
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
169
|
+
}
|
|
170
|
+
function stubFilter(stubs, mcpPlugin) {
|
|
171
|
+
const terms = Object.keys(stubs).map(escapeRegExp);
|
|
172
|
+
if (!mcpPlugin) terms.push(`${escapeRegExp(MCP_SDK_SUBPATH_PREFIX)}.+`);
|
|
173
|
+
return new RegExp(`^(?:${terms.join("|")})$`);
|
|
174
|
+
}
|
|
132
175
|
/**
|
|
133
176
|
* Bundle the function with Bun's JS API rather than by spawning `bun build`.
|
|
134
177
|
*
|
|
@@ -137,8 +180,9 @@ const unlistedMcpStub = `throw new Error(${JSON.stringify(MCP_UNAVAILABLE)})\n`;
|
|
|
137
180
|
* all while the other two did. The API takes plugins.
|
|
138
181
|
*/
|
|
139
182
|
async function bundleFunction(input) {
|
|
140
|
-
const
|
|
141
|
-
const
|
|
183
|
+
const mcpPlugin = appUsesMcpPlugin(input.root);
|
|
184
|
+
const stubs = stubbedModules(input.root, input.dialects, mcpPlugin);
|
|
185
|
+
const filter = stubFilter(stubs, mcpPlugin);
|
|
142
186
|
const result = await Bun.build({
|
|
143
187
|
entrypoints: [input.entrypoint],
|
|
144
188
|
throw: false,
|
|
@@ -149,7 +193,10 @@ async function bundleFunction(input) {
|
|
|
149
193
|
syntax: true,
|
|
150
194
|
identifiers: false
|
|
151
195
|
},
|
|
152
|
-
define: {
|
|
196
|
+
define: {
|
|
197
|
+
"process.env.NODE_ENV": "\"production\"",
|
|
198
|
+
...input.viteManifest ? { "process.env.GUREN_VITE_MANIFEST": JSON.stringify(input.viteManifest) } : {}
|
|
199
|
+
},
|
|
153
200
|
plugins: [{
|
|
154
201
|
name: "guren-vercel-stubs",
|
|
155
202
|
setup(build) {
|
|
@@ -169,9 +216,6 @@ async function bundleFunction(input) {
|
|
|
169
216
|
});
|
|
170
217
|
if (!result.success) throw new Error(`${LABEL}: bun build failed.\n${result.logs.map((log) => String(log)).join("\n")}`);
|
|
171
218
|
}
|
|
172
|
-
function escapeRegExp(value) {
|
|
173
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
174
|
-
}
|
|
175
219
|
function buildVercelEnvironment(publicDir, ssrDir) {
|
|
176
220
|
const env = {
|
|
177
221
|
NODE_ENV: "production",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-vercel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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.13.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^20.14.10",
|