@guren/plugin-vercel 0.4.0 → 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.
Files changed (2) hide show
  1. package/dist/index.js +48 -8
  2. 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 { DEV_ONLY_MODULES, MCP_SDK_SUBPATH_PREFIX, assertOutputDirOutsideRoot, clientManifestJson, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, unusedSqlClients } from "@guren/core/internal/deploy-build";
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));
@@ -75,6 +81,22 @@ async function buildVercelOutput(options = {}) {
75
81
  if (existsSync(docsDir)) cpSync(docsDir, resolve(funcDir, "docs"), { recursive: true });
76
82
  if (existsSync(publicDir)) cpSync(publicDir, resolve(out, "static"), { recursive: true });
77
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
+ }
78
100
  const MCP_UNAVAILABLE = "The MCP endpoint is unavailable on Vercel — it generates files on disk, and the function filesystem is read-only.";
79
101
  /**
80
102
  * Why each dev-only module cannot run here, or `null` for one that can and is
@@ -109,9 +131,15 @@ const UNAVAILABLE_ON_VERCEL = {
109
131
  * - The database clients for dialects the app does not use, decided per app
110
132
  * rather than per platform — the ones it *does* use are load-bearing here,
111
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`.
112
140
  */
113
- function stubbedModules(root, dialects) {
114
- const devOnly = DEV_ONLY_MODULES.flatMap((module) => {
141
+ function stubbedModules(root, dialects, mcpPlugin) {
142
+ const devOnly = stubbableDevOnlyModules({ mcpPlugin }).flatMap((module) => {
115
143
  const message = UNAVAILABLE_ON_VERCEL[module.kind];
116
144
  return message === null ? [] : [[module.specifier, renderDevOnlyStub(module, message)]];
117
145
  });
@@ -128,8 +156,22 @@ function stubbedModules(root, dialects) {
128
156
  * rather than resolving to an empty module: a subpath reached from app code
129
157
  * (not Guren's disabled MCP endpoint) must fail loudly at build or cold start,
130
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.
131
165
  */
132
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
+ }
133
175
  /**
134
176
  * Bundle the function with Bun's JS API rather than by spawning `bun build`.
135
177
  *
@@ -138,8 +180,9 @@ const unlistedMcpStub = `throw new Error(${JSON.stringify(MCP_UNAVAILABLE)})\n`;
138
180
  * all while the other two did. The API takes plugins.
139
181
  */
140
182
  async function bundleFunction(input) {
141
- const stubs = stubbedModules(input.root, input.dialects);
142
- const filter = new RegExp(`^(?:${[...Object.keys(stubs).map(escapeRegExp), `${escapeRegExp(MCP_SDK_SUBPATH_PREFIX)}.+`].join("|")})$`);
183
+ const mcpPlugin = appUsesMcpPlugin(input.root);
184
+ const stubs = stubbedModules(input.root, input.dialects, mcpPlugin);
185
+ const filter = stubFilter(stubs, mcpPlugin);
143
186
  const result = await Bun.build({
144
187
  entrypoints: [input.entrypoint],
145
188
  throw: false,
@@ -173,9 +216,6 @@ async function bundleFunction(input) {
173
216
  });
174
217
  if (!result.success) throw new Error(`${LABEL}: bun build failed.\n${result.logs.map((log) => String(log)).join("\n")}`);
175
218
  }
176
- function escapeRegExp(value) {
177
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
178
- }
179
219
  function buildVercelEnvironment(publicDir, ssrDir) {
180
220
  const env = {
181
221
  NODE_ENV: "production",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/plugin-vercel",
3
- "version": "0.4.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.10.0"
38
+ "@guren/core": "^1.13.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^20.14.10",