@guren/plugin-cloudflare 0.10.0 → 0.11.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
|
@@ -18,7 +18,7 @@ bunx wrangler deploy
|
|
|
18
18
|
|
|
19
19
|
`cloudflare:build` runs your app's `build` script, then assembles a `.cloudflare/` directory containing the worker entry, static assets for Workers Static Assets, and flattened D1 migrations. It is generated output — add it to `.gitignore` and rebuild before every deploy.
|
|
20
20
|
|
|
21
|
-
Before the app build it runs the deploy-runtime checks `guren doctor` reports and warns, without failing, when sessions or OAuth state would sit in process memory, a `
|
|
21
|
+
Before the app build it runs the deploy-runtime checks `guren doctor` reports and warns, without failing, when sessions or OAuth state would sit in process memory, a Bun-only password hasher (`Argon2Hasher`, `hasher: 'argon2'`, or `new Hash({ algorithm: 'argon2' })`) is selected, or providers are discovered from the filesystem. Each works locally and breaks on Workers, and the warning prints where you are still reading rather than after the Vite output.
|
|
22
22
|
|
|
23
23
|
`bunx guren cloudflare:size` (or `cloudflare:build --report-size`) measures the bundle a deploy would upload through wrangler's dry run and lists its largest sources by package. The platform limit is 64 MiB uncompressed on every plan; the report warns from half of it.
|
|
24
24
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
import { AGENTS_CONFIG_FILE, DATABASE_FACTORIES, DEV_ONLY_MODULES, DOCUMENT_ASSET_EXTENSIONS, DOCUMENT_ASSET_HEADERS, MCP_PLUGIN_PACKAGE, MCP_TRANSPORT_SPECIFIER, SQL_CLIENT_MODULES, appUsesMcpPlugin, assertOutputDirOutsideRoot,
|
|
4
|
+
import { AGENTS_CONFIG_FILE, DATABASE_FACTORIES, DEV_ONLY_MODULES, DOCUMENT_ASSET_EXTENSIONS, DOCUMENT_ASSET_HEADERS, MCP_PLUGIN_PACKAGE, MCP_TRANSPORT_SPECIFIER, SQL_CLIENT_MODULES, appUsesMcpPlugin, assertOutputDirOutsideRoot, bundledRuntimeEnv, detectDatabaseDialects, importSpecifier, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, stageStaticAssets, stubbableDevOnlyModules } from "@guren/core/internal/deploy-build";
|
|
5
5
|
import { reportDeployRuntimeHazards } from "@guren/core/internal/deploy-check";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
//#region src/templates.ts
|
|
@@ -77,13 +77,13 @@ async function buildCloudflareOutput(options = {}) {
|
|
|
77
77
|
if (!existsSync(appEntry)) throw new Error(`Cloudflare build: app entry not found at ${appEntry}. Pass "appEntry" if your Application lives elsewhere.`);
|
|
78
78
|
const ssrImport = await resolveSsrImport(ssrDir, ssrEntryKey);
|
|
79
79
|
const assetEnv = resolveClientAssetEnv(publicDir, clientEntryKey, "Cloudflare build");
|
|
80
|
-
const
|
|
80
|
+
const bundledEnv = bundledRuntimeEnv(root, publicDir, "Cloudflare build");
|
|
81
81
|
resetOutputDir(out, root, "Cloudflare build");
|
|
82
82
|
stageStaticAssets(publicDir, resolve(out, "assets"));
|
|
83
83
|
writeAssetHeaders(resolve(out, "assets"));
|
|
84
84
|
const workerEnv = renderWorkerEnvModule({
|
|
85
85
|
assetEnv,
|
|
86
|
-
|
|
86
|
+
bundledEnv
|
|
87
87
|
});
|
|
88
88
|
if (workerEnv) writeFileSync(resolve(out, "worker-env.js"), workerEnv);
|
|
89
89
|
writeFileSync(resolve(out, "worker.js"), renderWorkerModule({
|
|
@@ -653,7 +653,7 @@ function renderWorkerEnvModule(input) {
|
|
|
653
653
|
const lines = [];
|
|
654
654
|
if (input.assetEnv.entry) lines.push(`process.env.GUREN_INERTIA_ENTRY = ${JSON.stringify(input.assetEnv.entry)}`);
|
|
655
655
|
if (input.assetEnv.styles) lines.push(`process.env.GUREN_INERTIA_STYLES = ${JSON.stringify(input.assetEnv.styles)}`);
|
|
656
|
-
|
|
656
|
+
for (const [key, value] of Object.entries(input.bundledEnv)) lines.push(`process.env.${key} = ${JSON.stringify(value)}`);
|
|
657
657
|
if (lines.length === 0) return;
|
|
658
658
|
return [
|
|
659
659
|
"// Generated by `guren cloudflare:build`. Do not edit — regenerate instead.",
|
|
@@ -668,9 +668,11 @@ function renderWorkerModule(input) {
|
|
|
668
668
|
lines.push(input.mcpOAuth ? "import { createWorkersHandler, sweepOAuthStorage } from '@guren/plugin-cloudflare'" : "import { createWorkersHandler } from '@guren/plugin-cloudflare'");
|
|
669
669
|
if (hasAgents) lines.push(`import { configureAgentRuntime } from ${JSON.stringify(AGENTS_RUNTIME_SPECIFIER)}`, `import { routeGuardedAgentRequest } from ${JSON.stringify(AGENTS_ROUTER_SPECIFIER)}`, `import agentsConfig from ${quotedImport(input.out, resolve(input.root, AGENTS_CONFIG_FILE))}`);
|
|
670
670
|
if (input.mcpOAuth) lines.push(`import { OAuthProvider } from ${JSON.stringify(OAUTH_PROVIDER_PACKAGE)}`, `import { mcpOAuthPropsToAuth, presentExternalMcpAuth } from ${JSON.stringify(MCP_OAUTH_SEAM_SPECIFIER)}`);
|
|
671
|
-
if (input.ssrImport) lines.push(
|
|
671
|
+
if (input.ssrImport) lines.push(`import * as ssrModule from ${quotedImport(input.out, input.ssrImport.file)}`);
|
|
672
672
|
lines.push(`import app from ${quotedImport(input.out, input.appEntry)}`, "");
|
|
673
|
-
if (input.ssrImport) lines.push(`
|
|
673
|
+
if (input.ssrImport) lines.push(`if (!app.container.has('inertia.ssrRenderer')) {
|
|
674
|
+
app.container.instance('inertia.ssrRenderer', ssrModule.${input.ssrImport.rendererExport})
|
|
675
|
+
}`, "");
|
|
674
676
|
lines.push("const handler = createWorkersHandler(app)", "");
|
|
675
677
|
if (hasAgents) lines.push(renderAgentWiring(input.out, input.root, input.agents, input.agentBindings), "");
|
|
676
678
|
if (input.mcpOAuth) lines.push(renderOAuthProvider(input.mcpPath, hasAgents ? "agentEntry" : "handler"), "");
|
package/dist/commands.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as printBundleReport, c as buildCloudflareOutput, s as reportBundleSize } from "./bundle-size-
|
|
1
|
+
import { a as printBundleReport, c as buildCloudflareOutput, s as reportBundleSize } from "./bundle-size-B-2cTytq.js";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
3
|
//#region src/commands.ts
|
|
4
4
|
const rootArg = {
|
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,14 @@ interface WorkersScheduledEvent {
|
|
|
20
20
|
interface WorkersAppLike {
|
|
21
21
|
boot(): Promise<void>;
|
|
22
22
|
fetch(request: Request, env?: unknown, executionCtx?: unknown): Response | Promise<Response>;
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Read by the cron entrypoint. `has`/`instance` bind the entrypoint env as
|
|
25
|
+
* `env.source` before boot (RFC 0027 §1); optional, so an existing app-like still boots.
|
|
26
|
+
*/
|
|
24
27
|
container?: {
|
|
25
28
|
makeOptional<T>(key: string): T | undefined;
|
|
29
|
+
has?(key: string): boolean;
|
|
30
|
+
instance?(key: string, value: unknown): unknown;
|
|
26
31
|
};
|
|
27
32
|
}
|
|
28
33
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { captureWorkersEnv, getWorkersEnv, isWorkersRuntime, resetWorkersEnv } from "./env.js";
|
|
2
|
-
import { a as printBundleReport, c as buildCloudflareOutput, i as parseWranglerSize, l as flattenD1Migrations, n as WORKER_SIZE_WARN_SHARE, o as renderBundleReport, r as attributeBundle, s as reportBundleSize, t as WORKER_SIZE_LIMIT } from "./bundle-size-
|
|
2
|
+
import { a as printBundleReport, c as buildCloudflareOutput, i as parseWranglerSize, l as flattenD1Migrations, n as WORKER_SIZE_WARN_SHARE, o as renderBundleReport, r as attributeBundle, s as reportBundleSize, t as WORKER_SIZE_LIMIT } from "./bundle-size-B-2cTytq.js";
|
|
3
3
|
import { definePlugin } from "@guren/core";
|
|
4
4
|
//#region src/boot.ts
|
|
5
5
|
const latches = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
/** Wrangler `vars` may be missing from `process.env`; a value the app or a test bound itself is kept. */
|
|
7
|
+
function bindEnvSource(app, env) {
|
|
8
|
+
const container = app.container;
|
|
9
|
+
if (!container?.has || !container.instance || env === null || typeof env !== "object") return;
|
|
10
|
+
if (!container.has("env.source")) container.instance("env.source", env);
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
13
|
* Boot `app` against `env`, once per isolate.
|
|
8
14
|
*
|
|
@@ -16,6 +22,7 @@ async function bootWorkersApp(app, env) {
|
|
|
16
22
|
try {
|
|
17
23
|
attempt = latches.get(app);
|
|
18
24
|
if (!attempt) {
|
|
25
|
+
bindEnvSource(app, env);
|
|
19
26
|
attempt = app.boot();
|
|
20
27
|
latches.set(app, attempt);
|
|
21
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"typecheck": "tsc --noEmit"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@guren/core": "^1.
|
|
50
|
+
"@guren/core": "^1.19.0",
|
|
51
51
|
"citty": "^0.1.6"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|