@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,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const path = require("path");
|
|
4
|
+
const module$1 = require("module");
|
|
5
|
+
const fs = require("fs");
|
|
4
6
|
const ts = require("typescript");
|
|
5
7
|
const src_vitePlugin_transformers = require("./transformers.cjs");
|
|
6
8
|
const src_vitePlugin_extractPureFn = require("./extractPureFn.cjs");
|
|
@@ -8,6 +10,7 @@ const src_vitePlugin_virtualModule = require("./virtualModule.cjs");
|
|
|
8
10
|
const src_vitePlugin_constants = require("./constants.cjs");
|
|
9
11
|
const src_vitePlugin_aotCacheGenerator = require("./aotCacheGenerator.cjs");
|
|
10
12
|
const src_vitePlugin_aotDiskCache = require("./aotDiskCache.cjs");
|
|
13
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
11
14
|
function _interopNamespaceDefault(e) {
|
|
12
15
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
16
|
if (e) {
|
|
@@ -25,9 +28,6 @@ function _interopNamespaceDefault(e) {
|
|
|
25
28
|
return Object.freeze(n);
|
|
26
29
|
}
|
|
27
30
|
const ts__namespace = /* @__PURE__ */ _interopNamespaceDefault(ts);
|
|
28
|
-
function isRunningAsChild() {
|
|
29
|
-
return process.env.MION_COMPILE === "onlyAOT" || process.env.MION_COMPILE === "serve";
|
|
30
|
-
}
|
|
31
31
|
function mionVitePlugin(options) {
|
|
32
32
|
let extractedFns = null;
|
|
33
33
|
const pureFnOptions = options.serverPureFunctions;
|
|
@@ -37,7 +37,8 @@ function mionVitePlugin(options) {
|
|
|
37
37
|
const deepkitConfig = runTypesOptions ? src_vitePlugin_transformers.createDeepkitConfig(runTypesOptions) : null;
|
|
38
38
|
const defaultCompilerOptions = {
|
|
39
39
|
target: ts__namespace.ScriptTarget.ESNext,
|
|
40
|
-
module: ts__namespace.ModuleKind.ESNext
|
|
40
|
+
module: ts__namespace.ModuleKind.ESNext,
|
|
41
|
+
sourceMap: true
|
|
41
42
|
};
|
|
42
43
|
let pureServerFnCount = 0;
|
|
43
44
|
let registerPureFnFactoryCount = 0;
|
|
@@ -46,7 +47,7 @@ function mionVitePlugin(options) {
|
|
|
46
47
|
let aotGenerationPromise = null;
|
|
47
48
|
let aotCacheDir = "";
|
|
48
49
|
let ssrLoadModule = null;
|
|
49
|
-
const ssrEnabled = serverConfig?.
|
|
50
|
+
const ssrEnabled = serverConfig?.runMode === "middleware";
|
|
50
51
|
let ssrInitPromise = null;
|
|
51
52
|
let persistentChild = null;
|
|
52
53
|
let cleanupRegistered = false;
|
|
@@ -74,7 +75,7 @@ function mionVitePlugin(options) {
|
|
|
74
75
|
name: "mion",
|
|
75
76
|
enforce: "pre",
|
|
76
77
|
// literal type required: inferred 'string' is not assignable to Vite's 'pre' | 'post'
|
|
77
|
-
config(config) {
|
|
78
|
+
config(config, env) {
|
|
78
79
|
if (aotOptions?.excludeReflection && !isRunningAsChild()) {
|
|
79
80
|
const aliases = config.resolve?.alias;
|
|
80
81
|
if (aliases && !Array.isArray(aliases)) {
|
|
@@ -83,6 +84,13 @@ function mionVitePlugin(options) {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
}
|
|
87
|
+
const shimModules = [];
|
|
88
|
+
if (pureFnOptions) shimModules.push(src_vitePlugin_constants.SERVER_PURE_FNS_SHIM);
|
|
89
|
+
if (aotOptions) shimModules.push(src_vitePlugin_constants.AOT_CACHES_SHIM);
|
|
90
|
+
addSsrNoExternal(config, shimModules);
|
|
91
|
+
if (env.command === "build" && shimModules.length > 0) {
|
|
92
|
+
wrapBuildExternal(config, shimModules);
|
|
93
|
+
}
|
|
86
94
|
},
|
|
87
95
|
configResolved(config) {
|
|
88
96
|
if (aotOptions) {
|
|
@@ -91,7 +99,6 @@ function mionVitePlugin(options) {
|
|
|
91
99
|
},
|
|
92
100
|
async buildStart() {
|
|
93
101
|
if (serverConfig && !isRunningAsChild() && !ssrEnabled) {
|
|
94
|
-
if (serverConfig.port) process.env.MION_TEST_PORT = String(serverConfig.port);
|
|
95
102
|
try {
|
|
96
103
|
console.log("[mion] Generating AOT caches...");
|
|
97
104
|
const resultPromise = src_vitePlugin_aotDiskCache.getOrGenerateAOTCaches(serverConfig, aotOptions, aotCacheDir);
|
|
@@ -105,16 +112,23 @@ function mionVitePlugin(options) {
|
|
|
105
112
|
registerCleanupHandlers();
|
|
106
113
|
console.log(`[mion] Server process persisted (pid: ${persistentChild.pid})`);
|
|
107
114
|
}
|
|
108
|
-
if (serverConfig.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
if (result.platformReady && serverConfig.waitTimeout && serverConfig.runMode === "childProcess") {
|
|
116
|
+
console.log("[mion] Waiting for server to call setPlatformConfig()...");
|
|
117
|
+
const timeout = serverConfig.waitTimeout;
|
|
118
|
+
const timeoutId = setTimeout(() => {
|
|
119
|
+
if (result.childProcess?.connected) result.childProcess.disconnect();
|
|
120
|
+
console.error(
|
|
121
|
+
`[mion] Server did not call setPlatformConfig() within ${timeout / 1e3}s. Ensure your platform adapter (startNodeServer, etc.) is called after initMionRouter().`
|
|
122
|
+
);
|
|
123
|
+
}, timeout);
|
|
124
|
+
result.platformReady.then(() => {
|
|
125
|
+
clearTimeout(timeoutId);
|
|
126
|
+
if (result.childProcess?.connected) result.childProcess.disconnect();
|
|
127
|
+
console.log("[mion] Server ready");
|
|
113
128
|
onServerReady();
|
|
114
|
-
}).catch((err) => {
|
|
115
|
-
console.error(`[mion] ${err instanceof Error ? err.message : String(err)}`);
|
|
116
129
|
});
|
|
117
130
|
} else {
|
|
131
|
+
if (result.childProcess?.connected) result.childProcess.disconnect();
|
|
118
132
|
onServerReady();
|
|
119
133
|
}
|
|
120
134
|
} catch (err) {
|
|
@@ -126,12 +140,12 @@ function mionVitePlugin(options) {
|
|
|
126
140
|
configureServer(server) {
|
|
127
141
|
if (!ssrEnabled || !serverConfig) return;
|
|
128
142
|
ssrLoadModule = (url) => server.ssrLoadModule(url);
|
|
129
|
-
const
|
|
143
|
+
const startScript = path.resolve(serverConfig.startScript);
|
|
130
144
|
let nodeRequestHandler = null;
|
|
131
145
|
let basePath = null;
|
|
132
146
|
let initFailed = false;
|
|
133
147
|
console.log("[mion] Generating SSR AOT caches...");
|
|
134
|
-
ssrInitPromise = src_vitePlugin_aotCacheGenerator.loadSSRRouterAndGenerateAOTCaches(ssrLoadModule,
|
|
148
|
+
ssrInitPromise = src_vitePlugin_aotCacheGenerator.loadSSRRouterAndGenerateAOTCaches(ssrLoadModule, startScript).then(async (data) => {
|
|
135
149
|
aotData = data;
|
|
136
150
|
aotGenerationPromise = Promise.resolve(data);
|
|
137
151
|
console.log("[mion] SSR AOT caches generated successfully");
|
|
@@ -171,9 +185,33 @@ function mionVitePlugin(options) {
|
|
|
171
185
|
}
|
|
172
186
|
});
|
|
173
187
|
},
|
|
174
|
-
resolveId(id) {
|
|
188
|
+
resolveId(id, importer) {
|
|
175
189
|
if (id === src_vitePlugin_constants.VIRTUAL_SERVER_PURE_FNS) return src_vitePlugin_constants.resolveVirtualId(id);
|
|
176
190
|
if (aotVirtualModules.has(id)) return src_vitePlugin_constants.resolveVirtualId(id);
|
|
191
|
+
if (aotOptions) {
|
|
192
|
+
const resolved = resolveShimModule(
|
|
193
|
+
id,
|
|
194
|
+
importer,
|
|
195
|
+
src_vitePlugin_constants.AOT_CACHES_SHIM,
|
|
196
|
+
src_vitePlugin_constants.VIRTUAL_AOT_CACHES,
|
|
197
|
+
"aot-caches",
|
|
198
|
+
"aotCaches.ts",
|
|
199
|
+
"emptyCaches.ts"
|
|
200
|
+
);
|
|
201
|
+
if (resolved) return resolved;
|
|
202
|
+
}
|
|
203
|
+
if (pureFnOptions) {
|
|
204
|
+
const resolved = resolveShimModule(
|
|
205
|
+
id,
|
|
206
|
+
importer,
|
|
207
|
+
src_vitePlugin_constants.SERVER_PURE_FNS_SHIM,
|
|
208
|
+
src_vitePlugin_constants.VIRTUAL_SERVER_PURE_FNS,
|
|
209
|
+
"server-pure-fns",
|
|
210
|
+
"serverPureFnsCaches.ts",
|
|
211
|
+
"emptyServerPureFns.ts"
|
|
212
|
+
);
|
|
213
|
+
if (resolved) return resolved;
|
|
214
|
+
}
|
|
177
215
|
if (aotOptions?.excludeReflection && !isRunningAsChild() && src_vitePlugin_constants.REFLECTION_MODULES.includes(id)) {
|
|
178
216
|
return src_vitePlugin_constants.resolveVirtualId(src_vitePlugin_constants.VIRTUAL_STUB_PREFIX + id);
|
|
179
217
|
}
|
|
@@ -248,7 +286,8 @@ function mionVitePlugin(options) {
|
|
|
248
286
|
else pureServerFnCount++;
|
|
249
287
|
}
|
|
250
288
|
}
|
|
251
|
-
|
|
289
|
+
const outputCode = result.outputText.replace(/\n\/\/# sourceMappingURL=.*$/, "");
|
|
290
|
+
return { code: outputCode, map: result.sourceMapText };
|
|
252
291
|
},
|
|
253
292
|
buildEnd() {
|
|
254
293
|
if (pureServerFnCount > 0 || registerPureFnFactoryCount > 0) {
|
|
@@ -280,7 +319,7 @@ function mionVitePlugin(options) {
|
|
|
280
319
|
}
|
|
281
320
|
}
|
|
282
321
|
if (serverConfig && !isRunningAsChild()) {
|
|
283
|
-
const serverDir = path.resolve(serverConfig.
|
|
322
|
+
const serverDir = path.resolve(serverConfig.startScript, "..");
|
|
284
323
|
if (file.startsWith(serverDir)) {
|
|
285
324
|
const killPromise = cleanupChild();
|
|
286
325
|
const regeneratePromise = ssrEnabled && ssrLoadModule ? (
|
|
@@ -288,10 +327,7 @@ function mionVitePlugin(options) {
|
|
|
288
327
|
(async () => {
|
|
289
328
|
const routerModule = await ssrLoadModule("@mionjs/router");
|
|
290
329
|
routerModule.resetRouter();
|
|
291
|
-
return src_vitePlugin_aotCacheGenerator.loadSSRRouterAndGenerateAOTCaches(
|
|
292
|
-
ssrLoadModule,
|
|
293
|
-
path.resolve(serverConfig.startServerScript)
|
|
294
|
-
);
|
|
330
|
+
return src_vitePlugin_aotCacheGenerator.loadSSRRouterAndGenerateAOTCaches(ssrLoadModule, path.resolve(serverConfig.startScript));
|
|
295
331
|
})()
|
|
296
332
|
) : (
|
|
297
333
|
// IPC mode: wait for old child to die, then spawn new
|
|
@@ -306,15 +342,24 @@ function mionVitePlugin(options) {
|
|
|
306
342
|
persistentChild = result.childProcess;
|
|
307
343
|
console.log(`[mion] Server process re-persisted (pid: ${persistentChild.pid})`);
|
|
308
344
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
345
|
+
const platformReady = "platformReady" in result ? result.platformReady : void 0;
|
|
346
|
+
if (platformReady && serverConfig.waitTimeout && serverConfig.runMode === "childProcess") {
|
|
347
|
+
const timeout = serverConfig.waitTimeout;
|
|
348
|
+
console.log("[mion] Waiting for restarted server to call setPlatformConfig()...");
|
|
349
|
+
const timeoutId = setTimeout(() => {
|
|
350
|
+
if (persistentChild?.connected) persistentChild.disconnect();
|
|
351
|
+
console.error(
|
|
352
|
+
`[mion] Restarted server did not call setPlatformConfig() within ${timeout / 1e3}s.`
|
|
353
|
+
);
|
|
354
|
+
}, timeout);
|
|
355
|
+
platformReady.then(() => {
|
|
356
|
+
clearTimeout(timeoutId);
|
|
357
|
+
if (persistentChild?.connected) persistentChild.disconnect();
|
|
358
|
+
console.log("[mion] Restarted server ready");
|
|
314
359
|
onServerReady();
|
|
315
|
-
}).catch((err) => {
|
|
316
|
-
console.error(`[mion] ${err instanceof Error ? err.message : String(err)}`);
|
|
317
360
|
});
|
|
361
|
+
} else if ("childProcess" in result && result.childProcess?.connected) {
|
|
362
|
+
result.childProcess.disconnect();
|
|
318
363
|
}
|
|
319
364
|
if (!ssrEnabled) src_vitePlugin_aotDiskCache.updateDiskCache(serverConfig, aotOptions, data, aotCacheDir);
|
|
320
365
|
let invalidatedCount = 0;
|
|
@@ -337,6 +382,9 @@ function mionVitePlugin(options) {
|
|
|
337
382
|
}
|
|
338
383
|
};
|
|
339
384
|
}
|
|
385
|
+
function isRunningAsChild() {
|
|
386
|
+
return process.env.MION_COMPILE === "buildOnly" || process.env.MION_COMPILE === "childProcess";
|
|
387
|
+
}
|
|
340
388
|
function parseVueModuleId(id) {
|
|
341
389
|
const qIdx = id.indexOf("?");
|
|
342
390
|
if (qIdx === -1) return null;
|
|
@@ -382,6 +430,55 @@ function buildAOTVirtualModuleMaps(customVirtualModuleId) {
|
|
|
382
430
|
}
|
|
383
431
|
return { aotVirtualModules, aotResolvedIds };
|
|
384
432
|
}
|
|
433
|
+
function resolveShimModule(id, importer, shimSpecifier, virtualModuleId, entryName, sourceFileName, emptyFileName) {
|
|
434
|
+
if (id === shimSpecifier) {
|
|
435
|
+
try {
|
|
436
|
+
const resolved = module$1.createRequire(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("src/vite-plugin/mionVitePlugin.cjs", document.baseURI).href).resolve(shimSpecifier);
|
|
437
|
+
const sourceFile = path.resolve(resolved.replace(/[/\\].dist[/\\].*$/, ""), "src/aot/" + sourceFileName);
|
|
438
|
+
if (fs.existsSync(sourceFile)) return sourceFile;
|
|
439
|
+
return src_vitePlugin_constants.resolveVirtualId(virtualModuleId);
|
|
440
|
+
} catch {
|
|
441
|
+
return src_vitePlugin_constants.resolveVirtualId(virtualModuleId);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (id.endsWith("/" + entryName)) {
|
|
445
|
+
const sourceFile = path.resolve(id, "..", "src/aot/" + sourceFileName);
|
|
446
|
+
if (fs.existsSync(sourceFile)) return sourceFile;
|
|
447
|
+
}
|
|
448
|
+
const emptyBase = emptyFileName.replace(".ts", "");
|
|
449
|
+
const sourceBase = sourceFileName.replace(".ts", "");
|
|
450
|
+
if (new RegExp(`${emptyBase}\\.(ts|js|mjs|cjs)$`).test(id) && importer && new RegExp(`${sourceBase}\\.(ts|js|mjs|cjs)$`).test(importer)) {
|
|
451
|
+
return src_vitePlugin_constants.resolveVirtualId(virtualModuleId);
|
|
452
|
+
}
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
function addSsrNoExternal(config, moduleIds) {
|
|
456
|
+
if (moduleIds.length === 0) return;
|
|
457
|
+
const noExternal = config.ssr?.noExternal;
|
|
458
|
+
if (!config.ssr) config.ssr = {};
|
|
459
|
+
if (Array.isArray(noExternal)) {
|
|
460
|
+
for (const moduleId of moduleIds) {
|
|
461
|
+
if (!noExternal.includes(moduleId)) noExternal.push(moduleId);
|
|
462
|
+
}
|
|
463
|
+
} else if (typeof noExternal === "string") {
|
|
464
|
+
config.ssr.noExternal = [noExternal, ...moduleIds];
|
|
465
|
+
} else if (noExternal !== true) {
|
|
466
|
+
config.ssr.noExternal = noExternal ? [noExternal, ...moduleIds] : [...moduleIds];
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function wrapBuildExternal(config, shimModules) {
|
|
470
|
+
if (!config.build) config.build = {};
|
|
471
|
+
if (!config.build.rollupOptions) config.build.rollupOptions = {};
|
|
472
|
+
const original = config.build.rollupOptions.external;
|
|
473
|
+
if (!original) return;
|
|
474
|
+
config.build.rollupOptions.external = (id, ...rest) => {
|
|
475
|
+
if (shimModules.includes(id) || id.startsWith("virtual:mion")) return false;
|
|
476
|
+
if (typeof original === "function") return original(id, ...rest);
|
|
477
|
+
if (Array.isArray(original)) return original.some((ext) => ext instanceof RegExp ? ext.test(id) : ext === id);
|
|
478
|
+
if (original instanceof RegExp) return original.test(id);
|
|
479
|
+
return original === id;
|
|
480
|
+
};
|
|
481
|
+
}
|
|
385
482
|
const READY_KEY = /* @__PURE__ */ Symbol.for("mion.serverReady");
|
|
386
483
|
function getOrCreateServerReady() {
|
|
387
484
|
if (!globalThis[READY_KEY]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mionVitePlugin.cjs","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":["createDeepkitConfig","ts","killPersistentChild","REFLECTION_MODULES","resolveCacheDir","getOrGenerateAOTCaches","logAOTCaches","waitForServer","resolve","loadSSRRouterAndGenerateAOTCaches","VIRTUAL_SERVER_PURE_FNS","resolveVirtualId","VIRTUAL_STUB_PREFIX","generateServerPureFnsVirtualModule","scanClientSource","generateNoopModule","generateJitFnsModule","generatePureFnsModule","generateRouterCacheModule","generateNo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B,eAAA;AAC/B;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;;;;;"}
|
|
1
|
+
{"version":3,"file":"mionVitePlugin.cjs","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":["createDeepkitConfig","ts","killPersistentChild","REFLECTION_MODULES","SERVER_PURE_FNS_SHIM","AOT_CACHES_SHIM","resolveCacheDir","getOrGenerateAOTCaches","logAOTCaches","resolve","loadSSRRouterAndGenerateAOTCaches","VIRTUAL_SERVER_PURE_FNS","resolveVirtualId","VIRTUAL_AOT_CACHES","VIRTUAL_STUB_PREFIX","generateServerPureFnsVirtualModule","scanClientSource","generateNoopModule","generateJitFnsModule","generatePureFnsModule","generateRouterCacheModule","generateNoopCombinedModule","generateCombinedCachesModule","createPureFnTransformerFactory","generateAOTCaches","updateDiskCache","createRequire","existsSync"],"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,kBAAkBA,gDAAoB,eAAe,IAAI;AAGrG,QAAM,yBAA6C;AAAA,IAC/C,QAAQC,cAAG,aAAa;AAAA,IACxB,QAAQA,cAAG,WAAW;AAAA,IACtB,WAAW;AAAA,EAAA;AAIf,MAAI,oBAAoB;AACxB,MAAI,6BAA6B;AACjC,MAAI,mBAA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,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;;;;;"}
|
|
@@ -8,11 +8,11 @@ export interface MionPluginOptions {
|
|
|
8
8
|
export declare function mionVitePlugin(options: MionPluginOptions): {
|
|
9
9
|
name: string;
|
|
10
10
|
enforce: "pre";
|
|
11
|
-
config(config: any): void;
|
|
11
|
+
config(config: any, env: any): void;
|
|
12
12
|
configResolved(config: any): void;
|
|
13
13
|
buildStart(): Promise<void>;
|
|
14
14
|
configureServer(server: any): void;
|
|
15
|
-
resolveId(id: any): string | null;
|
|
15
|
+
resolveId(id: any, importer: any): string | null;
|
|
16
16
|
load(id: any): Promise<string | {
|
|
17
17
|
code: string;
|
|
18
18
|
syntheticNamedExports: boolean;
|
|
@@ -77,6 +77,7 @@ function createDeepkitConfig(options = {}) {
|
|
|
77
77
|
compilerOptions: {
|
|
78
78
|
target: ts__namespace.ScriptTarget.ESNext,
|
|
79
79
|
module: ts__namespace.ModuleKind.ESNext,
|
|
80
|
+
sourceMap: true,
|
|
80
81
|
configFilePath: options.tsConfig || process.cwd() + "/tsconfig.json",
|
|
81
82
|
...options.compilerOptions || {}
|
|
82
83
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.cjs","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":["ts","createFilter","transformer","declarationTransformer","extractPureFnsFromSource"],"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,CAACA,cAAG,oBAAoB,IAAI,EAAG,QAAO;AAC1C,QAAM,QAAQ,KAAK,gBAAgB;AACn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AAC,CAAC,CAAC;AAAA,IAAA;AAAA,IAEnG,QAAQ,yBAAyB,QAAQ,QAAQ,oBAAoB,KAAK,MAAM,CAAC;AAAA,EAAA,CACpF;AACL;;;"}
|
|
1
|
+
{"version":3,"file":"transformers.cjs","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":["ts","createFilter","transformer","declarationTransformer","extractPureFnsFromSource"],"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;AAC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,WAAW,EAAG,QAAO;AAC7F,eAAOA,cAAG,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;;;"}
|
|
@@ -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;
|