@base44-preview/vite-plugin 1.0.45-pr.134.9175d68 → 1.0.46-pr.136.11ca3d8

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
@@ -51,6 +51,25 @@ Dev and production are told apart by the Vite command (`serve` vs `build`), not
51
51
 
52
52
  Outside a sandbox, only the core plugin runs (with optional API proxy support via `VITE_BASE44_APP_BASE_URL`).
53
53
 
54
+ ### Cloudflare Workers compatibility
55
+
56
+ `base44-workerd-compat` adjusts only environments that resolve with the `workerd`
57
+ condition, which Cloudflare's Vite plugin uses for server code. The browser bundle
58
+ and Node-run servers are untouched. It covers both Vite's pipeline and the dev
59
+ dependency optimizer, for esbuild (Vite 7) and Rolldown (Vite 8):
60
+
61
+ - **`ws`** resolves to `compat/workerd-ws.cjs`, a `ws`-shaped client over workerd's
62
+ native WebSocket. The package's own browser build only throws. `WebSocketServer`
63
+ throws too: server code can open sockets but not listen.
64
+ - **`AsyncLocalStorage.enterWith()`**, which workerd omits, becomes a no-op. A module
65
+ that calls it first imports `compat/workerd-enter-with.mjs`.
66
+ - **`createRequire()` in dev** gets its argument's query string dropped. Optimized
67
+ dependencies carry Vite's `?v=` query, which workerd rejects. Builds are left
68
+ byte-for-byte alone.
69
+
70
+ Stagehand 3 needs all three. `@base44/functions-compiler` applies the first two to
71
+ backend functions.
72
+
54
73
  ### Build-status endpoint
55
74
 
56
75
  An opt-in, dev-only (`apply: "serve"`) endpoint that reports the last build /
@@ -0,0 +1,7 @@
1
+ // Imported ahead of any Cloudflare Workers server module that calls enterWith(),
2
+ // by the base44-workerd-compat plugin. workerd omits
3
+ // AsyncLocalStorage.enterWith(); libraries such as Stagehand call it to seed a
4
+ // context they also pass explicitly, so a no-op keeps them working.
5
+ import { AsyncLocalStorage } from "node:async_hooks";
6
+
7
+ AsyncLocalStorage.prototype.enterWith = () => {};
@@ -0,0 +1,75 @@
1
+ // Served for `ws` in Cloudflare Workers environments by the base44-workerd-compat
2
+ // plugin. The `ws` package's "browser" export is a stub that throws, and its Node
3
+ // build needs node:net; workerd has a native WebSocket client, so this is a
4
+ // `ws`-shaped client over it. Kept in step with @base44/functions-compiler's copy.
5
+ "use strict";
6
+ const toBuffer = (value) => (globalThis.Buffer ? globalThis.Buffer.from(value) : value);
7
+ class WebSocket {
8
+ static CONNECTING = 0;
9
+ static OPEN = 1;
10
+ static CLOSING = 2;
11
+ static CLOSED = 3;
12
+ #socket;
13
+ #listeners = new Map();
14
+ constructor(address, protocols) {
15
+ this.#socket = new globalThis.WebSocket(String(address), typeof protocols === "string" || Array.isArray(protocols) ? protocols : undefined);
16
+ try { this.#socket.binaryType = "arraybuffer"; } catch {}
17
+ this.#socket.addEventListener("open", () => this.emit("open"));
18
+ this.#socket.addEventListener("message", (event) => {
19
+ const isBinary = typeof event.data !== "string";
20
+ this.emit("message", toBuffer(isBinary ? new Uint8Array(event.data) : event.data), isBinary);
21
+ });
22
+ this.#socket.addEventListener("error", (event) => this.emit("error", event.error ?? new Error(event.message || "WebSocket error")));
23
+ this.#socket.addEventListener("close", (event) => this.emit("close", event.code, toBuffer(event.reason ?? "")));
24
+ }
25
+ get readyState() { return this.#socket.readyState; }
26
+ get url() { return this.#socket.url; }
27
+ get protocol() { return this.#socket.protocol; }
28
+ on(name, listener) { return this.#add(name, listener, false); }
29
+ addListener(name, listener) { return this.#add(name, listener, false); }
30
+ once(name, listener) { return this.#add(name, listener, true); }
31
+ off(name, listener) { return this.removeListener(name, listener); }
32
+ removeListener(name, listener) {
33
+ const listeners = this.#listeners.get(name);
34
+ if (listeners) this.#listeners.set(name, listeners.filter((entry) => entry.listener !== listener));
35
+ return this;
36
+ }
37
+ removeAllListeners(name) {
38
+ if (name === undefined) this.#listeners.clear();
39
+ else this.#listeners.delete(name);
40
+ return this;
41
+ }
42
+ emit(name, ...args) {
43
+ const listeners = this.#listeners.get(name) ?? [];
44
+ this.#listeners.set(name, listeners.filter((entry) => !entry.once));
45
+ for (const entry of listeners) entry.listener.apply(this, args);
46
+ return listeners.length > 0;
47
+ }
48
+ send(data, options, callback) {
49
+ const done = typeof options === "function" ? options : callback;
50
+ try {
51
+ this.#socket.send(data);
52
+ done?.();
53
+ } catch (error) {
54
+ if (!done) throw error;
55
+ done(error);
56
+ }
57
+ }
58
+ close(code, reason) { this.#socket.close(code, reason); }
59
+ terminate() { this.#socket.close(); }
60
+ #add(name, listener, once) {
61
+ const listeners = this.#listeners.get(name) ?? [];
62
+ listeners.push({ listener, once });
63
+ this.#listeners.set(name, listeners);
64
+ return this;
65
+ }
66
+ }
67
+ class WebSocketServer {
68
+ constructor() {
69
+ throw new Error("ws WebSocketServer is not available in Base44 functions: a function can open WebSocket connections but cannot listen for them.");
70
+ }
71
+ }
72
+ module.exports = WebSocket;
73
+ module.exports.WebSocket = WebSocket;
74
+ module.exports.WebSocketServer = WebSocketServer;
75
+ module.exports.default = WebSocket;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAS/C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAmBlD,eAAO,MAAM,uBAAuB,UAWnC,CAAC;AAeF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,IAAI,GAAE;IACJ,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,iBAwPP"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAU/C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAmBlD,eAAO,MAAM,uBAAuB,UAWnC,CAAC;AAeF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,IAAI,GAAE;IACJ,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,iBA2PP"}
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import { filterPackagesInProject } from "./utils.js";
6
6
  import { htmlInjectionsPlugin } from "./html-injections-plugin.js";
7
7
  import { buildStatusPlugin } from "./build-status-plugin.js";
8
8
  import { base44RuntimePlugin } from "./base44-runtime-plugin.js";
9
+ import { workerdCompatPlugin } from "./workerd-compat-plugin.js";
9
10
  import { routeRequestLogPlugin } from "./route-request-log/vite-plugin.js";
10
11
  const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
11
12
  // Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
@@ -228,6 +229,9 @@ export default function vitePlugin(opts = {}) {
228
229
  // notices it. Ordering comes from its own `enforce: "pre"`, not from its
229
230
  // position here — several tests index this array from the front.
230
231
  base44RuntimePlugin(),
232
+ // `ws` and `AsyncLocalStorage.enterWith()` for Cloudflare Workers server code.
233
+ // Inert outside environments that resolve with the "workerd" condition.
234
+ workerdCompatPlugin(),
231
235
  // Dev-only: tags a full-stack route's console output with the request's
232
236
  // X-B44-Request-Id. Registered as a Nitro module (the `nitro` property)
233
237
  // because Nitro runs dev routes in a worker whose console the Vite process
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,kBAAk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,UAAU,CAAC,CAAC;4BAC7C,GAAG,CAAC,SAAS,CAAC,yBAAyB,EAAE,oBAAoB,CAAC,CAAC;4BAC/D,IAAI,EAAE,CAAC;wBACT,CAAC,CAAC,CAAC;oBACL,CAAC;iBACQ;gBACX,kBAAkB,EAAE;gBACpB,gBAAgB,EAAE;aACnB;YACH,CAAC,CAAC,EAAE,CAAC;QACP,yEAAyE;QACzE,GAAG,oBAAoB,CAAC;YACtB,WAAW;YACX,kBAAkB;YAClB,eAAe;YACf,gBAAgB;YAChB,WAAW,EAAE,kBAAkB;SAChC,CAAC;QACF,yEAAyE;QACzE,iEAAiE;QACjE,sEAAsE;QACtE,wEAAwE;QACxE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,GAAG;YACjD,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACvB,CAAC,CAAC,EAAE,CAAC;QACP,yEAAyE;QACzE,2EAA2E;QAC3E,yEAAyE;QACzE,iEAAiE;QACjE,mBAAmB,EAAE;QACrB,+EAA+E;QAC/E,wEAAwE;QACxE,mBAAmB,EAAE;QACrB,wEAAwE;QACxE,wEAAwE;QACxE,2EAA2E;QAC3E,4EAA4E;QAC5E,qBAAqB,EAAE;KACxB,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"visual-edit-plugin.d.ts","sourceRoot":"","sources":["../src/visual-edit-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAa,MAAM,EAAc,MAAM,MAAM,CAAC;AAK1D,wBAAgB,gBAAgB,IA+EzB,MAAM,CACZ"}
1
+ {"version":3,"file":"visual-edit-plugin.d.ts","sourceRoot":"","sources":["../src/visual-edit-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAa,MAAM,EAAc,MAAM,MAAM,CAAC;AAK1D,wBAAgB,gBAAgB,IAoFzB,MAAM,CACZ"}
@@ -16,7 +16,6 @@ export function visualEditPlugin() {
16
16
  // code that doesn't exist on disk.
17
17
  apply: (config, env) => env.command === "serve" && config.mode === "development",
18
18
  enforce: "pre",
19
- order: "pre",
20
19
  transformIndexHtml(html) {
21
20
  const tailwindScript = ` <!-- Tailwind CSS CDN for visual editing -->\n <script src="${TAILWIND_CDN_SRC}"></script>\n `;
22
21
  return html.replace("</head>", tailwindScript + "</head>");
@@ -25,8 +24,16 @@ export function visualEditPlugin() {
25
24
  if (id.includes("node_modules") || id.includes("visual-edit-agent")) {
26
25
  return null;
27
26
  }
28
- if (!id.match(/\.(jsx?|tsx?)$/)) {
27
+ const [idPath = "", idQuery] = id.split("?");
28
+ if (!/\.(jsx?|tsx?)$/.test(idPath))
29
29
  return null;
30
+ // TanStack Router serves route components as `route.jsx?tsr-split=...` modules; other
31
+ // queries (?raw, ?url, ?worker) must not be transformed. Tag lines stay real only while
32
+ // base44() precedes tanstackStart() in vite.config, so this runs before the splitter.
33
+ if (idQuery) {
34
+ const params = new URLSearchParams(idQuery);
35
+ if (!params.has("tsr-split") && !params.has("tsr-shared"))
36
+ return null;
30
37
  }
31
38
  const filename = extractFilename(id);
32
39
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"visual-edit-plugin.js","sourceRoot":"","sources":["../src/visual-edit-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,mEAAmE;QACnE,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C"}
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from "vite";
2
+ export declare const WORKERD_WS_ADAPTER: string;
3
+ export declare const WORKERD_ENTER_WITH_PATCH: string;
4
+ /** Prepends the patch on the first line, so line numbers stay put. */
5
+ export declare function withEnterWithPatch(code: string, id: string): string | null;
6
+ /** Strips the query from `createRequire` arguments, for dev-served modules. */
7
+ export declare function withQueryFreeCreateRequire(code: string): string | null;
8
+ export declare function workerdCompatPlugin(): Plugin;
9
+ //# sourceMappingURL=workerd-compat-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerd-compat-plugin.d.ts","sourceRoot":"","sources":["../src/workerd-compat-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAsB,MAAM,EAAE,MAAM,MAAM,CAAC;AA0BvD,eAAO,MAAM,kBAAkB,QAA+B,CAAC;AAC/D,eAAO,MAAM,wBAAwB,QAAuC,CAAC;AAS7E,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO1E;AAKD,+EAA+E;AAC/E,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQtE;AAqDD,wBAAgB,mBAAmB,IAAI,MAAM,CAoB5C"}
@@ -0,0 +1,106 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import { version as viteVersion } from "vite";
4
+ /**
5
+ * Closes two workerd gaps that break Node-targeted npm clients (Stagehand among
6
+ * them) in full-stack server code, matching what @base44/functions-compiler does
7
+ * for backend functions:
8
+ *
9
+ * - `ws`: its exports map sends the "browser" condition (which Cloudflare's Vite
10
+ * plugin resolves with) to a stub that throws on use. It is served as a
11
+ * `ws`-shaped client over workerd's native WebSocket.
12
+ * - `AsyncLocalStorage.enterWith()`: workerd omits it. A module that calls it
13
+ * first imports a patch that makes it a no-op. Builtins never reach plugin
14
+ * resolution in Vite 8, so `async_hooks` itself cannot be swapped.
15
+ * - `createRequire()` in dev: optimized dependencies carry a `?v=` query in
16
+ * their ids, and workerd rejects a `createRequire` path with a query. Calls
17
+ * are routed through a wrapper that drops it. Builds have no query, so their
18
+ * bytes are left alone.
19
+ *
20
+ * Only environments that resolve with the "workerd" condition are touched, so
21
+ * the browser bundle and a Node-run server keep the real modules.
22
+ */
23
+ const compatFile = (name) => fileURLToPath(new URL(`../compat/${name}`, import.meta.url));
24
+ export const WORKERD_WS_ADAPTER = compatFile("workerd-ws.cjs");
25
+ export const WORKERD_ENTER_WITH_PATCH = compatFile("workerd-enter-with.mjs");
26
+ const isWorkerd = (conditions) => !!conditions?.includes("workerd");
27
+ const redirect = (id) => (id === "ws" ? WORKERD_WS_ADAPTER : null);
28
+ const ESM_SYNTAX = /^\s*(import|export)\b/m;
29
+ /** Prepends the patch on the first line, so line numbers stay put. */
30
+ export function withEnterWithPatch(code, id) {
31
+ if (!code.includes(".enterWith(") || id.split("?")[0] === WORKERD_ENTER_WITH_PATCH) {
32
+ return null;
33
+ }
34
+ const patch = JSON.stringify(WORKERD_ENTER_WITH_PATCH);
35
+ // An ESM import in a CommonJS module would turn it into ESM; require it there.
36
+ return ESM_SYNTAX.test(code) ? `import ${patch};${code}` : `require(${patch});${code}`;
37
+ }
38
+ // A call, not a property access or a local `function createRequire(` declaration.
39
+ const CREATE_REQUIRE_CALL = /(?<![.\w$]|function\s+)createRequire\(/g;
40
+ /** Strips the query from `createRequire` arguments, for dev-served modules. */
41
+ export function withQueryFreeCreateRequire(code) {
42
+ if (!code.match(CREATE_REQUIRE_CALL) || code.includes("__b44CreateRequireImpl"))
43
+ return null;
44
+ const wrapper = "const __b44CreateRequire = (path) => __b44CreateRequireImpl(String(path).replace(/[?#].*$/, \"\"));";
45
+ const binding = ESM_SYNTAX.test(code)
46
+ ? 'import { createRequire as __b44CreateRequireImpl } from "node:module";'
47
+ : 'const { createRequire: __b44CreateRequireImpl } = require("node:module");';
48
+ return binding + wrapper + code.replace(CREATE_REQUIRE_CALL, "__b44CreateRequire(");
49
+ }
50
+ function devTransform(code, id) {
51
+ const patched = withEnterWithPatch(code, id) ?? code;
52
+ return withQueryFreeCreateRequire(patched) ?? (patched === code ? null : patched);
53
+ }
54
+ // Dev pre-bundles dependencies without running Vite plugins, so the dependency
55
+ // optimizer, which only runs in dev, needs its own copy. Each copy checks the
56
+ // build's conditions itself: Cloudflare's plugin sets them after ours has run.
57
+ function esbuildOptimizerPlugin() {
58
+ return {
59
+ name: "base44-workerd-compat",
60
+ setup(build) {
61
+ if (!isWorkerd(build.initialOptions.conditions))
62
+ return;
63
+ build.onResolve({ filter: /^ws$/ }, () => ({ path: WORKERD_WS_ADAPTER }));
64
+ build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
65
+ const code = devTransform(await readFile(args.path, "utf8"), args.path);
66
+ return code === null ? undefined : { contents: code, loader: "js" };
67
+ });
68
+ },
69
+ };
70
+ }
71
+ function rolldownOptimizerPlugin() {
72
+ let active = false;
73
+ return {
74
+ name: "base44-workerd-compat",
75
+ options(options) {
76
+ active = isWorkerd(options.resolve?.conditionNames);
77
+ },
78
+ resolveId: (id) => (active ? redirect(id) : null),
79
+ transform: (code, id) => (active ? devTransform(code, id) : null),
80
+ };
81
+ }
82
+ const OPTIMIZED_DEP = /[\\/]node_modules[\\/]\.vite[\\/]/;
83
+ const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
84
+ export function workerdCompatPlugin() {
85
+ return {
86
+ name: "base44-workerd-compat",
87
+ enforce: "pre",
88
+ applyToEnvironment: (environment) => isWorkerd(environment.config.resolve.conditions),
89
+ configEnvironment(name) {
90
+ if (name === "client")
91
+ return;
92
+ const optimizeDeps = isVite8OrLater
93
+ ? { rolldownOptions: { plugins: [rolldownOptimizerPlugin()] } }
94
+ : { esbuildOptions: { plugins: [esbuildOptimizerPlugin()] } };
95
+ return { optimizeDeps };
96
+ },
97
+ resolveId: (id) => redirect(id),
98
+ transform(code, id) {
99
+ // The optimizer already patched its output.
100
+ if (OPTIMIZED_DEP.test(id))
101
+ return null;
102
+ return this.environment.mode === "dev" ? devTransform(code, id) : withEnterWithPatch(code, id);
103
+ },
104
+ };
105
+ }
106
+ //# sourceMappingURL=workerd-compat-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerd-compat-plugin.js","sourceRoot":"","sources":["../src/workerd-compat-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CAClC,aAAa,CAAC,IAAI,GAAG,CAAC,aAAa,IAAI,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAC,wBAAwB,CAAC,CAAC;AAE7E,MAAM,SAAS,GAAG,CAAC,UAAyC,EAAE,EAAE,CAC9D,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;AAEpC,MAAM,QAAQ,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAE3E,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAE5C,sEAAsE;AACtE,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,EAAU;IACzD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,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C,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAE9D,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE,KAAK;QACd,kBAAkB,EAAE,CAAC,WAAW,EAAE,EAAE,CAClC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;QAClD,iBAAiB,CAAC,IAAI;YACpB,IAAI,IAAI,KAAK,QAAQ;gBAAE,OAAO;YAC9B,MAAM,YAAY,GAAG,cAAc;gBACjC,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,CAAC,uBAAuB,EAAE,CAAC,EAAE,EAAE;gBAC/D,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,CAAC,sBAAsB,EAAE,CAAC,EAAE,EAAE,CAAC;YAChE,OAAO,EAAE,YAAY,EAAwB,CAAC;QAChD,CAAC;QACD,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,SAAS,CAAC,IAAI,EAAE,EAAE;YAChB,4CAA4C;YAC5C,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,OAAO,IAAI,CAAC;YACxC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjG,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/vite-plugin",
3
- "version": "1.0.45-pr.134.9175d68",
3
+ "version": "1.0.46-pr.136.11ca3d8",
4
4
  "description": "The Vite plugin for base44 based applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import { filterPackagesInProject } from "./utils.js";
7
7
  import { htmlInjectionsPlugin } from "./html-injections-plugin.js";
8
8
  import { buildStatusPlugin } from "./build-status-plugin.js";
9
9
  import { base44RuntimePlugin } from "./base44-runtime-plugin.js";
10
+ import { workerdCompatPlugin } from "./workerd-compat-plugin.js";
10
11
  import { routeRequestLogPlugin } from "./route-request-log/vite-plugin.js";
11
12
  export type { DocumentScript } from "./consts.js";
12
13
 
@@ -302,6 +303,9 @@ export default function vitePlugin(
302
303
  // notices it. Ordering comes from its own `enforce: "pre"`, not from its
303
304
  // position here — several tests index this array from the front.
304
305
  base44RuntimePlugin(),
306
+ // `ws` and `AsyncLocalStorage.enterWith()` for Cloudflare Workers server code.
307
+ // Inert outside environments that resolve with the "workerd" condition.
308
+ workerdCompatPlugin(),
305
309
  // Dev-only: tags a full-stack route's console output with the request's
306
310
  // X-B44-Request-Id. Registered as a Nitro module (the `nitro` property)
307
311
  // because Nitro runs dev routes in a worker whose console the Vite process
@@ -30,7 +30,8 @@ It adds two HTML `data-*` attributes to every JSX element:
30
30
  |-----------|-------|-----|
31
31
  | `MODAL_SANDBOX_ID` env var is set | `index.ts:8` | Only runs inside Modal sandbox containers |
32
32
  | Dev **server** in `"development"` mode | `apply: (config, env) => env.command === "serve" && config.mode === "development"` | The injected `data-*` markers are only consumed by the visual-edit agent in the live preview, which the dev server serves. Builds never use them — including `vite build --mode development` (the platform's validation build), where instrumenting user code once produced compile errors on code that wasn't on disk |
33
- | File is `.js`, `.jsx`, `.ts`, or `.tsx` | `id.match(/\.(jsx?\|tsx?)$/)` | Only JSX-capable files |
33
+ | File is `.js`, `.jsx`, `.ts`, or `.tsx` | `/\.(jsx?\|tsx?)$/.test(idPath)` | Only JSX-capable files |
34
+ | No query, or a `tsr-split` / `tsr-shared` key | `URLSearchParams(idQuery).has(...)` | TanStack Router serves route components as `route.jsx?tsr-split=component`; other queries (`?raw`, `?url`, `?worker`) must not be transformed. Lines stay accurate only while `base44()` precedes `tanstackStart()` in `vite.config`, so this runs before the splitter rewrites the file |
34
35
  | File is NOT in `node_modules` | `id.includes("node_modules")` | Skip third-party code |
35
36
  | File is NOT `visual-edit-agent` | `id.includes("visual-edit-agent")` | Don't instrument the agent itself |
36
37
 
@@ -57,8 +58,8 @@ It adds two HTML `data-*` attributes to every JSX element:
57
58
 
58
59
  ### Plugin Ordering
59
60
 
60
- - `enforce: "pre"` + `order: "pre"` ensures this runs **before** all other Vite transforms
61
- - This is critical because the plugin needs to process raw JSX before any other plugin modifies it
61
+ - `enforce: "pre"` runs this before all `normal`/`post` transforms. Among other `enforce: "pre"` plugins, array position in `vite.config` decides, so `base44()` must be listed before `tanstackStart()`: TanStack's code splitter is also `pre`, and tagging its output would point `data-source-location` at the wrong lines
62
+ - It also relies on Vite loading a queried id (`route.jsx?tsr-split=component`) from disk, so the split module's transform input is the original file, not the splitter's output. Both ids then tag identically, which keeps SSR and client hydration in agreement. Tags must come from raw JSX: tagging a rewritten file points `data-source-location` at generated lines
62
63
 
63
64
  ---
64
65
 
@@ -19,7 +19,6 @@ export function visualEditPlugin() {
19
19
  apply: (config: UserConfig, env: ConfigEnv) =>
20
20
  env.command === "serve" && config.mode === "development",
21
21
  enforce: "pre",
22
- order: "pre",
23
22
  transformIndexHtml(html: any) {
24
23
  const tailwindScript = ` <!-- Tailwind CSS CDN for visual editing -->\n <script src="${TAILWIND_CDN_SRC}"></script>\n `;
25
24
  return html.replace("</head>", tailwindScript + "</head>");
@@ -29,8 +28,14 @@ export function visualEditPlugin() {
29
28
  return null;
30
29
  }
31
30
 
32
- if (!id.match(/\.(jsx?|tsx?)$/)) {
33
- return null;
31
+ const [idPath = "", idQuery] = id.split("?");
32
+ if (!/\.(jsx?|tsx?)$/.test(idPath)) return null;
33
+ // TanStack Router serves route components as `route.jsx?tsr-split=...` modules; other
34
+ // queries (?raw, ?url, ?worker) must not be transformed. Tag lines stay real only while
35
+ // base44() precedes tanstackStart() in vite.config, so this runs before the splitter.
36
+ if (idQuery) {
37
+ const params = new URLSearchParams(idQuery);
38
+ if (!params.has("tsr-split") && !params.has("tsr-shared")) return null;
34
39
  }
35
40
 
36
41
  const filename = extractFilename(id);
@@ -0,0 +1,134 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import type { EnvironmentOptions, Plugin } from "vite";
4
+ import { version as viteVersion } from "vite";
5
+
6
+ /**
7
+ * Closes two workerd gaps that break Node-targeted npm clients (Stagehand among
8
+ * them) in full-stack server code, matching what @base44/functions-compiler does
9
+ * for backend functions:
10
+ *
11
+ * - `ws`: its exports map sends the "browser" condition (which Cloudflare's Vite
12
+ * plugin resolves with) to a stub that throws on use. It is served as a
13
+ * `ws`-shaped client over workerd's native WebSocket.
14
+ * - `AsyncLocalStorage.enterWith()`: workerd omits it. A module that calls it
15
+ * first imports a patch that makes it a no-op. Builtins never reach plugin
16
+ * resolution in Vite 8, so `async_hooks` itself cannot be swapped.
17
+ * - `createRequire()` in dev: optimized dependencies carry a `?v=` query in
18
+ * their ids, and workerd rejects a `createRequire` path with a query. Calls
19
+ * are routed through a wrapper that drops it. Builds have no query, so their
20
+ * bytes are left alone.
21
+ *
22
+ * Only environments that resolve with the "workerd" condition are touched, so
23
+ * the browser bundle and a Node-run server keep the real modules.
24
+ */
25
+
26
+ const compatFile = (name: string) =>
27
+ fileURLToPath(new URL(`../compat/${name}`, import.meta.url));
28
+
29
+ export const WORKERD_WS_ADAPTER = compatFile("workerd-ws.cjs");
30
+ export const WORKERD_ENTER_WITH_PATCH = compatFile("workerd-enter-with.mjs");
31
+
32
+ const isWorkerd = (conditions: readonly string[] | undefined) =>
33
+ !!conditions?.includes("workerd");
34
+
35
+ const redirect = (id: string) => (id === "ws" ? WORKERD_WS_ADAPTER : null);
36
+
37
+ const ESM_SYNTAX = /^\s*(import|export)\b/m;
38
+
39
+ /** Prepends the patch on the first line, so line numbers stay put. */
40
+ export function withEnterWithPatch(code: string, id: string): string | null {
41
+ if (!code.includes(".enterWith(") || id.split("?")[0] === WORKERD_ENTER_WITH_PATCH) {
42
+ return null;
43
+ }
44
+ const patch = JSON.stringify(WORKERD_ENTER_WITH_PATCH);
45
+ // An ESM import in a CommonJS module would turn it into ESM; require it there.
46
+ return ESM_SYNTAX.test(code) ? `import ${patch};${code}` : `require(${patch});${code}`;
47
+ }
48
+
49
+ // A call, not a property access or a local `function createRequire(` declaration.
50
+ const CREATE_REQUIRE_CALL = /(?<![.\w$]|function\s+)createRequire\(/g;
51
+
52
+ /** Strips the query from `createRequire` arguments, for dev-served modules. */
53
+ export function withQueryFreeCreateRequire(code: string): string | null {
54
+ if (!code.match(CREATE_REQUIRE_CALL) || code.includes("__b44CreateRequireImpl")) return null;
55
+ const wrapper =
56
+ "const __b44CreateRequire = (path) => __b44CreateRequireImpl(String(path).replace(/[?#].*$/, \"\"));";
57
+ const binding = ESM_SYNTAX.test(code)
58
+ ? 'import { createRequire as __b44CreateRequireImpl } from "node:module";'
59
+ : 'const { createRequire: __b44CreateRequireImpl } = require("node:module");';
60
+ return binding + wrapper + code.replace(CREATE_REQUIRE_CALL, "__b44CreateRequire(");
61
+ }
62
+
63
+ function devTransform(code: string, id: string): string | null {
64
+ const patched = withEnterWithPatch(code, id) ?? code;
65
+ return withQueryFreeCreateRequire(patched) ?? (patched === code ? null : patched);
66
+ }
67
+
68
+ // Structural esbuild types: esbuild is Vite's dependency, not ours.
69
+ interface EsbuildBuild {
70
+ initialOptions: { conditions?: string[] };
71
+ onResolve(
72
+ options: { filter: RegExp },
73
+ callback: (args: { path: string }) => { path: string } | undefined,
74
+ ): void;
75
+ onLoad(
76
+ options: { filter: RegExp },
77
+ callback: (args: { path: string }) => Promise<{ contents: string; loader: "js" } | undefined>,
78
+ ): void;
79
+ }
80
+
81
+ // Dev pre-bundles dependencies without running Vite plugins, so the dependency
82
+ // optimizer, which only runs in dev, needs its own copy. Each copy checks the
83
+ // build's conditions itself: Cloudflare's plugin sets them after ours has run.
84
+ function esbuildOptimizerPlugin() {
85
+ return {
86
+ name: "base44-workerd-compat",
87
+ setup(build: EsbuildBuild) {
88
+ if (!isWorkerd(build.initialOptions.conditions)) return;
89
+ build.onResolve({ filter: /^ws$/ }, () => ({ path: WORKERD_WS_ADAPTER }));
90
+ build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
91
+ const code = devTransform(await readFile(args.path, "utf8"), args.path);
92
+ return code === null ? undefined : { contents: code, loader: "js" };
93
+ });
94
+ },
95
+ };
96
+ }
97
+
98
+ function rolldownOptimizerPlugin() {
99
+ let active = false;
100
+ return {
101
+ name: "base44-workerd-compat",
102
+ options(options: { resolve?: { conditionNames?: string[] } }) {
103
+ active = isWorkerd(options.resolve?.conditionNames);
104
+ },
105
+ resolveId: (id: string) => (active ? redirect(id) : null),
106
+ transform: (code: string, id: string) => (active ? devTransform(code, id) : null),
107
+ };
108
+ }
109
+
110
+ const OPTIMIZED_DEP = /[\\/]node_modules[\\/]\.vite[\\/]/;
111
+
112
+ const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
113
+
114
+ export function workerdCompatPlugin(): Plugin {
115
+ return {
116
+ name: "base44-workerd-compat",
117
+ enforce: "pre",
118
+ applyToEnvironment: (environment) =>
119
+ isWorkerd(environment.config.resolve.conditions),
120
+ configEnvironment(name) {
121
+ if (name === "client") return;
122
+ const optimizeDeps = isVite8OrLater
123
+ ? { rolldownOptions: { plugins: [rolldownOptimizerPlugin()] } }
124
+ : { esbuildOptions: { plugins: [esbuildOptimizerPlugin()] } };
125
+ return { optimizeDeps } as EnvironmentOptions;
126
+ },
127
+ resolveId: (id) => redirect(id),
128
+ transform(code, id) {
129
+ // The optimizer already patched its output.
130
+ if (OPTIMIZED_DEP.test(id)) return null;
131
+ return this.environment.mode === "dev" ? devTransform(code, id) : withEnterWithPatch(code, id);
132
+ },
133
+ };
134
+ }