@guren/plugin-vercel 0.5.0 → 0.6.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/README.md CHANGED
@@ -16,6 +16,8 @@ bun run vercel:build
16
16
  vercel deploy --prebuilt
17
17
  ```
18
18
 
19
+ Before writing any output, `vercel:build` runs the deploy-runtime checks `guren doctor` reports and warns, without failing, on an in-memory session or OAuth store, a `ScryptHasher`, or filesystem provider discovery — each works locally and breaks across function invocations.
20
+
19
21
  ## API
20
22
 
21
23
  - **`createVercelHandler(app)`** — boots a Guren `Application` and returns a `fetch` handler for the serverless function.
package/dist/index.d.ts CHANGED
@@ -29,14 +29,7 @@ interface BuildVercelOutputOptions {
29
29
  * fields never force another registration-shape change.
30
30
  */
31
31
  interface VercelPluginConfig {}
32
- /**
33
- * Register the Vercel plugin.
34
- *
35
- * @example
36
- * ```typescript
37
- * createApp({ providers: [vercelPlugin()] })
38
- * ```
39
- */
32
+ /** Register the Vercel plugin. */
40
33
  declare function vercelPlugin(config?: VercelPluginConfig): ServiceProviderConstructor;
41
34
  declare function createVercelHandler(app: VercelAppLike): Promise<VercelHandler>;
42
35
  declare function buildVercelOutput(options?: BuildVercelOutputOptions): Promise<void>;
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
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 { 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";
4
+ import { DOCUMENT_ASSET_EXTENSIONS, DOCUMENT_ASSET_HEADERS, MCP_SDK_SUBPATH_PREFIX, appUsesMcpPlugin, assertOutputDirOutsideRoot, clientManifestJson, removeShadowingIndex, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stubbableDevOnlyModules, unusedSqlClients } from "@guren/core/internal/deploy-build";
5
+ import { reportDeployRuntimeHazards } from "@guren/core/internal/deploy-check";
5
6
  //#region src/index.ts
6
7
  /** Prefixes every diagnostic this build emits. */
7
8
  const LABEL = "Vercel build";
@@ -9,14 +10,7 @@ const factory = definePlugin({
9
10
  name: "vercel",
10
11
  register() {}
11
12
  });
12
- /**
13
- * Register the Vercel plugin.
14
- *
15
- * @example
16
- * ```typescript
17
- * createApp({ providers: [vercelPlugin()] })
18
- * ```
19
- */
13
+ /** Register the Vercel plugin. */
20
14
  function vercelPlugin(config = {}) {
21
15
  return factory(config);
22
16
  }
@@ -38,6 +32,10 @@ async function buildVercelOutput(options = {}) {
38
32
  const migrationsDir = resolvePathLike(options.migrationsDir ?? resolve(root, "db/migrations"));
39
33
  assertOutputDirOutsideRoot(out, root, LABEL);
40
34
  if (!existsSync(entrypoint)) throw new Error(`${LABEL}: entrypoint not found at ${entrypoint}. Run \`bunx guren plugin @guren/plugin-vercel\` to scaffold src/vercel.ts, or pass "entrypoint".`);
35
+ await reportDeployRuntimeHazards({
36
+ root,
37
+ label: LABEL
38
+ });
41
39
  const env = buildVercelEnvironment(publicDir, ssrDir);
42
40
  resetOutputDir(out, root, LABEL);
43
41
  mkdirSync(funcDir, { recursive: true });
@@ -79,38 +77,28 @@ async function buildVercelOutput(options = {}) {
79
77
  if (existsSync(ssrDir)) cpSync(ssrDir, resolve(funcDir, ".guren/ssr"), { recursive: true });
80
78
  if (existsSync(migrationsDir)) cpSync(migrationsDir, resolve(funcDir, "db/migrations"), { recursive: true });
81
79
  if (existsSync(docsDir)) cpSync(docsDir, resolve(funcDir, "docs"), { recursive: true });
82
- if (existsSync(publicDir)) cpSync(publicDir, resolve(out, "static"), { recursive: true });
80
+ if (existsSync(publicDir)) {
81
+ cpSync(publicDir, resolve(out, "static"), { recursive: true });
82
+ removeShadowingIndex(resolve(out, "static"));
83
+ }
83
84
  }
84
85
  /**
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.
86
+ * Matches a staged path whose extension a browser would render as a document;
87
+ * the CDN serves `.vercel/output/static` ahead of the function, so the
88
+ * framework's own guard never sees these files. A character class per letter
89
+ * because Vercel compiles `src` case-sensitively (a plain extension leaves
90
+ * logo.SVG inline) and validates it as a JavaScript `RegExp`, so no inline flag.
96
91
  */
97
92
  function documentAssetPattern() {
98
93
  return `^/.*\\.(?:${DOCUMENT_ASSET_EXTENSIONS.map((extension) => [...extension].map((character) => `[${character}${character.toUpperCase()}]`).join("")).join("|")})$`;
99
94
  }
100
95
  const MCP_UNAVAILABLE = "The MCP endpoint is unavailable on Vercel — it generates files on disk, and the function filesystem is read-only.";
101
96
  /**
102
- * Why each dev-only module cannot run here, or `null` for one that can and is
103
- * therefore left alone.
104
- *
105
- * `sqlite` is the `null`, and it is written as an entry rather than filtered
106
- * out somewhere else so the decision sits where the reason does: the function
107
- * runs on Vercel's Bun runtime, so `bun:sqlite` is a working database here —
108
- * unlike on Workers and Lambda, whose tables name a replacement for it.
109
- * Stubbing it would break an app that ships a read-only sqlite file beside
110
- * its function.
111
- *
112
- * Keyed on every kind `DEV_ONLY_MODULES` contains, so a kind added there is a
113
- * compile error here rather than a module that silently stubs to `undefined`.
97
+ * Why each dev-only module cannot run here, or `null` for one that can. `sqlite`
98
+ * is the `null`: the function runs on Vercel's Bun runtime, so `bun:sqlite` works
99
+ * and stubbing it would break an app shipping a read-only sqlite file beside its
100
+ * function. Keyed on every kind `DEV_ONLY_MODULES` contains, so a kind added
101
+ * there is a compile error here.
114
102
  */
115
103
  const UNAVAILABLE_ON_VERCEL = {
116
104
  sqlite: null,
@@ -118,25 +106,11 @@ const UNAVAILABLE_ON_VERCEL = {
118
106
  mcp: MCP_UNAVAILABLE
119
107
  };
120
108
  /**
121
- * Modules replaced with throwing stubs, in the order they are matched.
122
- *
123
- * Two separate reasons, both of them the same defect shape — a *literal*
124
- * dynamic import of a package the app never installed, which a bundler
125
- * follows whether or not the branch can be taken:
126
- *
127
- * - The dev-only ones. A scaffolded app could not be bundled for Vercel at
128
- * all: the disabled MCP endpoint's `import("@guren/cli")` resolves, and the
129
- * CLI's own `import("@guren/openapi")` behind it does not. Lambda never saw
130
- * this because it has stubbed these since it shipped.
131
- * - The database clients for dialects the app does not use, decided per app
132
- * rather than per platform — the ones it *does* use are load-bearing here,
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`.
109
+ * Modules replaced with throwing stubs, in match order. One defect shape — a
110
+ * *literal* dynamic import of a package the app never installed, followed by a
111
+ * bundler regardless of branch: dev-only modules, and SQL clients of unused
112
+ * dialects. An app declaring `@guren/plugin-mcp` serves the App MCP endpoint here,
113
+ * so its transport must reach the bundle (RFC 0016 §7); the *Dev* MCP stays stubbed.
140
114
  */
141
115
  function stubbedModules(root, dialects, mcpPlugin) {
142
116
  const devOnly = stubbableDevOnlyModules({ mcpPlugin }).flatMap((module) => {
@@ -152,16 +126,10 @@ function stubbedModules(root, dialects, mcpPlugin) {
152
126
  }
153
127
  /**
154
128
  * Fallback for an MCP SDK subpath `DEV_ONLY_MODULES` does not name. It cannot
155
- * know which names the importer destructures, so it throws on evaluation
156
- * rather than resolving to an empty module: a subpath reached from app code
157
- * (not Guren's disabled MCP endpoint) must fail loudly at build or cold start,
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.
129
+ * know which names the importer destructures, so it throws on evaluation rather
130
+ * than resolving to an empty module. Reachable only for an app that does *not*
131
+ * declare `@guren/plugin-mcp`, whose statically imported `server/index.js` and
132
+ * `types.js` this would otherwise leave compiled shut.
165
133
  */
166
134
  const unlistedMcpStub = `throw new Error(${JSON.stringify(MCP_UNAVAILABLE)})\n`;
167
135
  function escapeRegExp(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/plugin-vercel",
3
- "version": "0.5.0",
3
+ "version": "0.6.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.13.0"
38
+ "@guren/core": "^1.15.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^20.14.10",