@base44-preview/vite-plugin 1.0.46-pr.136.11ca3d8 → 1.0.46-pr.136.cc02f83

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
@@ -61,14 +61,18 @@ dependency optimizer, for esbuild (Vite 7) and Rolldown (Vite 8):
61
61
  - **`ws`** resolves to `compat/workerd-ws.cjs`, a `ws`-shaped client over workerd's
62
62
  native WebSocket. The package's own browser build only throws. `WebSocketServer`
63
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`.
64
+ - **`AsyncLocalStorage.enterWith()`**, which always throws in workerd, becomes a
65
+ no-op. A module that calls it first imports `compat/workerd-enter-with.mjs`. The
66
+ no-op is global to the isolate: any code that relies on `enterWith()` to
67
+ propagate state gets nothing, silently, instead of an exception. Use `run()`.
66
68
  - **`createRequire()` in dev** gets its argument's query string dropped. Optimized
67
69
  dependencies carry Vite's `?v=` query, which workerd rejects. Builds are left
68
70
  byte-for-byte alone.
69
71
 
70
72
  Stagehand 3 needs all three. `@base44/functions-compiler` applies the first two to
71
- backend functions.
73
+ backend functions. Cloudflare's `nodejs_compat` flag does not cover any of them:
74
+ its `node:http` client cannot upgrade a connection, which `ws` needs, `enterWith()`
75
+ throws by design, and `createRequire()` rejects queries.
72
76
 
73
77
  ### Build-status endpoint
74
78
 
@@ -1,7 +1,20 @@
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.
1
+ // Imported ahead of any Cloudflare Workers server module that calls enterWith,
2
+ // by the base44-workerd-compat plugin. workerd defines
3
+ // AsyncLocalStorage.prototype.enterWith but makes it always throw; libraries such
4
+ // as Stagehand call it to seed a context they also pass explicitly, so a no-op
5
+ // keeps them working.
6
+ //
7
+ // The no-op is global: any caller in the isolate that relies on enterWith to
8
+ // propagate state gets nothing instead of an exception. Storing the value per
9
+ // instance instead would leak it across the concurrent requests an isolate
10
+ // serves, which is worse. A runtime whose enterWith works is left alone.
5
11
  import { AsyncLocalStorage } from "node:async_hooks";
6
12
 
7
- AsyncLocalStorage.prototype.enterWith = () => {};
13
+ const native = AsyncLocalStorage.prototype.enterWith;
14
+ let works = false;
15
+ try {
16
+ native.call(new AsyncLocalStorage(), undefined);
17
+ works = true;
18
+ } catch {}
19
+
20
+ if (!works) AsyncLocalStorage.prototype.enterWith = function enterWith() {};
@@ -3,14 +3,23 @@
3
3
  // build needs node:net; workerd has a native WebSocket client, so this is a
4
4
  // `ws`-shaped client over it. Kept in step with @base44/functions-compiler's copy.
5
5
  "use strict";
6
+ const CONNECTING = 0;
7
+ const OPEN = 1;
8
+ const CLOSING = 2;
9
+ const CLOSED = 3;
6
10
  const toBuffer = (value) => (globalThis.Buffer ? globalThis.Buffer.from(value) : value);
11
+ // The WHATWG close() that workerd implements accepts fewer codes than `ws` does.
12
+ const isWhatwgCloseCode = (code) => code === 1000 || (code >= 3000 && code <= 4999);
13
+ const later = (fn, ...args) => queueMicrotask(() => fn(...args));
7
14
  class WebSocket {
8
- static CONNECTING = 0;
9
- static OPEN = 1;
10
- static CLOSING = 2;
11
- static CLOSED = 3;
15
+ static CONNECTING = CONNECTING;
16
+ static OPEN = OPEN;
17
+ static CLOSING = CLOSING;
18
+ static CLOSED = CLOSED;
12
19
  #socket;
13
20
  #listeners = new Map();
21
+ #maxListeners = 10;
22
+ #terminated = false;
14
23
  constructor(address, protocols) {
15
24
  this.#socket = new globalThis.WebSocket(String(address), typeof protocols === "string" || Array.isArray(protocols) ? protocols : undefined);
16
25
  try { this.#socket.binaryType = "arraybuffer"; } catch {}
@@ -20,14 +29,18 @@ class WebSocket {
20
29
  this.emit("message", toBuffer(isBinary ? new Uint8Array(event.data) : event.data), isBinary);
21
30
  });
22
31
  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 ?? "")));
32
+ this.#socket.addEventListener("close", (event) => {
33
+ if (!this.#terminated) this.emit("close", event.code, toBuffer(event.reason ?? ""));
34
+ });
24
35
  }
25
- get readyState() { return this.#socket.readyState; }
36
+ get readyState() { return this.#terminated ? CLOSED : this.#socket.readyState; }
26
37
  get url() { return this.#socket.url; }
27
38
  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); }
39
+ on(name, listener) { return this.#add(name, listener, false, false); }
40
+ addListener(name, listener) { return this.#add(name, listener, false, false); }
41
+ once(name, listener) { return this.#add(name, listener, true, false); }
42
+ prependListener(name, listener) { return this.#add(name, listener, false, true); }
43
+ prependOnceListener(name, listener) { return this.#add(name, listener, true, true); }
31
44
  off(name, listener) { return this.removeListener(name, listener); }
32
45
  removeListener(name, listener) {
33
46
  const listeners = this.#listeners.get(name);
@@ -39,7 +52,13 @@ class WebSocket {
39
52
  else this.#listeners.delete(name);
40
53
  return this;
41
54
  }
55
+ listeners(name) { return (this.#listeners.get(name) ?? []).map((entry) => entry.listener); }
56
+ listenerCount(name) { return this.#listeners.get(name)?.length ?? 0; }
57
+ eventNames() { return [...this.#listeners.keys()].filter((name) => this.listenerCount(name) > 0); }
58
+ setMaxListeners(count) { this.#maxListeners = count; return this; }
59
+ getMaxListeners() { return this.#maxListeners; }
42
60
  emit(name, ...args) {
61
+ // Dispatch to a snapshot, as Node's EventEmitter does.
43
62
  const listeners = this.#listeners.get(name) ?? [];
44
63
  this.#listeners.set(name, listeners.filter((entry) => !entry.once));
45
64
  for (const entry of listeners) entry.listener.apply(this, args);
@@ -49,27 +68,68 @@ class WebSocket {
49
68
  const done = typeof options === "function" ? options : callback;
50
69
  try {
51
70
  this.#socket.send(data);
52
- done?.();
53
71
  } catch (error) {
54
72
  if (!done) throw error;
55
- done(error);
73
+ later(done, error);
74
+ return;
56
75
  }
76
+ // `ws` reports completion asynchronously; so does this.
77
+ if (done) later(done);
78
+ }
79
+ // workerd answers the peer's pings itself but cannot send one. A keepalive
80
+ // loop waiting for "pong" would otherwise kill a healthy socket, so an open
81
+ // socket answers with one.
82
+ ping(data, mask, callback) {
83
+ const done = [data, mask, callback].find((arg) => typeof arg === "function");
84
+ if (this.readyState === OPEN) later(() => this.emit("pong", toBuffer("")));
85
+ if (done) later(done);
86
+ }
87
+ pong(data, mask, callback) {
88
+ const done = [data, mask, callback].find((arg) => typeof arg === "function");
89
+ if (done) later(done);
57
90
  }
58
- close(code, reason) { this.#socket.close(code, reason); }
59
- terminate() { this.#socket.close(); }
60
- #add(name, listener, once) {
91
+ close(code, reason) {
92
+ try {
93
+ this.#socket.close(code, reason);
94
+ } catch (error) {
95
+ // A code `ws` accepts but WHATWG close() rejects, such as 1001.
96
+ if (code === undefined || isWhatwgCloseCode(code)) throw error;
97
+ this.#socket.close(1000, reason);
98
+ }
99
+ }
100
+ // `ws` tears the connection down at once. workerd has no abrupt close, so the
101
+ // socket is closed normally and "close" is reported now, not on the reply.
102
+ terminate() {
103
+ if (this.#terminated || this.#socket.readyState === CLOSED) return;
104
+ this.#terminated = true;
105
+ try { this.#socket.close(); } catch {}
106
+ later(() => this.emit("close", 1006, toBuffer("")));
107
+ }
108
+ #add(name, listener, once, prepend) {
61
109
  const listeners = this.#listeners.get(name) ?? [];
62
- listeners.push({ listener, once });
110
+ if (prepend) listeners.unshift({ listener, once });
111
+ else listeners.push({ listener, once });
63
112
  this.#listeners.set(name, listeners);
64
113
  return this;
65
114
  }
66
115
  }
116
+ Object.assign(WebSocket.prototype, { CONNECTING, OPEN, CLOSING, CLOSED });
117
+ const unavailable = (what) => new Error(`ws ${what} is not available in Cloudflare Workers server code, which only supports the ws WebSocket client.`);
67
118
  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
- }
119
+ constructor() { throw unavailable("WebSocketServer"); }
120
+ }
121
+ class Receiver {
122
+ constructor() { throw unavailable("Receiver"); }
123
+ }
124
+ class Sender {
125
+ constructor() { throw unavailable("Sender"); }
71
126
  }
127
+ function createWebSocketStream() { throw unavailable("createWebSocketStream"); }
72
128
  module.exports = WebSocket;
73
129
  module.exports.WebSocket = WebSocket;
74
130
  module.exports.WebSocketServer = WebSocketServer;
131
+ module.exports.Server = WebSocketServer;
132
+ module.exports.Receiver = Receiver;
133
+ module.exports.Sender = Sender;
134
+ module.exports.createWebSocketStream = createWebSocketStream;
75
135
  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;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"}
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;AAiBlD,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
@@ -1,18 +1,16 @@
1
1
  import path from "node:path";
2
- import { loadEnv, version as viteVersion } from "vite";
2
+ import { loadEnv } from "vite";
3
3
  import { errorOverlayPlugin } from "./error-overlay-plugin.js";
4
4
  import { visualEditPlugin } from "./visual-edit-plugin.js";
5
- import { filterPackagesInProject } from "./utils.js";
5
+ import { filterPackagesInProject, isVite8OrLater } 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
9
  import { workerdCompatPlugin } from "./workerd-compat-plugin.js";
10
10
  import { routeRequestLogPlugin } from "./route-request-log/vite-plugin.js";
11
11
  const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
12
- // Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
13
- // `optimizeDeps.esbuildOptions`. Both spellings mean the same thing here:
14
- // treat .js files as JSX, since app code routinely puts JSX in .js.
15
- const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
12
+ // Both optimizer spellings mean the same thing here: treat .js files as JSX,
13
+ // since app code routinely puts JSX in .js.
16
14
  const jsxInJsFiles = isVite8OrLater
17
15
  ? { rolldownOptions: { moduleTypes: { ".js": "jsx" } } }
18
16
  : { esbuildOptions: { loader: { ".js": "jsx" } } };
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,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EAAE,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"}
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export declare const isVite8OrLater: boolean;
1
2
  export declare function filterPackagesInProject(packages: string[], root: string): string[];
2
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAeA,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,EAAE,MAAM,GACX,MAAM,EAAE,CAmBV"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,SAAyC,CAAC;AAcrE,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,EAAE,MAAM,GACX,MAAM,EAAE,CAmBV"}
package/dist/utils.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import { readFileSync, existsSync } from "fs";
2
2
  import { join } from "path";
3
+ import { version as viteVersion } from "vite";
4
+ // Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
5
+ // `optimizeDeps.esbuildOptions`.
6
+ export const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
3
7
  /**
4
8
  * The package that owns an optimizeDeps entry. Deep entries like
5
9
  * `react-dom/client` are separate entries to Vite's optimizer but are declared
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAC1B,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAChC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,QAAkB,EAClB,IAAY;IAEZ,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CA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C;QACH,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG;YACd,GAAG,WAAW,CAAC,YAAY;YAC3B,GAAG,WAAW,CAAC,eAAe;YAC9B,GAAG,WAAW,CAAC,gBAAgB;SAChC,CAAC;QAEF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -1,9 +1,21 @@
1
1
  import type { Plugin } from "vite";
2
2
  export declare const WORKERD_WS_ADAPTER: string;
3
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;
4
+ export interface PatchOptions {
5
+ /** Also route `createRequire` calls through the query-dropping wrapper. */
6
+ createRequire: boolean;
7
+ }
8
+ /**
9
+ * Patches a workerd server module: imports the enterWith no-op ahead of a module
10
+ * that calls `.enterWith()`, and, with `createRequire`, routes node:module's
11
+ * `createRequire` through a wrapper that drops the id's query. Code is inserted
12
+ * on the first line after any shebang or directive prologue, so strict mode
13
+ * holds and line numbers stay put. Returns null when nothing applies.
14
+ */
15
+ export declare function patchServerModule(code: string, id: string, options: PatchOptions): string | null;
16
+ export interface WorkerdCompatOptions {
17
+ /** Which dependency optimizer to hook. Defaults to the installed Vite's. */
18
+ rolldown?: boolean;
19
+ }
20
+ export declare function workerdCompatPlugin({ rolldown }?: WorkerdCompatOptions): Plugin;
9
21
  //# sourceMappingURL=workerd-compat-plugin.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"workerd-compat-plugin.d.ts","sourceRoot":"","sources":["../src/workerd-compat-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAsB,MAAM,EAAE,MAAM,MAAM,CAAC;AA4BvD,eAAO,MAAM,kBAAkB,QAA+B,CAAC;AAC/D,eAAO,MAAM,wBAAwB,QAAuC,CAAC;AA6G7E,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CA6DhG;AAiDD,MAAM,WAAW,oBAAoB;IACnC,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,QAAyB,EAAE,GAAE,oBAAyB,GAAG,MAAM,CAqBpG"}
@@ -1,10 +1,13 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { fileURLToPath } from "node:url";
3
- import { version as viteVersion } from "vite";
3
+ import { parse } from "@babel/parser";
4
+ import { default as traverse } from "@babel/traverse";
5
+ import { normalizePath } from "vite";
6
+ import { isVite8OrLater } from "./utils.js";
4
7
  /**
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
+ * Closes three workerd gaps that break Node-targeted npm clients (Stagehand among
9
+ * them) in full-stack server code. @base44/functions-compiler covers the first
10
+ * two for backend functions:
8
11
  *
9
12
  * - `ws`: its exports map sends the "browser" condition (which Cloudflare's Vite
10
13
  * plugin resolves with) to a stub that throws on use. It is served as a
@@ -20,37 +23,172 @@ import { version as viteVersion } from "vite";
20
23
  * Only environments that resolve with the "workerd" condition are touched, so
21
24
  * the browser bundle and a Node-run server keep the real modules.
22
25
  */
23
- const compatFile = (name) => fileURLToPath(new URL(`../compat/${name}`, import.meta.url));
26
+ // Vite ids use forward slashes on every platform, so these must too.
27
+ const compatFile = (name) => normalizePath(fileURLToPath(new URL(`../compat/${name}`, import.meta.url)));
24
28
  export const WORKERD_WS_ADAPTER = compatFile("workerd-ws.cjs");
25
29
  export const WORKERD_ENTER_WITH_PATCH = compatFile("workerd-enter-with.mjs");
26
30
  const isWorkerd = (conditions) => !!conditions?.includes("workerd");
31
+ // `ws` exports only its root, so a deep import never resolves to begin with.
27
32
  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
+ // JSON, CSS and the like reach a "pre" transform raw. Virtual ids often have no
34
+ // extension at all, and are JavaScript.
35
+ const NON_SCRIPT_FILE = /\.(?![cm]?[jt]sx?$)[a-z0-9]+$/i;
36
+ const NODE_MODULE = new Set(["module", "node:module"]);
37
+ const CREATE_REQUIRE_IMPL = "__b44CreateRequireImpl";
38
+ const CREATE_REQUIRE = "__b44CreateRequire";
39
+ // @babel/traverse is CommonJS: Node's ESM interop nests the function under
40
+ // `default`, while bundlers and Vitest hand it over directly.
41
+ const traverseAst = (traverse.default ?? traverse);
42
+ const pathOf = (id) => id.split("?")[0] ?? id;
43
+ function parserPlugins(file) {
44
+ if (/\.tsx$/.test(file))
45
+ return [["typescript", "jsx"]];
46
+ if (/\.[cm]?ts$/.test(file))
47
+ return [["typescript"]];
48
+ // Apps routinely put JSX in .js, but JSX parsing can misread plain JS, so it
49
+ // is only the fallback.
50
+ return [[], ["jsx"]];
51
+ }
52
+ function parseModule(code, file) {
53
+ for (const plugins of parserPlugins(file)) {
54
+ try {
55
+ return parse(code, {
56
+ // A module is ESM only if it has ESM syntax: text that merely looks
57
+ // like an import, inside a string or comment, does not count.
58
+ sourceType: /\.c[jt]s$/.test(file) ? "script" : /\.m[jt]s$/.test(file) ? "module" : "unambiguous",
59
+ allowReturnOutsideFunction: true,
60
+ allowAwaitOutsideFunction: true,
61
+ plugins,
62
+ });
63
+ }
64
+ catch {
65
+ // Try the next plugin set.
66
+ }
67
+ }
68
+ return null;
69
+ }
70
+ const isRequireOfNodeModule = (node) => node?.type === "CallExpression" &&
71
+ node.callee.type === "Identifier" &&
72
+ node.callee.name === "require" &&
73
+ node.arguments[0]?.type === "StringLiteral" &&
74
+ NODE_MODULE.has(node.arguments[0].value);
75
+ const keyName = (key) => key.type === "Identifier" ? key.name : key.type === "StringLiteral" ? key.value : undefined;
76
+ /** Whether `name` at `path` is node:module's createRequire, under any alias. */
77
+ function bindsCreateRequire(path, name) {
78
+ const binding = path.scope.getBinding(name);
79
+ if (!binding)
80
+ return false;
81
+ const decl = binding.path.node;
82
+ const parent = binding.path.parent;
83
+ if (decl.type === "ImportSpecifier") {
84
+ return (parent.type === "ImportDeclaration" &&
85
+ NODE_MODULE.has(parent.source.value) &&
86
+ keyName(decl.imported) === "createRequire");
33
87
  }
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}`;
88
+ // const { createRequire } = require("node:module")
89
+ if (decl.type === "VariableDeclarator" && decl.id.type === "ObjectPattern" && isRequireOfNodeModule(decl.init)) {
90
+ return decl.id.properties.some((prop) => prop.type === "ObjectProperty" &&
91
+ keyName(prop.key) === "createRequire" &&
92
+ prop.value.type === "Identifier" &&
93
+ prop.value.name === name);
94
+ }
95
+ return false;
96
+ }
97
+ /** Whether `name` at `path` is node:module itself, as a default, namespace or required binding. */
98
+ function bindsNodeModule(path, name) {
99
+ const binding = path.scope.getBinding(name);
100
+ if (!binding)
101
+ return false;
102
+ const decl = binding.path.node;
103
+ const parent = binding.path.parent;
104
+ if (decl.type === "ImportDefaultSpecifier" || decl.type === "ImportNamespaceSpecifier") {
105
+ return parent.type === "ImportDeclaration" && NODE_MODULE.has(parent.source.value);
106
+ }
107
+ return decl.type === "VariableDeclarator" && decl.id.type === "Identifier" && isRequireOfNodeModule(decl.init);
37
108
  }
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"))
109
+ /** The callee of a call that reaches node:module's createRequire, or null. */
110
+ function createRequireCallee(path) {
111
+ const callee = path.node.callee;
112
+ if (callee.type === "Identifier") {
113
+ return bindsCreateRequire(path, callee.name) ? callee : null;
114
+ }
115
+ if (callee.type !== "MemberExpression" || callee.computed || keyName(callee.property) !== "createRequire") {
43
116
  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(");
117
+ }
118
+ const object = callee.object;
119
+ if (object.type === "Identifier")
120
+ return bindsNodeModule(path, object.name) ? callee : null;
121
+ return isRequireOfNodeModule(object) ? callee : null;
49
122
  }
50
- function devTransform(code, id) {
51
- const patched = withEnterWithPatch(code, id) ?? code;
52
- return withQueryFreeCreateRequire(patched) ?? (patched === code ? null : patched);
123
+ /**
124
+ * Patches a workerd server module: imports the enterWith no-op ahead of a module
125
+ * that calls `.enterWith()`, and, with `createRequire`, routes node:module's
126
+ * `createRequire` through a wrapper that drops the id's query. Code is inserted
127
+ * on the first line after any shebang or directive prologue, so strict mode
128
+ * holds and line numbers stay put. Returns null when nothing applies.
129
+ */
130
+ export function patchServerModule(code, id, options) {
131
+ const file = pathOf(id);
132
+ if (NON_SCRIPT_FILE.test(file.slice(file.lastIndexOf("/") + 1)) || file === WORKERD_ENTER_WITH_PATCH)
133
+ return null;
134
+ const mayEnterWith = code.includes(".enterWith(");
135
+ const mayCreateRequire = options.createRequire && code.includes("createRequire") && !code.includes(CREATE_REQUIRE_IMPL);
136
+ if (!mayEnterWith && !mayCreateRequire)
137
+ return null;
138
+ const ast = parseModule(code, file);
139
+ if (!ast)
140
+ return null;
141
+ let callsEnterWith = false;
142
+ const callees = [];
143
+ const visit = (path) => {
144
+ const callee = path.node.callee;
145
+ if (mayEnterWith &&
146
+ (callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") &&
147
+ !callee.computed &&
148
+ keyName(callee.property) === "enterWith") {
149
+ callsEnterWith = true;
150
+ }
151
+ const target = mayCreateRequire ? createRequireCallee(path) : null;
152
+ if (target)
153
+ callees.push(target);
154
+ };
155
+ traverseAst(ast, { CallExpression: visit, OptionalCallExpression: visit });
156
+ if (!callsEnterWith && callees.length === 0)
157
+ return null;
158
+ const isEsm = ast.program.sourceType === "module";
159
+ let prefix = "";
160
+ if (callsEnterWith) {
161
+ const patch = JSON.stringify(WORKERD_ENTER_WITH_PATCH);
162
+ // An ESM import in a CommonJS module would turn it into ESM; require it there.
163
+ prefix += isEsm ? `import ${patch};` : `require(${patch});`;
164
+ }
165
+ if (callees.length > 0) {
166
+ prefix += isEsm
167
+ ? `import { createRequire as ${CREATE_REQUIRE_IMPL} } from "node:module";`
168
+ : `const { createRequire: ${CREATE_REQUIRE_IMPL} } = require("node:module");`;
169
+ prefix += `const ${CREATE_REQUIRE} = (path) => ${CREATE_REQUIRE_IMPL}(String(path).replace(/[?#].*$/, ""));`;
170
+ }
171
+ // A shebang line cannot be followed on the same line, so the code goes at the
172
+ // start of the next one.
173
+ const { interpreter, directives } = ast.program;
174
+ let afterInterpreter = 0;
175
+ if (interpreter) {
176
+ const newline = code.indexOf("\n", interpreter.end);
177
+ if (newline === -1)
178
+ prefix = `\n${prefix}`;
179
+ afterInterpreter = newline === -1 ? code.length : newline + 1;
180
+ }
181
+ const insertAt = Math.max(afterInterpreter, ...directives.map((d) => d.end));
182
+ const edits = [
183
+ { start: insertAt, end: insertAt, text: prefix },
184
+ ...callees.map((node) => ({ start: node.start, end: node.end, text: CREATE_REQUIRE })),
185
+ ].sort((a, b) => b.start - a.start);
186
+ let out = code;
187
+ for (const edit of edits)
188
+ out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
189
+ return out;
53
190
  }
191
+ const devTransform = (code, id) => patchServerModule(code, id, { createRequire: true });
54
192
  // Dev pre-bundles dependencies without running Vite plugins, so the dependency
55
193
  // optimizer, which only runs in dev, needs its own copy. Each copy checks the
56
194
  // build's conditions itself: Cloudflare's plugin sets them after ours has run.
@@ -61,7 +199,8 @@ function esbuildOptimizerPlugin() {
61
199
  if (!isWorkerd(build.initialOptions.conditions))
62
200
  return;
63
201
  build.onResolve({ filter: /^ws$/ }, () => ({ path: WORKERD_WS_ADAPTER }));
64
- build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
202
+ // Other namespaces hold virtual modules with no file to read.
203
+ build.onLoad({ filter: /\.[cm]?js$/, namespace: "file" }, async (args) => {
65
204
  const code = devTransform(await readFile(args.path, "utf8"), args.path);
66
205
  return code === null ? undefined : { contents: code, loader: "js" };
67
206
  });
@@ -80,8 +219,7 @@ function rolldownOptimizerPlugin() {
80
219
  };
81
220
  }
82
221
  const OPTIMIZED_DEP = /[\\/]node_modules[\\/]\.vite[\\/]/;
83
- const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
84
- export function workerdCompatPlugin() {
222
+ export function workerdCompatPlugin({ rolldown = isVite8OrLater } = {}) {
85
223
  return {
86
224
  name: "base44-workerd-compat",
87
225
  enforce: "pre",
@@ -89,9 +227,10 @@ export function workerdCompatPlugin() {
89
227
  configEnvironment(name) {
90
228
  if (name === "client")
91
229
  return;
92
- const optimizeDeps = isVite8OrLater
230
+ const optimizeDeps = rolldown
93
231
  ? { rolldownOptions: { plugins: [rolldownOptimizerPlugin()] } }
94
232
  : { esbuildOptions: { plugins: [esbuildOptimizerPlugin()] } };
233
+ // Vite 7's types do not know `rolldownOptions`, hence the cast.
95
234
  return { optimizeDeps };
96
235
  },
97
236
  resolveId: (id) => redirect(id),
@@ -99,7 +238,7 @@ export function workerdCompatPlugin() {
99
238
  // The optimizer already patched its output.
100
239
  if (OPTIMIZED_DEP.test(id))
101
240
  return null;
102
- return this.environment.mode === "dev" ? devTransform(code, id) : withEnterWithPatch(code, id);
241
+ return patchServerModule(code, id, { createRequire: this.environment.mode === "dev" });
103
242
  },
104
243
  };
105
244
  }
@@ -1 +1 @@
1
- {"version":3,"file":"workerd-compat-plugin.js","sourceRoot":"","sources":["../src/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
4
4
  "description": "The Vite plugin for base44 based applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import path from "node:path";
2
2
  import type { Plugin, UserConfig } from "vite";
3
- import { loadEnv, version as viteVersion } from "vite";
3
+ import { loadEnv } from "vite";
4
4
  import { errorOverlayPlugin } from "./error-overlay-plugin.js";
5
5
  import { visualEditPlugin } from "./visual-edit-plugin.js";
6
- import { filterPackagesInProject } from "./utils.js";
6
+ import { filterPackagesInProject, isVite8OrLater } 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";
@@ -13,10 +13,8 @@ export type { DocumentScript } from "./consts.js";
13
13
 
14
14
  const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
15
15
 
16
- // Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
17
- // `optimizeDeps.esbuildOptions`. Both spellings mean the same thing here:
18
- // treat .js files as JSX, since app code routinely puts JSX in .js.
19
- const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
16
+ // Both optimizer spellings mean the same thing here: treat .js files as JSX,
17
+ // since app code routinely puts JSX in .js.
20
18
  const jsxInJsFiles = isVite8OrLater
21
19
  ? { rolldownOptions: { moduleTypes: { ".js": "jsx" } } }
22
20
  : { esbuildOptions: { loader: { ".js": "jsx" } } };
package/src/utils.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { readFileSync, existsSync } from "fs";
2
2
  import { join } from "path";
3
+ import { version as viteVersion } from "vite";
4
+
5
+ // Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
6
+ // `optimizeDeps.esbuildOptions`.
7
+ export const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
3
8
 
4
9
  /**
5
10
  * The package that owns an optimizeDeps entry. Deep entries like
@@ -1,12 +1,16 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { fileURLToPath } from "node:url";
3
+ import { parse, type ParserPlugin } from "@babel/parser";
4
+ import { default as traverse, type NodePath } from "@babel/traverse";
5
+ import type * as t from "@babel/types";
3
6
  import type { EnvironmentOptions, Plugin } from "vite";
4
- import { version as viteVersion } from "vite";
7
+ import { normalizePath } from "vite";
8
+ import { isVite8OrLater } from "./utils.js";
5
9
 
6
10
  /**
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:
11
+ * Closes three workerd gaps that break Node-targeted npm clients (Stagehand among
12
+ * them) in full-stack server code. @base44/functions-compiler covers the first
13
+ * two for backend functions:
10
14
  *
11
15
  * - `ws`: its exports map sends the "browser" condition (which Cloudflare's Vite
12
16
  * plugin resolves with) to a stub that throws on use. It is served as a
@@ -23,8 +27,9 @@ import { version as viteVersion } from "vite";
23
27
  * the browser bundle and a Node-run server keep the real modules.
24
28
  */
25
29
 
30
+ // Vite ids use forward slashes on every platform, so these must too.
26
31
  const compatFile = (name: string) =>
27
- fileURLToPath(new URL(`../compat/${name}`, import.meta.url));
32
+ normalizePath(fileURLToPath(new URL(`../compat/${name}`, import.meta.url)));
28
33
 
29
34
  export const WORKERD_WS_ADAPTER = compatFile("workerd-ws.cjs");
30
35
  export const WORKERD_ENTER_WITH_PATCH = compatFile("workerd-enter-with.mjs");
@@ -32,39 +37,187 @@ export const WORKERD_ENTER_WITH_PATCH = compatFile("workerd-enter-with.mjs");
32
37
  const isWorkerd = (conditions: readonly string[] | undefined) =>
33
38
  !!conditions?.includes("workerd");
34
39
 
40
+ // `ws` exports only its root, so a deep import never resolves to begin with.
35
41
  const redirect = (id: string) => (id === "ws" ? WORKERD_WS_ADAPTER : null);
36
42
 
37
- const ESM_SYNTAX = /^\s*(import|export)\b/m;
43
+ // JSON, CSS and the like reach a "pre" transform raw. Virtual ids often have no
44
+ // extension at all, and are JavaScript.
45
+ const NON_SCRIPT_FILE = /\.(?![cm]?[jt]sx?$)[a-z0-9]+$/i;
46
+ const NODE_MODULE = new Set(["module", "node:module"]);
47
+ const CREATE_REQUIRE_IMPL = "__b44CreateRequireImpl";
48
+ const CREATE_REQUIRE = "__b44CreateRequire";
38
49
 
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) {
50
+ // @babel/traverse is CommonJS: Node's ESM interop nests the function under
51
+ // `default`, while bundlers and Vitest hand it over directly.
52
+ const traverseAst = ((traverse as unknown as { default?: typeof traverse }).default ?? traverse) as unknown as typeof traverse.default;
53
+
54
+ const pathOf = (id: string) => id.split("?")[0] ?? id;
55
+
56
+ function parserPlugins(file: string): ParserPlugin[][] {
57
+ if (/\.tsx$/.test(file)) return [["typescript", "jsx"]];
58
+ if (/\.[cm]?ts$/.test(file)) return [["typescript"]];
59
+ // Apps routinely put JSX in .js, but JSX parsing can misread plain JS, so it
60
+ // is only the fallback.
61
+ return [[], ["jsx"]];
62
+ }
63
+
64
+ function parseModule(code: string, file: string): t.File | null {
65
+ for (const plugins of parserPlugins(file)) {
66
+ try {
67
+ return parse(code, {
68
+ // A module is ESM only if it has ESM syntax: text that merely looks
69
+ // like an import, inside a string or comment, does not count.
70
+ sourceType: /\.c[jt]s$/.test(file) ? "script" : /\.m[jt]s$/.test(file) ? "module" : "unambiguous",
71
+ allowReturnOutsideFunction: true,
72
+ allowAwaitOutsideFunction: true,
73
+ plugins,
74
+ });
75
+ } catch {
76
+ // Try the next plugin set.
77
+ }
78
+ }
79
+ return null;
80
+ }
81
+
82
+ const isRequireOfNodeModule = (node: t.Node | null | undefined): boolean =>
83
+ node?.type === "CallExpression" &&
84
+ node.callee.type === "Identifier" &&
85
+ node.callee.name === "require" &&
86
+ node.arguments[0]?.type === "StringLiteral" &&
87
+ NODE_MODULE.has(node.arguments[0].value);
88
+
89
+ const keyName = (key: t.Node): string | undefined =>
90
+ key.type === "Identifier" ? key.name : key.type === "StringLiteral" ? key.value : undefined;
91
+
92
+ /** Whether `name` at `path` is node:module's createRequire, under any alias. */
93
+ function bindsCreateRequire(path: NodePath, name: string): boolean {
94
+ const binding = path.scope.getBinding(name);
95
+ if (!binding) return false;
96
+ const decl = binding.path.node;
97
+ const parent = binding.path.parent;
98
+ if (decl.type === "ImportSpecifier") {
99
+ return (
100
+ parent.type === "ImportDeclaration" &&
101
+ NODE_MODULE.has(parent.source.value) &&
102
+ keyName(decl.imported) === "createRequire"
103
+ );
104
+ }
105
+ // const { createRequire } = require("node:module")
106
+ if (decl.type === "VariableDeclarator" && decl.id.type === "ObjectPattern" && isRequireOfNodeModule(decl.init)) {
107
+ return decl.id.properties.some(
108
+ (prop) =>
109
+ prop.type === "ObjectProperty" &&
110
+ keyName(prop.key) === "createRequire" &&
111
+ prop.value.type === "Identifier" &&
112
+ prop.value.name === name,
113
+ );
114
+ }
115
+ return false;
116
+ }
117
+
118
+ /** Whether `name` at `path` is node:module itself, as a default, namespace or required binding. */
119
+ function bindsNodeModule(path: NodePath, name: string): boolean {
120
+ const binding = path.scope.getBinding(name);
121
+ if (!binding) return false;
122
+ const decl = binding.path.node;
123
+ const parent = binding.path.parent;
124
+ if (decl.type === "ImportDefaultSpecifier" || decl.type === "ImportNamespaceSpecifier") {
125
+ return parent.type === "ImportDeclaration" && NODE_MODULE.has(parent.source.value);
126
+ }
127
+ return decl.type === "VariableDeclarator" && decl.id.type === "Identifier" && isRequireOfNodeModule(decl.init);
128
+ }
129
+
130
+ /** The callee of a call that reaches node:module's createRequire, or null. */
131
+ function createRequireCallee(path: NodePath<t.CallExpression | t.OptionalCallExpression>): t.Node | null {
132
+ const callee = path.node.callee;
133
+ if (callee.type === "Identifier") {
134
+ return bindsCreateRequire(path, callee.name) ? callee : null;
135
+ }
136
+ if (callee.type !== "MemberExpression" || callee.computed || keyName(callee.property) !== "createRequire") {
42
137
  return null;
43
138
  }
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}`;
139
+ const object = callee.object;
140
+ if (object.type === "Identifier") return bindsNodeModule(path, object.name) ? callee : null;
141
+ return isRequireOfNodeModule(object) ? callee : null;
47
142
  }
48
143
 
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(");
144
+ export interface PatchOptions {
145
+ /** Also route `createRequire` calls through the query-dropping wrapper. */
146
+ createRequire: boolean;
61
147
  }
62
148
 
63
- function devTransform(code: string, id: string): string | null {
64
- const patched = withEnterWithPatch(code, id) ?? code;
65
- return withQueryFreeCreateRequire(patched) ?? (patched === code ? null : patched);
149
+ /**
150
+ * Patches a workerd server module: imports the enterWith no-op ahead of a module
151
+ * that calls `.enterWith()`, and, with `createRequire`, routes node:module's
152
+ * `createRequire` through a wrapper that drops the id's query. Code is inserted
153
+ * on the first line after any shebang or directive prologue, so strict mode
154
+ * holds and line numbers stay put. Returns null when nothing applies.
155
+ */
156
+ export function patchServerModule(code: string, id: string, options: PatchOptions): string | null {
157
+ const file = pathOf(id);
158
+ if (NON_SCRIPT_FILE.test(file.slice(file.lastIndexOf("/") + 1)) || file === WORKERD_ENTER_WITH_PATCH) return null;
159
+ const mayEnterWith = code.includes(".enterWith(");
160
+ const mayCreateRequire =
161
+ options.createRequire && code.includes("createRequire") && !code.includes(CREATE_REQUIRE_IMPL);
162
+ if (!mayEnterWith && !mayCreateRequire) return null;
163
+
164
+ const ast = parseModule(code, file);
165
+ if (!ast) return null;
166
+
167
+ let callsEnterWith = false;
168
+ const callees: t.Node[] = [];
169
+ const visit = (path: NodePath<t.CallExpression | t.OptionalCallExpression>) => {
170
+ const callee = path.node.callee;
171
+ if (
172
+ mayEnterWith &&
173
+ (callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") &&
174
+ !callee.computed &&
175
+ keyName(callee.property) === "enterWith"
176
+ ) {
177
+ callsEnterWith = true;
178
+ }
179
+ const target = mayCreateRequire ? createRequireCallee(path) : null;
180
+ if (target) callees.push(target);
181
+ };
182
+ traverseAst(ast, { CallExpression: visit, OptionalCallExpression: visit });
183
+ if (!callsEnterWith && callees.length === 0) return null;
184
+
185
+ const isEsm = ast.program.sourceType === "module";
186
+ let prefix = "";
187
+ if (callsEnterWith) {
188
+ const patch = JSON.stringify(WORKERD_ENTER_WITH_PATCH);
189
+ // An ESM import in a CommonJS module would turn it into ESM; require it there.
190
+ prefix += isEsm ? `import ${patch};` : `require(${patch});`;
191
+ }
192
+ if (callees.length > 0) {
193
+ prefix += isEsm
194
+ ? `import { createRequire as ${CREATE_REQUIRE_IMPL} } from "node:module";`
195
+ : `const { createRequire: ${CREATE_REQUIRE_IMPL} } = require("node:module");`;
196
+ prefix += `const ${CREATE_REQUIRE} = (path) => ${CREATE_REQUIRE_IMPL}(String(path).replace(/[?#].*$/, ""));`;
197
+ }
198
+
199
+ // A shebang line cannot be followed on the same line, so the code goes at the
200
+ // start of the next one.
201
+ const { interpreter, directives } = ast.program;
202
+ let afterInterpreter = 0;
203
+ if (interpreter) {
204
+ const newline = code.indexOf("\n", interpreter.end!);
205
+ if (newline === -1) prefix = `\n${prefix}`;
206
+ afterInterpreter = newline === -1 ? code.length : newline + 1;
207
+ }
208
+ const insertAt = Math.max(afterInterpreter, ...directives.map((d) => d.end!));
209
+
210
+ const edits = [
211
+ { start: insertAt, end: insertAt, text: prefix },
212
+ ...callees.map((node) => ({ start: node.start!, end: node.end!, text: CREATE_REQUIRE })),
213
+ ].sort((a, b) => b.start - a.start);
214
+ let out = code;
215
+ for (const edit of edits) out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
216
+ return out;
66
217
  }
67
218
 
219
+ const devTransform = (code: string, id: string) => patchServerModule(code, id, { createRequire: true });
220
+
68
221
  // Structural esbuild types: esbuild is Vite's dependency, not ours.
69
222
  interface EsbuildBuild {
70
223
  initialOptions: { conditions?: string[] };
@@ -73,7 +226,7 @@ interface EsbuildBuild {
73
226
  callback: (args: { path: string }) => { path: string } | undefined,
74
227
  ): void;
75
228
  onLoad(
76
- options: { filter: RegExp },
229
+ options: { filter: RegExp; namespace: string },
77
230
  callback: (args: { path: string }) => Promise<{ contents: string; loader: "js" } | undefined>,
78
231
  ): void;
79
232
  }
@@ -87,7 +240,8 @@ function esbuildOptimizerPlugin() {
87
240
  setup(build: EsbuildBuild) {
88
241
  if (!isWorkerd(build.initialOptions.conditions)) return;
89
242
  build.onResolve({ filter: /^ws$/ }, () => ({ path: WORKERD_WS_ADAPTER }));
90
- build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
243
+ // Other namespaces hold virtual modules with no file to read.
244
+ build.onLoad({ filter: /\.[cm]?js$/, namespace: "file" }, async (args) => {
91
245
  const code = devTransform(await readFile(args.path, "utf8"), args.path);
92
246
  return code === null ? undefined : { contents: code, loader: "js" };
93
247
  });
@@ -109,9 +263,12 @@ function rolldownOptimizerPlugin() {
109
263
 
110
264
  const OPTIMIZED_DEP = /[\\/]node_modules[\\/]\.vite[\\/]/;
111
265
 
112
- const isVite8OrLater = Number(viteVersion.split(".")[0]) >= 8;
266
+ export interface WorkerdCompatOptions {
267
+ /** Which dependency optimizer to hook. Defaults to the installed Vite's. */
268
+ rolldown?: boolean;
269
+ }
113
270
 
114
- export function workerdCompatPlugin(): Plugin {
271
+ export function workerdCompatPlugin({ rolldown = isVite8OrLater }: WorkerdCompatOptions = {}): Plugin {
115
272
  return {
116
273
  name: "base44-workerd-compat",
117
274
  enforce: "pre",
@@ -119,16 +276,17 @@ export function workerdCompatPlugin(): Plugin {
119
276
  isWorkerd(environment.config.resolve.conditions),
120
277
  configEnvironment(name) {
121
278
  if (name === "client") return;
122
- const optimizeDeps = isVite8OrLater
279
+ const optimizeDeps = rolldown
123
280
  ? { rolldownOptions: { plugins: [rolldownOptimizerPlugin()] } }
124
281
  : { esbuildOptions: { plugins: [esbuildOptimizerPlugin()] } };
282
+ // Vite 7's types do not know `rolldownOptions`, hence the cast.
125
283
  return { optimizeDeps } as EnvironmentOptions;
126
284
  },
127
285
  resolveId: (id) => redirect(id),
128
286
  transform(code, id) {
129
287
  // The optimizer already patched its output.
130
288
  if (OPTIMIZED_DEP.test(id)) return null;
131
- return this.environment.mode === "dev" ? devTransform(code, id) : withEnterWithPatch(code, id);
289
+ return patchServerModule(code, id, { createRequire: this.environment.mode === "dev" });
132
290
  },
133
291
  };
134
292
  }