@base44-preview/vite-plugin 1.0.35-pr.118.0488c70 → 1.0.36-pr.122.b6b8bb5

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.
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function base44RuntimePlugin(): Plugin;
3
+ //# sourceMappingURL=base44-runtime-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base44-runtime-plugin.d.ts","sourceRoot":"","sources":["../src/base44-runtime-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAmGnC,wBAAgB,mBAAmB,IAAI,MAAM,CAsC5C"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Serves `base44:runtime` to full-stack server routes, so a route reads secrets
3
+ * and schedules background work with the SAME import a backend function uses:
4
+ *
5
+ * import { secrets, waitUntil } from "base44:runtime";
6
+ *
7
+ * WHY A BUILD-TIME VIRTUAL MODULE. The Workers runtime cannot resolve a custom
8
+ * scheme: the legacy module registry special-cases only `node:` / `cloudflare:` /
9
+ * `workerd:`, and the new registry (`new_module_registry`) explicitly rejects a
10
+ * bundle module whose name carries a non-`file:` scheme. Import maps are not
11
+ * supported either. So `base44:runtime` has to be resolved before upload — there
12
+ * is no runtime path to it, and no amount of wrapping the deployed entry creates
13
+ * one.
14
+ *
15
+ * WHY NO ASYNCLOCALSTORAGE / NO WRAPPER ENTRY. Cloudflare now ships both
16
+ * primitives ambiently from `cloudflare:workers` (`env` since 2025-03-17,
17
+ * `waitUntil` since 2025-08-08), backed by workerd's own AsyncContextFrame and
18
+ * IoContext. The backend-function bundler predates that and threads a context
19
+ * through `globalThis.Base44` because it owns the generated entry; here the
20
+ * framework owns the entry, and borrowing the platform's ambient accessors means
21
+ * we never have to.
22
+ */
23
+ const SPECIFIER = "base44:runtime";
24
+ // Rollup convention: a resolved virtual id starts with NUL so no other plugin
25
+ // (and no filesystem lookup) tries to claim it.
26
+ const RESOLVED = "\0base44:runtime";
27
+ // Reserved so a server route importing one fails with an explanation instead of
28
+ // a bare "failed to resolve import". Both need bindings on the deployed script
29
+ // that full-stack uploads do not carry yet, so neither can work by resolving a
30
+ // module here — see the PR description.
31
+ const ACTORS_REASON = "Actors need Durable Object bindings and migrations on the deployed script, which full-stack apps do not have yet.";
32
+ const PRIVATE_DATA_SOURCES_REASON = "Private data sources need Hyperdrive/VPC bindings and the activation handshake on the deployed script, which full-stack apps do not have yet.";
33
+ function unsupportedReason(id) {
34
+ if (id === "base44:runtime/actors")
35
+ return ACTORS_REASON;
36
+ if (id === "base44:private-data-sources" || id.startsWith("base44:private-data-sources/")) {
37
+ return PRIVATE_DATA_SOURCES_REASON;
38
+ }
39
+ return null;
40
+ }
41
+ /**
42
+ * Production body. `cloudflare:workers` stays external — workerd provides it,
43
+ * and Nitro's cloudflare preset already treats `cloudflare:*` that way.
44
+ *
45
+ * `waitUntil` is WRAPPED rather than re-exported: ours returns the promise so it
46
+ * composes (`infra/base44-userapp-bundler/src/runtime/index.ts` in apper),
47
+ * Cloudflare's returns void. A bare re-export would make `const p = waitUntil(x)`
48
+ * work in a backend function and silently yield `undefined` here — one specifier
49
+ * with two behaviours is the exact failure this module exists to prevent.
50
+ */
51
+ const WORKER_BODY = `
52
+ import { env, waitUntil as cfWaitUntil } from "cloudflare:workers";
53
+
54
+ export function waitUntil(promise) {
55
+ cfWaitUntil(promise);
56
+ return promise;
57
+ }
58
+
59
+ export const secrets = {
60
+ get(name) {
61
+ const value = env[name];
62
+ return typeof value === "string" ? value : undefined;
63
+ },
64
+ };
65
+ `;
66
+ /**
67
+ * Dev body. `vite dev` may run the server environment outside workerd, where
68
+ * `cloudflare:workers` does not exist, so dev reads the same values from
69
+ * `process.env` — which Nitro populates from the local binding set.
70
+ *
71
+ * `waitUntil` here deliberately keeps the promise alive and lets a rejection
72
+ * surface rather than swallowing it. A no-op would make background work vanish
73
+ * in dev while working in production, which is the single nastiest shape this
74
+ * shim can take.
75
+ */
76
+ const DEV_BODY = `
77
+ export function waitUntil(promise) {
78
+ Promise.resolve(promise).catch((error) => {
79
+ console.error("[base44] waitUntil promise rejected:", error);
80
+ });
81
+ return promise;
82
+ }
83
+
84
+ export const secrets = {
85
+ get(name) {
86
+ const value = process.env[name];
87
+ return typeof value === "string" ? value : undefined;
88
+ },
89
+ };
90
+ `;
91
+ export function base44RuntimePlugin() {
92
+ let isDev = false;
93
+ return {
94
+ name: "base44-runtime",
95
+ // Ahead of Vite's own resolution so the bare `base44:` specifier is never
96
+ // mistaken for a URL protocol.
97
+ enforce: "pre",
98
+ configResolved(config) {
99
+ isDev = config.command === "serve";
100
+ },
101
+ resolveId(id) {
102
+ const reason = unsupportedReason(id);
103
+ if (reason) {
104
+ this.error(`"${id}" is not available in full-stack server routes. ${reason}`);
105
+ }
106
+ if (id !== SPECIFIER)
107
+ return null;
108
+ // `cloudflare:workers` has no browser equivalent, so a client-side import
109
+ // would bundle a module that cannot run. Fail with the reason instead.
110
+ if (this.environment?.name === "client") {
111
+ this.error(`"${SPECIFIER}" is server-only — it reads Worker bindings, which do not ` +
112
+ `exist in the browser. Move this import into a server route under src/server/.`);
113
+ }
114
+ return RESOLVED;
115
+ },
116
+ load(id) {
117
+ if (id !== RESOLVED)
118
+ return null;
119
+ return isDev ? DEV_BODY : WORKER_BODY;
120
+ },
121
+ };
122
+ }
123
+ //# sourceMappingURL=base44-runtime-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base44-runtime-plugin.js","sourceRoot":"","sources":["../src/base44-runtime-plugin.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,8EAA8E;AAC9E,gDAAgD;AAChD,MAAM,QAAQ,GAAG,kBAAkB,CAAC;AAEpC,gFAAgF;AAChF,+EAA+E;AAC/E,+EAA+E;AAC/E,wCAAwC;AACxC,MAAM,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;gBAAE,OAAO,IAAI,CAAC;YACjC,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -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;AAyB/C,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,iBAwOP"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AA0B/C,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,iBA6OP"}
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { visualEditPlugin } from "./visual-edit-plugin.js";
5
5
  import { filterPackagesInProject } from "./utils.js";
6
6
  import { htmlInjectionsPlugin } from "./html-injections-plugin.js";
7
7
  import { buildStatusPlugin } from "./build-status-plugin.js";
8
+ import { base44RuntimePlugin } from "./base44-runtime-plugin.js";
8
9
  const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
9
10
  // Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
10
11
  // `optimizeDeps.esbuildOptions`. Both spellings mean the same thing here:
@@ -215,6 +216,11 @@ export default function vitePlugin(opts = {}) {
215
216
  ...(process.env.BASE44_BUILD_STATUS_ENABLED === "1"
216
217
  ? [buildStatusPlugin()]
217
218
  : []),
219
+ // Serves `base44:runtime` to full-stack server routes. Unconditional: it
220
+ // only claims the `base44:` specifiers, so an app with no server dir never
221
+ // notices it. Ordering comes from its own `enforce: "pre"`, not from its
222
+ // position here — several tests index this array from the front.
223
+ base44RuntimePlugin(),
218
224
  ];
219
225
  }
220
226
  //# sourceMappingURL=index.js.map
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,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,kBAAkB,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;AAE1D,0EAA0E;AAC1E,0EAA0E;AAC1E,oEAAoE;AACpE,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC9D,MAAM,YAAY,GAAG,cAAc;IACjC,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,WAAW,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AAC;YACd,CAAC;SACQ;QACX,GAAG,CAAC,kBAAkB;YACpB,CAAC,CAAC;gBACE;oBACE,IAAI,EAAE,YAAY;oBAClB,eAAe,CAAC,MAAM;wBACpB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;4BACxC,yBAAyB;4BACzB,GAAG,CAAC,SAAS,CAAC,iBAAiB,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,oBAAoB,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC;QAC5F,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;KACtB,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/vite-plugin",
3
- "version": "1.0.35-pr.118.0488c70",
3
+ "version": "1.0.36-pr.122.b6b8bb5",
4
4
  "description": "The Vite plugin for base44 based applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -0,0 +1,138 @@
1
+ import type { Plugin } from "vite";
2
+
3
+ /**
4
+ * Serves `base44:runtime` to full-stack server routes, so a route reads secrets
5
+ * and schedules background work with the SAME import a backend function uses:
6
+ *
7
+ * import { secrets, waitUntil } from "base44:runtime";
8
+ *
9
+ * WHY A BUILD-TIME VIRTUAL MODULE. The Workers runtime cannot resolve a custom
10
+ * scheme: the legacy module registry special-cases only `node:` / `cloudflare:` /
11
+ * `workerd:`, and the new registry (`new_module_registry`) explicitly rejects a
12
+ * bundle module whose name carries a non-`file:` scheme. Import maps are not
13
+ * supported either. So `base44:runtime` has to be resolved before upload — there
14
+ * is no runtime path to it, and no amount of wrapping the deployed entry creates
15
+ * one.
16
+ *
17
+ * WHY NO ASYNCLOCALSTORAGE / NO WRAPPER ENTRY. Cloudflare now ships both
18
+ * primitives ambiently from `cloudflare:workers` (`env` since 2025-03-17,
19
+ * `waitUntil` since 2025-08-08), backed by workerd's own AsyncContextFrame and
20
+ * IoContext. The backend-function bundler predates that and threads a context
21
+ * through `globalThis.Base44` because it owns the generated entry; here the
22
+ * framework owns the entry, and borrowing the platform's ambient accessors means
23
+ * we never have to.
24
+ */
25
+
26
+ const SPECIFIER = "base44:runtime";
27
+ // Rollup convention: a resolved virtual id starts with NUL so no other plugin
28
+ // (and no filesystem lookup) tries to claim it.
29
+ const RESOLVED = "\0base44:runtime";
30
+
31
+ // Reserved so a server route importing one fails with an explanation instead of
32
+ // a bare "failed to resolve import". Both need bindings on the deployed script
33
+ // that full-stack uploads do not carry yet, so neither can work by resolving a
34
+ // module here — see the PR description.
35
+ const ACTORS_REASON =
36
+ "Actors need Durable Object bindings and migrations on the deployed script, which full-stack apps do not have yet.";
37
+ const PRIVATE_DATA_SOURCES_REASON =
38
+ "Private data sources need Hyperdrive/VPC bindings and the activation handshake on the deployed script, which full-stack apps do not have yet.";
39
+
40
+ function unsupportedReason(id: string): string | null {
41
+ if (id === "base44:runtime/actors") return ACTORS_REASON;
42
+ if (id === "base44:private-data-sources" || id.startsWith("base44:private-data-sources/")) {
43
+ return PRIVATE_DATA_SOURCES_REASON;
44
+ }
45
+ return null;
46
+ }
47
+
48
+ /**
49
+ * Production body. `cloudflare:workers` stays external — workerd provides it,
50
+ * and Nitro's cloudflare preset already treats `cloudflare:*` that way.
51
+ *
52
+ * `waitUntil` is WRAPPED rather than re-exported: ours returns the promise so it
53
+ * composes (`infra/base44-userapp-bundler/src/runtime/index.ts` in apper),
54
+ * Cloudflare's returns void. A bare re-export would make `const p = waitUntil(x)`
55
+ * work in a backend function and silently yield `undefined` here — one specifier
56
+ * with two behaviours is the exact failure this module exists to prevent.
57
+ */
58
+ const WORKER_BODY = `
59
+ import { env, waitUntil as cfWaitUntil } from "cloudflare:workers";
60
+
61
+ export function waitUntil(promise) {
62
+ cfWaitUntil(promise);
63
+ return promise;
64
+ }
65
+
66
+ export const secrets = {
67
+ get(name) {
68
+ const value = env[name];
69
+ return typeof value === "string" ? value : undefined;
70
+ },
71
+ };
72
+ `;
73
+
74
+ /**
75
+ * Dev body. `vite dev` may run the server environment outside workerd, where
76
+ * `cloudflare:workers` does not exist, so dev reads the same values from
77
+ * `process.env` — which Nitro populates from the local binding set.
78
+ *
79
+ * `waitUntil` here deliberately keeps the promise alive and lets a rejection
80
+ * surface rather than swallowing it. A no-op would make background work vanish
81
+ * in dev while working in production, which is the single nastiest shape this
82
+ * shim can take.
83
+ */
84
+ const DEV_BODY = `
85
+ export function waitUntil(promise) {
86
+ Promise.resolve(promise).catch((error) => {
87
+ console.error("[base44] waitUntil promise rejected:", error);
88
+ });
89
+ return promise;
90
+ }
91
+
92
+ export const secrets = {
93
+ get(name) {
94
+ const value = process.env[name];
95
+ return typeof value === "string" ? value : undefined;
96
+ },
97
+ };
98
+ `;
99
+
100
+ export function base44RuntimePlugin(): Plugin {
101
+ let isDev = false;
102
+
103
+ return {
104
+ name: "base44-runtime",
105
+ // Ahead of Vite's own resolution so the bare `base44:` specifier is never
106
+ // mistaken for a URL protocol.
107
+ enforce: "pre",
108
+
109
+ configResolved(config) {
110
+ isDev = config.command === "serve";
111
+ },
112
+
113
+ resolveId(id) {
114
+ const reason = unsupportedReason(id);
115
+ if (reason) {
116
+ this.error(
117
+ `"${id}" is not available in full-stack server routes. ${reason}`
118
+ );
119
+ }
120
+ if (id !== SPECIFIER) return null;
121
+
122
+ // `cloudflare:workers` has no browser equivalent, so a client-side import
123
+ // would bundle a module that cannot run. Fail with the reason instead.
124
+ if (this.environment?.name === "client") {
125
+ this.error(
126
+ `"${SPECIFIER}" is server-only — it reads Worker bindings, which do not ` +
127
+ `exist in the browser. Move this import into a server route under src/server/.`
128
+ );
129
+ }
130
+ return RESOLVED;
131
+ },
132
+
133
+ load(id) {
134
+ if (id !== RESOLVED) return null;
135
+ return isDev ? DEV_BODY : WORKER_BODY;
136
+ },
137
+ };
138
+ }
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ import { visualEditPlugin } from "./visual-edit-plugin.js";
6
6
  import { filterPackagesInProject } from "./utils.js";
7
7
  import { htmlInjectionsPlugin } from "./html-injections-plugin.js";
8
8
  import { buildStatusPlugin } from "./build-status-plugin.js";
9
+ import { base44RuntimePlugin } from "./base44-runtime-plugin.js";
9
10
 
10
11
  const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
11
12
 
@@ -288,5 +289,10 @@ export default function vitePlugin(
288
289
  ...(process.env.BASE44_BUILD_STATUS_ENABLED === "1"
289
290
  ? [buildStatusPlugin()]
290
291
  : []),
292
+ // Serves `base44:runtime` to full-stack server routes. Unconditional: it
293
+ // only claims the `base44:` specifiers, so an app with no server dir never
294
+ // notices it. Ordering comes from its own `enforce: "pre"`, not from its
295
+ // position here — several tests index this array from the front.
296
+ base44RuntimePlugin(),
291
297
  ];
292
298
  }