@mionjs/devtools 0.8.0-alpha.0 → 0.8.4

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.
Files changed (34) hide show
  1. package/build/vite-plugin/cjs/src/vite-plugin/aotCacheGenerator.cjs +62 -26
  2. package/build/vite-plugin/cjs/src/vite-plugin/aotCacheGenerator.cjs.map +1 -1
  3. package/build/vite-plugin/cjs/src/vite-plugin/aotCacheGenerator.d.ts +11 -3
  4. package/build/vite-plugin/cjs/src/vite-plugin/aotDiskCache.cjs +5 -4
  5. package/build/vite-plugin/cjs/src/vite-plugin/aotDiskCache.cjs.map +1 -1
  6. package/build/vite-plugin/cjs/src/vite-plugin/constants.cjs +4 -0
  7. package/build/vite-plugin/cjs/src/vite-plugin/constants.cjs.map +1 -1
  8. package/build/vite-plugin/cjs/src/vite-plugin/constants.d.ts +2 -0
  9. package/build/vite-plugin/cjs/src/vite-plugin/mionVitePlugin.cjs +137 -30
  10. package/build/vite-plugin/cjs/src/vite-plugin/mionVitePlugin.cjs.map +1 -1
  11. package/build/vite-plugin/cjs/src/vite-plugin/mionVitePlugin.d.ts +2 -2
  12. package/build/vite-plugin/cjs/src/vite-plugin/transformers.cjs +1 -0
  13. package/build/vite-plugin/cjs/src/vite-plugin/transformers.cjs.map +1 -1
  14. package/build/vite-plugin/cjs/src/vite-plugin/types.d.ts +6 -4
  15. package/build/vite-plugin/cjs/src/vite-plugin/virtualModule.cjs +3 -2
  16. package/build/vite-plugin/cjs/src/vite-plugin/virtualModule.cjs.map +1 -1
  17. package/build/vite-plugin/esm/src/vite-plugin/aotCacheGenerator.d.ts +11 -3
  18. package/build/vite-plugin/esm/src/vite-plugin/aotCacheGenerator.js +62 -26
  19. package/build/vite-plugin/esm/src/vite-plugin/aotCacheGenerator.js.map +1 -1
  20. package/build/vite-plugin/esm/src/vite-plugin/aotDiskCache.js +5 -4
  21. package/build/vite-plugin/esm/src/vite-plugin/aotDiskCache.js.map +1 -1
  22. package/build/vite-plugin/esm/src/vite-plugin/constants.d.ts +2 -0
  23. package/build/vite-plugin/esm/src/vite-plugin/constants.js +4 -0
  24. package/build/vite-plugin/esm/src/vite-plugin/constants.js.map +1 -1
  25. package/build/vite-plugin/esm/src/vite-plugin/mionVitePlugin.d.ts +2 -2
  26. package/build/vite-plugin/esm/src/vite-plugin/mionVitePlugin.js +138 -32
  27. package/build/vite-plugin/esm/src/vite-plugin/mionVitePlugin.js.map +1 -1
  28. package/build/vite-plugin/esm/src/vite-plugin/transformers.js +1 -0
  29. package/build/vite-plugin/esm/src/vite-plugin/transformers.js.map +1 -1
  30. package/build/vite-plugin/esm/src/vite-plugin/types.d.ts +6 -4
  31. package/build/vite-plugin/esm/src/vite-plugin/virtualModule.js +3 -2
  32. package/build/vite-plugin/esm/src/vite-plugin/virtualModule.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/vite-plugin/virtual-modules.d.ts +1 -1
@@ -4,11 +4,11 @@ const child_process = require("child_process");
4
4
  const path = require("path");
5
5
  const src_vitePlugin_resolveModule = require("./resolveModule.cjs");
6
6
  const DEFAULT_TIMEOUT = 3e4;
7
- async function generateAOTCaches(serverConfig, startScriptOverride) {
8
- const persist = serverConfig.mode === "IPC";
9
- const startScript = path.resolve(startScriptOverride ?? serverConfig.startServerScript);
7
+ async function generateAOTCaches(serverConfig, startScriptOverride, isClient) {
8
+ const persist = serverConfig.runMode === "childProcess";
9
+ const startScript = path.resolve(startScriptOverride ?? serverConfig.startScript);
10
10
  const scriptDir = path.dirname(startScript);
11
- const viteConfigArgs = serverConfig.serverViteConfig ? ["--config", path.resolve(serverConfig.serverViteConfig)] : [];
11
+ const viteConfigArgs = serverConfig.viteConfig ? ["--config", path.resolve(serverConfig.viteConfig)] : [];
12
12
  let viteNodePath;
13
13
  try {
14
14
  viteNodePath = await src_vitePlugin_resolveModule.resolveModule("vite-node/cli", scriptDir);
@@ -24,8 +24,13 @@ Original error: ${err instanceof Error ? err.message : String(err)}`
24
24
  let resolved = false;
25
25
  let stderr = "";
26
26
  try {
27
- child = child_process.fork(viteNodePath, [...viteConfigArgs, startScript], {
28
- env: { ...process.env, MION_COMPILE: persist ? "serve" : "onlyAOT" },
27
+ child = child_process.fork(viteNodePath, [...viteConfigArgs, startScript, ...serverConfig.args || []], {
28
+ env: {
29
+ ...process.env,
30
+ ...serverConfig.env,
31
+ MION_COMPILE: serverConfig.runMode,
32
+ ...isClient ? { MION_AOT_IS_CLIENT: "true" } : {}
33
+ },
29
34
  stdio: ["pipe", "pipe", "pipe", "ipc"],
30
35
  cwd: scriptDir
31
36
  });
@@ -41,9 +46,13 @@ Original error: ${err instanceof Error ? err.message : String(err)}`
41
46
  }
42
47
  const cleanup = () => {
43
48
  clearTimeout(timeoutId);
44
- if (child.connected) child.disconnect();
49
+ if (!persist && child.connected) child.disconnect();
45
50
  if (!persist) child.kill();
46
51
  };
52
+ let platformReadyResolve;
53
+ const platformReady = persist ? new Promise((res) => {
54
+ platformReadyResolve = res;
55
+ }) : void 0;
47
56
  child.on("message", (msg) => {
48
57
  const message = msg;
49
58
  if (message?.type === "mion-aot-caches") {
@@ -55,8 +64,12 @@ Original error: ${err instanceof Error ? err.message : String(err)}`
55
64
  pureFnsCode: message.pureFnsCode,
56
65
  routerCacheCode: message.routerCacheCode
57
66
  },
58
- childProcess: persist ? child : void 0
67
+ childProcess: persist ? child : void 0,
68
+ platformReady
59
69
  });
70
+ } else if (message?.type === "mion-platform-ready" && platformReadyResolve) {
71
+ platformReadyResolve({ routerConfig: message.routerConfig, platformConfig: message.platformConfig });
72
+ platformReadyResolve = void 0;
60
73
  }
61
74
  });
62
75
  child.stderr?.on("data", (data) => {
@@ -84,7 +97,7 @@ Original error: ${err instanceof Error ? err.message : String(err)}`
84
97
  reject(
85
98
  new Error(
86
99
  `vite-node exited with code ${code} before emitting AOT caches.
87
- Make sure the startServerScript calls initMionRouter() and the router is fully initialized.
100
+ Make sure the startScript calls initMionRouter() and the router is fully initialized.
88
101
  ` + (stderr ? `stderr: ${stderr}` : "")
89
102
  )
90
103
  );
@@ -103,11 +116,13 @@ Make sure the startServerScript calls initMionRouter() and the router is fully i
103
116
  }, DEFAULT_TIMEOUT);
104
117
  });
105
118
  }
106
- async function loadSSRRouterAndGenerateAOTCaches(loadModule, startServerScript) {
119
+ async function loadSSRRouterAndGenerateAOTCaches(loadModule, startScript, isClient) {
107
120
  const prevCompile = process.env.MION_COMPILE;
108
- process.env.MION_COMPILE = "viteSSR";
121
+ const prevIsClient = process.env.MION_AOT_IS_CLIENT;
122
+ process.env.MION_COMPILE = "middleware";
123
+ if (isClient) process.env.MION_AOT_IS_CLIENT = "true";
109
124
  try {
110
- const mod = await loadModule(startServerScript);
125
+ const mod = await loadModule(startScript);
111
126
  const promises = Object.values(mod).filter((v) => v instanceof Promise);
112
127
  if (promises.length > 0) await Promise.all(promises);
113
128
  const aotModule = await loadModule("@mionjs/router/aot");
@@ -116,6 +131,8 @@ async function loadSSRRouterAndGenerateAOTCaches(loadModule, startServerScript)
116
131
  } finally {
117
132
  if (prevCompile === void 0) delete process.env.MION_COMPILE;
118
133
  else process.env.MION_COMPILE = prevCompile;
134
+ if (prevIsClient === void 0) delete process.env.MION_AOT_IS_CLIENT;
135
+ else process.env.MION_AOT_IS_CLIENT = prevIsClient;
119
136
  }
120
137
  }
121
138
  async function killPersistentChild(child) {
@@ -186,39 +203,58 @@ export const routerCache = ${routerCacheCode};
186
203
  }
187
204
  function generateCombinedCachesModule() {
188
205
  return `/* Auto-generated combined AOT caches - do not edit */
189
- import { addAOTCaches, addRoutesToCache } from '@mionjs/core';
190
206
  import { pureFnsCache } from 'virtual:mion-aot/pure-fns';
191
207
  import { jitFnsCache } from 'virtual:mion-aot/jit-fns';
192
208
  import { routerCache } from 'virtual:mion-aot/router-cache';
209
+ import { addAOTCaches, addRoutesToCache } from '@mionjs/core';
193
210
 
211
+ // Auto-register AOT caches as a side effect so they survive tree-shaking
194
212
  addAOTCaches(jitFnsCache, pureFnsCache);
195
213
  addRoutesToCache(routerCache);
196
214
 
197
215
  export { jitFnsCache, pureFnsCache, routerCache };
216
+
217
+ /** Loads pre-compiled AOT caches (no-op: caches are auto-registered on import). */
218
+ export function loadAOTCaches() {}
219
+
220
+ /** Returns the raw AOT caches. */
221
+ export function getRawAOTCaches() {
222
+ return { jitFnsCache, pureFnsCache, routerCache };
223
+ }
198
224
  `;
199
225
  }
200
226
  function generateNoopModule(comment) {
201
227
  return `/* ${comment} */
202
228
  `;
203
229
  }
204
- async function waitForServer(port, timeoutMs = 3e4) {
205
- const startTime = Date.now();
206
- const checkInterval = 100;
207
- while (Date.now() - startTime < timeoutMs) {
208
- try {
209
- const response = await fetch(`http://localhost:${port}/`);
210
- if (response.ok || response.status === 404) return;
211
- } catch {
212
- }
213
- await new Promise((r) => setTimeout(r, checkInterval));
214
- }
215
- throw new Error(`[mion] Server failed to become ready on port ${port} within ${timeoutMs}ms`);
230
+ function waitForPlatformReady(child, timeoutMs = 3e4) {
231
+ return new Promise((resolve2, reject) => {
232
+ const onMessage = (msg) => {
233
+ const message = msg;
234
+ if (message?.type === "mion-platform-ready") {
235
+ clearTimeout(timeoutId);
236
+ child.removeListener("message", onMessage);
237
+ resolve2({ routerConfig: message.routerConfig, platformConfig: message.platformConfig });
238
+ }
239
+ };
240
+ child.on("message", onMessage);
241
+ const timeoutId = setTimeout(() => {
242
+ child.removeListener("message", onMessage);
243
+ reject(
244
+ new Error(
245
+ `Server did not call setPlatformConfig() within ${timeoutMs / 1e3}s. Ensure your platform adapter (startNodeServer, startBunServer, etc.) is called after initMionRouter().`
246
+ )
247
+ );
248
+ }, timeoutMs);
249
+ });
216
250
  }
217
251
  function generateNoopCombinedModule() {
218
252
  return `/* No-op: AOT caches not generated */
219
253
  export const jitFnsCache = {};
220
254
  export const pureFnsCache = {};
221
255
  export const routerCache = {};
256
+ export function loadAOTCaches() {}
257
+ export function getRawAOTCaches() { return { jitFnsCache, pureFnsCache, routerCache }; }
222
258
  `;
223
259
  }
224
260
  exports.generateAOTCaches = generateAOTCaches;
@@ -231,5 +267,5 @@ exports.generateRouterCacheModule = generateRouterCacheModule;
231
267
  exports.killPersistentChild = killPersistentChild;
232
268
  exports.loadSSRRouterAndGenerateAOTCaches = loadSSRRouterAndGenerateAOTCaches;
233
269
  exports.logAOTCaches = logAOTCaches;
234
- exports.waitForServer = waitForServer;
270
+ exports.waitForPlatformReady = waitForPlatformReady;
235
271
  //# sourceMappingURL=aotCacheGenerator.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"aotCacheGenerator.cjs","sources":["../../../../../src/vite-plugin/aotCacheGenerator.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {fork, ChildProcess} from 'child_process';\nimport {resolve, dirname} from 'path';\nimport {MionServerConfig} from './types.ts';\nimport {resolveModule} from './resolveModule.ts';\n\n/** AOT cache data returned from the generator */\nexport interface AOTCacheData {\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** AOT cache result including optional persistent child process */\nexport interface AOTCacheResult {\n data: AOTCacheData;\n /** The child process, only present when server mode is 'IPC' (persist) */\n childProcess?: ChildProcess;\n}\n\n/** IPC message type from the router's aotEmitter */\ninterface AOTCacheMessage {\n type: 'mion-aot-caches';\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** Default timeout for AOT cache generation (30 seconds) */\nconst DEFAULT_TIMEOUT = 30000;\n\n/**\n * Generates AOT caches by spawning vite-node to run the server's start script.\n *\n * vite-node is used instead of plain node/ts-node because:\n * 1. The server needs deepkit type compiler transformations\n * 2. The server's vite.config.ts has aliases and plugins that must be applied\n * 3. vite-node provides the same environment as the actual server build\n *\n * The router's emitAOTCaches() (called automatically from initMionRouter)\n * detects MION_COMPILE and sends the serialized caches via IPC.\n */\nexport async function generateAOTCaches(serverConfig: MionServerConfig, startScriptOverride?: string): Promise<AOTCacheResult> {\n const persist = serverConfig.mode === 'IPC';\n const startScript = resolve(startScriptOverride ?? serverConfig.startServerScript);\n const scriptDir = dirname(startScript);\n\n // Determine the vite config to use\n // If serverViteConfig is provided, use it; otherwise let vite-node auto-discover\n const viteConfigArgs = serverConfig.serverViteConfig ? ['--config', resolve(serverConfig.serverViteConfig)] : [];\n\n // Resolve vite-node path in both CJS and ESM environments\n let viteNodePath: string;\n try {\n viteNodePath = await resolveModule('vite-node/cli', scriptDir);\n } catch (err) {\n throw new Error(\n `Failed to resolve vite-node. Make sure vite-node is installed.\\n` +\n `You can install it with: npm install -D vite-node\\n` +\n `Original error: ${err instanceof Error ? err.message : String(err)}`\n );\n }\n\n return new Promise((resolvePromise, reject) => {\n let child: ChildProcess;\n let resolved = false;\n let stderr = '';\n\n try {\n // Spawn vite-node as a child process with IPC channel\n // 'serve' mode tells platform adapters to proceed with server.listen()\n child = fork(viteNodePath, [...viteConfigArgs, startScript], {\n env: {...process.env, MION_COMPILE: persist ? 'serve' : 'onlyAOT'},\n stdio: ['pipe', 'pipe', 'pipe', 'ipc'],\n cwd: scriptDir,\n });\n } catch (err) {\n // If vite-node is not found, provide a helpful error message\n reject(\n new Error(\n `Failed to spawn vite-node. Make sure vite-node is installed.\\n` +\n `You can install it with: npm install -D vite-node\\n` +\n `Original error: ${err instanceof Error ? err.message : String(err)}`\n )\n );\n return;\n }\n\n /** Cleanup child process: disconnect IPC, clear timeout, and optionally kill */\n const cleanup = () => {\n clearTimeout(timeoutId);\n if (child.connected) child.disconnect();\n if (!persist) child.kill();\n };\n\n child.on('message', (msg: unknown) => {\n const message = msg as AOTCacheMessage;\n if (message?.type === 'mion-aot-caches') {\n resolved = true;\n cleanup();\n resolvePromise({\n data: {\n jitFnsCode: message.jitFnsCode,\n pureFnsCode: message.pureFnsCode,\n routerCacheCode: message.routerCacheCode,\n },\n childProcess: persist ? child : undefined,\n });\n }\n });\n\n // Capture stderr for error reporting (and pipe through in persist mode)\n child.stderr?.on('data', (data: Buffer) => {\n const msg = data.toString().trim();\n if (!resolved) stderr += msg + '\\n';\n if (persist && msg) console.error(`[mion-server] ${msg}`);\n });\n\n // Pipe stdout through (always in persist mode, only with DEBUG_AOT otherwise)\n child.stdout?.on('data', (data: Buffer) => {\n const msg = data.toString().trim();\n if (persist && msg) {\n console.log(`[mion-server] ${msg}`);\n } else if (process.env.DEBUG_AOT && msg) {\n console.log('[mion-aot] stdout:', msg);\n }\n });\n\n child.on('error', (err) => {\n if (!resolved) {\n cleanup();\n reject(new Error(`vite-node failed to start: ${err.message}`));\n }\n });\n\n child.on('exit', (code) => {\n if (!resolved) {\n cleanup();\n reject(\n new Error(\n `vite-node exited with code ${code} before emitting AOT caches.\\n` +\n `Make sure the startServerScript calls initMionRouter() and the router ` +\n `is fully initialized.\\n` +\n (stderr ? `stderr: ${stderr}` : '')\n )\n );\n }\n });\n\n // Timeout safety\n const timeoutId = setTimeout(() => {\n if (!resolved) {\n cleanup();\n if (persist) child.kill();\n reject(\n new Error(\n `AOT cache generation timed out (${DEFAULT_TIMEOUT / 1000}s). ` +\n `Make sure the server start script completes initialization.`\n )\n );\n }\n }, DEFAULT_TIMEOUT);\n });\n}\n\n/** Loads a module by URL — abstracts over ssrLoadModule and Environment Runner */\nexport type ModuleLoader = (url: string) => Promise<Record<string, any>>;\n\n/**\n * Loads the startServerScript with MION_COMPILE=SSR so platform adapters skip server.listen().\n * Generates AOT caches via SSR using a module loader (for same-Vite-process scenarios like Nuxt).\n * After loading, retrieves the caches directly from the router's global state via getSerializedCaches(). */\nexport async function loadSSRRouterAndGenerateAOTCaches(\n loadModule: ModuleLoader,\n startServerScript: string\n): Promise<AOTCacheData> {\n const prevCompile = process.env.MION_COMPILE;\n process.env.MION_COMPILE = 'viteSSR';\n\n try {\n // Load the start server script — triggers initMionRouter(), populates caches,\n // skips process.send (SSR mode) and skips server.listen() (platform adapters)\n const mod = await loadModule(startServerScript);\n // Await any Promise-valued exports (e.g. initMionRouter() without top-level await)\n const promises = Object.values(mod).filter((v): v is Promise<any> => v instanceof Promise);\n if (promises.length > 0) await Promise.all(promises);\n\n // Get caches directly from the router's global state\n const aotModule = await loadModule('@mionjs/router/aot');\n const caches: AOTCacheData = await aotModule.getSerializedCaches();\n return caches;\n } finally {\n if (prevCompile === undefined) delete process.env.MION_COMPILE;\n else process.env.MION_COMPILE = prevCompile;\n }\n}\n\n// ============ Persistent child management ============\n\n/** Kills a persistent child process gracefully (SIGTERM then SIGKILL after 5s) */\nexport async function killPersistentChild(child: ChildProcess | null): Promise<void> {\n if (!child || child.killed) return;\n const pid = child.pid;\n\n if (pid) {\n try {\n process.kill(-pid, 'SIGTERM');\n } catch {\n child.kill('SIGTERM');\n }\n } else {\n child.kill('SIGTERM');\n }\n\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => {\n if (child && !child.killed) {\n if (pid) {\n try {\n process.kill(-pid, 'SIGKILL');\n } catch {\n child.kill('SIGKILL');\n }\n } else {\n child.kill('SIGKILL');\n }\n }\n resolve();\n }, 5000);\n\n child!.on('exit', () => {\n clearTimeout(timeout);\n resolve();\n });\n });\n}\n\n// ============ Logging ============\n\n/** Formats byte size to human-readable string */\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n const kb = bytes / 1024;\n if (kb < 1024) return `${kb.toFixed(1)} KB`;\n const mb = kb / 1024;\n return `${mb.toFixed(1)} MB`;\n}\n\n/** Logs AOT cache sizes and optionally full contents in verbose mode (DEBUG_AOT) */\nexport function logAOTCaches(data: AOTCacheData): void {\n const jitSize = formatBytes(Buffer.byteLength(data.jitFnsCode, 'utf-8'));\n const pureSize = formatBytes(Buffer.byteLength(data.pureFnsCode, 'utf-8'));\n const routerSize = formatBytes(Buffer.byteLength(data.routerCacheCode, 'utf-8'));\n console.log(`[mion] jitFns: ${jitSize}, pureFns: ${pureSize}, routerCache: ${routerSize}`);\n\n if (process.env.DEBUG_AOT) {\n console.log('[mion] AOT jitFns cache:\\n', data.jitFnsCode);\n console.log('[mion] AOT pureFns cache:\\n', data.pureFnsCode);\n console.log('[mion] AOT routerCache:\\n', data.routerCacheCode);\n }\n}\n\n// ============ Module Generators ============\n\n/** Generates the virtual module code for JIT functions cache (exports only). */\nexport function generateJitFnsModule(jitFnsCode: string): string {\n return `/* Auto-generated AOT JIT functions cache - do not edit */\nexport const jitFnsCache = ${jitFnsCode};\n`;\n}\n\n/** Generates the virtual module code for pure functions cache (exports only). */\nexport function generatePureFnsModule(pureFnsCode: string): string {\n return `/* Auto-generated AOT pure functions cache - do not edit */\nexport const pureFnsCache = ${pureFnsCode};\n`;\n}\n\n/** Generates the virtual module code for router methods cache (exports only). */\nexport function generateRouterCacheModule(routerCacheCode: string): string {\n return `/* Auto-generated AOT router cache - do not edit */\nexport const routerCache = ${routerCacheCode};\n`;\n}\n\n/** Generates the combined virtual module that imports all 3 caches, registers them, and re-exports. */\nexport function generateCombinedCachesModule(): string {\n return `/* Auto-generated combined AOT caches - do not edit */\nimport { addAOTCaches, addRoutesToCache } from '@mionjs/core';\nimport { pureFnsCache } from 'virtual:mion-aot/pure-fns';\nimport { jitFnsCache } from 'virtual:mion-aot/jit-fns';\nimport { routerCache } from 'virtual:mion-aot/router-cache';\n\naddAOTCaches(jitFnsCache, pureFnsCache);\naddRoutesToCache(routerCache);\n\nexport { jitFnsCache, pureFnsCache, routerCache };\n`;\n}\n\n/** Generates a no-op module for when AOT caches are disabled. */\nexport function generateNoopModule(comment: string): string {\n return `/* ${comment} */\\n`;\n}\n\n/** Poll an HTTP port until the server responds (2xx or 404). */\nexport async function waitForServer(port: number, timeoutMs = 30000): Promise<void> {\n const startTime = Date.now();\n const checkInterval = 100;\n while (Date.now() - startTime < timeoutMs) {\n try {\n const response = await fetch(`http://localhost:${port}/`);\n if (response.ok || response.status === 404) return;\n } catch {\n // Server not ready yet\n }\n await new Promise((r) => setTimeout(r, checkInterval));\n }\n throw new Error(`[mion] Server failed to become ready on port ${port} within ${timeoutMs}ms`);\n}\n\n/** Generates a no-op combined module that exports empty caches. */\nexport function generateNoopCombinedModule(): string {\n return `/* No-op: AOT caches not generated */\nexport const jitFnsCache = {};\nexport const pureFnsCache = {};\nexport const routerCache = {};\n`;\n}\n"],"names":["resolve","dirname","resolveModule","fork"],"mappings":";;;;;AAmCA,MAAM,kBAAkB;AAaxB,eAAsB,kBAAkB,cAAgC,qBAAuD;AAC3H,QAAM,UAAU,aAAa,SAAS;AACtC,QAAM,cAAcA,KAAAA,QAAQ,uBAAuB,aAAa,iBAAiB;AACjF,QAAM,YAAYC,KAAAA,QAAQ,WAAW;AAIrC,QAAM,iBAAiB,aAAa,mBAAmB,CAAC,YAAYD,KAAAA,QAAQ,aAAa,gBAAgB,CAAC,IAAI,CAAA;AAG9G,MAAI;AACJ,MAAI;AACA,mBAAe,MAAME,6BAAAA,cAAc,iBAAiB,SAAS;AAAA,EACjE,SAAS,KAAK;AACV,UAAM,IAAI;AAAA,MACN;AAAA;AAAA,kBAEuB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,IAAA;AAAA,EAE/E;AAEA,SAAO,IAAI,QAAQ,CAAC,gBAAgB,WAAW;AAC3C,QAAI;AACJ,QAAI,WAAW;AACf,QAAI,SAAS;AAEb,QAAI;AAGA,cAAQC,cAAAA,KAAK,cAAc,CAAC,GAAG,gBAAgB,WAAW,GAAG;AAAA,QACzD,KAAK,EAAC,GAAG,QAAQ,KAAK,cAAc,UAAU,UAAU,UAAA;AAAA,QACxD,OAAO,CAAC,QAAQ,QAAQ,QAAQ,KAAK;AAAA,QACrC,KAAK;AAAA,MAAA,CACR;AAAA,IACL,SAAS,KAAK;AAEV;AAAA,QACI,IAAI;AAAA,UACA;AAAA;AAAA,kBAEuB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,QAAA;AAAA,MAC3E;AAEJ;AAAA,IACJ;AAGA,UAAM,UAAU,MAAM;AAClB,mBAAa,SAAS;AACtB,UAAI,MAAM,UAAW,OAAM,WAAA;AAC3B,UA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ChF,QAAM,YAAY,KAAK,IAAA;AACvB,QAAM,gBAAgB;AACtB,SAAO,KAAK,QAAQ,YAAY,WAAW;AACvC,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,oBAAoB,IAAI,GAAG;AACxD,UAAI,SAAS,MAAM,SAAS,WAAW,IAAK;AAAA,IAChD,QAAQ;AAAA,IAER;AACA,UAAM,IAAI,QAAQ,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AAAA,EACzD;AACA,QAAM,IAAI,MAAM,gDAAgD,IAAI,WAAW,SAAS,IAAI;AAChG;AAGO,SAAS,6BAAqC;AACjD,SAAO;AAAA;AAAA;AAAA;AAAA;AAKX;;;;;;;;;;;;"}
1
+ {"version":3,"file":"aotCacheGenerator.cjs","sources":["../../../../../src/vite-plugin/aotCacheGenerator.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {fork, ChildProcess} from 'child_process';\nimport {resolve, dirname} from 'path';\nimport {MionServerConfig} from './types.ts';\nimport {resolveModule} from './resolveModule.ts';\n\n/** AOT cache data returned from the generator */\nexport interface AOTCacheData {\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** AOT cache result including optional persistent child process */\nexport interface AOTCacheResult {\n data: AOTCacheData;\n /** The child process, only present when runMode is 'childProcess' (persist) */\n childProcess?: ChildProcess;\n /** Promise that resolves when the server calls setPlatformConfig() (childProcess mode only) */\n platformReady?: Promise<PlatformReadyData>;\n}\n\n/** IPC message type from the router's aotEmitter */\ninterface AOTCacheMessage {\n type: 'mion-aot-caches';\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** Platform config received from the server via IPC */\nexport interface PlatformReadyData {\n routerConfig: Record<string, unknown>;\n platformConfig: Record<string, unknown>;\n}\n\ninterface PlatformReadyMessage extends PlatformReadyData {\n type: 'mion-platform-ready';\n}\n\n/** Default timeout for AOT cache generation (30 seconds) */\nconst DEFAULT_TIMEOUT = 30000;\n\n/**\n * Generates AOT caches by spawning vite-node to run the server's start script.\n *\n * vite-node is used instead of plain node/ts-node because:\n * 1. The server needs deepkit type compiler transformations\n * 2. The server's vite.config.ts has aliases and plugins that must be applied\n * 3. vite-node provides the same environment as the actual server build\n *\n * The router's emitAOTCaches() (called automatically from initMionRouter)\n * detects MION_COMPILE and sends the serialized caches via IPC.\n */\nexport async function generateAOTCaches(\n serverConfig: MionServerConfig,\n startScriptOverride?: string,\n isClient?: boolean\n): Promise<AOTCacheResult> {\n const persist = serverConfig.runMode === 'childProcess';\n const startScript = resolve(startScriptOverride ?? serverConfig.startScript);\n const scriptDir = dirname(startScript);\n\n // Determine the vite config to use\n // If viteConfig is provided, use it; otherwise let vite-node auto-discover\n const viteConfigArgs = serverConfig.viteConfig ? ['--config', resolve(serverConfig.viteConfig)] : [];\n\n // Resolve vite-node path in both CJS and ESM environments\n let viteNodePath: string;\n try {\n viteNodePath = await resolveModule('vite-node/cli', scriptDir);\n } catch (err) {\n throw new Error(\n `Failed to resolve vite-node. Make sure vite-node is installed.\\n` +\n `You can install it with: npm install -D vite-node\\n` +\n `Original error: ${err instanceof Error ? err.message : String(err)}`\n );\n }\n\n return new Promise((resolvePromise, reject) => {\n let child: ChildProcess;\n let resolved = false;\n let stderr = '';\n\n try {\n // Spawn vite-node as a child process with IPC channel\n // 'serve' mode tells platform adapters to proceed with server.listen()\n child = fork(viteNodePath, [...viteConfigArgs, startScript, ...(serverConfig.args || [])], {\n env: {\n ...process.env,\n ...serverConfig.env,\n MION_COMPILE: serverConfig.runMode,\n ...(isClient ? {MION_AOT_IS_CLIENT: 'true'} : {}),\n },\n stdio: ['pipe', 'pipe', 'pipe', 'ipc'],\n cwd: scriptDir,\n });\n } catch (err) {\n // If vite-node is not found, provide a helpful error message\n reject(\n new Error(\n `Failed to spawn vite-node. Make sure vite-node is installed.\\n` +\n `You can install it with: npm install -D vite-node\\n` +\n `Original error: ${err instanceof Error ? err.message : String(err)}`\n )\n );\n return;\n }\n\n /** Cleanup child process: clear timeout, disconnect IPC (only in non-persist mode), and optionally kill.\n * In persist mode, IPC stays open for the mion-platform-ready message. */\n const cleanup = () => {\n clearTimeout(timeoutId);\n if (!persist && child.connected) child.disconnect();\n if (!persist) child.kill();\n };\n\n // Set up platform-ready listener BEFORE any messages arrive to avoid race conditions.\n // The child may send mion-platform-ready very quickly after mion-aot-caches.\n let platformReadyResolve: ((value: PlatformReadyData) => void) | undefined;\n const platformReady = persist\n ? new Promise<PlatformReadyData>((res) => {\n platformReadyResolve = res;\n })\n : undefined;\n\n child.on('message', (msg: unknown) => {\n const message = msg as AOTCacheMessage | PlatformReadyMessage;\n if (message?.type === 'mion-aot-caches') {\n resolved = true;\n cleanup();\n resolvePromise({\n data: {\n jitFnsCode: message.jitFnsCode,\n pureFnsCode: message.pureFnsCode,\n routerCacheCode: message.routerCacheCode,\n },\n childProcess: persist ? child : undefined,\n platformReady,\n });\n } else if (message?.type === 'mion-platform-ready' && platformReadyResolve) {\n platformReadyResolve({routerConfig: message.routerConfig, platformConfig: message.platformConfig});\n platformReadyResolve = undefined;\n }\n });\n\n // Capture stderr for error reporting (and pipe through in persist mode)\n child.stderr?.on('data', (data: Buffer) => {\n const msg = data.toString().trim();\n if (!resolved) stderr += msg + '\\n';\n if (persist && msg) console.error(`[mion-server] ${msg}`);\n });\n\n // Pipe stdout through (always in persist mode, only with DEBUG_AOT otherwise)\n child.stdout?.on('data', (data: Buffer) => {\n const msg = data.toString().trim();\n if (persist && msg) {\n console.log(`[mion-server] ${msg}`);\n } else if (process.env.DEBUG_AOT && msg) {\n console.log('[mion-aot] stdout:', msg);\n }\n });\n\n child.on('error', (err) => {\n if (!resolved) {\n cleanup();\n reject(new Error(`vite-node failed to start: ${err.message}`));\n }\n });\n\n child.on('exit', (code) => {\n if (!resolved) {\n cleanup();\n reject(\n new Error(\n `vite-node exited with code ${code} before emitting AOT caches.\\n` +\n `Make sure the startScript calls initMionRouter() and the router ` +\n `is fully initialized.\\n` +\n (stderr ? `stderr: ${stderr}` : '')\n )\n );\n }\n });\n\n // Timeout safety\n const timeoutId = setTimeout(() => {\n if (!resolved) {\n cleanup();\n if (persist) child.kill();\n reject(\n new Error(\n `AOT cache generation timed out (${DEFAULT_TIMEOUT / 1000}s). ` +\n `Make sure the server start script completes initialization.`\n )\n );\n }\n }, DEFAULT_TIMEOUT);\n });\n}\n\n/** Loads a module by URL — abstracts over ssrLoadModule and Environment Runner */\nexport type ModuleLoader = (url: string) => Promise<Record<string, any>>;\n\n/**\n * Loads the startScript with MION_COMPILE=middleware so platform adapters skip server.listen().\n * Generates AOT caches via SSR using a module loader (for same-Vite-process scenarios like Nuxt).\n * After loading, retrieves the caches directly from the router's global state via getSerializedCaches(). */\nexport async function loadSSRRouterAndGenerateAOTCaches(\n loadModule: ModuleLoader,\n startScript: string,\n isClient?: boolean\n): Promise<AOTCacheData> {\n const prevCompile = process.env.MION_COMPILE;\n const prevIsClient = process.env.MION_AOT_IS_CLIENT;\n process.env.MION_COMPILE = 'middleware';\n if (isClient) process.env.MION_AOT_IS_CLIENT = 'true';\n\n try {\n // Load the start server script — triggers initMionRouter(), populates caches,\n // skips process.send (SSR mode) and skips server.listen() (platform adapters)\n const mod = await loadModule(startScript);\n // Await any Promise-valued exports (e.g. initMionRouter() without top-level await)\n const promises = Object.values(mod).filter((v): v is Promise<any> => v instanceof Promise);\n if (promises.length > 0) await Promise.all(promises);\n\n // Get caches directly from the router's global state\n const aotModule = await loadModule('@mionjs/router/aot');\n const caches: AOTCacheData = await aotModule.getSerializedCaches();\n return caches;\n } finally {\n if (prevCompile === undefined) delete process.env.MION_COMPILE;\n else process.env.MION_COMPILE = prevCompile;\n if (prevIsClient === undefined) delete process.env.MION_AOT_IS_CLIENT;\n else process.env.MION_AOT_IS_CLIENT = prevIsClient;\n }\n}\n\n// ============ Persistent child management ============\n\n/** Kills a persistent child process gracefully (SIGTERM then SIGKILL after 5s) */\nexport async function killPersistentChild(child: ChildProcess | null): Promise<void> {\n if (!child || child.killed) return;\n const pid = child.pid;\n\n if (pid) {\n try {\n process.kill(-pid, 'SIGTERM');\n } catch {\n child.kill('SIGTERM');\n }\n } else {\n child.kill('SIGTERM');\n }\n\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => {\n if (child && !child.killed) {\n if (pid) {\n try {\n process.kill(-pid, 'SIGKILL');\n } catch {\n child.kill('SIGKILL');\n }\n } else {\n child.kill('SIGKILL');\n }\n }\n resolve();\n }, 5000);\n\n child!.on('exit', () => {\n clearTimeout(timeout);\n resolve();\n });\n });\n}\n\n// ============ Logging ============\n\n/** Formats byte size to human-readable string */\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n const kb = bytes / 1024;\n if (kb < 1024) return `${kb.toFixed(1)} KB`;\n const mb = kb / 1024;\n return `${mb.toFixed(1)} MB`;\n}\n\n/** Logs AOT cache sizes and optionally full contents in verbose mode (DEBUG_AOT) */\nexport function logAOTCaches(data: AOTCacheData): void {\n const jitSize = formatBytes(Buffer.byteLength(data.jitFnsCode, 'utf-8'));\n const pureSize = formatBytes(Buffer.byteLength(data.pureFnsCode, 'utf-8'));\n const routerSize = formatBytes(Buffer.byteLength(data.routerCacheCode, 'utf-8'));\n console.log(`[mion] jitFns: ${jitSize}, pureFns: ${pureSize}, routerCache: ${routerSize}`);\n\n if (process.env.DEBUG_AOT) {\n console.log('[mion] AOT jitFns cache:\\n', data.jitFnsCode);\n console.log('[mion] AOT pureFns cache:\\n', data.pureFnsCode);\n console.log('[mion] AOT routerCache:\\n', data.routerCacheCode);\n }\n}\n\n// ============ Module Generators ============\n\n/** Generates the virtual module code for JIT functions cache (exports only). */\nexport function generateJitFnsModule(jitFnsCode: string): string {\n return `/* Auto-generated AOT JIT functions cache - do not edit */\nexport const jitFnsCache = ${jitFnsCode};\n`;\n}\n\n/** Generates the virtual module code for pure functions cache (exports only). */\nexport function generatePureFnsModule(pureFnsCode: string): string {\n return `/* Auto-generated AOT pure functions cache - do not edit */\nexport const pureFnsCache = ${pureFnsCode};\n`;\n}\n\n/** Generates the virtual module code for router methods cache (exports only). */\nexport function generateRouterCacheModule(routerCacheCode: string): string {\n return `/* Auto-generated AOT router cache - do not edit */\nexport const routerCache = ${routerCacheCode};\n`;\n}\n\n/** Generates the combined virtual module that imports all 3 caches and re-exports them. */\nexport function generateCombinedCachesModule(): string {\n return `/* Auto-generated combined AOT caches - do not edit */\nimport { pureFnsCache } from 'virtual:mion-aot/pure-fns';\nimport { jitFnsCache } from 'virtual:mion-aot/jit-fns';\nimport { routerCache } from 'virtual:mion-aot/router-cache';\nimport { addAOTCaches, addRoutesToCache } from '@mionjs/core';\n\n// Auto-register AOT caches as a side effect so they survive tree-shaking\naddAOTCaches(jitFnsCache, pureFnsCache);\naddRoutesToCache(routerCache);\n\nexport { jitFnsCache, pureFnsCache, routerCache };\n\n/** Loads pre-compiled AOT caches (no-op: caches are auto-registered on import). */\nexport function loadAOTCaches() {}\n\n/** Returns the raw AOT caches. */\nexport function getRawAOTCaches() {\n return { jitFnsCache, pureFnsCache, routerCache };\n}\n`;\n}\n\n/** Generates a no-op module for when AOT caches are disabled. */\nexport function generateNoopModule(comment: string): string {\n return `/* ${comment} */\\n`;\n}\n\n/** Waits for the server child process to send a mion-platform-ready IPC message. */\nexport function waitForPlatformReady(\n child: ChildProcess,\n timeoutMs = 30000\n): Promise<{routerConfig: Record<string, unknown>; platformConfig: Record<string, unknown>}> {\n return new Promise((resolve, reject) => {\n const onMessage = (msg: unknown) => {\n const message = msg as PlatformReadyMessage;\n if (message?.type === 'mion-platform-ready') {\n clearTimeout(timeoutId);\n child.removeListener('message', onMessage);\n resolve({routerConfig: message.routerConfig, platformConfig: message.platformConfig});\n }\n };\n child.on('message', onMessage);\n const timeoutId = setTimeout(() => {\n child.removeListener('message', onMessage);\n reject(\n new Error(\n `Server did not call setPlatformConfig() within ${timeoutMs / 1000}s. ` +\n `Ensure your platform adapter (startNodeServer, startBunServer, etc.) is called after initMionRouter().`\n )\n );\n }, timeoutMs);\n });\n}\n\n/** Generates a no-op combined module that exports empty caches. */\nexport function generateNoopCombinedModule(): string {\n return `/* No-op: AOT caches not generated */\nexport const jitFnsCache = {};\nexport const pureFnsCache = {};\nexport const routerCache = {};\nexport function loadAOTCaches() {}\nexport function getRawAOTCaches() { return { jitFnsCache, pureFnsCache, routerCache }; }\n`;\n}\n"],"names":["resolve","dirname","resolveModule","fork"],"mappings":";;;;;AA+CA,MAAM,kBAAkB;AAaxB,eAAsB,kBAClB,cACA,qBACA,UACuB;AACvB,QAAM,UAAU,aAAa,YAAY;AACzC,QAAM,cAAcA,KAAAA,QAAQ,uBAAuB,aAAa,WAAW;AAC3E,QAAM,YAAYC,KAAAA,QAAQ,WAAW;AAIrC,QAAM,iBAAiB,aAAa,aAAa,CAAC,YAAYD,KAAAA,QAAQ,aAAa,UAAU,CAAC,IAAI,CAAA;AAGlG,MAAI;AACJ,MAAI;AACA,mBAAe,MAAME,6BAAAA,cAAc,iBAAiB,SAAS;AAAA,EACjE,SAAS,KAAK;AACV,UAAM,IAAI;AAAA,MACN;AAAA;AAAA,kBAEuB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,IAAA;AAAA,EAE/E;AAEA,SAAO,IAAI,QAAQ,CAAC,gBAAgB,WAAW;AAC3C,QAAI;AACJ,QAAI,WAAW;AACf,QAAI,SAAS;AAEb,QAAI;AAGA,cAAQC,cAAAA,KAAK,cAAc,CAAC,GAAG,gBAAgB,aAAa,GAAI,aAAa,QAAQ,CAAA,CAAG,GAAG;AAAA,QACvF,KAAK;AAAA,UACD,GAAG,QAAQ;AAAA,UACX,GAAG,aAAa;AAAA,UAChB,cAAc,aAAa;AAAA,UAC3B,GAAI,WAAW,EAAC,oBAAoB,WAAU,CAAA;AAAA,QAAC;AAAA,QAEnD,OAAO,CAAC,QAAQ,QAAQ,QAAQ,KAAK;AAAA,QACrC,KAAK;AAAA,MAAA,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A;AAAA;AAAA;AAAA;AAAA;AAOX;;;;;;;;;;;;"}
@@ -8,10 +8,15 @@ export interface AOTCacheData {
8
8
  export interface AOTCacheResult {
9
9
  data: AOTCacheData;
10
10
  childProcess?: ChildProcess;
11
+ platformReady?: Promise<PlatformReadyData>;
11
12
  }
12
- export declare function generateAOTCaches(serverConfig: MionServerConfig, startScriptOverride?: string): Promise<AOTCacheResult>;
13
+ export interface PlatformReadyData {
14
+ routerConfig: Record<string, unknown>;
15
+ platformConfig: Record<string, unknown>;
16
+ }
17
+ export declare function generateAOTCaches(serverConfig: MionServerConfig, startScriptOverride?: string, isClient?: boolean): Promise<AOTCacheResult>;
13
18
  export type ModuleLoader = (url: string) => Promise<Record<string, any>>;
14
- export declare function loadSSRRouterAndGenerateAOTCaches(loadModule: ModuleLoader, startServerScript: string): Promise<AOTCacheData>;
19
+ export declare function loadSSRRouterAndGenerateAOTCaches(loadModule: ModuleLoader, startScript: string, isClient?: boolean): Promise<AOTCacheData>;
15
20
  export declare function killPersistentChild(child: ChildProcess | null): Promise<void>;
16
21
  export declare function logAOTCaches(data: AOTCacheData): void;
17
22
  export declare function generateJitFnsModule(jitFnsCode: string): string;
@@ -19,5 +24,8 @@ export declare function generatePureFnsModule(pureFnsCode: string): string;
19
24
  export declare function generateRouterCacheModule(routerCacheCode: string): string;
20
25
  export declare function generateCombinedCachesModule(): string;
21
26
  export declare function generateNoopModule(comment: string): string;
22
- export declare function waitForServer(port: number, timeoutMs?: number): Promise<void>;
27
+ export declare function waitForPlatformReady(child: ChildProcess, timeoutMs?: number): Promise<{
28
+ routerConfig: Record<string, unknown>;
29
+ platformConfig: Record<string, unknown>;
30
+ }>;
23
31
  export declare function generateNoopCombinedModule(): string;
@@ -49,7 +49,7 @@ function collectFileStats(dir, baseDir) {
49
49
  return entries;
50
50
  }
51
51
  function computeSourceHash(serverConfig, aotOptions) {
52
- const serverDir = path.dirname(path.resolve(serverConfig.startServerScript));
52
+ const serverDir = path.dirname(path.resolve(serverConfig.startScript));
53
53
  const fileStats = collectFileStats(serverDir, serverDir);
54
54
  fileStats.sort();
55
55
  const hashInput = [
@@ -57,7 +57,8 @@ function computeSourceHash(serverConfig, aotOptions) {
57
57
  `cacheVersion:${AOT_DISK_CACHE_VERSION}`,
58
58
  `devtoolsVersion:${getDevtoolsVersion()}`,
59
59
  `excludedFns:${JSON.stringify((aotOptions?.excludedFns || []).slice().sort())}`,
60
- `excludedPureFns:${JSON.stringify((aotOptions?.excludedPureFns || []).slice().sort())}`
60
+ `excludedPureFns:${JSON.stringify((aotOptions?.excludedPureFns || []).slice().sort())}`,
61
+ `isClient:${!!aotOptions?.isClient}`
61
62
  ].join("\n");
62
63
  return crypto.createHash("sha256").update(hashInput).digest("hex");
63
64
  }
@@ -97,7 +98,7 @@ function resolveCacheDir(options, viteCacheDir) {
97
98
  }
98
99
  async function getOrGenerateAOTCaches(serverConfig, aotOptions, cacheDir) {
99
100
  const forceRegenerate = process.env.MION_AOT_FORCE === "true";
100
- const isIPCMode = serverConfig.mode === "IPC";
101
+ const isIPCMode = serverConfig.runMode === "childProcess";
101
102
  const cachingEnabled = cacheDir !== "" && !forceRegenerate && !isIPCMode;
102
103
  let hash = "";
103
104
  if (cachingEnabled) {
@@ -114,7 +115,7 @@ async function getOrGenerateAOTCaches(serverConfig, aotOptions, cacheDir) {
114
115
  };
115
116
  }
116
117
  }
117
- const result = await src_vitePlugin_aotCacheGenerator.generateAOTCaches(serverConfig);
118
+ const result = await src_vitePlugin_aotCacheGenerator.generateAOTCaches(serverConfig, void 0, aotOptions?.isClient);
118
119
  if (cachingEnabled) {
119
120
  if (!hash) hash = computeSourceHash(serverConfig, aotOptions);
120
121
  writeDiskCache(cacheDir, hash, result.data);
@@ -1 +1 @@
1
- {"version":3,"file":"aotDiskCache.cjs","sources":["../../../../../src/vite-plugin/aotDiskCache.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {createHash} from 'crypto';\nimport {readFileSync, writeFileSync, mkdirSync, readdirSync, statSync} from 'fs';\nimport {join, resolve, dirname, relative} from 'path';\nimport {AOTCacheOptions, MionServerConfig} from './types.ts';\nimport {generateAOTCaches, AOTCacheData, AOTCacheResult} from './aotCacheGenerator.ts';\n\n/** Schema for the on-disk cache file */\ninterface AOTDiskCacheFile {\n cacheVersion: string;\n hash: string;\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** Bump when mion internals change in a way that invalidates cached output */\nconst AOT_DISK_CACHE_VERSION = '2';\n\n/** Cache file name */\nconst CACHE_FILENAME = 'mion-aot-cache.json';\n\n/** Directories to skip when walking the server source tree */\nconst SKIP_DIRS = new Set(['node_modules', '.dist', 'dist', '.git', '.vite', 'build', 'coverage', '.coverage']);\n\n/** File extensions to include in hash computation */\nconst SOURCE_EXTENSIONS = /\\.(ts|tsx)$/;\n\n/** Test file patterns to exclude from hash computation */\nconst TEST_FILE_PATTERN = /\\.(spec|test)\\.(ts|tsx)$/;\n\n/** Read the devtools package version (cached after first call) */\nlet devtoolsVersion: string | null = null;\nfunction getDevtoolsVersion(): string {\n if (devtoolsVersion) return devtoolsVersion;\n try {\n const pkgPath = resolve(dirname(new URL(import.meta.url).pathname), '../../package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n devtoolsVersion = pkg.version || '0.0.0';\n } catch {\n devtoolsVersion = '0.0.0';\n }\n return devtoolsVersion as string;\n}\n\n/** Recursively collect file stats (relativePath:mtimeMs:size) for source files */\nfunction collectFileStats(dir: string, baseDir: string): string[] {\n const entries: string[] = [];\n let files: string[];\n try {\n files = readdirSync(dir);\n } catch {\n return entries;\n }\n for (const file of files) {\n const fullPath = join(dir, file);\n let stat;\n try {\n stat = statSync(fullPath);\n } catch {\n continue;\n }\n if (stat.isDirectory()) {\n if (SKIP_DIRS.has(file)) continue;\n entries.push(...collectFileStats(fullPath, baseDir));\n } else if (SOURCE_EXTENSIONS.test(file) && !TEST_FILE_PATTERN.test(file)) {\n const relativePath = relative(baseDir, fullPath);\n entries.push(`${relativePath}:${stat.mtimeMs}:${stat.size}`);\n }\n }\n return entries;\n}\n\n/** Compute a SHA-256 hash of the server source directory + options */\nexport function computeSourceHash(serverConfig: MionServerConfig, aotOptions?: AOTCacheOptions): string {\n const serverDir = dirname(resolve(serverConfig.startServerScript));\n const fileStats = collectFileStats(serverDir, serverDir);\n fileStats.sort();\n\n const hashInput = [\n ...fileStats,\n `cacheVersion:${AOT_DISK_CACHE_VERSION}`,\n `devtoolsVersion:${getDevtoolsVersion()}`,\n `excludedFns:${JSON.stringify((aotOptions?.excludedFns || []).slice().sort())}`,\n `excludedPureFns:${JSON.stringify((aotOptions?.excludedPureFns || []).slice().sort())}`,\n ].join('\\n');\n\n return createHash('sha256').update(hashInput).digest('hex');\n}\n\n/** Read and validate the disk cache file. Returns null on any error. */\nfunction readDiskCache(cacheDir: string): AOTDiskCacheFile | null {\n const cachePath = join(cacheDir, CACHE_FILENAME);\n try {\n const raw = readFileSync(cachePath, 'utf-8');\n const parsed = JSON.parse(raw);\n if (\n typeof parsed.cacheVersion === 'string' &&\n typeof parsed.hash === 'string' &&\n typeof parsed.jitFnsCode === 'string' &&\n typeof parsed.pureFnsCode === 'string' &&\n typeof parsed.routerCacheCode === 'string'\n ) {\n return parsed as AOTDiskCacheFile;\n }\n return null;\n } catch {\n return null;\n }\n}\n\n/** Write cache data to disk. Best-effort — logs warning on failure. */\nfunction writeDiskCache(cacheDir: string, hash: string, data: AOTCacheData): void {\n const cachePath = join(cacheDir, CACHE_FILENAME);\n try {\n mkdirSync(cacheDir, {recursive: true});\n const cacheFile: AOTDiskCacheFile = {\n cacheVersion: AOT_DISK_CACHE_VERSION,\n hash,\n jitFnsCode: data.jitFnsCode,\n pureFnsCode: data.pureFnsCode,\n routerCacheCode: data.routerCacheCode,\n };\n writeFileSync(cachePath, JSON.stringify(cacheFile), 'utf-8');\n } catch (err) {\n console.warn(`[mion] Warning: Could not write AOT disk cache: ${err instanceof Error ? err.message : String(err)}`);\n }\n}\n\n/** Resolve the cache directory from options and Vite's cacheDir */\nexport function resolveCacheDir(options: AOTCacheOptions, viteCacheDir?: string): string {\n if (options.cache === false) return '';\n if (typeof options.cache === 'string') return resolve(options.cache);\n return viteCacheDir || resolve(process.cwd(), 'node_modules/.vite');\n}\n\n/** Load AOT caches from disk if valid, otherwise generate fresh and save to disk. */\nexport async function getOrGenerateAOTCaches(\n serverConfig: MionServerConfig,\n aotOptions: AOTCacheOptions | undefined,\n cacheDir: string\n): Promise<AOTCacheResult> {\n const forceRegenerate = process.env.MION_AOT_FORCE === 'true';\n // IPC mode always needs a live child process (the server), so skip disk caching entirely\n const isIPCMode = serverConfig.mode === 'IPC';\n const cachingEnabled = cacheDir !== '' && !forceRegenerate && !isIPCMode;\n\n let hash = '';\n if (cachingEnabled) {\n hash = computeSourceHash(serverConfig, aotOptions);\n const cached = readDiskCache(cacheDir);\n if (cached && cached.cacheVersion === AOT_DISK_CACHE_VERSION && cached.hash === hash) {\n console.log('[mion] AOT caches loaded from disk cache (source unchanged)');\n return {\n data: {\n jitFnsCode: cached.jitFnsCode,\n pureFnsCode: cached.pureFnsCode,\n routerCacheCode: cached.routerCacheCode,\n },\n };\n }\n }\n\n // Cache miss or caching disabled — generate fresh\n const result = await generateAOTCaches(serverConfig);\n\n if (cachingEnabled) {\n if (!hash) hash = computeSourceHash(serverConfig, aotOptions);\n writeDiskCache(cacheDir, hash, result.data);\n console.log('[mion] AOT caches saved to disk cache');\n }\n\n return result;\n}\n\n/** Update the disk cache after HMR regeneration */\nexport function updateDiskCache(\n serverConfig: MionServerConfig,\n aotOptions: AOTCacheOptions | undefined,\n data: AOTCacheData,\n cacheDir: string\n): void {\n if (!cacheDir || aotOptions?.cache === false) return;\n const hash = computeSourceHash(serverConfig, aotOptions);\n writeDiskCache(cacheDir, hash, data);\n}\n"],"names":["resolve","dirname","readFileSync","readdirSync","join","statSync","relative","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}
1
+ {"version":3,"file":"aotDiskCache.cjs","sources":["../../../../../src/vite-plugin/aotDiskCache.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {createHash} from 'crypto';\nimport {readFileSync, writeFileSync, mkdirSync, readdirSync, statSync} from 'fs';\nimport {join, resolve, dirname, relative} from 'path';\nimport {AOTCacheOptions, MionServerConfig} from './types.ts';\nimport {generateAOTCaches, AOTCacheData, AOTCacheResult} from './aotCacheGenerator.ts';\n\n/** Schema for the on-disk cache file */\ninterface AOTDiskCacheFile {\n cacheVersion: string;\n hash: string;\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** Bump when mion internals change in a way that invalidates cached output */\nconst AOT_DISK_CACHE_VERSION = '2';\n\n/** Cache file name */\nconst CACHE_FILENAME = 'mion-aot-cache.json';\n\n/** Directories to skip when walking the server source tree */\nconst SKIP_DIRS = new Set(['node_modules', '.dist', 'dist', '.git', '.vite', 'build', 'coverage', '.coverage']);\n\n/** File extensions to include in hash computation */\nconst SOURCE_EXTENSIONS = /\\.(ts|tsx)$/;\n\n/** Test file patterns to exclude from hash computation */\nconst TEST_FILE_PATTERN = /\\.(spec|test)\\.(ts|tsx)$/;\n\n/** Read the devtools package version (cached after first call) */\nlet devtoolsVersion: string | null = null;\nfunction getDevtoolsVersion(): string {\n if (devtoolsVersion) return devtoolsVersion;\n try {\n const pkgPath = resolve(dirname(new URL(import.meta.url).pathname), '../../package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n devtoolsVersion = pkg.version || '0.0.0';\n } catch {\n devtoolsVersion = '0.0.0';\n }\n return devtoolsVersion as string;\n}\n\n/** Recursively collect file stats (relativePath:mtimeMs:size) for source files */\nfunction collectFileStats(dir: string, baseDir: string): string[] {\n const entries: string[] = [];\n let files: string[];\n try {\n files = readdirSync(dir);\n } catch {\n return entries;\n }\n for (const file of files) {\n const fullPath = join(dir, file);\n let stat;\n try {\n stat = statSync(fullPath);\n } catch {\n continue;\n }\n if (stat.isDirectory()) {\n if (SKIP_DIRS.has(file)) continue;\n entries.push(...collectFileStats(fullPath, baseDir));\n } else if (SOURCE_EXTENSIONS.test(file) && !TEST_FILE_PATTERN.test(file)) {\n const relativePath = relative(baseDir, fullPath);\n entries.push(`${relativePath}:${stat.mtimeMs}:${stat.size}`);\n }\n }\n return entries;\n}\n\n/** Compute a SHA-256 hash of the server source directory + options */\nexport function computeSourceHash(serverConfig: MionServerConfig, aotOptions?: AOTCacheOptions): string {\n const serverDir = dirname(resolve(serverConfig.startScript));\n const fileStats = collectFileStats(serverDir, serverDir);\n fileStats.sort();\n\n const hashInput = [\n ...fileStats,\n `cacheVersion:${AOT_DISK_CACHE_VERSION}`,\n `devtoolsVersion:${getDevtoolsVersion()}`,\n `excludedFns:${JSON.stringify((aotOptions?.excludedFns || []).slice().sort())}`,\n `excludedPureFns:${JSON.stringify((aotOptions?.excludedPureFns || []).slice().sort())}`,\n `isClient:${!!aotOptions?.isClient}`,\n ].join('\\n');\n\n return createHash('sha256').update(hashInput).digest('hex');\n}\n\n/** Read and validate the disk cache file. Returns null on any error. */\nfunction readDiskCache(cacheDir: string): AOTDiskCacheFile | null {\n const cachePath = join(cacheDir, CACHE_FILENAME);\n try {\n const raw = readFileSync(cachePath, 'utf-8');\n const parsed = JSON.parse(raw);\n if (\n typeof parsed.cacheVersion === 'string' &&\n typeof parsed.hash === 'string' &&\n typeof parsed.jitFnsCode === 'string' &&\n typeof parsed.pureFnsCode === 'string' &&\n typeof parsed.routerCacheCode === 'string'\n ) {\n return parsed as AOTDiskCacheFile;\n }\n return null;\n } catch {\n return null;\n }\n}\n\n/** Write cache data to disk. Best-effort — logs warning on failure. */\nfunction writeDiskCache(cacheDir: string, hash: string, data: AOTCacheData): void {\n const cachePath = join(cacheDir, CACHE_FILENAME);\n try {\n mkdirSync(cacheDir, {recursive: true});\n const cacheFile: AOTDiskCacheFile = {\n cacheVersion: AOT_DISK_CACHE_VERSION,\n hash,\n jitFnsCode: data.jitFnsCode,\n pureFnsCode: data.pureFnsCode,\n routerCacheCode: data.routerCacheCode,\n };\n writeFileSync(cachePath, JSON.stringify(cacheFile), 'utf-8');\n } catch (err) {\n console.warn(`[mion] Warning: Could not write AOT disk cache: ${err instanceof Error ? err.message : String(err)}`);\n }\n}\n\n/** Resolve the cache directory from options and Vite's cacheDir */\nexport function resolveCacheDir(options: AOTCacheOptions, viteCacheDir?: string): string {\n if (options.cache === false) return '';\n if (typeof options.cache === 'string') return resolve(options.cache);\n return viteCacheDir || resolve(process.cwd(), 'node_modules/.vite');\n}\n\n/** Load AOT caches from disk if valid, otherwise generate fresh and save to disk. */\nexport async function getOrGenerateAOTCaches(\n serverConfig: MionServerConfig,\n aotOptions: AOTCacheOptions | undefined,\n cacheDir: string\n): Promise<AOTCacheResult> {\n const forceRegenerate = process.env.MION_AOT_FORCE === 'true';\n // IPC mode always needs a live child process (the server), so skip disk caching entirely\n const isIPCMode = serverConfig.runMode === 'childProcess';\n const cachingEnabled = cacheDir !== '' && !forceRegenerate && !isIPCMode;\n\n let hash = '';\n if (cachingEnabled) {\n hash = computeSourceHash(serverConfig, aotOptions);\n const cached = readDiskCache(cacheDir);\n if (cached && cached.cacheVersion === AOT_DISK_CACHE_VERSION && cached.hash === hash) {\n console.log('[mion] AOT caches loaded from disk cache (source unchanged)');\n return {\n data: {\n jitFnsCode: cached.jitFnsCode,\n pureFnsCode: cached.pureFnsCode,\n routerCacheCode: cached.routerCacheCode,\n },\n };\n }\n }\n\n // Cache miss or caching disabled — generate fresh\n const result = await generateAOTCaches(serverConfig, undefined, aotOptions?.isClient);\n\n if (cachingEnabled) {\n if (!hash) hash = computeSourceHash(serverConfig, aotOptions);\n writeDiskCache(cacheDir, hash, result.data);\n console.log('[mion] AOT caches saved to disk cache');\n }\n\n return result;\n}\n\n/** Update the disk cache after HMR regeneration */\nexport function updateDiskCache(\n serverConfig: MionServerConfig,\n aotOptions: AOTCacheOptions | undefined,\n data: AOTCacheData,\n cacheDir: string\n): void {\n if (!cacheDir || aotOptions?.cache === false) return;\n const hash = computeSourceHash(serverConfig, aotOptions);\n writeDiskCache(cacheDir, hash, data);\n}\n"],"names":["resolve","dirname","readFileSync","readdirSync","join","statSync","relative","createHash","mkdirSync","writeFileSync","generateAOTCaches"],"mappings":";;;;;;;AAuBA,MAAM,yBAAyB;AAG/B,MAAM,iBAAiB;AAGvB,MAAM,YAAY,oBAAI,IAAI,CAAC,gBAAgB,SAAS,QAAQ,QAAQ,SAAS,SAAS,YAAY,WAAW,CAAC;AAG9G,MAAM,oBAAoB;AAG1B,MAAM,oBAAoB;AAG1B,IAAI,kBAAiC;AACrC,SAAS,qBAA6B;AAClC,MAAI,gBAAiB,QAAO;AAC5B,MAAI;AACA,UAAM,UAAUA,KAAAA,QAAQC,aAAQ,IAAI,6QAAmB,EAAE,QAAQ,GAAG,oBAAoB;AACxF,UAAM,MAAM,KAAK,MAAMC,GAAAA,aAAa,SAAS,OAAO,CAAC;AACrD,sBAAkB,IAAI,WAAW;AAAA,EACrC,QAAQ;AACJ,sBAAkB;AAAA,EACtB;AACA,SAAO;AACX;AAGA,SAAS,iBAAiB,KAAa,SAA2B;AAC9D,QAAM,UAAoB,CAAA;AAC1B,MAAI;AACJ,MAAI;AACA,YAAQC,GAAAA,YAAY,GAAG;AAAA,EAC3B,QAAQ;AACJ,WAAO;AAAA,EACX;AACA,aAAW,QAAQ,OAAO;AACtB,UAAM,WAAWC,KAAAA,KAAK,KAAK,IAAI;AAC/B,QAAI;AACJ,QAAI;AACA,aAAOC,GAAAA,SAAS,QAAQ;AAAA,IAC5B,QAAQ;AACJ;AAAA,IACJ;AACA,QAAI,KAAK,eAAe;AACpB,UAAI,UAAU,IAAI,IAAI,EAAG;AACzB,cAAQ,KAAK,GAAG,iBAAiB,UAAU,OAAO,CAAC;AAAA,IACvD,WAAW,kBAAkB,KAAK,IAAI,KAAK,CAAC,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U;AAC5D,mBAAe,UAAU,MAAM,OAAO,IAAI;AAC1C,YAAQ,IAAI,uCAAuC;AAAA,EACvD;AAEA,SAAO;AACX;AAGO,SAAS,gBACZ,cACA,YACA,MACA,UACI;AACJ,MAAI,CAAC,YAAY,YAAY,UAAU,MAAO;AAC9C,QAAM,OAAO,kBAAkB,cAAc,UAAU;AACvD,iBAAe,UAAU,MAAM,IAAI;AACvC;;;;;"}
@@ -6,15 +6,19 @@ const VIRTUAL_AOT_JIT_FNS = "virtual:mion-aot/jit-fns";
6
6
  const VIRTUAL_AOT_PURE_FNS = "virtual:mion-aot/pure-fns";
7
7
  const VIRTUAL_AOT_ROUTER_CACHE = "virtual:mion-aot/router-cache";
8
8
  const VIRTUAL_AOT_CACHES = "virtual:mion-aot/caches";
9
+ const AOT_CACHES_SHIM = "@mionjs/core/aot-caches";
10
+ const SERVER_PURE_FNS_SHIM = "@mionjs/core/server-pure-fns";
9
11
  const PURE_SERVER_FN_NAMESPACE = "pureServerFn";
10
12
  function resolveVirtualId(id) {
11
13
  return "\0" + id + ".ts";
12
14
  }
13
15
  const REFLECTION_MODULES = ["@mionjs/run-types", "@deepkit/type", "@deepkit/core"];
14
16
  const VIRTUAL_STUB_PREFIX = "virtual:mion-stub/";
17
+ exports.AOT_CACHES_SHIM = AOT_CACHES_SHIM;
15
18
  exports.BODY_HASH_LENGTH = BODY_HASH_LENGTH;
16
19
  exports.PURE_SERVER_FN_NAMESPACE = PURE_SERVER_FN_NAMESPACE;
17
20
  exports.REFLECTION_MODULES = REFLECTION_MODULES;
21
+ exports.SERVER_PURE_FNS_SHIM = SERVER_PURE_FNS_SHIM;
18
22
  exports.VIRTUAL_AOT_CACHES = VIRTUAL_AOT_CACHES;
19
23
  exports.VIRTUAL_AOT_JIT_FNS = VIRTUAL_AOT_JIT_FNS;
20
24
  exports.VIRTUAL_AOT_PURE_FNS = VIRTUAL_AOT_PURE_FNS;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sources":["../../../../../src/vite-plugin/constants.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nexport const BODY_HASH_LENGTH = 14;\n\n/** Virtual module ID for the pure functions registry (client-extracted pure functions) */\nexport const VIRTUAL_SERVER_PURE_FNS = 'virtual:mion-server-pure-fns';\n\n// ============ AOT Virtual Modules ============\n\n/** Virtual module ID for JIT functions + pure functions cache (from running the router) */\nexport const VIRTUAL_AOT_JIT_FNS = 'virtual:mion-aot/jit-fns';\n\n/** Virtual module ID for pure functions cache (standalone, from client AST extraction) */\nexport const VIRTUAL_AOT_PURE_FNS = 'virtual:mion-aot/pure-fns';\n\n/** Virtual module ID for router methods cache */\nexport const VIRTUAL_AOT_ROUTER_CACHE = 'virtual:mion-aot/router-cache';\n\n/** Virtual module ID for combined AOT caches (re-exports all 3 cache modules) */\nexport const VIRTUAL_AOT_CACHES = 'virtual:mion-aot/caches';\n\n/** The namespace used for all pureServerFn functions */\nexport const PURE_SERVER_FN_NAMESPACE = 'pureServerFn';\n\n/** Resolves a virtual module ID to its internal Vite ID (\\0 prefix + .ts extension) */\nexport function resolveVirtualId(id: string): string {\n return '\\0' + id + '.ts';\n}\n\n// ============ Reflection Stubs (for excludeReflection) ============\n\n/** Modules stubbed out when excludeReflection is enabled (not needed at runtime in AOT mode) */\nexport const REFLECTION_MODULES = ['@mionjs/run-types', '@deepkit/type', '@deepkit/core'];\n\n/** Prefix for virtual stub module IDs */\nexport const VIRTUAL_STUB_PREFIX = 'virtual:mion-stub/';\n\n// Purity validation constants (ALLOWED_GLOBALS, FORBIDDEN_IDENTIFIERS, FACTORY_FORBIDDEN_IDENTIFIERS)\n// are in ../pureFns/purityRules.ts, shared with the eslint plugin.\n"],"names":[],"mappings":";;AAOO,MAAM,mBAAmB;AAGzB,MAAM,0BAA0B;AAKhC,MAAM,sBAAsB;AAG5B,MAAM,uBAAuB;AAG7B,MAAM,2BAA2B;AAGjC,MAAM,qBAAqB;AAG3B,MAAM,2BAA2B;AAGjC,SAAS,iBAAiB,IAAoB;AACjD,SAAO,OAAO,KAAK;AACvB;AAKO,MAAM,qBAAqB,CAAC,qBAAqB,iBAAiB,eAAe;AAGjF,MAAM,sBAAsB;;;;;;;;;;;"}
1
+ {"version":3,"file":"constants.cjs","sources":["../../../../../src/vite-plugin/constants.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nexport const BODY_HASH_LENGTH = 14;\n\n/** Virtual module ID for the pure functions registry (client-extracted pure functions) */\nexport const VIRTUAL_SERVER_PURE_FNS = 'virtual:mion-server-pure-fns';\n\n// ============ AOT Virtual Modules ============\n\n/** Virtual module ID for JIT functions + pure functions cache (from running the router) */\nexport const VIRTUAL_AOT_JIT_FNS = 'virtual:mion-aot/jit-fns';\n\n/** Virtual module ID for pure functions cache (standalone, from client AST extraction) */\nexport const VIRTUAL_AOT_PURE_FNS = 'virtual:mion-aot/pure-fns';\n\n/** Virtual module ID for router methods cache */\nexport const VIRTUAL_AOT_ROUTER_CACHE = 'virtual:mion-aot/router-cache';\n\n/** Virtual module ID for combined AOT caches (re-exports all 3 cache modules) */\nexport const VIRTUAL_AOT_CACHES = 'virtual:mion-aot/caches';\n\n/** The real module that acts as a shim for AOT caches (empty caches). Swapped by the plugin when AOT is enabled. */\nexport const AOT_CACHES_SHIM = '@mionjs/core/aot-caches';\n\n/** The real module that acts as a shim for server pure functions (empty cache). Swapped by the plugin when serverPureFunctions is enabled. */\nexport const SERVER_PURE_FNS_SHIM = '@mionjs/core/server-pure-fns';\n\n/** The namespace used for all pureServerFn functions */\nexport const PURE_SERVER_FN_NAMESPACE = 'pureServerFn';\n\n/** Resolves a virtual module ID to its internal Vite ID (\\0 prefix + .ts extension) */\nexport function resolveVirtualId(id: string): string {\n return '\\0' + id + '.ts';\n}\n\n// ============ Reflection Stubs (for excludeReflection) ============\n\n/** Modules stubbed out when excludeReflection is enabled (not needed at runtime in AOT mode) */\nexport const REFLECTION_MODULES = ['@mionjs/run-types', '@deepkit/type', '@deepkit/core'];\n\n/** Prefix for virtual stub module IDs */\nexport const VIRTUAL_STUB_PREFIX = 'virtual:mion-stub/';\n\n// Purity validation constants (ALLOWED_GLOBALS, FORBIDDEN_IDENTIFIERS, FACTORY_FORBIDDEN_IDENTIFIERS)\n// are in ../pureFns/purityRules.ts, shared with the eslint plugin.\n"],"names":[],"mappings":";;AAOO,MAAM,mBAAmB;AAGzB,MAAM,0BAA0B;AAKhC,MAAM,sBAAsB;AAG5B,MAAM,uBAAuB;AAG7B,MAAM,2BAA2B;AAGjC,MAAM,qBAAqB;AAG3B,MAAM,kBAAkB;AAGxB,MAAM,uBAAuB;AAG7B,MAAM,2BAA2B;AAGjC,SAAS,iBAAiB,IAAoB;AACjD,SAAO,OAAO,KAAK;AACvB;AAKO,MAAM,qBAAqB,CAAC,qBAAqB,iBAAiB,eAAe;AAGjF,MAAM,sBAAsB;;;;;;;;;;;;;"}
@@ -4,6 +4,8 @@ export declare const VIRTUAL_AOT_JIT_FNS = "virtual:mion-aot/jit-fns";
4
4
  export declare const VIRTUAL_AOT_PURE_FNS = "virtual:mion-aot/pure-fns";
5
5
  export declare const VIRTUAL_AOT_ROUTER_CACHE = "virtual:mion-aot/router-cache";
6
6
  export declare const VIRTUAL_AOT_CACHES = "virtual:mion-aot/caches";
7
+ export declare const AOT_CACHES_SHIM = "@mionjs/core/aot-caches";
8
+ export declare const SERVER_PURE_FNS_SHIM = "@mionjs/core/server-pure-fns";
7
9
  export declare const PURE_SERVER_FN_NAMESPACE = "pureServerFn";
8
10
  export declare function resolveVirtualId(id: string): string;
9
11
  export declare const REFLECTION_MODULES: string[];