@mionjs/devtools 0.8.0-alpha.0 → 0.8.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/vite-plugin/cjs/src/vite-plugin/aotCacheGenerator.cjs +52 -25
- package/build/vite-plugin/cjs/src/vite-plugin/aotCacheGenerator.cjs.map +1 -1
- package/build/vite-plugin/cjs/src/vite-plugin/aotCacheGenerator.d.ts +10 -2
- package/build/vite-plugin/cjs/src/vite-plugin/aotDiskCache.cjs +2 -2
- package/build/vite-plugin/cjs/src/vite-plugin/aotDiskCache.cjs.map +1 -1
- package/build/vite-plugin/cjs/src/vite-plugin/constants.cjs +4 -0
- package/build/vite-plugin/cjs/src/vite-plugin/constants.cjs.map +1 -1
- package/build/vite-plugin/cjs/src/vite-plugin/constants.d.ts +2 -0
- package/build/vite-plugin/cjs/src/vite-plugin/mionVitePlugin.cjs +127 -30
- package/build/vite-plugin/cjs/src/vite-plugin/mionVitePlugin.cjs.map +1 -1
- package/build/vite-plugin/cjs/src/vite-plugin/mionVitePlugin.d.ts +2 -2
- package/build/vite-plugin/cjs/src/vite-plugin/transformers.cjs +1 -0
- package/build/vite-plugin/cjs/src/vite-plugin/transformers.cjs.map +1 -1
- package/build/vite-plugin/cjs/src/vite-plugin/types.d.ts +5 -4
- package/build/vite-plugin/esm/src/vite-plugin/aotCacheGenerator.d.ts +10 -2
- package/build/vite-plugin/esm/src/vite-plugin/aotCacheGenerator.js +52 -25
- package/build/vite-plugin/esm/src/vite-plugin/aotCacheGenerator.js.map +1 -1
- package/build/vite-plugin/esm/src/vite-plugin/aotDiskCache.js +2 -2
- package/build/vite-plugin/esm/src/vite-plugin/aotDiskCache.js.map +1 -1
- package/build/vite-plugin/esm/src/vite-plugin/constants.d.ts +2 -0
- package/build/vite-plugin/esm/src/vite-plugin/constants.js +4 -0
- package/build/vite-plugin/esm/src/vite-plugin/constants.js.map +1 -1
- package/build/vite-plugin/esm/src/vite-plugin/mionVitePlugin.d.ts +2 -2
- package/build/vite-plugin/esm/src/vite-plugin/mionVitePlugin.js +128 -32
- package/build/vite-plugin/esm/src/vite-plugin/mionVitePlugin.js.map +1 -1
- package/build/vite-plugin/esm/src/vite-plugin/transformers.js +1 -0
- package/build/vite-plugin/esm/src/vite-plugin/transformers.js.map +1 -1
- package/build/vite-plugin/esm/src/vite-plugin/types.d.ts +5 -4
- package/package.json +2 -2
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { resolve } from "path";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
import { existsSync } from "fs";
|
|
2
4
|
import * as ts from "typescript";
|
|
3
5
|
import { createDeepkitConfig, createPureFnTransformerFactory } from "./transformers.js";
|
|
4
6
|
import { scanClientSource } from "./extractPureFn.js";
|
|
5
7
|
import { generateServerPureFnsVirtualModule } from "./virtualModule.js";
|
|
6
|
-
import { resolveVirtualId, VIRTUAL_SERVER_PURE_FNS, REFLECTION_MODULES, VIRTUAL_STUB_PREFIX } from "./constants.js";
|
|
7
|
-
import { generateAOTCaches, logAOTCaches,
|
|
8
|
+
import { resolveVirtualId, VIRTUAL_SERVER_PURE_FNS, REFLECTION_MODULES, VIRTUAL_STUB_PREFIX, VIRTUAL_AOT_CACHES, AOT_CACHES_SHIM, SERVER_PURE_FNS_SHIM } from "./constants.js";
|
|
9
|
+
import { generateAOTCaches, logAOTCaches, generateNoopCombinedModule, generateCombinedCachesModule, generateNoopModule, generateRouterCacheModule, generatePureFnsModule, generateJitFnsModule, loadSSRRouterAndGenerateAOTCaches, killPersistentChild } from "./aotCacheGenerator.js";
|
|
8
10
|
import { updateDiskCache, getOrGenerateAOTCaches, resolveCacheDir } from "./aotDiskCache.js";
|
|
9
|
-
function isRunningAsChild() {
|
|
10
|
-
return process.env.MION_COMPILE === "onlyAOT" || process.env.MION_COMPILE === "serve";
|
|
11
|
-
}
|
|
12
11
|
function mionVitePlugin(options) {
|
|
13
12
|
let extractedFns = null;
|
|
14
13
|
const pureFnOptions = options.serverPureFunctions;
|
|
@@ -18,7 +17,8 @@ function mionVitePlugin(options) {
|
|
|
18
17
|
const deepkitConfig = runTypesOptions ? createDeepkitConfig(runTypesOptions) : null;
|
|
19
18
|
const defaultCompilerOptions = {
|
|
20
19
|
target: ts.ScriptTarget.ESNext,
|
|
21
|
-
module: ts.ModuleKind.ESNext
|
|
20
|
+
module: ts.ModuleKind.ESNext,
|
|
21
|
+
sourceMap: true
|
|
22
22
|
};
|
|
23
23
|
let pureServerFnCount = 0;
|
|
24
24
|
let registerPureFnFactoryCount = 0;
|
|
@@ -27,7 +27,7 @@ function mionVitePlugin(options) {
|
|
|
27
27
|
let aotGenerationPromise = null;
|
|
28
28
|
let aotCacheDir = "";
|
|
29
29
|
let ssrLoadModule = null;
|
|
30
|
-
const ssrEnabled = serverConfig?.
|
|
30
|
+
const ssrEnabled = serverConfig?.runMode === "middleware";
|
|
31
31
|
let ssrInitPromise = null;
|
|
32
32
|
let persistentChild = null;
|
|
33
33
|
let cleanupRegistered = false;
|
|
@@ -55,7 +55,7 @@ function mionVitePlugin(options) {
|
|
|
55
55
|
name: "mion",
|
|
56
56
|
enforce: "pre",
|
|
57
57
|
// literal type required: inferred 'string' is not assignable to Vite's 'pre' | 'post'
|
|
58
|
-
config(config) {
|
|
58
|
+
config(config, env) {
|
|
59
59
|
if (aotOptions?.excludeReflection && !isRunningAsChild()) {
|
|
60
60
|
const aliases = config.resolve?.alias;
|
|
61
61
|
if (aliases && !Array.isArray(aliases)) {
|
|
@@ -64,6 +64,13 @@ function mionVitePlugin(options) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
const shimModules = [];
|
|
68
|
+
if (pureFnOptions) shimModules.push(SERVER_PURE_FNS_SHIM);
|
|
69
|
+
if (aotOptions) shimModules.push(AOT_CACHES_SHIM);
|
|
70
|
+
addSsrNoExternal(config, shimModules);
|
|
71
|
+
if (env.command === "build" && shimModules.length > 0) {
|
|
72
|
+
wrapBuildExternal(config, shimModules);
|
|
73
|
+
}
|
|
67
74
|
},
|
|
68
75
|
configResolved(config) {
|
|
69
76
|
if (aotOptions) {
|
|
@@ -72,7 +79,6 @@ function mionVitePlugin(options) {
|
|
|
72
79
|
},
|
|
73
80
|
async buildStart() {
|
|
74
81
|
if (serverConfig && !isRunningAsChild() && !ssrEnabled) {
|
|
75
|
-
if (serverConfig.port) process.env.MION_TEST_PORT = String(serverConfig.port);
|
|
76
82
|
try {
|
|
77
83
|
console.log("[mion] Generating AOT caches...");
|
|
78
84
|
const resultPromise = getOrGenerateAOTCaches(serverConfig, aotOptions, aotCacheDir);
|
|
@@ -86,16 +92,23 @@ function mionVitePlugin(options) {
|
|
|
86
92
|
registerCleanupHandlers();
|
|
87
93
|
console.log(`[mion] Server process persisted (pid: ${persistentChild.pid})`);
|
|
88
94
|
}
|
|
89
|
-
if (serverConfig.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
if (result.platformReady && serverConfig.waitTimeout && serverConfig.runMode === "childProcess") {
|
|
96
|
+
console.log("[mion] Waiting for server to call setPlatformConfig()...");
|
|
97
|
+
const timeout = serverConfig.waitTimeout;
|
|
98
|
+
const timeoutId = setTimeout(() => {
|
|
99
|
+
if (result.childProcess?.connected) result.childProcess.disconnect();
|
|
100
|
+
console.error(
|
|
101
|
+
`[mion] Server did not call setPlatformConfig() within ${timeout / 1e3}s. Ensure your platform adapter (startNodeServer, etc.) is called after initMionRouter().`
|
|
102
|
+
);
|
|
103
|
+
}, timeout);
|
|
104
|
+
result.platformReady.then(() => {
|
|
105
|
+
clearTimeout(timeoutId);
|
|
106
|
+
if (result.childProcess?.connected) result.childProcess.disconnect();
|
|
107
|
+
console.log("[mion] Server ready");
|
|
94
108
|
onServerReady();
|
|
95
|
-
}).catch((err) => {
|
|
96
|
-
console.error(`[mion] ${err instanceof Error ? err.message : String(err)}`);
|
|
97
109
|
});
|
|
98
110
|
} else {
|
|
111
|
+
if (result.childProcess?.connected) result.childProcess.disconnect();
|
|
99
112
|
onServerReady();
|
|
100
113
|
}
|
|
101
114
|
} catch (err) {
|
|
@@ -107,12 +120,12 @@ function mionVitePlugin(options) {
|
|
|
107
120
|
configureServer(server) {
|
|
108
121
|
if (!ssrEnabled || !serverConfig) return;
|
|
109
122
|
ssrLoadModule = (url) => server.ssrLoadModule(url);
|
|
110
|
-
const
|
|
123
|
+
const startScript = resolve(serverConfig.startScript);
|
|
111
124
|
let nodeRequestHandler = null;
|
|
112
125
|
let basePath = null;
|
|
113
126
|
let initFailed = false;
|
|
114
127
|
console.log("[mion] Generating SSR AOT caches...");
|
|
115
|
-
ssrInitPromise = loadSSRRouterAndGenerateAOTCaches(ssrLoadModule,
|
|
128
|
+
ssrInitPromise = loadSSRRouterAndGenerateAOTCaches(ssrLoadModule, startScript).then(async (data) => {
|
|
116
129
|
aotData = data;
|
|
117
130
|
aotGenerationPromise = Promise.resolve(data);
|
|
118
131
|
console.log("[mion] SSR AOT caches generated successfully");
|
|
@@ -152,9 +165,33 @@ function mionVitePlugin(options) {
|
|
|
152
165
|
}
|
|
153
166
|
});
|
|
154
167
|
},
|
|
155
|
-
resolveId(id) {
|
|
168
|
+
resolveId(id, importer) {
|
|
156
169
|
if (id === VIRTUAL_SERVER_PURE_FNS) return resolveVirtualId(id);
|
|
157
170
|
if (aotVirtualModules.has(id)) return resolveVirtualId(id);
|
|
171
|
+
if (aotOptions) {
|
|
172
|
+
const resolved = resolveShimModule(
|
|
173
|
+
id,
|
|
174
|
+
importer,
|
|
175
|
+
AOT_CACHES_SHIM,
|
|
176
|
+
VIRTUAL_AOT_CACHES,
|
|
177
|
+
"aot-caches",
|
|
178
|
+
"aotCaches.ts",
|
|
179
|
+
"emptyCaches.ts"
|
|
180
|
+
);
|
|
181
|
+
if (resolved) return resolved;
|
|
182
|
+
}
|
|
183
|
+
if (pureFnOptions) {
|
|
184
|
+
const resolved = resolveShimModule(
|
|
185
|
+
id,
|
|
186
|
+
importer,
|
|
187
|
+
SERVER_PURE_FNS_SHIM,
|
|
188
|
+
VIRTUAL_SERVER_PURE_FNS,
|
|
189
|
+
"server-pure-fns",
|
|
190
|
+
"serverPureFnsCaches.ts",
|
|
191
|
+
"emptyServerPureFns.ts"
|
|
192
|
+
);
|
|
193
|
+
if (resolved) return resolved;
|
|
194
|
+
}
|
|
158
195
|
if (aotOptions?.excludeReflection && !isRunningAsChild() && REFLECTION_MODULES.includes(id)) {
|
|
159
196
|
return resolveVirtualId(VIRTUAL_STUB_PREFIX + id);
|
|
160
197
|
}
|
|
@@ -229,7 +266,8 @@ function mionVitePlugin(options) {
|
|
|
229
266
|
else pureServerFnCount++;
|
|
230
267
|
}
|
|
231
268
|
}
|
|
232
|
-
|
|
269
|
+
const outputCode = result.outputText.replace(/\n\/\/# sourceMappingURL=.*$/, "");
|
|
270
|
+
return { code: outputCode, map: result.sourceMapText };
|
|
233
271
|
},
|
|
234
272
|
buildEnd() {
|
|
235
273
|
if (pureServerFnCount > 0 || registerPureFnFactoryCount > 0) {
|
|
@@ -261,7 +299,7 @@ function mionVitePlugin(options) {
|
|
|
261
299
|
}
|
|
262
300
|
}
|
|
263
301
|
if (serverConfig && !isRunningAsChild()) {
|
|
264
|
-
const serverDir = resolve(serverConfig.
|
|
302
|
+
const serverDir = resolve(serverConfig.startScript, "..");
|
|
265
303
|
if (file.startsWith(serverDir)) {
|
|
266
304
|
const killPromise = cleanupChild();
|
|
267
305
|
const regeneratePromise = ssrEnabled && ssrLoadModule ? (
|
|
@@ -269,10 +307,7 @@ function mionVitePlugin(options) {
|
|
|
269
307
|
(async () => {
|
|
270
308
|
const routerModule = await ssrLoadModule("@mionjs/router");
|
|
271
309
|
routerModule.resetRouter();
|
|
272
|
-
return loadSSRRouterAndGenerateAOTCaches(
|
|
273
|
-
ssrLoadModule,
|
|
274
|
-
resolve(serverConfig.startServerScript)
|
|
275
|
-
);
|
|
310
|
+
return loadSSRRouterAndGenerateAOTCaches(ssrLoadModule, resolve(serverConfig.startScript));
|
|
276
311
|
})()
|
|
277
312
|
) : (
|
|
278
313
|
// IPC mode: wait for old child to die, then spawn new
|
|
@@ -287,15 +322,24 @@ function mionVitePlugin(options) {
|
|
|
287
322
|
persistentChild = result.childProcess;
|
|
288
323
|
console.log(`[mion] Server process re-persisted (pid: ${persistentChild.pid})`);
|
|
289
324
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
325
|
+
const platformReady = "platformReady" in result ? result.platformReady : void 0;
|
|
326
|
+
if (platformReady && serverConfig.waitTimeout && serverConfig.runMode === "childProcess") {
|
|
327
|
+
const timeout = serverConfig.waitTimeout;
|
|
328
|
+
console.log("[mion] Waiting for restarted server to call setPlatformConfig()...");
|
|
329
|
+
const timeoutId = setTimeout(() => {
|
|
330
|
+
if (persistentChild?.connected) persistentChild.disconnect();
|
|
331
|
+
console.error(
|
|
332
|
+
`[mion] Restarted server did not call setPlatformConfig() within ${timeout / 1e3}s.`
|
|
333
|
+
);
|
|
334
|
+
}, timeout);
|
|
335
|
+
platformReady.then(() => {
|
|
336
|
+
clearTimeout(timeoutId);
|
|
337
|
+
if (persistentChild?.connected) persistentChild.disconnect();
|
|
338
|
+
console.log("[mion] Restarted server ready");
|
|
295
339
|
onServerReady();
|
|
296
|
-
}).catch((err) => {
|
|
297
|
-
console.error(`[mion] ${err instanceof Error ? err.message : String(err)}`);
|
|
298
340
|
});
|
|
341
|
+
} else if ("childProcess" in result && result.childProcess?.connected) {
|
|
342
|
+
result.childProcess.disconnect();
|
|
299
343
|
}
|
|
300
344
|
if (!ssrEnabled) updateDiskCache(serverConfig, aotOptions, data, aotCacheDir);
|
|
301
345
|
let invalidatedCount = 0;
|
|
@@ -318,6 +362,9 @@ function mionVitePlugin(options) {
|
|
|
318
362
|
}
|
|
319
363
|
};
|
|
320
364
|
}
|
|
365
|
+
function isRunningAsChild() {
|
|
366
|
+
return process.env.MION_COMPILE === "buildOnly" || process.env.MION_COMPILE === "childProcess";
|
|
367
|
+
}
|
|
321
368
|
function parseVueModuleId(id) {
|
|
322
369
|
const qIdx = id.indexOf("?");
|
|
323
370
|
if (qIdx === -1) return null;
|
|
@@ -363,6 +410,55 @@ function buildAOTVirtualModuleMaps(customVirtualModuleId) {
|
|
|
363
410
|
}
|
|
364
411
|
return { aotVirtualModules, aotResolvedIds };
|
|
365
412
|
}
|
|
413
|
+
function resolveShimModule(id, importer, shimSpecifier, virtualModuleId, entryName, sourceFileName, emptyFileName) {
|
|
414
|
+
if (id === shimSpecifier) {
|
|
415
|
+
try {
|
|
416
|
+
const resolved = createRequire(import.meta.url).resolve(shimSpecifier);
|
|
417
|
+
const sourceFile = resolve(resolved.replace(/[/\\].dist[/\\].*$/, ""), "src/aot/" + sourceFileName);
|
|
418
|
+
if (existsSync(sourceFile)) return sourceFile;
|
|
419
|
+
return resolveVirtualId(virtualModuleId);
|
|
420
|
+
} catch {
|
|
421
|
+
return resolveVirtualId(virtualModuleId);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (id.endsWith("/" + entryName)) {
|
|
425
|
+
const sourceFile = resolve(id, "..", "src/aot/" + sourceFileName);
|
|
426
|
+
if (existsSync(sourceFile)) return sourceFile;
|
|
427
|
+
}
|
|
428
|
+
const emptyBase = emptyFileName.replace(".ts", "");
|
|
429
|
+
const sourceBase = sourceFileName.replace(".ts", "");
|
|
430
|
+
if (new RegExp(`${emptyBase}\\.(ts|js|mjs|cjs)$`).test(id) && importer && new RegExp(`${sourceBase}\\.(ts|js|mjs|cjs)$`).test(importer)) {
|
|
431
|
+
return resolveVirtualId(virtualModuleId);
|
|
432
|
+
}
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
function addSsrNoExternal(config, moduleIds) {
|
|
436
|
+
if (moduleIds.length === 0) return;
|
|
437
|
+
const noExternal = config.ssr?.noExternal;
|
|
438
|
+
if (!config.ssr) config.ssr = {};
|
|
439
|
+
if (Array.isArray(noExternal)) {
|
|
440
|
+
for (const moduleId of moduleIds) {
|
|
441
|
+
if (!noExternal.includes(moduleId)) noExternal.push(moduleId);
|
|
442
|
+
}
|
|
443
|
+
} else if (typeof noExternal === "string") {
|
|
444
|
+
config.ssr.noExternal = [noExternal, ...moduleIds];
|
|
445
|
+
} else if (noExternal !== true) {
|
|
446
|
+
config.ssr.noExternal = noExternal ? [noExternal, ...moduleIds] : [...moduleIds];
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function wrapBuildExternal(config, shimModules) {
|
|
450
|
+
if (!config.build) config.build = {};
|
|
451
|
+
if (!config.build.rollupOptions) config.build.rollupOptions = {};
|
|
452
|
+
const original = config.build.rollupOptions.external;
|
|
453
|
+
if (!original) return;
|
|
454
|
+
config.build.rollupOptions.external = (id, ...rest) => {
|
|
455
|
+
if (shimModules.includes(id) || id.startsWith("virtual:mion")) return false;
|
|
456
|
+
if (typeof original === "function") return original(id, ...rest);
|
|
457
|
+
if (Array.isArray(original)) return original.some((ext) => ext instanceof RegExp ? ext.test(id) : ext === id);
|
|
458
|
+
if (original instanceof RegExp) return original.test(id);
|
|
459
|
+
return original === id;
|
|
460
|
+
};
|
|
461
|
+
}
|
|
366
462
|
const READY_KEY = /* @__PURE__ */ Symbol.for("mion.serverReady");
|
|
367
463
|
function getOrCreateServerReady() {
|
|
368
464
|
if (!globalThis[READY_KEY]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mionVitePlugin.js","sources":["../../../../../src/vite-plugin/mionVitePlugin.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 {resolve} from 'path';\nimport * as ts from 'typescript';\nimport {ChildProcess} from 'child_process';\nimport {createDeepkitConfig, DeepkitConfig, createPureFnTransformerFactory} from './transformers.ts';\nimport {ServerPureFunctionsOptions, ExtractedPureFn, DeepkitTypeOptions, AOTCacheOptions, MionServerConfig} from './types.ts';\nimport {scanClientSource} from './extractPureFn.ts';\nimport {generateServerPureFnsVirtualModule} from './virtualModule.ts';\nimport {VIRTUAL_SERVER_PURE_FNS, REFLECTION_MODULES, VIRTUAL_STUB_PREFIX, resolveVirtualId} from './constants.ts';\nimport {\n generateAOTCaches,\n loadSSRRouterAndGenerateAOTCaches,\n killPersistentChild,\n logAOTCaches,\n waitForServer,\n generateJitFnsModule,\n generatePureFnsModule,\n generateRouterCacheModule,\n generateCombinedCachesModule,\n generateNoopModule,\n generateNoopCombinedModule,\n AOTCacheData,\n} from './aotCacheGenerator.ts';\nimport {getOrGenerateAOTCaches, updateDiskCache, resolveCacheDir} from './aotDiskCache.ts';\n\nexport interface MionPluginOptions {\n /** Options for pure function extraction - omit to disable */\n serverPureFunctions?: ServerPureFunctionsOptions;\n /** Options for deepkit type transformation - omit to disable */\n runTypes?: DeepkitTypeOptions;\n /** Options for AOT cache generation - omit to disable */\n aotCaches?: AOTCacheOptions | true;\n /** Server configuration - controls how the server process is managed */\n server?: MionServerConfig;\n}\n\n/** Whether the current process is a child spawned by the mion plugin */\nfunction isRunningAsChild(): boolean {\n return process.env.MION_COMPILE === 'onlyAOT' || process.env.MION_COMPILE === 'serve';\n}\n\n/**\n * Creates the unified mion Vite plugin.\n * This plugin combines pure function extraction, type compiler transformations,\n * and AOT cache generation in a single plugin with correct execution order.\n *\n * Execution order:\n * 1. Extract pure functions from original TypeScript source\n * 2. Apply type metadata transformations to the code\n *\n * This ensures pure function extraction happens on clean, untransformed TypeScript.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import {mionPlugin} from '@mionjs/devtools/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * mionPlugin({\n * runTypes: {\n * tsConfig: './tsconfig.json',\n * },\n * server: {\n * startServerScript: '../server/src/init.ts',\n * mode: 'onlyAOT',\n * },\n * }),\n * ],\n * });\n * ```\n */\nexport function mionVitePlugin(options: MionPluginOptions) {\n let extractedFns: ExtractedPureFn[] | null = null;\n const pureFnOptions = options.serverPureFunctions;\n const runTypesOptions = options.runTypes;\n const aotOptions: AOTCacheOptions | undefined = options.aotCaches === true ? {} : options.aotCaches;\n const serverConfig = options.server;\n const deepkitConfig: DeepkitConfig | null = runTypesOptions ? createDeepkitConfig(runTypesOptions) : null;\n\n // Default compiler options for when deepkit is disabled\n const defaultCompilerOptions: ts.CompilerOptions = {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n };\n\n // Pure function injection counters — accumulated during transform, logged in buildEnd\n let pureServerFnCount = 0;\n let registerPureFnFactoryCount = 0;\n let pureFnFilesCount = 0;\n\n // AOT cache data - populated during buildStart (IPC) or configureServer (in-process)\n let aotData: AOTCacheData | null = null;\n let aotGenerationPromise: Promise<AOTCacheData> | null = null;\n\n // Resolved cache directory from Vite's config — set in configResolved\n let aotCacheDir = '';\n\n // SSR AOT: module loader (set in configureServer when SSR mode is active)\n let ssrLoadModule: ((url: string) => Promise<Record<string, any>>) | null = null;\n /** Whether SSR mode is active — resolved from server config */\n const ssrEnabled = serverConfig?.mode === 'viteSSR';\n /** SSR init promise: AOT generation + router/platform module loading */\n let ssrInitPromise: Promise<void> | null = null;\n\n // Persistent child process for IPC mode\n let persistentChild: ChildProcess | null = null;\n let cleanupRegistered = false;\n\n const {aotVirtualModules, aotResolvedIds} = buildAOTVirtualModuleMaps(aotOptions?.customVirtualModuleId);\n\n /** Kill persistent child process and clear reference */\n async function cleanupChild() {\n if (persistentChild) {\n await killPersistentChild(persistentChild);\n persistentChild = null;\n }\n }\n\n /** Register process exit handlers (once) */\n function registerCleanupHandlers() {\n if (cleanupRegistered) return;\n cleanupRegistered = true;\n const onExit = () => {\n if (persistentChild && !persistentChild.killed) {\n persistentChild.kill('SIGTERM');\n persistentChild = null;\n }\n };\n process.on('exit', onExit);\n process.on('SIGINT', onExit);\n process.on('SIGTERM', onExit);\n }\n\n return {\n name: 'mion',\n enforce: 'pre' as const, // literal type required: inferred 'string' is not assignable to Vite's 'pre' | 'post'\n\n config(config) {\n // Strip reflection module aliases in bundle build mode so our resolveId can stub them.\n // Vite's alias plugin runs before our resolveId, so we remove aliases here to prevent\n // them from transforming bare package names into file paths before we can intercept.\n if (aotOptions?.excludeReflection && !isRunningAsChild()) {\n const aliases = config.resolve?.alias;\n if (aliases && !Array.isArray(aliases)) {\n for (const mod of REFLECTION_MODULES) {\n delete (aliases as Record<string, string>)[mod];\n }\n }\n }\n },\n\n configResolved(config) {\n if (aotOptions) {\n aotCacheDir = resolveCacheDir(aotOptions, config.cacheDir);\n }\n },\n\n async buildStart() {\n // Generate AOT caches if server is configured\n // Skip when already running as a child process to prevent infinite recursion\n // Skip when SSR mode — configureServer will handle it\n if (serverConfig && !isRunningAsChild() && !ssrEnabled) {\n // Set port env before spawning child so the server uses the correct port\n if (serverConfig.port) process.env.MION_TEST_PORT = String(serverConfig.port);\n try {\n console.log('[mion] Generating AOT caches...');\n const resultPromise = getOrGenerateAOTCaches(serverConfig, aotOptions, aotCacheDir);\n aotGenerationPromise = resultPromise.then((r) => r.data);\n const result = await resultPromise;\n aotData = result.data;\n console.log('[mion] AOT caches generated successfully');\n logAOTCaches(aotData);\n\n // Store persistent child for IPC mode\n if (result.childProcess) {\n persistentChild = result.childProcess;\n registerCleanupHandlers();\n console.log(`[mion] Server process persisted (pid: ${persistentChild.pid})`);\n }\n\n // Non-blocking: poll server port and resolve serverReady promise (IPC mode)\n if (serverConfig.port && serverConfig.mode === 'IPC') {\n const timeout = serverConfig.waitTimeout ?? 30000;\n console.log(`[mion] Waiting for server on port ${serverConfig.port}...`);\n waitForServer(serverConfig.port, timeout)\n .then(() => {\n console.log(`[mion] Server ready on port ${serverConfig.port}`);\n onServerReady();\n })\n .catch((err) => {\n console.error(`[mion] ${err instanceof Error ? err.message : String(err)}`);\n });\n } else {\n // onlyAOT mode: no persistent server, resolve immediately\n onServerReady();\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`[mion] Failed to generate AOT caches: ${message}`);\n }\n }\n },\n\n configureServer(server) {\n if (!ssrEnabled || !serverConfig) return;\n // SSR mode: use ssrLoadModule to load the server in the same Vite process.\n // ssrLoadModule uses Vite's internal transform pipeline (not HTTP),\n ssrLoadModule = (url: string) => server.ssrLoadModule(url);\n const startServerScript = resolve(serverConfig.startServerScript);\n // Single init chain: generate AOT caches → load router + platform modules\n let nodeRequestHandler: ((req: any, res: any) => void) | null = null;\n let basePath: string | null = null;\n let initFailed = false;\n\n console.log('[mion] Generating SSR AOT caches...');\n ssrInitPromise = loadSSRRouterAndGenerateAOTCaches(ssrLoadModule, startServerScript)\n .then(async (data) => {\n aotData = data;\n aotGenerationPromise = Promise.resolve(data);\n console.log('[mion] SSR AOT caches generated successfully');\n logAOTCaches(data);\n // Invalidate virtual modules so they reload with real data\n for (const resolvedId of aotResolvedIds.keys()) {\n const mod = server.moduleGraph.getModuleById(resolvedId);\n if (mod) server.moduleGraph.invalidateModule(mod);\n }\n // Load router and platform modules now that caches are ready\n const routerModule = await server.ssrLoadModule('@mionjs/router');\n const opts = routerModule.getRouterOptions();\n basePath = '/' + (opts.basePath || '').replace(/^\\//, '');\n const platformNode = await server.ssrLoadModule('@mionjs/platform-node');\n nodeRequestHandler = platformNode.httpRequestHandler;\n console.log('[mion] Dev server proxy initialized');\n onServerReady();\n })\n .catch((err) => {\n initFailed = true;\n const message = err instanceof Error ? err.message : String(err);\n console.error(`[mion] Failed to initialize SSR: ${message}`);\n });\n\n // Dev server proxy: route matching requests to mion's httpRequestHandler\n server.middlewares.use(async (req: any, res: any, next: () => void) => {\n try {\n if (!basePath && !initFailed) await ssrInitPromise;\n if (!basePath || !req.url?.startsWith(basePath)) return next();\n if (nodeRequestHandler) {\n nodeRequestHandler(req, res);\n } else {\n res.statusCode = 503;\n res.end('mion API failed to initialize');\n }\n } catch (err) {\n console.error('[mion] Dev server proxy error:', err);\n if (!res.writableEnded) {\n res.statusCode = 500;\n res.end('Internal Server Error');\n }\n }\n });\n },\n\n resolveId(id) {\n // Pure functions virtual module — always resolve, returns empty cache if not configured\n if (id === VIRTUAL_SERVER_PURE_FNS) return resolveVirtualId(id);\n // AOT virtual modules (default + custom prefix both resolve)\n if (aotVirtualModules.has(id)) return resolveVirtualId(id);\n // Stub out reflection modules in the bundle build (not needed at runtime in AOT mode)\n if (aotOptions?.excludeReflection && !isRunningAsChild() && REFLECTION_MODULES.includes(id)) {\n return resolveVirtualId(VIRTUAL_STUB_PREFIX + id);\n }\n return null;\n },\n\n async load(id) {\n // Pure functions virtual module\n if (id === resolveVirtualId(VIRTUAL_SERVER_PURE_FNS)) {\n // No serverPureFunctions configured — return empty cache\n if (!pureFnOptions) return generateServerPureFnsVirtualModule([]);\n // Lazily scan client source on first load\n if (!extractedFns) extractedFns = scanClientSource(pureFnOptions);\n return generateServerPureFnsVirtualModule(extractedFns);\n }\n\n // AOT virtual modules — check resolved ID against the map\n const aotType = aotResolvedIds.get(id);\n if (aotType) {\n const initPromise = ssrInitPromise || aotGenerationPromise;\n if (!aotData && initPromise) await initPromise;\n\n switch (aotType) {\n case 'jit-fns': {\n if (!aotData) return generateNoopModule('No-op: AOT JIT caches not generated');\n return generateJitFnsModule(aotData.jitFnsCode);\n }\n case 'pure-fns': {\n if (!aotData) return generateNoopModule('No-op: AOT pure fns not generated');\n return generatePureFnsModule(aotData.pureFnsCode);\n }\n case 'router-cache': {\n if (!aotData) return generateNoopModule('No-op: AOT router cache not generated');\n return generateRouterCacheModule(aotData.routerCacheCode);\n }\n case 'caches': {\n if (!aotData) return generateNoopCombinedModule();\n return generateCombinedCachesModule();\n }\n }\n }\n\n // Reflection module stubs (empty modules — all reflection is pre-compiled in AOT caches)\n // syntheticNamedExports tells Rollup to derive named exports from the default export,\n // so any `import {foo} from '...'` resolves to undefined without build errors.\n for (const mod of REFLECTION_MODULES) {\n if (id === resolveVirtualId(VIRTUAL_STUB_PREFIX + mod)) {\n return {code: 'export default {}', syntheticNamedExports: true};\n }\n }\n\n return null;\n },\n\n transform(code: string, fileName: string) {\n // For Vue SFC virtual modules, resolve the base path and lang for downstream tools\n const vueInfo = parseVueModuleId(fileName);\n // Strip any query params (e.g. ?macro=true from Nuxt) to get the real file path\n const basePath = fileName.includes('?') ? fileName.slice(0, fileName.indexOf('?')) : fileName;\n const filterPath = vueInfo ? vueInfo.basePath : basePath;\n\n // Skip .vue files unless they are Vue script virtual modules (?vue&type=script).\n // Bare .vue files and other .vue queries (e.g. ?macro=true from Nuxt) contain raw\n // SFC content — wait for the Vue plugin to extract the <script> block first.\n if (basePath.endsWith('.vue') && !vueInfo) return null;\n\n const lang = vueInfo?.lang || 'ts';\n const tsFileName = vueInfo ? `${vueInfo.basePath}.${lang}` : fileName;\n const isTsx = tsFileName.endsWith('.tsx') || tsFileName.endsWith('.jsx');\n\n const hasPureFns =\n code.includes('pureServerFn') || code.includes('registerPureFnFactory') || code.includes('mapFrom');\n const needsDeepkit = deepkitConfig ? deepkitConfig.filter(filterPath) : false;\n\n if (!hasPureFns && !needsDeepkit) return null;\n\n const before: ts.CustomTransformerFactory[] = [];\n const after: ts.CustomTransformerFactory[] = [];\n\n // Pure function transformer (runs first — sees clean AST)\n const collected: ExtractedPureFn[] | undefined = hasPureFns ? [] : undefined;\n if (hasPureFns) {\n before.push(createPureFnTransformerFactory(code, tsFileName, collected, pureFnOptions?.noViteClient));\n }\n\n // Deepkit has two functions: type metadata emission (follows include/exclude filters)\n // and import restoration (always runs globally for all ts.transpileModule calls).\n // afterTransformers (including requireToImport) must always be included to convert\n // deepkit's CJS require() back to ESM imports in the restored import statements.\n if (deepkitConfig) after.push(...deepkitConfig.afterTransformers);\n if (needsDeepkit) before.push(...deepkitConfig!.beforeTransformers);\n\n const baseCompilerOptions = deepkitConfig?.compilerOptions ?? defaultCompilerOptions;\n const compilerOptions = isTsx ? {...baseCompilerOptions, jsx: ts.JsxEmit.ReactJSX} : baseCompilerOptions;\n\n const result = ts.transpileModule(code, {\n compilerOptions,\n fileName: tsFileName,\n transformers: {before, after},\n });\n\n // Count injected pure functions (collector is populated synchronously by transpileModule)\n if (collected && collected.length > 0) {\n pureFnFilesCount++;\n for (const fn of collected) {\n if (fn.isFactory) registerPureFnFactoryCount++;\n else pureServerFnCount++;\n }\n }\n\n return {code: result.outputText, map: result.sourceMapText};\n },\n\n buildEnd() {\n if (pureServerFnCount > 0 || registerPureFnFactoryCount > 0) {\n const total = pureServerFnCount + registerPureFnFactoryCount;\n const parts = [\n pureServerFnCount > 0 ? `${pureServerFnCount} pureServerFn` : '',\n registerPureFnFactoryCount > 0 ? `${registerPureFnFactoryCount} registerPureFnFactory` : '',\n ].filter(Boolean);\n console.log(`[mion] Injected ${total} pure functions across ${pureFnFilesCount} files (${parts.join(', ')})`);\n }\n },\n\n async closeBundle() {\n await cleanupChild();\n },\n\n handleHotUpdate({file, server}) {\n // In dev mode, re-scan when client source changes (for pure functions)\n if (pureFnOptions) {\n const clientSrcPath = resolve(pureFnOptions.clientSrcPath);\n if (file.startsWith(clientSrcPath)) {\n const include = pureFnOptions.include || ['**/*.ts', '**/*.tsx', '**/*.vue'];\n const exclude = pureFnOptions.exclude || ['../node_modules/**', '**/.dist/**', '**/dist/**'];\n if (isIncluded(file, include, exclude)) {\n // Clear cache and invalidate virtual module\n extractedFns = null;\n const mod = server.moduleGraph.getModuleById(resolveVirtualId(VIRTUAL_SERVER_PURE_FNS));\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n return [mod];\n }\n }\n }\n }\n\n // In dev mode, regenerate AOT caches when server source changes\n // Skip when running as a child process\n if (serverConfig && !isRunningAsChild()) {\n const serverDir = resolve(serverConfig.startServerScript, '..');\n\n if (file.startsWith(serverDir)) {\n // Kill existing persistent child before regenerating\n const killPromise = cleanupChild();\n\n const regeneratePromise =\n ssrEnabled && ssrLoadModule\n ? // SSR mode: reset router and re-init via ssrLoadModule\n (async () => {\n const routerModule = await ssrLoadModule!('@mionjs/router');\n routerModule.resetRouter();\n return loadSSRRouterAndGenerateAOTCaches(\n ssrLoadModule!,\n resolve(serverConfig.startServerScript)\n );\n })()\n : // IPC mode: wait for old child to die, then spawn new\n killPromise.then(() => generateAOTCaches(serverConfig));\n\n aotGenerationPromise = regeneratePromise.then((r) => ('data' in r ? r.data : r));\n regeneratePromise\n .then((result) => {\n const data = 'data' in result ? result.data : result;\n aotData = data;\n logAOTCaches(data);\n\n // Store new persistent child if IPC mode\n if ('childProcess' in result && result.childProcess) {\n persistentChild = result.childProcess;\n console.log(`[mion] Server process re-persisted (pid: ${persistentChild!.pid})`);\n }\n\n // Non-blocking: poll restarted server and resolve serverReady promise\n if (serverConfig.port && serverConfig.mode === 'IPC') {\n const timeout = serverConfig.waitTimeout ?? 30000;\n console.log(`[mion] Waiting for restarted server on port ${serverConfig.port}...`);\n waitForServer(serverConfig.port, timeout)\n .then(() => {\n console.log(`[mion] Restarted server ready on port ${serverConfig.port}`);\n onServerReady();\n })\n .catch((err) => {\n console.error(`[mion] ${err instanceof Error ? err.message : String(err)}`);\n });\n }\n\n if (!ssrEnabled) updateDiskCache(serverConfig, aotOptions, data, aotCacheDir);\n // Invalidate all AOT virtual modules\n let invalidatedCount = 0;\n for (const resolvedId of aotResolvedIds.keys()) {\n const mod = server.moduleGraph.getModuleById(resolvedId);\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n invalidatedCount++;\n }\n }\n if (invalidatedCount > 0) {\n console.log('[mion] AOT caches regenerated, invalidating virtual modules');\n }\n })\n .catch((err) => {\n console.error('[mion] Failed to regenerate AOT caches:', err.message);\n });\n }\n }\n\n return undefined;\n },\n };\n}\n\n/** Extracts the base file path and lang from a Vue SFC virtual module ID (e.g. Component.vue?vue&type=script&lang=ts) */\nexport function parseVueModuleId(id: string): {basePath: string; lang: string | null} | null {\n const qIdx = id.indexOf('?');\n if (qIdx === -1) return null;\n const basePath = id.slice(0, qIdx);\n if (!basePath.endsWith('.vue')) return null;\n const params = new URLSearchParams(id.slice(qIdx));\n if (!params.has('vue') || params.get('type') !== 'script') return null;\n return {basePath, lang: params.get('lang')};\n}\n\n/** Checks if a file path matches the include/exclude patterns */\nexport function isIncluded(filePath: string, include: string[], exclude: string[]): boolean {\n // For Vue virtual module IDs, use the base .vue path for matching\n const vueInfo = parseVueModuleId(filePath);\n const effectivePath = vueInfo ? vueInfo.basePath : filePath;\n\n const isTs = /\\.(ts|tsx|js|jsx)$/.test(effectivePath);\n const isVue = effectivePath.endsWith('.vue');\n const isDir = effectivePath.endsWith('/');\n if (!isTs && !isVue && !isDir) return false;\n\n // Check exclude patterns\n for (const pattern of exclude) {\n if (matchGlob(effectivePath, pattern)) return false;\n }\n\n return true;\n}\n\n/** Simple glob matching for common patterns */\nfunction matchGlob(filePath: string, pattern: string): boolean {\n // Handle **/ prefix\n if (pattern.startsWith('**/')) {\n const suffix = pattern.slice(3);\n return filePath.includes(suffix.replace(/\\*/g, ''));\n }\n // Handle simple wildcard\n const regex = new RegExp('^' + pattern.replace(/\\*\\*/g, '.*').replace(/\\*/g, '[^/]*') + '$');\n return regex.test(filePath);\n}\n\n/** AOT virtual module types — each maps to a different cache export */\nconst AOT_MODULE_TYPES = ['jit-fns', 'pure-fns', 'router-cache', 'caches'] as const;\ntype AOTModuleType = (typeof AOT_MODULE_TYPES)[number];\n\n/** Builds maps from virtual module names → AOT type for resolveId and load hooks.\n * Default 'virtual:mion-aot/*' is always registered. If customVirtualModuleId is set,\n * 'virtual:${custom}/*' is also registered — both map to the same cache data. */\nfunction buildAOTVirtualModuleMaps(customVirtualModuleId?: string) {\n const aotVirtualModules = new Map<string, AOTModuleType>();\n const aotResolvedIds = new Map<string, AOTModuleType>();\n for (const type of AOT_MODULE_TYPES) {\n const defaultId = `virtual:mion-aot/${type}`;\n aotVirtualModules.set(defaultId, type);\n aotResolvedIds.set(resolveVirtualId(defaultId), type);\n if (customVirtualModuleId) {\n const customId = `virtual:${customVirtualModuleId}/${type}`;\n aotVirtualModules.set(customId, type);\n aotResolvedIds.set(resolveVirtualId(customId), type);\n }\n }\n return {aotVirtualModules, aotResolvedIds};\n}\n\n// #################### SERVER READY ####################\n\n// Uses globalThis with Symbol.for because vitest loads vitest.config.ts and globalSetup.ts\n// in separate module contexts — without globalThis they'd get different promise instances.\nconst READY_KEY = Symbol.for('mion.serverReady');\nfunction getOrCreateServerReady(): {promise: Promise<void>; resolve: () => void} {\n if (!(globalThis as any)[READY_KEY]) {\n let _resolve: () => void;\n (globalThis as any)[READY_KEY] = {\n promise: new Promise<void>((r) => {\n _resolve = r;\n }),\n resolve: () => _resolve(),\n };\n }\n return (globalThis as any)[READY_KEY];\n}\n\n/** Promise that resolves when the server is ready. Await this in vitest globalSetup. */\nexport const serverReady: Promise<void> = getOrCreateServerReady().promise;\nconst onServerReady: () => void = getOrCreateServerReady().resolve;\n"],"names":[],"mappings":";;;;;;;;AA2CA,SAAS,mBAA4B;AACjC,SAAO,QAAQ,IAAI,iBAAiB,aAAa,QAAQ,IAAI,iBAAiB;AAClF;AAiCO,SAAS,eAAe,SAA4B;AACvD,MAAI,eAAyC;AAC7C,QAAM,gBAAgB,QAAQ;AAC9B,QAAM,kBAAkB,QAAQ;AAChC,QAAM,aAA0C,QAAQ,cAAc,OAAO,CAAA,IAAK,QAAQ;AAC1F,QAAM,eAAe,QAAQ;AAC7B,QAAM,gBAAsC,kBAAkB,oBAAoB,eAAe,IAAI;AAGrG,QAAM,yBAA6C;AAAA,IAC/C,QAAQ,GAAG,aAAa;AAAA,IACxB,QAAQ,GAAG,WAAW;AAAA,EAAA;AAI1B,MAAI,oBAAoB;AACxB,MAAI,6BAA6B;AACjC,MAAI,mBAAmB;AAGvB,MAAI,UAA+B;AACnC,MAAI,uBAAqD;AAGzD,MAAI,cAAc;AAGlB,MAAI,gBAAwE;AAE5E,QAAM,aAAa,cAAc,SAAS;AAE1C,MAAI,iBAAuC;AAG3C,MAAI,kBAAuC;AAC3C,MAAI,oBAAoB;AAExB,QAAM,EAAC,mBAAmB,eAAA,IAAkB,0BAA0B,YAAY,qBAAqB;AAGvG,iBAAe,eAAe;AAC1B,QAAI,iBAAiB;AACjB,YAAM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AAM,YAAY,uBAAO,IAAI,kBAAkB;AAC/C,SAAS,yBAAwE;AAC7E,MAAI,CAAE,WAAmB,SAAS,GAAG;AACjC,QAAI;AACH,eAAmB,SAAS,IAAI;AAAA,MAC7B,SAAS,IAAI,QAAc,CAAC,MAAM;AAC9B,mBAAW;AAAA,MACf,CAAC;AAAA,MACD,SAAS,MAAM,SAAA;AAAA,IAAS;AAAA,EAEhC;AACA,SAAQ,WAAmB,SAAS;AACxC;AAGO,MAAM,cAA6B,yBAAyB;AACnE,MAAM,gBAA4B,yBAAyB;"}
|
|
1
|
+
{"version":3,"file":"mionVitePlugin.js","sources":["../../../../../src/vite-plugin/mionVitePlugin.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 {resolve} from 'path';\nimport {createRequire} from 'module';\nimport {existsSync} from 'fs';\nimport * as ts from 'typescript';\nimport {ChildProcess} from 'child_process';\nimport {createDeepkitConfig, DeepkitConfig, createPureFnTransformerFactory} from './transformers.ts';\nimport {ServerPureFunctionsOptions, ExtractedPureFn, DeepkitTypeOptions, AOTCacheOptions, MionServerConfig} from './types.ts';\nimport {scanClientSource} from './extractPureFn.ts';\nimport {generateServerPureFnsVirtualModule} from './virtualModule.ts';\nimport {\n VIRTUAL_SERVER_PURE_FNS,\n REFLECTION_MODULES,\n VIRTUAL_STUB_PREFIX,\n VIRTUAL_AOT_CACHES,\n AOT_CACHES_SHIM,\n SERVER_PURE_FNS_SHIM,\n resolveVirtualId,\n} from './constants.ts';\nimport {\n generateAOTCaches,\n loadSSRRouterAndGenerateAOTCaches,\n killPersistentChild,\n logAOTCaches,\n generateJitFnsModule,\n generatePureFnsModule,\n generateRouterCacheModule,\n generateCombinedCachesModule,\n generateNoopModule,\n generateNoopCombinedModule,\n AOTCacheData,\n} from './aotCacheGenerator.ts';\nimport {getOrGenerateAOTCaches, updateDiskCache, resolveCacheDir} from './aotDiskCache.ts';\n\nexport interface MionPluginOptions {\n /** Options for pure function extraction - omit to disable */\n serverPureFunctions?: ServerPureFunctionsOptions;\n /** Options for deepkit type transformation - omit to disable */\n runTypes?: DeepkitTypeOptions;\n /** Options for AOT cache generation - omit to disable */\n aotCaches?: AOTCacheOptions | true;\n /** Server configuration - controls how the server process is managed */\n server?: MionServerConfig;\n}\n\n/**\n * Creates the unified mion Vite plugin.\n * This plugin combines pure function extraction, type compiler transformations,\n * and AOT cache generation in a single plugin with correct execution order.\n *\n * Execution order:\n * 1. Extract pure functions from original TypeScript source\n * 2. Apply type metadata transformations to the code\n *\n * This ensures pure function extraction happens on clean, untransformed TypeScript.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import {mionPlugin} from '@mionjs/devtools/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * mionPlugin({\n * runTypes: {\n * tsConfig: './tsconfig.json',\n * },\n * server: {\n * startScript: '../server/src/init.ts',\n * runMode: 'buildOnly',\n * },\n * }),\n * ],\n * });\n * ```\n */\nexport function mionVitePlugin(options: MionPluginOptions) {\n let extractedFns: ExtractedPureFn[] | null = null;\n const pureFnOptions = options.serverPureFunctions;\n const runTypesOptions = options.runTypes;\n const aotOptions: AOTCacheOptions | undefined = options.aotCaches === true ? {} : options.aotCaches;\n const serverConfig = options.server;\n const deepkitConfig: DeepkitConfig | null = runTypesOptions ? createDeepkitConfig(runTypesOptions) : null;\n\n // Default compiler options for when deepkit is disabled\n const defaultCompilerOptions: ts.CompilerOptions = {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n sourceMap: true,\n };\n\n // Pure function injection counters — accumulated during transform, logged in buildEnd\n let pureServerFnCount = 0;\n let registerPureFnFactoryCount = 0;\n let pureFnFilesCount = 0;\n\n // AOT cache data - populated during buildStart (IPC) or configureServer (in-process)\n let aotData: AOTCacheData | null = null;\n let aotGenerationPromise: Promise<AOTCacheData> | null = null;\n\n // Resolved cache directory from Vite's config — set in configResolved\n let aotCacheDir = '';\n\n // SSR AOT: module loader (set in configureServer when SSR mode is active)\n let ssrLoadModule: ((url: string) => Promise<Record<string, any>>) | null = null;\n /** Whether SSR mode is active — resolved from server config */\n const ssrEnabled = serverConfig?.runMode === 'middleware';\n /** SSR init promise: AOT generation + router/platform module loading */\n let ssrInitPromise: Promise<void> | null = null;\n\n // Persistent child process for IPC mode\n let persistentChild: ChildProcess | null = null;\n let cleanupRegistered = false;\n\n const {aotVirtualModules, aotResolvedIds} = buildAOTVirtualModuleMaps(aotOptions?.customVirtualModuleId);\n\n /** Kill persistent child process and clear reference */\n async function cleanupChild() {\n if (persistentChild) {\n await killPersistentChild(persistentChild);\n persistentChild = null;\n }\n }\n\n /** Register process exit handlers (once) */\n function registerCleanupHandlers() {\n if (cleanupRegistered) return;\n cleanupRegistered = true;\n const onExit = () => {\n if (persistentChild && !persistentChild.killed) {\n persistentChild.kill('SIGTERM');\n persistentChild = null;\n }\n };\n process.on('exit', onExit);\n process.on('SIGINT', onExit);\n process.on('SIGTERM', onExit);\n }\n\n return {\n name: 'mion',\n enforce: 'pre' as const, // literal type required: inferred 'string' is not assignable to Vite's 'pre' | 'post'\n\n config(config, env) {\n // Strip reflection module aliases in bundle build mode so our resolveId can stub them.\n // Vite's alias plugin runs before our resolveId, so we remove aliases here to prevent\n // them from transforming bare package names into file paths before we can intercept.\n if (aotOptions?.excludeReflection && !isRunningAsChild()) {\n const aliases = config.resolve?.alias;\n if (aliases && !Array.isArray(aliases)) {\n for (const mod of REFLECTION_MODULES) {\n delete (aliases as Record<string, string>)[mod];\n }\n }\n }\n\n // Ensure Vite bundles shim modules instead of externalizing them\n const shimModules: string[] = [];\n if (pureFnOptions) shimModules.push(SERVER_PURE_FNS_SHIM);\n if (aotOptions) shimModules.push(AOT_CACHES_SHIM);\n addSsrNoExternal(config, shimModules);\n\n // Wrap build.rollupOptions.external so shim and virtual modules are never externalized\n if (env.command === 'build' && shimModules.length > 0) {\n wrapBuildExternal(config, shimModules);\n }\n },\n\n configResolved(config) {\n if (aotOptions) {\n aotCacheDir = resolveCacheDir(aotOptions, config.cacheDir);\n }\n },\n\n async buildStart() {\n // Generate AOT caches if server is configured\n // Skip when already running as a child process to prevent infinite recursion\n // Skip when SSR mode — configureServer will handle it\n if (serverConfig && !isRunningAsChild() && !ssrEnabled) {\n try {\n console.log('[mion] Generating AOT caches...');\n const resultPromise = getOrGenerateAOTCaches(serverConfig, aotOptions, aotCacheDir);\n aotGenerationPromise = resultPromise.then((r) => r.data);\n const result = await resultPromise;\n aotData = result.data;\n console.log('[mion] AOT caches generated successfully');\n logAOTCaches(aotData);\n\n // Store persistent child for IPC mode\n if (result.childProcess) {\n persistentChild = result.childProcess;\n registerCleanupHandlers();\n console.log(`[mion] Server process persisted (pid: ${persistentChild.pid})`);\n }\n\n // Non-blocking: wait for setPlatformConfig() IPC and resolve serverReady promise\n if (result.platformReady && serverConfig.waitTimeout && serverConfig.runMode === 'childProcess') {\n console.log('[mion] Waiting for server to call setPlatformConfig()...');\n const timeout = serverConfig.waitTimeout;\n const timeoutId = setTimeout(() => {\n if (result.childProcess?.connected) result.childProcess.disconnect();\n console.error(\n `[mion] Server did not call setPlatformConfig() within ${timeout / 1000}s. ` +\n `Ensure your platform adapter (startNodeServer, etc.) is called after initMionRouter().`\n );\n }, timeout);\n result.platformReady.then(() => {\n clearTimeout(timeoutId);\n if (result.childProcess?.connected) result.childProcess.disconnect();\n console.log('[mion] Server ready');\n onServerReady();\n });\n } else {\n // buildOnly mode or no waitTimeout: resolve immediately\n if (result.childProcess?.connected) result.childProcess.disconnect();\n onServerReady();\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`[mion] Failed to generate AOT caches: ${message}`);\n }\n }\n },\n\n configureServer(server) {\n if (!ssrEnabled || !serverConfig) return;\n // SSR mode: use ssrLoadModule to load the server in the same Vite process.\n // ssrLoadModule uses Vite's internal transform pipeline (not HTTP),\n ssrLoadModule = (url: string) => server.ssrLoadModule(url);\n const startScript = resolve(serverConfig.startScript);\n // Single init chain: generate AOT caches → load router + platform modules\n let nodeRequestHandler: ((req: any, res: any) => void) | null = null;\n let basePath: string | null = null;\n let initFailed = false;\n\n console.log('[mion] Generating SSR AOT caches...');\n ssrInitPromise = loadSSRRouterAndGenerateAOTCaches(ssrLoadModule, startScript)\n .then(async (data) => {\n aotData = data;\n aotGenerationPromise = Promise.resolve(data);\n console.log('[mion] SSR AOT caches generated successfully');\n logAOTCaches(data);\n // Invalidate virtual modules so they reload with real data\n for (const resolvedId of aotResolvedIds.keys()) {\n const mod = server.moduleGraph.getModuleById(resolvedId);\n if (mod) server.moduleGraph.invalidateModule(mod);\n }\n // Load router and platform modules now that caches are ready\n const routerModule = await server.ssrLoadModule('@mionjs/router');\n const opts = routerModule.getRouterOptions();\n basePath = '/' + (opts.basePath || '').replace(/^\\//, '');\n const platformNode = await server.ssrLoadModule('@mionjs/platform-node');\n nodeRequestHandler = platformNode.httpRequestHandler;\n console.log('[mion] Dev server proxy initialized');\n onServerReady();\n })\n .catch((err) => {\n initFailed = true;\n const message = err instanceof Error ? err.message : String(err);\n console.error(`[mion] Failed to initialize SSR: ${message}`);\n });\n\n // Dev server proxy: route matching requests to mion's httpRequestHandler\n server.middlewares.use(async (req: any, res: any, next: () => void) => {\n try {\n if (!basePath && !initFailed) await ssrInitPromise;\n if (!basePath || !req.url?.startsWith(basePath)) return next();\n if (nodeRequestHandler) {\n nodeRequestHandler(req, res);\n } else {\n res.statusCode = 503;\n res.end('mion API failed to initialize');\n }\n } catch (err) {\n console.error('[mion] Dev server proxy error:', err);\n if (!res.writableEnded) {\n res.statusCode = 500;\n res.end('Internal Server Error');\n }\n }\n });\n },\n\n resolveId(id, importer) {\n // Pure functions virtual module — always resolve, returns empty cache if not configured\n if (id === VIRTUAL_SERVER_PURE_FNS) return resolveVirtualId(id);\n // AOT virtual modules (default + custom prefix both resolve)\n if (aotVirtualModules.has(id)) return resolveVirtualId(id);\n // Resolve shim modules: intercept empty cache imports and replace with virtual modules\n if (aotOptions) {\n const resolved = resolveShimModule(\n id,\n importer,\n AOT_CACHES_SHIM,\n VIRTUAL_AOT_CACHES,\n 'aot-caches',\n 'aotCaches.ts',\n 'emptyCaches.ts'\n );\n if (resolved) return resolved;\n }\n if (pureFnOptions) {\n const resolved = resolveShimModule(\n id,\n importer,\n SERVER_PURE_FNS_SHIM,\n VIRTUAL_SERVER_PURE_FNS,\n 'server-pure-fns',\n 'serverPureFnsCaches.ts',\n 'emptyServerPureFns.ts'\n );\n if (resolved) return resolved;\n }\n // Stub out reflection modules in the bundle build (not needed at runtime in AOT mode)\n if (aotOptions?.excludeReflection && !isRunningAsChild() && REFLECTION_MODULES.includes(id)) {\n return resolveVirtualId(VIRTUAL_STUB_PREFIX + id);\n }\n return null;\n },\n\n async load(id) {\n // Pure functions virtual module\n if (id === resolveVirtualId(VIRTUAL_SERVER_PURE_FNS)) {\n // No serverPureFunctions configured — return empty cache\n if (!pureFnOptions) return generateServerPureFnsVirtualModule([]);\n // Lazily scan client source on first load\n if (!extractedFns) extractedFns = scanClientSource(pureFnOptions);\n return generateServerPureFnsVirtualModule(extractedFns);\n }\n\n // AOT virtual modules — check resolved ID against the map\n const aotType = aotResolvedIds.get(id);\n if (aotType) {\n const initPromise = ssrInitPromise || aotGenerationPromise;\n if (!aotData && initPromise) await initPromise;\n\n switch (aotType) {\n case 'jit-fns': {\n if (!aotData) return generateNoopModule('No-op: AOT JIT caches not generated');\n return generateJitFnsModule(aotData.jitFnsCode);\n }\n case 'pure-fns': {\n if (!aotData) return generateNoopModule('No-op: AOT pure fns not generated');\n return generatePureFnsModule(aotData.pureFnsCode);\n }\n case 'router-cache': {\n if (!aotData) return generateNoopModule('No-op: AOT router cache not generated');\n return generateRouterCacheModule(aotData.routerCacheCode);\n }\n case 'caches': {\n if (!aotData) return generateNoopCombinedModule();\n return generateCombinedCachesModule();\n }\n }\n }\n\n // Reflection module stubs (empty modules — all reflection is pre-compiled in AOT caches)\n // syntheticNamedExports tells Rollup to derive named exports from the default export,\n // so any `import {foo} from '...'` resolves to undefined without build errors.\n for (const mod of REFLECTION_MODULES) {\n if (id === resolveVirtualId(VIRTUAL_STUB_PREFIX + mod)) {\n return {code: 'export default {}', syntheticNamedExports: true};\n }\n }\n\n return null;\n },\n\n transform(code: string, fileName: string) {\n // For Vue SFC virtual modules, resolve the base path and lang for downstream tools\n const vueInfo = parseVueModuleId(fileName);\n // Strip any query params (e.g. ?macro=true from Nuxt) to get the real file path\n const basePath = fileName.includes('?') ? fileName.slice(0, fileName.indexOf('?')) : fileName;\n const filterPath = vueInfo ? vueInfo.basePath : basePath;\n\n // Skip .vue files unless they are Vue script virtual modules (?vue&type=script).\n // Bare .vue files and other .vue queries (e.g. ?macro=true from Nuxt) contain raw\n // SFC content — wait for the Vue plugin to extract the <script> block first.\n if (basePath.endsWith('.vue') && !vueInfo) return null;\n\n const lang = vueInfo?.lang || 'ts';\n const tsFileName = vueInfo ? `${vueInfo.basePath}.${lang}` : fileName;\n const isTsx = tsFileName.endsWith('.tsx') || tsFileName.endsWith('.jsx');\n\n const hasPureFns =\n code.includes('pureServerFn') || code.includes('registerPureFnFactory') || code.includes('mapFrom');\n const needsDeepkit = deepkitConfig ? deepkitConfig.filter(filterPath) : false;\n\n if (!hasPureFns && !needsDeepkit) return null;\n\n const before: ts.CustomTransformerFactory[] = [];\n const after: ts.CustomTransformerFactory[] = [];\n\n // Pure function transformer (runs first — sees clean AST)\n const collected: ExtractedPureFn[] | undefined = hasPureFns ? [] : undefined;\n if (hasPureFns) {\n before.push(createPureFnTransformerFactory(code, tsFileName, collected, pureFnOptions?.noViteClient));\n }\n\n // Deepkit has two functions: type metadata emission (follows include/exclude filters)\n // and import restoration (always runs globally for all ts.transpileModule calls).\n // afterTransformers (including requireToImport) must always be included to convert\n // deepkit's CJS require() back to ESM imports in the restored import statements.\n if (deepkitConfig) after.push(...deepkitConfig.afterTransformers);\n if (needsDeepkit) before.push(...deepkitConfig!.beforeTransformers);\n\n const baseCompilerOptions = deepkitConfig?.compilerOptions ?? defaultCompilerOptions;\n const compilerOptions = isTsx ? {...baseCompilerOptions, jsx: ts.JsxEmit.ReactJSX} : baseCompilerOptions;\n\n const result = ts.transpileModule(code, {\n compilerOptions,\n fileName: tsFileName,\n transformers: {before, after},\n });\n\n // Count injected pure functions (collector is populated synchronously by transpileModule)\n if (collected && collected.length > 0) {\n pureFnFilesCount++;\n for (const fn of collected) {\n if (fn.isFactory) registerPureFnFactoryCount++;\n else pureServerFnCount++;\n }\n }\n\n // Strip the //# sourceMappingURL comment that ts.transpileModule appends —\n // Vite consumes the source map via the `map` property, not inline comments.\n const outputCode = result.outputText.replace(/\\n\\/\\/# sourceMappingURL=.*$/, '');\n return {code: outputCode, map: result.sourceMapText};\n },\n\n buildEnd() {\n if (pureServerFnCount > 0 || registerPureFnFactoryCount > 0) {\n const total = pureServerFnCount + registerPureFnFactoryCount;\n const parts = [\n pureServerFnCount > 0 ? `${pureServerFnCount} pureServerFn` : '',\n registerPureFnFactoryCount > 0 ? `${registerPureFnFactoryCount} registerPureFnFactory` : '',\n ].filter(Boolean);\n console.log(`[mion] Injected ${total} pure functions across ${pureFnFilesCount} files (${parts.join(', ')})`);\n }\n },\n\n async closeBundle() {\n await cleanupChild();\n },\n\n handleHotUpdate({file, server}) {\n // In dev mode, re-scan when client source changes (for pure functions)\n if (pureFnOptions) {\n const clientSrcPath = resolve(pureFnOptions.clientSrcPath);\n if (file.startsWith(clientSrcPath)) {\n const include = pureFnOptions.include || ['**/*.ts', '**/*.tsx', '**/*.vue'];\n const exclude = pureFnOptions.exclude || ['../node_modules/**', '**/.dist/**', '**/dist/**'];\n if (isIncluded(file, include, exclude)) {\n // Clear cache and invalidate virtual module\n extractedFns = null;\n const mod = server.moduleGraph.getModuleById(resolveVirtualId(VIRTUAL_SERVER_PURE_FNS));\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n return [mod];\n }\n }\n }\n }\n\n // In dev mode, regenerate AOT caches when server source changes\n // Skip when running as a child process\n if (serverConfig && !isRunningAsChild()) {\n const serverDir = resolve(serverConfig.startScript, '..');\n\n if (file.startsWith(serverDir)) {\n // Kill existing persistent child before regenerating\n const killPromise = cleanupChild();\n\n const regeneratePromise =\n ssrEnabled && ssrLoadModule\n ? // SSR mode: reset router and re-init via ssrLoadModule\n (async () => {\n const routerModule = await ssrLoadModule!('@mionjs/router');\n routerModule.resetRouter();\n return loadSSRRouterAndGenerateAOTCaches(ssrLoadModule!, resolve(serverConfig.startScript));\n })()\n : // IPC mode: wait for old child to die, then spawn new\n killPromise.then(() => generateAOTCaches(serverConfig));\n\n aotGenerationPromise = regeneratePromise.then((r) => ('data' in r ? r.data : r));\n regeneratePromise\n .then((result) => {\n const data = 'data' in result ? result.data : result;\n aotData = data;\n logAOTCaches(data);\n\n // Store new persistent child if IPC mode\n if ('childProcess' in result && result.childProcess) {\n persistentChild = result.childProcess;\n console.log(`[mion] Server process re-persisted (pid: ${persistentChild!.pid})`);\n }\n\n // Non-blocking: wait for setPlatformConfig() IPC from restarted server\n const platformReady = 'platformReady' in result ? result.platformReady : undefined;\n if (platformReady && serverConfig.waitTimeout && serverConfig.runMode === 'childProcess') {\n const timeout = serverConfig.waitTimeout;\n console.log('[mion] Waiting for restarted server to call setPlatformConfig()...');\n const timeoutId = setTimeout(() => {\n if (persistentChild?.connected) persistentChild.disconnect();\n console.error(\n `[mion] Restarted server did not call setPlatformConfig() within ${timeout / 1000}s.`\n );\n }, timeout);\n platformReady.then(() => {\n clearTimeout(timeoutId);\n if (persistentChild?.connected) persistentChild.disconnect();\n console.log('[mion] Restarted server ready');\n onServerReady();\n });\n } else if ('childProcess' in result && result.childProcess?.connected) {\n result.childProcess.disconnect();\n }\n\n if (!ssrEnabled) updateDiskCache(serverConfig, aotOptions, data, aotCacheDir);\n // Invalidate all AOT virtual modules\n let invalidatedCount = 0;\n for (const resolvedId of aotResolvedIds.keys()) {\n const mod = server.moduleGraph.getModuleById(resolvedId);\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n invalidatedCount++;\n }\n }\n if (invalidatedCount > 0) {\n console.log('[mion] AOT caches regenerated, invalidating virtual modules');\n }\n })\n .catch((err) => {\n console.error('[mion] Failed to regenerate AOT caches:', err.message);\n });\n }\n }\n\n return undefined;\n },\n };\n}\n\n/** Whether the current process is a child spawned by the mion plugin */\nfunction isRunningAsChild(): boolean {\n return process.env.MION_COMPILE === 'buildOnly' || process.env.MION_COMPILE === 'childProcess';\n}\n\n/** Extracts the base file path and lang from a Vue SFC virtual module ID (e.g. Component.vue?vue&type=script&lang=ts) */\nexport function parseVueModuleId(id: string): {basePath: string; lang: string | null} | null {\n const qIdx = id.indexOf('?');\n if (qIdx === -1) return null;\n const basePath = id.slice(0, qIdx);\n if (!basePath.endsWith('.vue')) return null;\n const params = new URLSearchParams(id.slice(qIdx));\n if (!params.has('vue') || params.get('type') !== 'script') return null;\n return {basePath, lang: params.get('lang')};\n}\n\n/** Checks if a file path matches the include/exclude patterns */\nexport function isIncluded(filePath: string, include: string[], exclude: string[]): boolean {\n // For Vue virtual module IDs, use the base .vue path for matching\n const vueInfo = parseVueModuleId(filePath);\n const effectivePath = vueInfo ? vueInfo.basePath : filePath;\n\n const isTs = /\\.(ts|tsx|js|jsx)$/.test(effectivePath);\n const isVue = effectivePath.endsWith('.vue');\n const isDir = effectivePath.endsWith('/');\n if (!isTs && !isVue && !isDir) return false;\n\n // Check exclude patterns\n for (const pattern of exclude) {\n if (matchGlob(effectivePath, pattern)) return false;\n }\n\n return true;\n}\n\n/** Simple glob matching for common patterns */\nfunction matchGlob(filePath: string, pattern: string): boolean {\n // Handle **/ prefix\n if (pattern.startsWith('**/')) {\n const suffix = pattern.slice(3);\n return filePath.includes(suffix.replace(/\\*/g, ''));\n }\n // Handle simple wildcard\n const regex = new RegExp('^' + pattern.replace(/\\*\\*/g, '.*').replace(/\\*/g, '[^/]*') + '$');\n return regex.test(filePath);\n}\n\n/** AOT virtual module types — each maps to a different cache export */\nconst AOT_MODULE_TYPES = ['jit-fns', 'pure-fns', 'router-cache', 'caches'] as const;\ntype AOTModuleType = (typeof AOT_MODULE_TYPES)[number];\n\n/** Builds maps from virtual module names → AOT type for resolveId and load hooks.\n * Default 'virtual:mion-aot/*' is always registered. If customVirtualModuleId is set,\n * 'virtual:${custom}/*' is also registered — both map to the same cache data. */\nfunction buildAOTVirtualModuleMaps(customVirtualModuleId?: string) {\n const aotVirtualModules = new Map<string, AOTModuleType>();\n const aotResolvedIds = new Map<string, AOTModuleType>();\n for (const type of AOT_MODULE_TYPES) {\n const defaultId = `virtual:mion-aot/${type}`;\n aotVirtualModules.set(defaultId, type);\n aotResolvedIds.set(resolveVirtualId(defaultId), type);\n if (customVirtualModuleId) {\n const customId = `virtual:${customVirtualModuleId}/${type}`;\n aotVirtualModules.set(customId, type);\n aotResolvedIds.set(resolveVirtualId(customId), type);\n }\n }\n return {aotVirtualModules, aotResolvedIds};\n}\n\n/**\n * Resolves a shim module (e.g. @mionjs/core/aot-caches) to its source file,\n * and intercepts the empty cache import to replace it with the virtual module.\n * Returns the resolved id or null if no match.\n */\nfunction resolveShimModule(\n id: string,\n importer: string | undefined,\n shimSpecifier: string,\n virtualModuleId: string,\n entryName: string,\n sourceFileName: string,\n emptyFileName: string\n): string | null {\n // Bare specifier: resolve to the TS source file so Vite can process it through the plugin pipeline.\n // Using createRequire would return CJS built output whose require() calls bypass resolveId.\n if (id === shimSpecifier) {\n try {\n // Resolve the package directory via Node resolution, then find the source file\n const resolved = createRequire(import.meta.url).resolve(shimSpecifier);\n const sourceFile = resolve(resolved.replace(/[/\\\\].dist[/\\\\].*$/, ''), 'src/aot/' + sourceFileName);\n if (existsSync(sourceFile)) return sourceFile;\n // No source file (tarball/npm install) — resolve to virtual module directly.\n // Returning the .dist path would bypass resolveId (CJS require() calls skip Vite pipeline).\n return resolveVirtualId(virtualModuleId);\n } catch {\n return resolveVirtualId(virtualModuleId);\n }\n }\n // Alias-resolved absolute path (monorepo dev where source files always exist)\n if (id.endsWith('/' + entryName)) {\n const sourceFile = resolve(id, '..', 'src/aot/' + sourceFileName);\n if (existsSync(sourceFile)) return sourceFile;\n }\n // Intercept empty cache imports from the shim loader file (any extension)\n const emptyBase = emptyFileName.replace('.ts', '');\n const sourceBase = sourceFileName.replace('.ts', '');\n if (\n new RegExp(`${emptyBase}\\\\.(ts|js|mjs|cjs)$`).test(id) &&\n importer &&\n new RegExp(`${sourceBase}\\\\.(ts|js|mjs|cjs)$`).test(importer)\n ) {\n return resolveVirtualId(virtualModuleId);\n }\n return null;\n}\n\n/** Adds module specifiers to Vite's ssr.noExternal so they are bundled instead of externalized. */\nfunction addSsrNoExternal(config: Record<string, any>, moduleIds: string[]): void {\n if (moduleIds.length === 0) return;\n const noExternal = config.ssr?.noExternal;\n if (!config.ssr) config.ssr = {};\n if (Array.isArray(noExternal)) {\n for (const moduleId of moduleIds) {\n if (!noExternal.includes(moduleId)) noExternal.push(moduleId);\n }\n } else if (typeof noExternal === 'string') {\n config.ssr.noExternal = [noExternal, ...moduleIds];\n } else if (noExternal !== true) {\n config.ssr.noExternal = noExternal ? [noExternal, ...moduleIds] : [...moduleIds];\n }\n}\n\n/** Wraps build.rollupOptions.external so shim and virtual modules are always bundled. */\nfunction wrapBuildExternal(config: Record<string, any>, shimModules: string[]): void {\n if (!config.build) config.build = {};\n if (!config.build.rollupOptions) config.build.rollupOptions = {};\n const original = config.build.rollupOptions.external;\n if (!original) return; // no external config — nothing to wrap\n config.build.rollupOptions.external = (id: string, ...rest: any[]) => {\n // Never externalize shim modules or virtual modules (plugin replaces them with generated code)\n if (shimModules.includes(id) || id.startsWith('virtual:mion')) return false;\n // Delegate to original external config\n if (typeof original === 'function') return original(id, ...rest);\n if (Array.isArray(original)) return original.some((ext) => (ext instanceof RegExp ? ext.test(id) : ext === id));\n if (original instanceof RegExp) return original.test(id);\n return original === id;\n };\n}\n\n// #################### SERVER READY ####################\n\n// Uses globalThis with Symbol.for because vitest loads vitest.config.ts and globalSetup.ts\n// in separate module contexts — without globalThis they'd get different promise instances.\nconst READY_KEY = Symbol.for('mion.serverReady');\nfunction getOrCreateServerReady(): {promise: Promise<void>; resolve: () => void} {\n if (!(globalThis as any)[READY_KEY]) {\n let _resolve: () => void;\n (globalThis as any)[READY_KEY] = {\n promise: new Promise<void>((r) => {\n _resolve = r;\n }),\n resolve: () => _resolve(),\n };\n }\n return (globalThis as any)[READY_KEY];\n}\n\n/** Promise that resolves when the server is ready. Await this in vitest globalSetup. */\nexport const serverReady: Promise<void> = getOrCreateServerReady().promise;\nconst onServerReady: () => void = getOrCreateServerReady().resolve;\n"],"names":[],"mappings":";;;;;;;;;;AAkFO,SAAS,eAAe,SAA4B;AACvD,MAAI,eAAyC;AAC7C,QAAM,gBAAgB,QAAQ;AAC9B,QAAM,kBAAkB,QAAQ;AAChC,QAAM,aAA0C,QAAQ,cAAc,OAAO,CAAA,IAAK,QAAQ;AAC1F,QAAM,eAAe,QAAQ;AAC7B,QAAM,gBAAsC,kBAAkB,oBAAoB,eAAe,IAAI;AAGrG,QAAM,yBAA6C;AAAA,IAC/C,QAAQ,GAAG,aAAa;AAAA,IACxB,QAAQ,GAAG,WAAW;AAAA,IACtB,WAAW;AAAA,EAAA;AAIf,MAAI,oBAAoB;AACxB,MAAI,6BAA6B;AACjC,MAAI,mBAAmB;AAGvB,MAAI,UAA+B;AACnC,MAAI,uBAAqD;AAGzD,MAAI,cAAc;AAGlB,MAAI,gBAAwE;AAE5E,QAAM,aAAa,cAAc,YAAY;AAE7C,MAAI,iBAAuC;AAG3C,MAAI,kBAAuC;AAC3C,MAAI,oBAAoB;AAExB,QAAM,EAAC,mBAAmB,eAAA,IAAkB,0BAA0B,YAAY,qBAAqB;AAGvG,iBAAe,eAAe;AAC1B,QAAI,iBAAiB;AACjB,YAAM,oBAAoB,eAAe;AACzC,wBAAkB;AAAA,IACtB;AAAA,EACJ;AAGA,WAAS,0BAA0B;AAC/B,QAAI,kBAAmB;AACvB,wBAAoB;AACpB,UAAM,SAAS,MAAM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eAAe,SAAS,IAAI,KAAK,EAAE,IAAI,QAAQ,EAAG;AAC9G,QAAI,oBAAoB,OAAQ,QAAO,SAAS,KAAK,EAAE;AACvD,WAAO,aAAa;AAAA,EACxB;AACJ;AAMA,MAAM,YAAY,uBAAO,IAAI,kBAAkB;AAC/C,SAAS,yBAAwE;AAC7E,MAAI,CAAE,WAAmB,SAAS,GAAG;AACjC,QAAI;AACH,eAAmB,SAAS,IAAI;AAAA,MAC7B,SAAS,IAAI,QAAc,CAAC,MAAM;AAC9B,mBAAW;AAAA,MACf,CAAC;AAAA,MACD,SAAS,MAAM,SAAA;AAAA,IAAS;AAAA,EAEhC;AACA,SAAQ,WAAmB,SAAS;AACxC;AAGO,MAAM,cAA6B,yBAAyB;AACnE,MAAM,gBAA4B,yBAAyB;"}
|
|
@@ -58,6 +58,7 @@ function createDeepkitConfig(options = {}) {
|
|
|
58
58
|
compilerOptions: {
|
|
59
59
|
target: ts.ScriptTarget.ESNext,
|
|
60
60
|
module: ts.ModuleKind.ESNext,
|
|
61
|
+
sourceMap: true,
|
|
61
62
|
configFilePath: options.tsConfig || process.cwd() + "/tsconfig.json",
|
|
62
63
|
...options.compilerOptions || {}
|
|
63
64
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.js","sources":["../../../../../src/vite-plugin/transformers.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\n// based on https://github.com/marcj/deepkit/blob/e7da3b48c50115d6e59e233eb9f018513d4d68ce/packages/vite/src/plugin.ts\n\nimport {createFilter} from '@rollup/pluginutils';\nimport * as ts from 'typescript';\nimport {transformer, declarationTransformer} from '@deepkit/type-compiler';\nimport {DeepkitTypeOptions, ExtractedPureFn} from './types.ts';\nimport {extractPureFnsFromSource} from './extractPureFn.ts';\n\n// ── Deepkit ─────────────────────────────────────────────────────────\n\n/** Deepkit configuration components for integration into the unified transform pipeline */\nexport interface DeepkitConfig {\n filter: (fileName: string) => boolean;\n compilerOptions: ts.CompilerOptions;\n beforeTransformers: ts.CustomTransformerFactory[];\n afterTransformers: ts.CustomTransformerFactory[];\n}\n\n/**\n * Post-deepkit transformer that converts require() calls back to import declarations.\n * Deepkit's getModuleType() reads tsconfig's module:NodeNext and falls back to 'cjs'\n * because ts.transpileModule doesn't set sourceFile.impliedNodeFormat. This causes\n * deepkit to emit `var {__ΩFoo} = require(\"./bar.ts\")` instead of ESM imports.\n * This transformer converts those back to `import {__ΩFoo} from \"./bar.ts\"` so Rollup\n * can properly resolve and rewrite the module specifiers.\n */\nconst requireToImport: ts.CustomTransformerFactory = (context: ts.TransformationContext): ts.CustomTransformer => ({\n transformSourceFile(sf: ts.SourceFile): ts.SourceFile {\n const newStatements: ts.Statement[] = [];\n let changed = false;\n for (const stmt of sf.statements) {\n const converted = tryConvertRequireToImport(context.factory, stmt);\n if (converted) {\n newStatements.push(converted);\n changed = true;\n } else {\n newStatements.push(stmt);\n }\n }\n return changed ? context.factory.updateSourceFile(sf, newStatements) : sf;\n },\n transformBundle(b: ts.Bundle): ts.Bundle {\n return b;\n },\n});\n\n/**\n * Converts CJS require patterns to ESM import declarations:\n * - `var {a, b} = require(\"./path\")` → `import {a, b} from \"./path\"`\n * - `var mod = require(\"./path\")` → `import mod from \"./path\"`\n */\nfunction tryConvertRequireToImport(f: ts.NodeFactory, stmt: ts.Statement): ts.ImportDeclaration | undefined {\n if (!ts.isVariableStatement(stmt)) return undefined;\n const decls = stmt.declarationList.declarations;\n if (decls.length !== 1) return undefined;\n const decl = decls[0];\n if (!decl.initializer || !ts.isCallExpression(decl.initializer)) return undefined;\n const callee = decl.initializer.expression;\n if (!ts.isIdentifier(callee) || callee.text !== 'require') return undefined;\n if (decl.initializer.arguments.length !== 1) return undefined;\n const specArg = decl.initializer.arguments[0];\n if (!ts.isStringLiteral(specArg)) return undefined;\n\n // var {a, b} = require(\"./path\") → import {a, b} from \"./path\"\n if (ts.isObjectBindingPattern(decl.name)) {\n const specifiers = decl.name.elements.map((el) =>\n f.createImportSpecifier(false, undefined, f.createIdentifier((el.name as ts.Identifier).text))\n );\n return f.createImportDeclaration(\n undefined,\n f.createImportClause(false, undefined, f.createNamedImports(specifiers)),\n f.createStringLiteral(specArg.text)\n );\n }\n\n // var mod = require(\"./path\") → import mod from \"./path\"\n if (ts.isIdentifier(decl.name)) {\n return f.createImportDeclaration(\n undefined,\n f.createImportClause(false, f.createIdentifier(decl.name.text), undefined),\n f.createStringLiteral(specArg.text)\n );\n }\n\n return undefined;\n}\n\n/** Creates deepkit config components that can be integrated into a unified ts.transpileModule call */\nexport function createDeepkitConfig(options: DeepkitTypeOptions = {}): DeepkitConfig {\n const filter = createFilter(options.include ?? ['**/*.tsx', '**/*.ts'], options.exclude ?? 'node_modules/**');\n return {\n filter: (fileName: string) => filter(fileName),\n compilerOptions: {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n configFilePath: options.tsConfig || process.cwd() + '/tsconfig.json',\n ...(options.compilerOptions || {}),\n },\n beforeTransformers: [transformer],\n afterTransformers: [declarationTransformer, requireToImport],\n };\n}\n\n// ── Pure function transformer ───────────────────────────────────────\n\n/**\n * Creates a TypeScript CustomTransformerFactory that injects build-time data into pure function calls.\n * For pureServerFn(def): injects bodyHash as 2nd argument.\n * For registerPureFnFactory(ns, id, fn): injects ParsedFactoryFn as 4th argument.\n *\n * Pre-extracts data using existing extractPureFnsFromSource to ensure hash consistency\n * with the virtual module cache (same whole-file esbuild strip + JS AST path).\n */\nexport function createPureFnTransformerFactory(\n originalSource: string,\n filePath: string,\n collector?: ExtractedPureFn[],\n noViteClient = false\n): ts.CustomTransformerFactory {\n const hasPureServerFn = originalSource.includes('pureServerFn');\n const hasFactory = originalSource.includes('registerPureFnFactory');\n const hasMapFrom = originalSource.includes('mapFrom');\n\n const pureServerFns = hasPureServerFn ? extractPureFnsFromSource(originalSource, filePath, 'pureServerFn', noViteClient) : [];\n const factoryFns = hasFactory ? extractPureFnsFromSource(originalSource, filePath, 'registerPureFnFactory') : [];\n const mapFromFns = hasMapFrom ? extractPureFnsFromSource(originalSource, filePath, 'mapFrom', noViteClient) : [];\n\n return (context: ts.TransformationContext): ts.CustomTransformer => {\n let pureIdx = 0;\n let factoryIdx = 0;\n let mapFromIdx = 0;\n\n function visitor(node: ts.Node): ts.Node {\n if (ts.isCallExpression(node)) {\n const callee = node.expression;\n if (ts.isIdentifier(callee)) {\n if (callee.text === 'pureServerFn' && pureIdx < pureServerFns.length) {\n if (node.arguments.length >= 2) {\n pureIdx++;\n return ts.visitEachChild(node, visitor, context);\n }\n const data = pureServerFns[pureIdx++];\n collector?.push(data);\n return context.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n ...node.arguments,\n context.factory.createStringLiteral(data.bodyHash),\n ]);\n }\n if (callee.text === 'registerPureFnFactory' && factoryIdx < factoryFns.length) {\n if (node.arguments.length >= 4) {\n factoryIdx++;\n return ts.visitEachChild(node, visitor, context);\n }\n const data = factoryFns[factoryIdx++];\n collector?.push(data);\n return context.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n ...node.arguments,\n createParsedFactoryFnNode(context.factory, data),\n ]);\n }\n if (callee.text === 'mapFrom' && mapFromIdx < mapFromFns.length) {\n // mapFrom(source, mapper) -> mapFrom(source, mapper, 'bodyHash')\n if (node.arguments.length >= 3) {\n mapFromIdx++;\n return ts.visitEachChild(node, visitor, context);\n }\n const data = mapFromFns[mapFromIdx++];\n collector?.push(data);\n return context.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n ...node.arguments,\n context.factory.createStringLiteral(data.bodyHash),\n ]);\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n }\n\n return {\n transformSourceFile(sourceFile: ts.SourceFile): ts.SourceFile {\n if (pureServerFns.length === 0 && factoryFns.length === 0 && mapFromFns.length === 0) return sourceFile;\n return ts.visitNode(sourceFile, visitor) as ts.SourceFile;\n },\n transformBundle(bundle: ts.Bundle): ts.Bundle {\n return bundle;\n },\n };\n };\n}\n\n/** Creates an AST node for {bodyHash: '...', paramNames: [...], code: '...'} */\nfunction createParsedFactoryFnNode(factory: ts.NodeFactory, data: ExtractedPureFn): ts.ObjectLiteralExpression {\n return factory.createObjectLiteralExpression([\n factory.createPropertyAssignment('bodyHash', factory.createStringLiteral(data.bodyHash)),\n factory.createPropertyAssignment(\n 'paramNames',\n factory.createArrayLiteralExpression(data.paramNames.map((n) => factory.createStringLiteral(n)))\n ),\n factory.createPropertyAssignment('code', factory.createStringLiteral(data.fnBody)),\n ]);\n}\n"],"names":[],"mappings":";;;;AAiCA,MAAM,kBAA+C,CAAC,aAA6D;AAAA,EAC/G,oBAAoB,IAAkC;AAClD,UAAM,gBAAgC,CAAA;AACtC,QAAI,UAAU;AACd,eAAW,QAAQ,GAAG,YAAY;AAC9B,YAAM,YAAY,0BAA0B,QAAQ,SAAS,IAAI;AACjE,UAAI,WAAW;AACX,sBAAc,KAAK,SAAS;AAC5B,kBAAU;AAAA,MACd,OAAO;AACH,sBAAc,KAAK,IAAI;AAAA,MAC3B;AAAA,IACJ;AACA,WAAO,UAAU,QAAQ,QAAQ,iBAAiB,IAAI,aAAa,IAAI;AAAA,EAC3E;AAAA,EACA,gBAAgB,GAAyB;AACrC,WAAO;AAAA,EACX;AACJ;AAOA,SAAS,0BAA0B,GAAmB,MAAsD;AACxG,MAAI,CAAC,GAAG,oBAAoB,IAAI,EAAG,QAAO;AAC1C,QAAM,QAAQ,KAAK,gBAAgB;AACnC,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,OAAO,MAAM,CAAC;AACpB,MAAI,CAAC,KAAK,eAAe,CAAC,GAAG,iBAAiB,KAAK,WAAW,EAAG,QAAO;AACxE,QAAM,SAAS,KAAK,YAAY;AAChC,MAAI,CAAC,GAAG,aAAa,MAAM,KAAK,OAAO,SAAS,UAAW,QAAO;AAClE,MAAI,KAAK,YAAY,UAAU,WAAW,EAAG,QAAO;AACpD,QAAM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a,WAAW,QAAQ;AAE7D,gBAAI,KAAK,UAAU,UAAU,GAAG;AAC5B;AACA,qBAAO,GAAG,eAAe,MAAM,SAAS,OAAO;AAAA,YACnD;AACA,kBAAM,OAAO,WAAW,YAAY;AACpC,uBAAW,KAAK,IAAI;AACpB,mBAAO,QAAQ,QAAQ,qBAAqB,MAAM,KAAK,YAAY,KAAK,eAAe;AAAA,cACnF,GAAG,KAAK;AAAA,cACR,QAAQ,QAAQ,oBAAoB,KAAK,QAAQ;AAAA,YAAA,CACpD;AAAA,UACL;AAAA,QACJ;AAAA,MACJ;AACA,aAAO,GAAG,eAAe,MAAM,SAAS,OAAO;AAAA,IACnD;AAEA,WAAO;AAAA,MACH,oBAAoB,YAA0C;AAC1D,YAAI,cAAc,WAAW,KAAK,WAAW,WAAW,KAAK,WAAW,WAAW,EAAG,QAAO;AAC7F,eAAO,GAAG,UAAU,YAAY,OAAO;AAAA,MAC3C;AAAA,MACA,gBAAgB,QAA8B;AAC1C,eAAO;AAAA,MACX;AAAA,IAAA;AAAA,EAER;AACJ;AAGA,SAAS,0BAA0B,SAAyB,MAAmD;AAC3G,SAAO,QAAQ,8BAA8B;AAAA,IACzC,QAAQ,yBAAyB,YAAY,QAAQ,oBAAoB,KAAK,QAAQ,CAAC;AAAA,IACvF,QAAQ;AAAA,MACJ;AAAA,MACA,QAAQ,6BAA6B,KAAK,WAAW,IAAI,CAAC,MAAM,QAAQ,oBAAoB,CAAC,CAAC,CAAC;AAAA,IAAA;AAAA,IAEnG,QAAQ,yBAAyB,QAAQ,QAAQ,oBAAoB,KAAK,MAAM,CAAC;AAAA,EAAA,CACpF;AACL;"}
|
|
1
|
+
{"version":3,"file":"transformers.js","sources":["../../../../../src/vite-plugin/transformers.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\n// based on https://github.com/marcj/deepkit/blob/e7da3b48c50115d6e59e233eb9f018513d4d68ce/packages/vite/src/plugin.ts\n\nimport {createFilter} from '@rollup/pluginutils';\nimport * as ts from 'typescript';\nimport {transformer, declarationTransformer} from '@deepkit/type-compiler';\nimport {DeepkitTypeOptions, ExtractedPureFn} from './types.ts';\nimport {extractPureFnsFromSource} from './extractPureFn.ts';\n\n// ── Deepkit ─────────────────────────────────────────────────────────\n\n/** Deepkit configuration components for integration into the unified transform pipeline */\nexport interface DeepkitConfig {\n filter: (fileName: string) => boolean;\n compilerOptions: ts.CompilerOptions;\n beforeTransformers: ts.CustomTransformerFactory[];\n afterTransformers: ts.CustomTransformerFactory[];\n}\n\n/**\n * Post-deepkit transformer that converts require() calls back to import declarations.\n * Deepkit's getModuleType() reads tsconfig's module:NodeNext and falls back to 'cjs'\n * because ts.transpileModule doesn't set sourceFile.impliedNodeFormat. This causes\n * deepkit to emit `var {__ΩFoo} = require(\"./bar.ts\")` instead of ESM imports.\n * This transformer converts those back to `import {__ΩFoo} from \"./bar.ts\"` so Rollup\n * can properly resolve and rewrite the module specifiers.\n */\nconst requireToImport: ts.CustomTransformerFactory = (context: ts.TransformationContext): ts.CustomTransformer => ({\n transformSourceFile(sf: ts.SourceFile): ts.SourceFile {\n const newStatements: ts.Statement[] = [];\n let changed = false;\n for (const stmt of sf.statements) {\n const converted = tryConvertRequireToImport(context.factory, stmt);\n if (converted) {\n newStatements.push(converted);\n changed = true;\n } else {\n newStatements.push(stmt);\n }\n }\n return changed ? context.factory.updateSourceFile(sf, newStatements) : sf;\n },\n transformBundle(b: ts.Bundle): ts.Bundle {\n return b;\n },\n});\n\n/**\n * Converts CJS require patterns to ESM import declarations:\n * - `var {a, b} = require(\"./path\")` → `import {a, b} from \"./path\"`\n * - `var mod = require(\"./path\")` → `import mod from \"./path\"`\n */\nfunction tryConvertRequireToImport(f: ts.NodeFactory, stmt: ts.Statement): ts.ImportDeclaration | undefined {\n if (!ts.isVariableStatement(stmt)) return undefined;\n const decls = stmt.declarationList.declarations;\n if (decls.length !== 1) return undefined;\n const decl = decls[0];\n if (!decl.initializer || !ts.isCallExpression(decl.initializer)) return undefined;\n const callee = decl.initializer.expression;\n if (!ts.isIdentifier(callee) || callee.text !== 'require') return undefined;\n if (decl.initializer.arguments.length !== 1) return undefined;\n const specArg = decl.initializer.arguments[0];\n if (!ts.isStringLiteral(specArg)) return undefined;\n\n // var {a, b} = require(\"./path\") → import {a, b} from \"./path\"\n if (ts.isObjectBindingPattern(decl.name)) {\n const specifiers = decl.name.elements.map((el) =>\n f.createImportSpecifier(false, undefined, f.createIdentifier((el.name as ts.Identifier).text))\n );\n return f.createImportDeclaration(\n undefined,\n f.createImportClause(false, undefined, f.createNamedImports(specifiers)),\n f.createStringLiteral(specArg.text)\n );\n }\n\n // var mod = require(\"./path\") → import mod from \"./path\"\n if (ts.isIdentifier(decl.name)) {\n return f.createImportDeclaration(\n undefined,\n f.createImportClause(false, f.createIdentifier(decl.name.text), undefined),\n f.createStringLiteral(specArg.text)\n );\n }\n\n return undefined;\n}\n\n/** Creates deepkit config components that can be integrated into a unified ts.transpileModule call */\nexport function createDeepkitConfig(options: DeepkitTypeOptions = {}): DeepkitConfig {\n const filter = createFilter(options.include ?? ['**/*.tsx', '**/*.ts'], options.exclude ?? 'node_modules/**');\n return {\n filter: (fileName: string) => filter(fileName),\n compilerOptions: {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n sourceMap: true,\n configFilePath: options.tsConfig || process.cwd() + '/tsconfig.json',\n ...(options.compilerOptions || {}),\n },\n beforeTransformers: [transformer],\n afterTransformers: [declarationTransformer, requireToImport],\n };\n}\n\n// ── Pure function transformer ───────────────────────────────────────\n\n/**\n * Creates a TypeScript CustomTransformerFactory that injects build-time data into pure function calls.\n * For pureServerFn(def): injects bodyHash as 2nd argument.\n * For registerPureFnFactory(ns, id, fn): injects ParsedFactoryFn as 4th argument.\n *\n * Pre-extracts data using existing extractPureFnsFromSource to ensure hash consistency\n * with the virtual module cache (same whole-file esbuild strip + JS AST path).\n */\nexport function createPureFnTransformerFactory(\n originalSource: string,\n filePath: string,\n collector?: ExtractedPureFn[],\n noViteClient = false\n): ts.CustomTransformerFactory {\n const hasPureServerFn = originalSource.includes('pureServerFn');\n const hasFactory = originalSource.includes('registerPureFnFactory');\n const hasMapFrom = originalSource.includes('mapFrom');\n\n const pureServerFns = hasPureServerFn ? extractPureFnsFromSource(originalSource, filePath, 'pureServerFn', noViteClient) : [];\n const factoryFns = hasFactory ? extractPureFnsFromSource(originalSource, filePath, 'registerPureFnFactory') : [];\n const mapFromFns = hasMapFrom ? extractPureFnsFromSource(originalSource, filePath, 'mapFrom', noViteClient) : [];\n\n return (context: ts.TransformationContext): ts.CustomTransformer => {\n let pureIdx = 0;\n let factoryIdx = 0;\n let mapFromIdx = 0;\n\n function visitor(node: ts.Node): ts.Node {\n if (ts.isCallExpression(node)) {\n const callee = node.expression;\n if (ts.isIdentifier(callee)) {\n if (callee.text === 'pureServerFn' && pureIdx < pureServerFns.length) {\n if (node.arguments.length >= 2) {\n pureIdx++;\n return ts.visitEachChild(node, visitor, context);\n }\n const data = pureServerFns[pureIdx++];\n collector?.push(data);\n return context.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n ...node.arguments,\n context.factory.createStringLiteral(data.bodyHash),\n ]);\n }\n if (callee.text === 'registerPureFnFactory' && factoryIdx < factoryFns.length) {\n if (node.arguments.length >= 4) {\n factoryIdx++;\n return ts.visitEachChild(node, visitor, context);\n }\n const data = factoryFns[factoryIdx++];\n collector?.push(data);\n return context.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n ...node.arguments,\n createParsedFactoryFnNode(context.factory, data),\n ]);\n }\n if (callee.text === 'mapFrom' && mapFromIdx < mapFromFns.length) {\n // mapFrom(source, mapper) -> mapFrom(source, mapper, 'bodyHash')\n if (node.arguments.length >= 3) {\n mapFromIdx++;\n return ts.visitEachChild(node, visitor, context);\n }\n const data = mapFromFns[mapFromIdx++];\n collector?.push(data);\n return context.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n ...node.arguments,\n context.factory.createStringLiteral(data.bodyHash),\n ]);\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n }\n\n return {\n transformSourceFile(sourceFile: ts.SourceFile): ts.SourceFile {\n if (pureServerFns.length === 0 && factoryFns.length === 0 && mapFromFns.length === 0) return sourceFile;\n return ts.visitNode(sourceFile, visitor) as ts.SourceFile;\n },\n transformBundle(bundle: ts.Bundle): ts.Bundle {\n return bundle;\n },\n };\n };\n}\n\n/** Creates an AST node for {bodyHash: '...', paramNames: [...], code: '...'} */\nfunction createParsedFactoryFnNode(factory: ts.NodeFactory, data: ExtractedPureFn): ts.ObjectLiteralExpression {\n return factory.createObjectLiteralExpression([\n factory.createPropertyAssignment('bodyHash', factory.createStringLiteral(data.bodyHash)),\n factory.createPropertyAssignment(\n 'paramNames',\n factory.createArrayLiteralExpression(data.paramNames.map((n) => factory.createStringLiteral(n)))\n ),\n factory.createPropertyAssignment('code', factory.createStringLiteral(data.fnBody)),\n ]);\n}\n"],"names":[],"mappings":";;;;AAiCA,MAAM,kBAA+C,CAAC,aAA6D;AAAA,EAC/G,oBAAoB,IAAkC;AAClD,UAAM,gBAAgC,CAAA;AACtC,QAAI,UAAU;AACd,eAAW,QAAQ,GAAG,YAAY;AAC9B,YAAM,YAAY,0BAA0B,QAAQ,SAAS,IAAI;AACjE,UAAI,WAAW;AACX,sBAAc,KAAK,SAAS;AAC5B,kBAAU;AAAA,MACd,OAAO;AACH,sBAAc,KAAK,IAAI;AAAA,MAC3B;AAAA,IACJ;AACA,WAAO,UAAU,QAAQ,QAAQ,iBAAiB,IAAI,aAAa,IAAI;AAAA,EAC3E;AAAA,EACA,gBAAgB,GAAyB;AACrC,WAAO;AAAA,EACX;AACJ;AAOA,SAAS,0BAA0B,GAAmB,MAAsD;AACxG,MAAI,CAAC,GAAG,oBAAoB,IAAI,EAAG,QAAO;AAC1C,QAAM,QAAQ,KAAK,gBAAgB;AACnC,MAAI,MAAM,WAAW,EAAG,QAAO;AA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,QAAQ,oBAAoB,KAAK,MAAM,CAAC;AAAA,EAAA,CACpF;AACL;"}
|
|
@@ -7,11 +7,12 @@ export interface AOTCacheOptions {
|
|
|
7
7
|
customVirtualModuleId?: string;
|
|
8
8
|
}
|
|
9
9
|
export interface MionServerConfig {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
port?: number;
|
|
10
|
+
startScript: string;
|
|
11
|
+
viteConfig?: string;
|
|
12
|
+
runMode: 'buildOnly' | 'childProcess' | 'middleware';
|
|
14
13
|
waitTimeout?: number;
|
|
14
|
+
env?: Record<string, string>;
|
|
15
|
+
args?: string[];
|
|
15
16
|
}
|
|
16
17
|
export interface PureServerFnRegistryEntry {
|
|
17
18
|
readonly namespace: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mionjs/devtools",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-alpha.0",
|
|
4
4
|
"description": "Development tooling for mion (ESLint plugin and Vite plugin).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@typescript-eslint/rule-tester": "^8.17.0"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "26f07a965e43529d4255e6f2ac8a633513026314"
|
|
94
94
|
}
|