@guren/plugin-cloudflare 0.3.0 → 0.3.1
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.
|
@@ -4,6 +4,7 @@ import { relative, resolve, sep } from "path";
|
|
|
4
4
|
import { pathToFileURL } from "url";
|
|
5
5
|
import {
|
|
6
6
|
DEV_ONLY_MODULES,
|
|
7
|
+
SQL_CLIENT_MODULES,
|
|
7
8
|
importSpecifier,
|
|
8
9
|
renderDevOnlyStub,
|
|
9
10
|
assertOutputDirOutsideRoot,
|
|
@@ -39,20 +40,26 @@ async function buildCloudflareOutput(options = {}) {
|
|
|
39
40
|
scaffoldWranglerConfig(root, out, packageJson.name);
|
|
40
41
|
}
|
|
41
42
|
var MCP_UNAVAILABLE = "The MCP endpoint is unavailable on Cloudflare Workers \u2014 it generates files on disk.";
|
|
43
|
+
var STUBBED_MODULES = [...DEV_ONLY_MODULES, ...SQL_CLIENT_MODULES];
|
|
42
44
|
var UNAVAILABLE_ON_WORKERS = {
|
|
43
45
|
sqlite: "bun:sqlite is unavailable on Cloudflare Workers \u2014 use createD1Database().",
|
|
44
46
|
vite: "The Vite dev server is unavailable on Cloudflare Workers \u2014 assets are served by Workers Static Assets.",
|
|
45
|
-
mcp: MCP_UNAVAILABLE
|
|
47
|
+
mcp: MCP_UNAVAILABLE,
|
|
48
|
+
"sql-driver": "This database client is unavailable on Cloudflare Workers \u2014 use createD1Database(). It is stubbed because @guren/orm names it in a dynamic import that bundlers follow even when the branch cannot be taken."
|
|
46
49
|
};
|
|
47
50
|
var STUB_FILES = {
|
|
48
51
|
"bun:sqlite": "stub-bun-sqlite.js",
|
|
49
52
|
vite: "stub-vite.js",
|
|
50
53
|
"@guren/cli": "stub-guren-cli.js",
|
|
51
54
|
"@modelcontextprotocol/sdk/server/mcp.js": "stub-mcp-server.js",
|
|
52
|
-
"@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js": "stub-mcp-transport.js"
|
|
55
|
+
"@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js": "stub-mcp-transport.js",
|
|
56
|
+
postgres: "stub-postgres.js",
|
|
57
|
+
mysql2: "stub-mysql2.js",
|
|
58
|
+
"mysql2/promise": "stub-mysql2-promise.js",
|
|
59
|
+
"@aws-sdk/client-rds-data": "stub-rds-data.js"
|
|
53
60
|
};
|
|
54
61
|
function writeDevOnlyStubs(out) {
|
|
55
|
-
for (const module of
|
|
62
|
+
for (const module of STUBBED_MODULES) {
|
|
56
63
|
writeFileSync(
|
|
57
64
|
resolve(out, STUB_FILES[module.specifier]),
|
|
58
65
|
renderDevOnlyStub(module, UNAVAILABLE_ON_WORKERS[module.kind])
|
|
@@ -61,7 +68,7 @@ function writeDevOnlyStubs(out) {
|
|
|
61
68
|
}
|
|
62
69
|
function devOnlyAliases(outRelative) {
|
|
63
70
|
return Object.fromEntries(
|
|
64
|
-
|
|
71
|
+
STUBBED_MODULES.map((module) => [
|
|
65
72
|
module.specifier,
|
|
66
73
|
`./${outRelative}/${STUB_FILES[module.specifier]}`
|
|
67
74
|
])
|
|
@@ -227,22 +234,74 @@ function scaffoldWranglerConfig(root, out, packageName) {
|
|
|
227
234
|
}
|
|
228
235
|
console.log(`Cloudflare build: scaffolded ${configPath} \u2014 fill in d1_databases[0].database_id before deploying.`);
|
|
229
236
|
}
|
|
237
|
+
function parseJsonc(text) {
|
|
238
|
+
const out = [];
|
|
239
|
+
let index = 0;
|
|
240
|
+
while (index < text.length) {
|
|
241
|
+
const char = text[index];
|
|
242
|
+
if (char === '"') {
|
|
243
|
+
const start = index;
|
|
244
|
+
index += 1;
|
|
245
|
+
while (index < text.length) {
|
|
246
|
+
if (text[index] === "\\") {
|
|
247
|
+
index += 2;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (text[index] === '"') {
|
|
251
|
+
index += 1;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
index += 1;
|
|
255
|
+
}
|
|
256
|
+
out.push(text.slice(start, index));
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (char === "/" && text[index + 1] === "/") {
|
|
260
|
+
while (index < text.length && text[index] !== "\n") {
|
|
261
|
+
index += 1;
|
|
262
|
+
}
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (char === "/" && text[index + 1] === "*") {
|
|
266
|
+
const end = text.indexOf("*/", index + 2);
|
|
267
|
+
index = end === -1 ? text.length : end + 2;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (char === "}" || char === "]") {
|
|
271
|
+
let back = out.length - 1;
|
|
272
|
+
while (back >= 0 && /^\s+$/.test(out[back])) {
|
|
273
|
+
back -= 1;
|
|
274
|
+
}
|
|
275
|
+
if (back >= 0 && out[back] === ",") {
|
|
276
|
+
out.splice(back, 1);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
out.push(char);
|
|
280
|
+
index += 1;
|
|
281
|
+
}
|
|
282
|
+
return JSON.parse(out.join(""));
|
|
283
|
+
}
|
|
230
284
|
function warnMissingBuildOwnedKeys(configPath, outRelative) {
|
|
231
285
|
let config;
|
|
232
286
|
try {
|
|
233
|
-
config =
|
|
287
|
+
config = parseJsonc(readFileSync(configPath, "utf8"));
|
|
234
288
|
} catch {
|
|
289
|
+
console.warn(
|
|
290
|
+
`Cloudflare build: could not parse ${configPath}, so its build-owned keys went unchecked. Fix the file, or compare it against a config scaffolded in an empty directory.`
|
|
291
|
+
);
|
|
235
292
|
return;
|
|
236
293
|
}
|
|
237
294
|
const missing = [];
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
295
|
+
const configAlias = config.alias;
|
|
296
|
+
const alias = typeof configAlias === "object" && configAlias !== null ? configAlias : {};
|
|
297
|
+
for (const [specifier, target] of Object.entries(devOnlyAliases(outRelative))) {
|
|
298
|
+
if (!(specifier in alias)) {
|
|
299
|
+
missing.push(`${JSON.stringify(specifier)}: ${JSON.stringify(target)} (inside "alias")`);
|
|
300
|
+
}
|
|
242
301
|
}
|
|
243
302
|
const define = config.define;
|
|
244
303
|
if (!define?.["process.env.NODE_ENV"]) {
|
|
245
|
-
missing.push('"
|
|
304
|
+
missing.push('"process.env.NODE_ENV": "\\"production\\"" (inside "define")');
|
|
246
305
|
}
|
|
247
306
|
const d1 = config.d1_databases?.[0];
|
|
248
307
|
if (d1 && d1.migrations_dir !== `${outRelative}/d1-migrations`) {
|
|
@@ -250,7 +309,7 @@ function warnMissingBuildOwnedKeys(configPath, outRelative) {
|
|
|
250
309
|
}
|
|
251
310
|
if (missing.length > 0) {
|
|
252
311
|
console.warn(
|
|
253
|
-
`Cloudflare build: ${configPath} predates this plugin version. Add the
|
|
312
|
+
`Cloudflare build: ${configPath} predates this plugin version. Add these entries, alongside whatever the file already has under the same keys, or the worker will fail to start or skip migrations:
|
|
254
313
|
${missing.join("\n ")}`
|
|
255
314
|
);
|
|
256
315
|
}
|
package/dist/commands.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-cloudflare",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
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.6.2",
|
|
45
45
|
"citty": "^0.1.6"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|