@base44/vite-plugin 1.0.36 → 1.0.37

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;AA4EnC,wBAAgB,mBAAmB,IAAI,MAAM,CA0B5C"}
@@ -0,0 +1,95 @@
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 route importing it fails with an explanation instead of a bare
28
+ // "failed to resolve import". Actors are never imported — they live in the app's
29
+ // actors directory, in server routes exactly as in backend functions.
30
+ const ACTORS_REASON = "Actors are defined in the app's actors directory, not imported into a route.";
31
+ function unsupportedReason(id) {
32
+ if (id === "base44:runtime/actors")
33
+ return ACTORS_REASON;
34
+ return null;
35
+ }
36
+ /**
37
+ * `cloudflare:workers` stays external — workerd provides it, and Nitro's
38
+ * cloudflare preset already treats `cloudflare:*` that way.
39
+ *
40
+ * There is deliberately no separate dev body. Nitro's `cloudflareDev` preset
41
+ * (aliased for `cloudflare-module`, which is what these apps build with) sets
42
+ * `devServer.runner: "miniflare"`, so dev runs in workerd too and the same
43
+ * import resolves there. A `process.env` fallback would buy nothing and cost a
44
+ * dev/prod behaviour split — the shape that makes background work silently
45
+ * vanish locally while working in production. If someone overrides the runner
46
+ * away from workerd, this fails loudly at resolution rather than quietly
47
+ * serving a different value.
48
+ *
49
+ * `waitUntil` is WRAPPED rather than re-exported: ours returns the promise so it
50
+ * composes (`infra/base44-userapp-bundler/src/runtime/index.ts` in apper),
51
+ * Cloudflare's returns void. A bare re-export would make `const p = waitUntil(x)`
52
+ * work in a backend function and silently yield `undefined` here — one specifier
53
+ * with two behaviours is the exact failure this module exists to prevent.
54
+ */
55
+ const RUNTIME_MODULE = `
56
+ import { env, waitUntil as cfWaitUntil } from "cloudflare:workers";
57
+
58
+ export function waitUntil(promise) {
59
+ cfWaitUntil(promise);
60
+ return promise;
61
+ }
62
+
63
+ export const secrets = {
64
+ get(name) {
65
+ const value = env[name];
66
+ return typeof value === "string" ? value : undefined;
67
+ },
68
+ };
69
+ `;
70
+ export function base44RuntimePlugin() {
71
+ return {
72
+ name: "base44-runtime",
73
+ // Ahead of Vite's own resolution so the bare `base44:` specifier is never
74
+ // mistaken for a URL protocol.
75
+ enforce: "pre",
76
+ resolveId(id) {
77
+ const reason = unsupportedReason(id);
78
+ if (reason) {
79
+ this.error(`"${id}" is not available in server routes. ${reason}`);
80
+ }
81
+ if (id !== SPECIFIER)
82
+ return null;
83
+ // `cloudflare:workers` has no browser equivalent, so a client-side import
84
+ // would bundle a module that cannot run. Fail with the reason instead.
85
+ if (this.environment?.name === "client") {
86
+ this.error(`"${SPECIFIER}" is server-only. Move this import into a server route.`);
87
+ }
88
+ return RESOLVED;
89
+ },
90
+ load(id) {
91
+ return id === RESOLVED ? RUNTIME_MODULE : null;
92
+ },
93
+ };
94
+ }
95
+ //# 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,+EAA+E;AAC/E,iFAAiF;AACjF,sEAAsE;AACtE,MAAM,aAAa,GACjB,8EAA8E,CAAC;AAEjF,SAAS,iBAAiB,CAAC,EAAU;IACnC,IAAI,EAAE,KAAK,uBAAuB;QAAE,OAAO,aAAa,CAAC;IACzD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,cAAc,GAAG;;;;;;;;;;;;;;CActB,CAAC;AAEF,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,0EAA0E;QAC1E,+BAA+B;QAC/B,OAAO,EAAE,KAAK;QAEd,SAAS,CAAC,EAAE;YACV,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;YACrC,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,wCAAwC,MAAM,EAAE,CAAC,CAAC;YACrE,CAAC;YACD,IAAI,EAAE,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAC;YAElC,0EAA0E;YAC1E,uEAAuE;YACvE,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACxC,IAAI,CAAC,KAAK,CAAC,IAAI,SAAS,yDAAyD,CAAC,CAAC;YACrF,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,EAAE;YACL,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,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,0E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.37",
4
4
  "description": "The Vite plugin for base44 based applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -0,0 +1,103 @@
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 route importing it fails with an explanation instead of a bare
32
+ // "failed to resolve import". Actors are never imported — they live in the app's
33
+ // actors directory, in server routes exactly as in backend functions.
34
+ const ACTORS_REASON =
35
+ "Actors are defined in the app's actors directory, not imported into a route.";
36
+
37
+ function unsupportedReason(id: string): string | null {
38
+ if (id === "base44:runtime/actors") return ACTORS_REASON;
39
+ return null;
40
+ }
41
+
42
+ /**
43
+ * `cloudflare:workers` stays external — workerd provides it, and Nitro's
44
+ * cloudflare preset already treats `cloudflare:*` that way.
45
+ *
46
+ * There is deliberately no separate dev body. Nitro's `cloudflareDev` preset
47
+ * (aliased for `cloudflare-module`, which is what these apps build with) sets
48
+ * `devServer.runner: "miniflare"`, so dev runs in workerd too and the same
49
+ * import resolves there. A `process.env` fallback would buy nothing and cost a
50
+ * dev/prod behaviour split — the shape that makes background work silently
51
+ * vanish locally while working in production. If someone overrides the runner
52
+ * away from workerd, this fails loudly at resolution rather than quietly
53
+ * serving a different value.
54
+ *
55
+ * `waitUntil` is WRAPPED rather than re-exported: ours returns the promise so it
56
+ * composes (`infra/base44-userapp-bundler/src/runtime/index.ts` in apper),
57
+ * Cloudflare's returns void. A bare re-export would make `const p = waitUntil(x)`
58
+ * work in a backend function and silently yield `undefined` here — one specifier
59
+ * with two behaviours is the exact failure this module exists to prevent.
60
+ */
61
+ const RUNTIME_MODULE = `
62
+ import { env, waitUntil as cfWaitUntil } from "cloudflare:workers";
63
+
64
+ export function waitUntil(promise) {
65
+ cfWaitUntil(promise);
66
+ return promise;
67
+ }
68
+
69
+ export const secrets = {
70
+ get(name) {
71
+ const value = env[name];
72
+ return typeof value === "string" ? value : undefined;
73
+ },
74
+ };
75
+ `;
76
+
77
+ export function base44RuntimePlugin(): Plugin {
78
+ return {
79
+ name: "base44-runtime",
80
+ // Ahead of Vite's own resolution so the bare `base44:` specifier is never
81
+ // mistaken for a URL protocol.
82
+ enforce: "pre",
83
+
84
+ resolveId(id) {
85
+ const reason = unsupportedReason(id);
86
+ if (reason) {
87
+ this.error(`"${id}" is not available in server routes. ${reason}`);
88
+ }
89
+ if (id !== SPECIFIER) return null;
90
+
91
+ // `cloudflare:workers` has no browser equivalent, so a client-side import
92
+ // would bundle a module that cannot run. Fail with the reason instead.
93
+ if (this.environment?.name === "client") {
94
+ this.error(`"${SPECIFIER}" is server-only. Move this import into a server route.`);
95
+ }
96
+ return RESOLVED;
97
+ },
98
+
99
+ load(id) {
100
+ return id === RESOLVED ? RUNTIME_MODULE : null;
101
+ },
102
+ };
103
+ }
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
  }