@guren/plugin-cloudflare 0.3.2 → 0.4.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/{build-DxgM3l-5.js → build-B7zQ13ai.js} +33 -6
- package/dist/commands.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { relative, resolve, sep } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { DEV_ONLY_MODULES, SQL_CLIENT_MODULES, assertOutputDirOutsideRoot, importSpecifier, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, stageStaticAssets } from "@guren/core/internal/deploy-build";
|
|
4
|
+
import { DEV_ONLY_MODULES, SQL_CLIENT_MODULES, assertOutputDirOutsideRoot, clientManifestJson, importSpecifier, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, stageStaticAssets } from "@guren/core/internal/deploy-build";
|
|
5
5
|
//#region src/build.ts
|
|
6
6
|
/**
|
|
7
7
|
* Assemble a deployable Cloudflare Workers directory (`.cloudflare/`) from a
|
|
@@ -23,13 +23,19 @@ async function buildCloudflareOutput(options = {}) {
|
|
|
23
23
|
if (!existsSync(appEntry)) throw new Error(`Cloudflare build: app entry not found at ${appEntry}. Pass "appEntry" if your Application lives elsewhere.`);
|
|
24
24
|
const ssrImport = await resolveSsrImport(ssrDir, ssrEntryKey);
|
|
25
25
|
const assetEnv = resolveClientAssetEnv(publicDir, clientEntryKey, "Cloudflare build");
|
|
26
|
+
const viteManifest = clientManifestJson(publicDir);
|
|
26
27
|
resetOutputDir(out, root, "Cloudflare build");
|
|
27
28
|
stageStaticAssets(publicDir, resolve(out, "assets"));
|
|
29
|
+
const workerEnv = renderWorkerEnvModule({
|
|
30
|
+
assetEnv,
|
|
31
|
+
viteManifest
|
|
32
|
+
});
|
|
33
|
+
if (workerEnv) writeFileSync(resolve(out, "worker-env.js"), workerEnv);
|
|
28
34
|
writeFileSync(resolve(out, "worker.js"), renderWorkerModule({
|
|
29
35
|
out,
|
|
30
36
|
appEntry,
|
|
31
37
|
ssrImport,
|
|
32
|
-
|
|
38
|
+
hasEnvModule: workerEnv !== void 0
|
|
33
39
|
}));
|
|
34
40
|
flattenD1Migrations(resolve(root, "db/migrations"), resolve(out, "d1-migrations"));
|
|
35
41
|
writeDevOnlyStubs(out);
|
|
@@ -163,13 +169,34 @@ async function resolveSsrImport(ssrDir, ssrEntryKey) {
|
|
|
163
169
|
rendererExport
|
|
164
170
|
};
|
|
165
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Statements assigning the build-derived environment, emitted as a module of
|
|
174
|
+
* their own rather than as lines in worker.js: worker.js imports this module
|
|
175
|
+
* *first*, which is the only ordering ESM import hoisting cannot defeat. A
|
|
176
|
+
* statement in the worker body runs after the app's module graph has already
|
|
177
|
+
* evaluated, so a module-scope `viteAsset()` call in the app would see no
|
|
178
|
+
* manifest and throw before the worker could start. (The Lambda wrapper
|
|
179
|
+
* solves the same hazard by assigning env before dynamically importing the
|
|
180
|
+
* app.)
|
|
181
|
+
*/
|
|
182
|
+
function renderWorkerEnvModule(input) {
|
|
183
|
+
const lines = [];
|
|
184
|
+
if (input.assetEnv.entry) lines.push(`process.env.GUREN_INERTIA_ENTRY = ${JSON.stringify(input.assetEnv.entry)}`);
|
|
185
|
+
if (input.assetEnv.styles) lines.push(`process.env.GUREN_INERTIA_STYLES = ${JSON.stringify(input.assetEnv.styles)}`);
|
|
186
|
+
if (input.viteManifest) lines.push(`process.env.GUREN_VITE_MANIFEST = ${JSON.stringify(input.viteManifest)}`);
|
|
187
|
+
if (lines.length === 0) return;
|
|
188
|
+
return [
|
|
189
|
+
"// Generated by `guren cloudflare:build`. Do not edit — regenerate instead.",
|
|
190
|
+
...lines,
|
|
191
|
+
""
|
|
192
|
+
].join("\n");
|
|
193
|
+
}
|
|
166
194
|
function renderWorkerModule(input) {
|
|
167
|
-
const lines = ["// Generated by `guren cloudflare:build`. Do not edit — regenerate instead."
|
|
195
|
+
const lines = ["// Generated by `guren cloudflare:build`. Do not edit — regenerate instead."];
|
|
196
|
+
if (input.hasEnvModule) lines.push("import './worker-env.js'");
|
|
197
|
+
lines.push("import { createWorkersHandler } from '@guren/plugin-cloudflare'");
|
|
168
198
|
if (input.ssrImport) lines.push("import { setInertiaSsrRenderer } from '@guren/core'", `import * as ssrModule from ${JSON.stringify(importSpecifier(input.out, input.ssrImport.file, "Cloudflare build"))}`);
|
|
169
199
|
lines.push(`import app from ${JSON.stringify(importSpecifier(input.out, input.appEntry, "Cloudflare build"))}`, "");
|
|
170
|
-
if (input.assetEnv.entry) lines.push(`process.env.GUREN_INERTIA_ENTRY = ${JSON.stringify(input.assetEnv.entry)}`);
|
|
171
|
-
if (input.assetEnv.styles) lines.push(`process.env.GUREN_INERTIA_STYLES = ${JSON.stringify(input.assetEnv.styles)}`);
|
|
172
|
-
if (input.assetEnv.entry || input.assetEnv.styles) lines.push("");
|
|
173
200
|
if (input.ssrImport) lines.push(`setInertiaSsrRenderer(ssrModule.${input.ssrImport.rendererExport})`, "");
|
|
174
201
|
lines.push("export default createWorkersHandler(app)", "");
|
|
175
202
|
return lines.join("\n");
|
package/dist/commands.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -222,8 +222,8 @@ declare class R2Driver implements StorageDriver {
|
|
|
222
222
|
private objects;
|
|
223
223
|
/**
|
|
224
224
|
* Follows `cursor` until `truncated` is false. A single `list()` call is
|
|
225
|
-
* capped at 1000 keys, so a one-page read
|
|
226
|
-
*
|
|
225
|
+
* capped at 1000 keys, so a one-page read silently truncates larger
|
|
226
|
+
* directories.
|
|
227
227
|
*/
|
|
228
228
|
private pages;
|
|
229
229
|
makeDirectory(path: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as flattenD1Migrations, t as buildCloudflareOutput } from "./build-
|
|
1
|
+
import { n as flattenD1Migrations, t as buildCloudflareOutput } from "./build-B7zQ13ai.js";
|
|
2
2
|
import { definePlugin } from "@guren/core";
|
|
3
3
|
//#region src/env.ts
|
|
4
4
|
let holder;
|
|
@@ -301,8 +301,8 @@ var R2Driver = class {
|
|
|
301
301
|
}
|
|
302
302
|
/**
|
|
303
303
|
* Follows `cursor` until `truncated` is false. A single `list()` call is
|
|
304
|
-
* capped at 1000 keys, so a one-page read
|
|
305
|
-
*
|
|
304
|
+
* capped at 1000 keys, so a one-page read silently truncates larger
|
|
305
|
+
* directories.
|
|
306
306
|
*/
|
|
307
307
|
async *pages(options) {
|
|
308
308
|
const bucket = this.bucket();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"typecheck": "tsc --noEmit"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@guren/core": "^1.
|
|
44
|
+
"@guren/core": "^1.10.0",
|
|
45
45
|
"citty": "^0.1.6"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|