@mionjs/devtools 0.13.0 → 0.14.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/README.md +4 -4
- package/dist/core/apply-edits.d.ts +1 -1
- package/dist/core/apply-edits.js +2 -3
- package/dist/core/apply-edits.js.map +1 -1
- package/dist/core/bundledApiStub.js.map +1 -1
- package/dist/core/devReporter.js.map +1 -1
- package/dist/core/diagnosticCatalog.js.map +1 -1
- package/dist/core/downgradeErrors.js.map +1 -1
- package/dist/core/edit-buffer.d.ts +0 -2
- package/dist/core/edit-buffer.js +1 -8
- package/dist/core/edit-buffer.js.map +1 -1
- package/dist/core/go-generated/diagnosticCatalog.generated.js +6 -1
- package/dist/core/go-generated/diagnosticCatalog.generated.js.map +1 -1
- package/dist/core/go-generated/reflectionKind.generated.js.map +1 -1
- package/dist/core/go-generated/runtypes-constants.generated.d.ts +1 -1
- package/dist/core/go-generated/runtypes-constants.generated.js +1 -1
- package/dist/core/go-generated/runtypes-constants.generated.js.map +1 -1
- package/dist/core/go-generated/tsconfig-plugin-keys.generated.d.ts +1 -1
- package/dist/core/go-generated/tsconfig-plugin-keys.generated.js +1 -0
- package/dist/core/go-generated/tsconfig-plugin-keys.generated.js.map +1 -1
- package/dist/core/groupedLog.js.map +1 -1
- package/dist/core/levels.js.map +1 -1
- package/dist/core/markerImports.js.map +1 -1
- package/dist/core/option-guards.js.map +1 -1
- package/dist/core/plugin-option-keys.js +1 -0
- package/dist/core/plugin-option-keys.js.map +1 -1
- package/dist/core/protocol.d.ts +2 -0
- package/dist/core/protocol.js.map +1 -1
- package/dist/core/resolver-client.d.ts +4 -0
- package/dist/core/resolver-client.js +26 -4
- package/dist/core/resolver-client.js.map +1 -1
- package/dist/core/scan-batcher.js.map +1 -1
- package/dist/core/surface.js.map +1 -1
- package/dist/core/type-deps.js.map +1 -1
- package/dist/core/types.d.ts +8 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/typescript-floor.js.map +1 -1
- package/dist/core/unplugin.d.ts +1 -0
- package/dist/core/unplugin.js +63 -10
- package/dist/core/unplugin.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lint/diagnosticRouting.js.map +1 -1
- package/dist/lint/index.js.map +1 -1
- package/dist/lint/lint-worker.js +11 -6
- package/dist/lint/lint-worker.js.map +1 -1
- package/dist/lint/prefilter.js.map +1 -1
- package/dist/lint/session-protocol.js.map +1 -1
- package/dist/lint/session.js.map +1 -1
- package/dist/lint/spawn-shim.js.map +1 -1
- package/dist/lint/vueSfc.d.ts +9 -0
- package/dist/lint/vueSfc.js +112 -0
- package/dist/lint/vueSfc.js.map +1 -0
- package/dist/options.js.map +1 -1
- package/dist/runtypes/bun.js.map +1 -1
- package/dist/runtypes/esbuild.js.map +1 -1
- package/dist/runtypes/next/broker.js +13 -13
- package/dist/runtypes/next/broker.js.map +1 -1
- package/dist/runtypes/next/index.d.ts +0 -1
- package/dist/runtypes/next/index.js +2 -0
- package/dist/runtypes/next/index.js.map +1 -1
- package/dist/runtypes/next/loader.js.map +1 -1
- package/dist/runtypes/next/wire.js.map +1 -1
- package/dist/runtypes/rolldown.js.map +1 -1
- package/dist/runtypes/rollup.js.map +1 -1
- package/dist/runtypes/rspack.js.map +1 -1
- package/dist/runtypes/vite.js.map +1 -1
- package/dist/runtypes/webpack.js.map +1 -1
- package/dist/vite/buildEntries.js +14 -11
- package/dist/vite/buildEntries.js.map +1 -1
- package/dist/vite/index.d.ts +0 -1
- package/dist/vite/index.js +0 -1
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/middlewareMode.d.ts +3 -2
- package/dist/vite/middlewareMode.js +73 -59
- package/dist/vite/middlewareMode.js.map +1 -1
- package/dist/vite/mionVitePlugin.d.ts +0 -1
- package/dist/vite/mionVitePlugin.js +28 -8
- package/dist/vite/mionVitePlugin.js.map +1 -1
- package/dist/vite/nodeWebBridge.js.map +1 -1
- package/dist/vite/sfcTransform.d.ts +1 -0
- package/dist/vite/sfcTransform.js +17 -7
- package/dist/vite/sfcTransform.js.map +1 -1
- package/package.json +8 -13
- package/dist/next/index.d.ts +0 -11
- package/dist/next/index.js +0 -17
- package/dist/next/index.js.map +0 -1
- package/dist/vite/cjsPackageJsonPlugin.d.ts +0 -3
- package/dist/vite/cjsPackageJsonPlugin.js +0 -12
- package/dist/vite/cjsPackageJsonPlugin.js.map +0 -1
|
@@ -13,7 +13,6 @@ interface TurbopackRule {
|
|
|
13
13
|
interface NextConfigLike {
|
|
14
14
|
turbopack?: {
|
|
15
15
|
rules?: Record<string, unknown>;
|
|
16
|
-
resolveAlias?: Record<string, unknown>;
|
|
17
16
|
[key: string]: unknown;
|
|
18
17
|
};
|
|
19
18
|
webpack?: (config: WebpackConfigLike, context: unknown) => WebpackConfigLike;
|
|
@@ -16,6 +16,8 @@ export function isTurbopack() {
|
|
|
16
16
|
return false;
|
|
17
17
|
if (process.env.TURBOPACK)
|
|
18
18
|
return true;
|
|
19
|
+
if (process.env.__NEXT_DEV_SERVER)
|
|
20
|
+
return false;
|
|
19
21
|
return !process.argv.includes('--webpack');
|
|
20
22
|
}
|
|
21
23
|
export async function withRunTypes(nextConfig = {}, options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtypes/next/index.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAsC,MAAM,aAAa,CAAC;AAEnH,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAC,CAAC;AAI3D,MAAM,CAAC,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAIvE,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAmBvD,MAAM,U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BACL,GAAG,UAAU,CAAC,SAAS,EAAE,KAAK;gBAC9B,GAAG,sBAAsB,CAAC,UAAU,CAAC;aACtC;SACF;KACF,CAAC;AACJ,CAAC;AAGD,SAAS,iBAAiB,CAAC,UAA0B,EAAE,OAAoB;IACzE,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC;IACpC,OAAO;QACL,GAAG,UAAU;QACb,OAAO,EAAE,CAAC,MAAyB,EAAE,OAAgB,EAAE,EAAE;YACvD,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC3D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;YAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAGD,SAAS,aAAa,CAAC,OAAoB;IACzC,MAAM,EAAC,UAAU,EAAE,WAAW,EAAE,GAAG,aAAa,EAAC,GAAG,OAAO,CAAC;IAE5D,OAAO,QAAQ,CAAC,OAAO,CAAC,EAAC,GAAG,aAAa,EAAE,SAAS,EAAE,aAAa,CAAC,SAAS,IAAI,SAAS,EAAE,EAAC,CAAC,CAAC;AACjG,CAAC;AAED,eAAe,YAAY,CAAC","sourcesContent":["// Turbopack runs loaders, not plugins; one config-process broker serves the loader workers.\n// Read ./AGENTS.md for invariants and container-only build coverage.\nimport path from 'node:path';\nimport {unplugin} from '../../core/unplugin.ts';\nimport {startBroker, socketPathFor, ownsBroker, isNextDev, type BrokerHandle, type NextOptions} from './broker.ts';\n\nexport {startBroker, socketPathFor, ownsBroker, isNextDev};\nexport type {BrokerHandle, NextOptions};\n\n/** The loader specifier to put in `turbopack.rules`. */\nexport const RUNTYPES_LOADER = '@mionjs/devtools/runtypes/next/loader';\n\n// `condition: {not: 'foreign'}` below keeps the loader off node_modules and Next's own internals: a large\n// speed-up, and the documented way to scope a Turbopack rule.\nconst RULE_GLOBS = ['*.ts', '*.tsx', '*.mts', '*.cts'];\n\n// A structural view of the NextConfig bits this touches, so the package needs no dependency on `next`.\ninterface TurbopackRule {\n loaders: Array<string | {loader: string; options?: Record<string, unknown>}>;\n condition?: unknown;\n as?: string;\n}\ninterface NextConfigLike {\n turbopack?: {rules?: Record<string, unknown>; [key: string]: unknown};\n webpack?: (config: WebpackConfigLike, context: unknown) => WebpackConfigLike;\n [key: string]: unknown;\n}\ninterface WebpackConfigLike {\n plugins?: unknown[];\n [key: string]: unknown;\n}\n\n/** Builds the `turbopack.rules` entries that point Turbopack at the broker. */\nexport function runTypesTurbopackRules(socketPath: string): Record<string, TurbopackRule> {\n const rule: TurbopackRule = {\n // Loader options cross into the worker as plain JSON, no functions, so `onPureFnReport` is set on the broker.\n loaders: [{loader: RUNTYPES_LOADER, options: {socketPath}}],\n condition: {not: 'foreign'},\n };\n return Object.fromEntries(RULE_GLOBS.map((glob) => [glob, rule]));\n}\n\n// Next 16 makes Turbopack the default and `--webpack` the opt-out, so the check is for the opt-out.\nexport function isTurbopack(): boolean {\n if (process.env.TURBOPACK === '0') return false;\n if (process.env.TURBOPACK) return true;\n // `next dev` forks its server with `__NEXT_DEV_SERVER` set and passes TURBOPACK only to a Turbopack one, never\n // the `--webpack` flag: without this the `next dev --webpack` server got the Turbopack rules and no rewrite.\n if (process.env.__NEXT_DEV_SERVER) return false;\n return !process.argv.includes('--webpack');\n}\n\n/**\n * Wraps a Next config so RunTypes runs on both bundlers: the Turbopack loader\n * plus the broker, and the existing unplugin webpack plugin for `next --webpack`.\n *\n * `next.config.ts` must await it, because the whole-program scan has to finish\n * before Turbopack starts handing files to loader workers:\n *\n * ```ts\n * import {withRunTypes} from '@mionjs/devtools/runtypes/next';\n * export default await withRunTypes({reactStrictMode: true});\n * ```\n */\nexport async function withRunTypes(nextConfig: NextConfigLike = {}, options: NextOptions = {}): Promise<NextConfigLike> {\n const root = options.cwd ?? process.cwd();\n\n // The webpack lane has a real plugin host with its own buildStart; a broker there would spawn a second resolver.\n if (!isTurbopack()) return withWebpackPlugin(nextConfig, options);\n\n // The artifact lands in Next's output dir like any bundler's, written by the broker: Turbopack has no hook.\n const artifactDir =\n options.artifactDir ?? path.resolve(root, typeof nextConfig.distDir === 'string' ? nextConfig.distDir : '.next');\n // A process that loads the config without bundling (Next's detached telemetry flush) never calls a loader.\n const socketPath = ownsBroker()\n ? (await startBroker(root, {...options, artifactDir})).socketPath\n : (options.socketPath ?? socketPathFor(root));\n\n return {\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n rules: {\n ...nextConfig.turbopack?.rules,\n ...runTypesTurbopackRules(socketPath),\n },\n },\n };\n}\n\n// withWebpackPlugin composes onto whatever webpack function the user already had, rather than replacing it.\nfunction withWebpackPlugin(nextConfig: NextConfigLike, options: NextOptions): NextConfigLike {\n const previous = nextConfig.webpack;\n return {\n ...nextConfig,\n webpack: (config: WebpackConfigLike, context: unknown) => {\n const next = previous ? previous(config, context) : config;\n next.plugins = next.plugins ?? [];\n next.plugins.push(webpackPlugin(options));\n return next;\n },\n };\n}\n\n// socketPath is a broker-only concern; the webpack lane has no broker.\nfunction webpackPlugin(options: NextOptions): unknown {\n const {socketPath: _socketPath, ...pluginOptions} = options;\n // webpack's config carries no `next dev` signal, so the lane is decided here, as the broker does for Turbopack.\n return unplugin.webpack({...pluginOptions, devServer: pluginOptions.devServer ?? isNextDev()});\n}\n\nexport default withRunTypes;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/runtypes/next/loader.ts"],"names":[],"mappings":"AAIA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAC,gBAAgB,EAAuC,MAAM,WAAW,CAAC;AAiBjF,IAAI,UAAU,GAA+B,IAAI,CAAC;AAClD,IAAI,QAAQ,GAAG,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cesContent":["// The Turbopack loader: it owns no resolver and runs no buildStart, it hands one file to the broker\n// (./broker.ts) and returns the rewrite. Turbopack runs webpack-style loaders through `loader-runner` in a\n// pool of Node workers, which carries only part of that API: the members used here were verified against a\n// real Next 16.3 build, while `this.emitFile` and `this._compiler` are NOT available under Turbopack.\nimport net from 'node:net';\nimport {createLineReader, type BrokerReply, type BrokerRequest} from './wire.ts';\n\n// Options cross the Turbopack boundary as plain JSON; everything else the broker already decided in next.config.\ninterface LoaderOptions {\n socketPath: string;\n}\n\n// The slice of the webpack loader API this file touches, typed structurally so the package needs no webpack types.\ninterface LoaderContext {\n async: () => (error: Error | null, code?: string, map?: unknown) => void;\n getOptions: () => LoaderOptions;\n resourcePath: string;\n addDependency?: (file: string) => void;\n emitWarning?: (warning: Error) => void;\n}\n\n// One connection per worker process, shared by every file that worker handles.\nlet connection: Promise<net.Socket> | null = null;\nlet sequence = 0;\nconst pending = new Map<number, (reply: BrokerReply) => void>();\n\nfunction connect(socketPath: string): Promise<net.Socket> {\n if (connection) return connection;\n connection = new Promise<net.Socket>((resolve, reject) => {\n const socket = net.connect(socketPath, () => resolve(socket));\n socket.once('error', (error) => {\n // A connection that never came up must not leave every later file waiting on a promise that cannot settle.\n connection = null;\n for (const settle of pending.values()) settle({id: -1, ok: false, error: String(error)});\n pending.clear();\n reject(error);\n });\n socket.on(\n 'data',\n createLineReader((line) => {\n let reply: BrokerReply;\n try {\n reply = JSON.parse(line) as BrokerReply;\n } catch {\n return;\n }\n const settle = pending.get(reply.id);\n if (!settle) return;\n pending.delete(reply.id);\n settle(reply);\n })\n );\n });\n return connection;\n}\n\nexport default function runTypesNextLoader(this: LoaderContext, source: string): void {\n const callback = this.async();\n const {socketPath} = this.getOptions();\n const file = this.resourcePath;\n const emitWarning = this.emitWarning?.bind(this);\n const addDependency = this.addDependency?.bind(this);\n\n void (async () => {\n const socket = await connect(socketPath);\n const id = ++sequence;\n const request: BrokerRequest = {id, file, code: source};\n const reply = await new Promise<BrokerReply>((resolve) => {\n pending.set(id, resolve);\n socket.write(`${JSON.stringify(request)}\\n`);\n });\n\n for (const warning of reply.warnings ?? []) emitWarning?.(new Error(warning));\n if (!reply.ok) throw new Error(reply.error ?? 'mion broker failed');\n // Declaring these is what makes a type edit in ANOTHER file re-run this one, instead of Turbopack serving a\n // stale cached rewrite. Declare BOTH: typeDeps names the exact files, and the stamp (one path every rewritten\n // file declares, so ANY type change re-runs ALL of them) covers an empty typeDeps, which means \"unknown\".\n for (const dep of reply.typeDeps ?? []) addDependency?.(dep);\n if (reply.stamp && addDependency) addDependency(reply.stamp);\n // No rewrite for this file.\n if (typeof reply.code !== 'string') return callback(null, source);\n callback(null, reply.code, reply.map);\n })().catch((error: unknown) => {\n callback(error instanceof Error ? error : new Error(String(error)));\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/runtypes/next/wire.ts"],"names":[],"mappings":"AA6BA,MAAM,UAAU,gBAAgB,CAAC,MAA8B;IAC7D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrE,IAAI,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YACtC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YACnC,IAAI,IAAI;gBAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YACvB,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/runtypes/next/wire.ts"],"names":[],"mappings":"AA6BA,MAAM,UAAU,gBAAgB,CAAC,MAA8B;IAC7D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrE,IAAI,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YACtC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YACnC,IAAI,IAAI;gBAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YACvB,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// The broker <-> loader wire: the loader never speaks to the Go resolver, it only asks the broker to rewrite\n// one file. One JSON object per line, like the resolver wire, but multiplexed (workers share a connection and\n// one worker may have several files in flight), so every request carries an id the reply echoes back.\n\n/** `code` is the source Turbopack handed the loader. */\nexport interface BrokerRequest {\n id: number;\n file: string;\n code: string;\n}\n\nexport interface BrokerReply {\n id: number;\n ok: boolean;\n // Absent when the resolver had no rewrite; the loader then hands Turbopack the original source back.\n code?: string;\n map?: unknown;\n // Warnings from rewriting THIS file, re-emitted by the loader so Turbopack attributes them to the right module.\n warnings?: string[];\n // The invalidation stamp path (see broker.ts), declared as a loader dependency so a type edit anywhere re-runs\n // this file. Always present on success: it is the FALLBACK for an empty typeDeps, which means \"unknown\".\n stamp?: string;\n // Absolute paths of the files declaring the types this file's call sites reflect. Not in Turbopack's import\n // graph: a type-only import is erased and an ambient `.d.ts` type was never imported. Declared by the loader\n // so editing a type re-runs exactly the files reflecting it, not every marker-bearing file.\n typeDeps?: string[];\n error?: string;\n}\n\nexport function createLineReader(onLine: (line: string) => void): (chunk: Buffer | string) => void {\n let buffer = '';\n return (chunk) => {\n buffer += typeof chunk === 'string' ? chunk : chunk.toString('utf8');\n let newline = buffer.indexOf('\\n');\n while (newline !== -1) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n if (line) onLine(line);\n newline = buffer.indexOf('\\n');\n }\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rolldown.js","sourceRoot":"","sources":["../../src/runtypes/rolldown.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"rolldown.js","sourceRoot":"","sources":["../../src/runtypes/rolldown.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,QAAQ,CAAC","sourcesContent":["// For consumers invoking Rolldown directly: Vite 8 runs on Rolldown internally, so the /vite entry covers Vite users.\nimport {unplugin} from '../core/unplugin.ts';\n\nexport * from '../core/unplugin.ts';\nexport default unplugin.rolldown;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["../../src/runtypes/rollup.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["../../src/runtypes/rollup.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,MAAM,CAAC","sourcesContent":["// Rollup resolves the on-disk modules under `<genDir>/types/` natively, so this behaves the same as under Vite.\nimport {unplugin} from '../core/unplugin.ts';\n\nexport * from '../core/unplugin.ts';\nexport default unplugin.rollup;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rspack.js","sourceRoot":"","sources":["../../src/runtypes/rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"rspack.js","sourceRoot":"","sources":["../../src/runtypes/rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,MAAM,CAAC","sourcesContent":["import {unplugin} from '../core/unplugin.ts';\n\nexport * from '../core/unplugin.ts';\nexport default unplugin.rspack;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../src/runtypes/vite.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../src/runtypes/vite.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,IAAI,CAAC","sourcesContent":["// `unplugin.vite(options)` returns a Vite plugin or a small array Vite flattens, so `plugins: [runtypes()]` works.\nimport {unplugin} from '../core/unplugin.ts';\n\nexport * from '../core/unplugin.ts';\nexport default unplugin.vite;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../src/runtypes/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../src/runtypes/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,cAAc,qBAAqB,CAAC;AACpC,eAAe,QAAQ,CAAC,OAAO,CAAC","sourcesContent":["import {unplugin} from '../core/unplugin.ts';\n\nexport * from '../core/unplugin.ts';\nexport default unplugin.webpack;\n"]}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import { execFileSync } from 'child_process';
|
|
1
2
|
import { relative, resolve, sep } from 'path';
|
|
2
|
-
import
|
|
3
|
+
import { getExePath } from '@mionjs/bin-compiler';
|
|
3
4
|
export function collectBuildEntries(packageDir, tsconfigFile = 'tsconfig.build.json') {
|
|
4
5
|
const configPath = resolve(packageDir, tsconfigFile);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
let listed;
|
|
7
|
+
try {
|
|
8
|
+
listed = execFileSync(getExePath(), ['compile', '--list-files-only', '--cwd', packageDir, '--tsconfig', configPath], {
|
|
9
|
+
encoding: 'utf8',
|
|
10
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const stderr = (error.stderr ?? '').trim();
|
|
15
|
+
throw new Error(`[collectBuildEntries] could not parse ${configPath}: ${stderr || error.message}`);
|
|
16
|
+
}
|
|
14
17
|
const entries = {};
|
|
15
|
-
for (const fileName of
|
|
18
|
+
for (const fileName of listed.split('\n').filter(Boolean)) {
|
|
16
19
|
if (!fileName.endsWith('.ts') || fileName.endsWith('.d.ts'))
|
|
17
20
|
continue;
|
|
18
21
|
const relativePath = relative(packageDir, fileName).split(sep).join('/');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildEntries.js","sourceRoot":"","sources":["../../src/vite/buildEntries.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,MAAM,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"buildEntries.js","sourceRoot":"","sources":["../../src/vite/buildEntries.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAKhD,MAAM,UAAU,mBAAmB,CAAC,UAAkB,EAAE,YAAY,GAAG,qBAAqB;IAC1F,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAErD,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,YAAY,CAAC,UAAU,EAAE,EAAE,CAAC,SAAS,EAAE,mBAAmB,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE;YACnH,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;SAClC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,CAAE,KAA2B,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,yCAAyC,UAAU,KAAK,MAAM,IAAK,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAChH,CAAC;IACD,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,SAAS;QACtE,MAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzE,IAAI,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QAC5C,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC;IACxD,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,yBAAyB,UAAU,2DAA2D,CAAC,CAAC;IAClH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","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 {execFileSync} from 'child_process';\nimport {relative, resolve, sep} from 'path';\nimport {getExePath} from '@mionjs/bin-compiler';\n\n/** Rollup lib entries derived from the package's OWN build tsconfig: its include/exclude decide what ships.\n * Point vite-plugin-dts (tsconfigPath) and the mion plugin (tsConfig) at the same file, so all\n * three lanes agree on one list. `tsconfigFile` is resolved against packageDir. */\nexport function collectBuildEntries(packageDir: string, tsconfigFile = 'tsconfig.build.json'): Record<string, string> {\n const configPath = resolve(packageDir, tsconfigFile);\n // Importing the Vite plugin must never load TypeScript's JS API\n let listed: string;\n try {\n listed = execFileSync(getExePath(), ['compile', '--list-files-only', '--cwd', packageDir, '--tsconfig', configPath], {\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n } catch (error) {\n const stderr = ((error as {stderr?: string}).stderr ?? '').trim();\n throw new Error(`[collectBuildEntries] could not parse ${configPath}: ${stderr || (error as Error).message}`);\n }\n const entries: Record<string, string> = {};\n for (const fileName of listed.split('\\n').filter(Boolean)) {\n if (!fileName.endsWith('.ts') || fileName.endsWith('.d.ts')) continue;\n const relativePath = relative(packageDir, fileName).split(sep).join('/');\n if (relativePath.startsWith('..')) continue; // ambient files outside the package\n entries[relativePath.replace(/\\.ts$/, '')] = fileName;\n }\n if (Object.keys(entries).length === 0) {\n throw new Error(`[collectBuildEntries] ${configPath} matched no TypeScript files — check its include/exclude.`);\n }\n return entries;\n}\n"]}
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { mionVitePlugin, resolveRtBinary } from './mionVitePlugin.ts';
|
|
2
2
|
export type { MionClientOptions, MionPluginOptions, MionRunTypesOptions, MionServerBuildOptions, MionServerOptions, } from './mionVitePlugin.ts';
|
|
3
3
|
export { DEFAULT_MIDDLEWARE_EXCLUDE } from './middlewareMode.ts';
|
|
4
|
-
export { cjsPackageJsonPlugin } from './cjsPackageJsonPlugin.ts';
|
|
5
4
|
export { collectBuildEntries } from './buildEntries.ts';
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/vite/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { mionVitePlugin, resolveRtBinary } from "./mionVitePlugin.js";
|
|
2
2
|
export { DEFAULT_MIDDLEWARE_EXCLUDE } from "./middlewareMode.js";
|
|
3
|
-
export { cjsPackageJsonPlugin } from "./cjsPackageJsonPlugin.js";
|
|
4
3
|
export { collectBuildEntries } from "./buildEntries.js";
|
|
5
4
|
//# sourceMappingURL=index.js.map
|
package/dist/vite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAWpE,OAAO,EAAC,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAWpE,OAAO,EAAC,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC","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/** Vite plugin for mion — a thin preset over the runtypes core */\nexport {mionVitePlugin, resolveRtBinary} from './mionVitePlugin.ts';\nexport type {\n MionClientOptions,\n MionPluginOptions,\n MionRunTypesOptions,\n MionServerBuildOptions,\n MionServerOptions,\n} from './mionVitePlugin.ts';\n\n/** Paths middleware mode leaves to vite when the router has no basePath. Extend it, don't replace it, unless\n * you know every vite-internal URL you would take over. */\nexport {DEFAULT_MIDDLEWARE_EXCLUDE} from './middlewareMode.ts';\n\nexport {collectBuildEntries} from './buildEntries.ts';\n"]}
|
|
@@ -4,7 +4,8 @@ export declare const DEFAULT_MIDDLEWARE_EXCLUDE: RegExp[];
|
|
|
4
4
|
export interface MiddlewareReadySignals {
|
|
5
5
|
onReady: () => void;
|
|
6
6
|
onError: (err: Error) => void;
|
|
7
|
-
batchesModuleOf?: () => string;
|
|
8
7
|
}
|
|
9
|
-
export declare function mionMiddlewarePlugin(options: MionServerOptions, signals: MiddlewareReadySignals): Plugin
|
|
8
|
+
export declare function mionMiddlewarePlugin(options: MionServerOptions, signals: MiddlewareReadySignals): Plugin & {
|
|
9
|
+
markStale: () => void;
|
|
10
|
+
};
|
|
10
11
|
//# sourceMappingURL=middlewareMode.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
3
4
|
import { serveFetchHandler } from "./nodeWebBridge.js";
|
|
4
5
|
const NODE_HANDLER_EXPORTS = ['httpRequestHandler'];
|
|
5
6
|
const FETCH_HANDLER_EXPORTS = ['requestHandler', 'bunRequestHandler', 'fetch'];
|
|
@@ -22,7 +23,9 @@ export function mionMiddlewarePlugin(options, signals) {
|
|
|
22
23
|
let nodeHandler;
|
|
23
24
|
let fetchHandler;
|
|
24
25
|
let mountPath = '';
|
|
25
|
-
let
|
|
26
|
+
let isStale = false;
|
|
27
|
+
let reloading;
|
|
28
|
+
let apiFiles = new Set();
|
|
26
29
|
let routerModule;
|
|
27
30
|
let closed = false;
|
|
28
31
|
let inFlight = Promise.resolve();
|
|
@@ -44,26 +47,49 @@ export function mionMiddlewarePlugin(options, signals) {
|
|
|
44
47
|
nodeHandler = handlers.node;
|
|
45
48
|
fetchHandler = handlers.fetch;
|
|
46
49
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
50
|
+
async function collectApiFiles(server) {
|
|
51
|
+
const graph = ssrGraphOf(server);
|
|
52
|
+
const entryModule = await graph.getModuleByUrl(entryPath, true);
|
|
53
|
+
const files = new Set([path.resolve(entryPath)]);
|
|
54
|
+
if (entryModule)
|
|
55
|
+
for (const mod of moduleTreeOf(entryModule))
|
|
56
|
+
if (mod.file)
|
|
57
|
+
files.add(path.resolve(mod.file));
|
|
58
|
+
apiFiles = files;
|
|
59
|
+
}
|
|
60
|
+
async function loadAndSettle(server) {
|
|
61
|
+
try {
|
|
62
|
+
await track(load(server));
|
|
63
|
+
initError = undefined;
|
|
64
|
+
signals.onReady();
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
49
67
|
initError = err instanceof Error ? err : new Error(String(err));
|
|
50
68
|
console.error(`[mion] middleware mode failed to load ${entryPath}:`, initError);
|
|
51
69
|
signals.onError(initError);
|
|
52
|
-
}
|
|
70
|
+
}
|
|
71
|
+
if (!closed)
|
|
72
|
+
await collectApiFiles(server).catch((err) => console.error('[mion] could not read the API module tree:', err));
|
|
73
|
+
}
|
|
74
|
+
function init(server) {
|
|
75
|
+
initPromise ??= loadAndSettle(server);
|
|
53
76
|
return initPromise;
|
|
54
77
|
}
|
|
55
78
|
async function reload(server) {
|
|
56
|
-
const
|
|
57
|
-
const graph = ssrGraph ?? server.moduleGraph;
|
|
79
|
+
const graph = ssrGraphOf(server);
|
|
58
80
|
const entryModule = await graph.getModuleByUrl(entryPath, true);
|
|
59
81
|
if (entryModule)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
for (const mod of moduleTreeOf(entryModule))
|
|
83
|
+
graph.invalidateModule(mod);
|
|
84
|
+
await loadAndSettle(server);
|
|
85
|
+
}
|
|
86
|
+
function markStale() {
|
|
87
|
+
if (initPromise && options.hotReload !== false)
|
|
88
|
+
isStale = true;
|
|
64
89
|
}
|
|
65
90
|
return {
|
|
66
91
|
name: 'mion-middleware-server',
|
|
92
|
+
markStale,
|
|
67
93
|
configResolved(config) {
|
|
68
94
|
entryPath = path.resolve(config.root, options.entry);
|
|
69
95
|
},
|
|
@@ -85,14 +111,20 @@ export function mionMiddlewarePlugin(options, signals) {
|
|
|
85
111
|
if (mountPath && !isUnderMountPath(url, mountPath))
|
|
86
112
|
return next();
|
|
87
113
|
await init(server);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
while (isStale || reloading) {
|
|
115
|
+
if (!reloading) {
|
|
116
|
+
isStale = false;
|
|
117
|
+
reloading = reload(server).finally(() => (reloading = undefined));
|
|
118
|
+
}
|
|
119
|
+
await reloading;
|
|
91
120
|
}
|
|
92
121
|
if (!matches(req.url || '/', mountPath, exclude))
|
|
93
122
|
return next();
|
|
94
|
-
if (initError)
|
|
123
|
+
if (initError) {
|
|
124
|
+
if (!mountPath && isPageNavigation(req))
|
|
125
|
+
return next();
|
|
95
126
|
return fail(res, initError);
|
|
127
|
+
}
|
|
96
128
|
if (nodeHandler)
|
|
97
129
|
return nodeHandler(req, res);
|
|
98
130
|
if (fetchHandler)
|
|
@@ -109,35 +141,37 @@ export function mionMiddlewarePlugin(options, signals) {
|
|
|
109
141
|
void init(server);
|
|
110
142
|
if (options.hotReload === false)
|
|
111
143
|
return;
|
|
112
|
-
server.watcher.on('add', (file) => {
|
|
113
|
-
if (!initPromise || staleSince !== undefined)
|
|
114
|
-
return;
|
|
115
|
-
const batchesModule = signals.batchesModuleOf?.() ?? '';
|
|
116
|
-
if (batchesModule && path.resolve(file) === batchesModule)
|
|
117
|
-
staleSince = Date.now();
|
|
118
|
-
});
|
|
119
144
|
server.watcher.on('change', (file) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return;
|
|
124
|
-
let realFile = file;
|
|
125
|
-
try {
|
|
126
|
-
realFile = fs.realpathSync(file);
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
}
|
|
130
|
-
const candidates = realFile === file ? [file] : [file, realFile];
|
|
131
|
-
const graphs = server.environments
|
|
132
|
-
? Object.values(server.environments).map((env) => env.moduleGraph)
|
|
133
|
-
: [server.moduleGraph];
|
|
134
|
-
if (!graphs.some((graph) => candidates.some((f) => graph?.getModulesByFile?.(f)?.size)))
|
|
135
|
-
return;
|
|
136
|
-
staleSince = Date.now();
|
|
145
|
+
const unknownTree = initError !== undefined || apiFiles.size === 0;
|
|
146
|
+
if (unknownTree ? !file.includes('node_modules') : isApiFile(apiFiles, file))
|
|
147
|
+
markStale();
|
|
137
148
|
});
|
|
138
149
|
},
|
|
139
150
|
};
|
|
140
151
|
}
|
|
152
|
+
function ssrGraphOf(server) {
|
|
153
|
+
return server.environments?.ssr?.moduleGraph ?? server.moduleGraph;
|
|
154
|
+
}
|
|
155
|
+
function moduleTreeOf(entryModule) {
|
|
156
|
+
const seen = new Set();
|
|
157
|
+
const walk = (mod) => {
|
|
158
|
+
if (seen.has(mod))
|
|
159
|
+
return;
|
|
160
|
+
seen.add(mod);
|
|
161
|
+
(mod.ssrImportedModules ?? mod.importedModules ?? []).forEach(walk);
|
|
162
|
+
};
|
|
163
|
+
walk(entryModule);
|
|
164
|
+
return seen;
|
|
165
|
+
}
|
|
166
|
+
function isApiFile(apiFiles, file) {
|
|
167
|
+
const resolved = path.resolve(file);
|
|
168
|
+
return apiFiles.has(resolved) || apiFiles.has(safeRealpath(resolved));
|
|
169
|
+
}
|
|
170
|
+
function isPageNavigation(req) {
|
|
171
|
+
if (req.method !== 'GET' && req.method !== 'HEAD')
|
|
172
|
+
return false;
|
|
173
|
+
return String(req.headers.accept ?? '').includes('text/html');
|
|
174
|
+
}
|
|
141
175
|
function assertNotListening(router) {
|
|
142
176
|
const platformConfig = router.getPlatformConfig?.();
|
|
143
177
|
if (!platformConfig)
|
|
@@ -196,30 +230,10 @@ function safeRealpath(p) {
|
|
|
196
230
|
return p;
|
|
197
231
|
}
|
|
198
232
|
}
|
|
199
|
-
function isOwnFile(server, file) {
|
|
200
|
-
if (file.includes('node_modules'))
|
|
201
|
-
return false;
|
|
202
|
-
const resolved = path.resolve(file);
|
|
203
|
-
const root = path.resolve(server.config.root);
|
|
204
|
-
return resolved.startsWith(root) || safeRealpath(resolved).startsWith(safeRealpath(root));
|
|
205
|
-
}
|
|
206
|
-
function invalidateOwnModules(server, graph, entryModule) {
|
|
207
|
-
const seen = new Set();
|
|
208
|
-
const walk = (mod) => {
|
|
209
|
-
if (seen.has(mod))
|
|
210
|
-
return;
|
|
211
|
-
seen.add(mod);
|
|
212
|
-
if (mod.file && !isOwnFile(server, mod.file))
|
|
213
|
-
return;
|
|
214
|
-
graph.invalidateModule(mod);
|
|
215
|
-
(mod.ssrImportedModules ?? mod.importedModules ?? []).forEach(walk);
|
|
216
|
-
};
|
|
217
|
-
walk(entryModule);
|
|
218
|
-
}
|
|
219
233
|
function fail(res, err) {
|
|
220
234
|
res.statusCode = 503;
|
|
221
235
|
res.setHeader('content-type', 'text/plain; charset=utf-8');
|
|
222
|
-
res.end(`mion API failed to initialize:\n${err.message}`);
|
|
236
|
+
res.end(`mion API failed to initialize:\n${stripVTControlCharacters(err.message)}`);
|
|
223
237
|
}
|
|
224
238
|
function isSecure(server) {
|
|
225
239
|
return !!server.config.server?.https;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewareMode.js","sourceRoot":"","sources":["../../src/vite/middlewareMode.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AAerD,MAAM,oBAAoB,GAAG,CAAC,oBAAoB,CAAC,CAAC;AACpD,MAAM,qBAAqB,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,OAAO,CAAC,CAAC;AAE/E,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAIjD,MAAM,CAAC,MAAM,0BAA0B,GAAa;IAClD,MAAM;IACN,WAAW;IACX,mBAAmB;IACnB,WAAW;IACX,oCAAoC;IACpC,uBAAuB;IACvB,+HAA+H;CAChI,CAAC;AAYF,MAAM,UAAU,oBAAoB,CAAC,OAA0B,EAAE,OAA+B;IAE9F,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,0BAA0B,CAAC;IAC9D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,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AgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACvD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACvD,CAAC;AAGD,SAAS,YAAY,CAAC,CAAS;IAC7B,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAGD,SAAS,IAAI,CAAC,GAAmB,EAAE,GAAU;IAC3C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;IACrB,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,2BAA2B,CAAC,CAAC;IAC3D,GAAG,CAAC,GAAG,CAAC,mCAAmC,wBAAwB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AACtF,CAAC;AAGD,SAAS,QAAQ,CAAC,MAAqB;IACrC,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;AACvC,CAAC","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 fs from 'node:fs';\nimport path from 'node:path';\nimport {stripVTControlCharacters} from 'node:util';\nimport type {IncomingMessage, ServerResponse} from 'node:http';\nimport type {ModuleGraph, ModuleNode, Plugin, ViteDevServer} from 'vite';\nimport {serveFetchHandler} from './nodeWebBridge.ts';\nimport type {MionServerOptions} from './mionVitePlugin.ts';\n\n// ############# in-process (middleware) server mode #############\n// The entry is `ssrLoadModule`d, sharing the app's module graph, and its handler mounted as connect middleware.\n// The router's host flag, set before the entry loads, makes any adapter it starts skip listening and hand over\n// its handler, so an unchanged `initRoutes(routes); startNodeServer();` entry works as written.\n\n/** Node-style handler, as exported by @mionjs/platform-node. */\ntype NodeHandler = (req: IncomingMessage, res: ServerResponse) => void;\n/** Fetch-style handler, as exported by @mionjs/platform-bun and buildable from the edge adapters. */\ntype FetchHandler = (req: Request) => Response | Promise<Response>;\ntype RequestHandlers = {node?: NodeHandler; fetch?: FetchHandler};\n\n/** Export names searched for a handler on the entry module, and on the node adapter when nothing else gave one. */\nconst NODE_HANDLER_EXPORTS = ['httpRequestHandler'];\nconst FETCH_HANDLER_EXPORTS = ['requestHandler', 'bunRequestHandler', 'fetch'];\n/** Serves an entry that registers routes but starts no adapter. */\nconst DEFAULT_PLATFORM = '@mionjs/platform-node';\n\n/** Paths never sent to mion when the router has no basePath, the same shape as @hono/vite-dev-server's\n * defaults: vite internals, HMR pings and static assets must reach vite's own middlewares. */\nexport const DEFAULT_MIDDLEWARE_EXCLUDE: RegExp[] = [\n /^\\/@/, // /@vite/client, /@fs/…, /@id/…\n /^\\/__vite/,\n /^\\/node_modules\\//,\n /[?&]t=\\d+/, // HMR cache-busting\n /[?&](import|worker|url|raw)(&|=|$)/,\n /^\\/favicon\\.ico($|\\?)/,\n /\\.(m?[jt]sx?|vue|svelte|astro|css|scss|sass|less|styl|html|map|svg|png|jpe?g|gif|webp|avif|ico|woff2?|ttf|otf|eot|wasm)($|\\?)/,\n];\n\n/** Signals handed back to the plugin: they drive the 503 path, nothing leaves the preset. */\nexport interface MiddlewareReadySignals {\n onReady: () => void;\n onError: (err: Error) => void;\n}\n\n/** The preset's only API runner. `markStale` covers what no watcher reports in time: the batch table added or removed. */\nexport function mionMiddlewarePlugin(\n options: MionServerOptions,\n signals: MiddlewareReadySignals\n): Plugin & {markStale: () => void} {\n // A relative entry is the vite root's, settled in configResolved.\n let entryPath = path.resolve(options.entry);\n const exclude = options.exclude ?? DEFAULT_MIDDLEWARE_EXCLUDE;\n let mounted = false;\n let initPromise: Promise<void> | undefined;\n let initError: Error | undefined;\n let nodeHandler: NodeHandler | undefined;\n let fetchHandler: FetchHandler | undefined;\n let mountPath = '';\n let isStale = false;\n let reloading: Promise<void> | undefined;\n /** Files the last API load evaluated: a change to one makes the API stale. */\n let apiFiles = new Set<string>();\n let routerModule: Record<string, any> | undefined;\n let closed = false;\n let inFlight: Promise<unknown> = Promise.resolve();\n\n /** Remembers the latest load, so closing waits for an entry that may still start an adapter. */\n function track(loading: Promise<void>): Promise<void> {\n inFlight = loading.catch(() => undefined);\n return loading;\n }\n\n /** Loads the entry through vite's SSR pipeline and resolves its handler + mount path. */\n async function load(server: ViteDevServer): Promise<void> {\n const router = await server.ssrLoadModule('@mionjs/router');\n // A warm-up load still in flight when the server closes must not leave the process-wide flag set.\n if (closed) return;\n routerModule = router;\n router.setHostOwnsSocket(true);\n const entry = await server.ssrLoadModule(entryPath);\n // `mion.initRoutes()` is synchronous, but an entry may still export a promise of its own (a\n // platform start it did not await); awaiting those keeps the first request from racing it.\n await Promise.all(Object.values(entry).filter((value): value is Promise<unknown> => value instanceof Promise));\n assertNotListening(router);\n mountPath = normalizeMountPath(router.getRouterOptions?.().basePath);\n const handlers = await pickHandler(server, entry, router.getHostRequestHandler?.());\n nodeHandler = handlers.node;\n fetchHandler = handlers.fetch;\n }\n\n /** Also runs after a failed load: whatever did load is still watched. */\n async function collectApiFiles(server: ViteDevServer): Promise<void> {\n const graph = ssrGraphOf(server);\n const entryModule = await graph.getModuleByUrl(entryPath, true);\n const files = new Set<string>([path.resolve(entryPath)]);\n if (entryModule) for (const mod of moduleTreeOf(entryModule)) if (mod.file) files.add(path.resolve(mod.file));\n apiFiles = files;\n }\n\n async function loadAndSettle(server: ViteDevServer): Promise<void> {\n try {\n await track(load(server));\n initError = undefined;\n signals.onReady();\n } catch (err) {\n initError = err instanceof Error ? err : new Error(String(err));\n console.error(`[mion] middleware mode failed to load ${entryPath}:`, initError);\n signals.onError(initError);\n }\n if (!closed) await collectApiFiles(server).catch((err) => console.error('[mion] could not read the API module tree:', err));\n }\n\n /** Single init chain — every request awaits this one before matching. */\n function init(server: ViteDevServer): Promise<void> {\n initPromise ??= loadAndSettle(server);\n return initPromise;\n }\n\n /** A fresh copy of the API, mion's own modules included, so no shared state needs a reset. */\n async function reload(server: ViteDevServer): Promise<void> {\n const graph = ssrGraphOf(server);\n const entryModule = await graph.getModuleByUrl(entryPath, true);\n if (entryModule) for (const mod of moduleTreeOf(entryModule)) graph.invalidateModule(mod);\n await loadAndSettle(server);\n }\n\n function markStale(): void {\n if (initPromise && options.hotReload !== false) isStale = true;\n }\n\n return {\n name: 'mion-middleware-server',\n markStale,\n\n configResolved(config) {\n entryPath = path.resolve(config.root, options.entry);\n },\n\n // Cleared only once a loading entry finished: its adapter would otherwise see no host and listen.\n async closeBundle() {\n closed = true;\n await inFlight;\n routerModule?.setHostOwnsSocket(false);\n },\n\n config() {\n // API and app share one SSR module graph: two @mionjs/core instances would mean two route registries.\n return {ssr: {noExternal: [/@mionjs\\//]}};\n },\n\n configureServer(server) {\n // Nuxt (and any environment-API host) calls configureServer once per environment.\n if (mounted) return;\n mounted = true;\n\n // Registered from inside the hook body, so it runs BEFORE vite's transform/static\n // middlewares — a returned post-hook would sit after them.\n server.middlewares.use(async (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => {\n try {\n const url = req.url || '/';\n if (mountPath && !isUnderMountPath(url, mountPath)) return next();\n await init(server);\n // Every request waits on the SAME reload, none sees it half done; an edit made during one starts another.\n while (isStale || reloading) {\n if (!reloading) {\n isStale = false;\n reloading = reload(server).finally(() => (reloading = undefined));\n }\n await reloading;\n }\n if (!matches(req.url || '/', mountPath, exclude)) return next();\n if (initError) {\n // No load ever got far enough to read the basePath: a page navigation is the app's, not the API's.\n if (!mountPath && isPageNavigation(req)) return next();\n return fail(res, initError);\n }\n if (nodeHandler) return nodeHandler(req, res);\n if (fetchHandler) return await serveFetchHandler(fetchHandler, req, res, isSecure(server));\n return fail(res, new Error('no mion request handler was resolved'));\n } catch (err) {\n console.error('[mion] middleware error:', err);\n if (!res.writableEnded) fail(res, err instanceof Error ? err : new Error(String(err)));\n }\n });\n\n // Warm up so a broken API shows at boot; skipped under vitest, whose own vite server fires configureServer too.\n if (!process.env.VITEST) void init(server);\n\n if (options.hotReload === false) return;\n // Lazy: reloading eagerly would re-run initRoutes for every unrelated frontend edit.\n server.watcher.on('change', (file) => {\n // A failed or still-running load has no complete tree, so any non-dependency edit is worth a (re)load.\n const unknownTree = initError !== undefined || apiFiles.size === 0;\n if (unknownTree ? !file.includes('node_modules') : isApiFile(apiFiles, file)) markStale();\n });\n },\n };\n}\n\n/** ssrLoadModule reads the ssr graph: under vite 8, invalidating the legacy mixed one leaves it serving a stale entry. */\nfunction ssrGraphOf(server: ViteDevServer): Pick<ModuleGraph, 'getModuleByUrl' | 'invalidateModule'> {\n return (server as any).environments?.ssr?.moduleGraph ?? server.moduleGraph;\n}\n\n/** ssrImportedModules is the ssr environment graph's name for imports, importedModules the legacy mixed graph's. */\nfunction moduleTreeOf(entryModule: ModuleNode): Set<ModuleNode> {\n const seen = new Set<ModuleNode>();\n const walk = (mod: ModuleNode): void => {\n if (seen.has(mod)) return;\n seen.add(mod);\n ((mod as any).ssrImportedModules ?? (mod as any).importedModules ?? []).forEach(walk);\n };\n walk(entryModule);\n return seen;\n}\n\n/** vite 8 keys graphs by real path; watcher events may carry the symlinked one (macOS /var vs /private/var). */\nfunction isApiFile(apiFiles: Set<string>, file: string): boolean {\n const resolved = path.resolve(file);\n return apiFiles.has(resolved) || apiFiles.has(safeRealpath(resolved));\n}\n\n/** A browser page load; mion's client never asks for text/html. */\nfunction isPageNavigation(req: IncomingMessage): boolean {\n if (req.method !== 'GET' && req.method !== 'HEAD') return false;\n return String(req.headers.accept ?? '').includes('text/html');\n}\n\n/** An entry that opened a port anyway got a DIFFERENT router copy than the one the host flag was set on. */\nfunction assertNotListening(router: Record<string, any>): void {\n const platformConfig = router.getPlatformConfig?.();\n // No adapter was started at all (a pure initRoutes entry): nothing to check.\n if (!platformConfig) return;\n if (platformConfig.asMiddleware === true) return;\n throw new Error(\n `[mionVitePlugin] middleware mode: the server entry opened its own port. @mionjs/router was loaded twice, ` +\n `so the platform adapter never saw that vite owns the socket. Make sure ssr.noExternal keeps @mionjs/* ` +\n `in one instance (the plugin adds /@mionjs\\\\// for you; a custom ssr.noExternal must not drop it).`\n );\n}\n\n/** A node-style handler wins when both exist: no Request/Response is built for it. */\nasync function pickHandler(\n server: ViteDevServer,\n entry: Record<string, any>,\n hostHandler: RequestHandlers | undefined\n): Promise<RequestHandlers> {\n const fromEntry = handlerExportOf(entry);\n if (fromEntry) return fromEntry;\n if (hostHandler?.node || hostHandler?.fetch) return hostHandler;\n let loadError: unknown;\n const nodeAdapter = await server.ssrLoadModule(DEFAULT_PLATFORM).catch((error: unknown) => void (loadError = error));\n const fromAdapter = nodeAdapter && handlerExportOf(nodeAdapter);\n if (fromAdapter) return fromAdapter;\n throw new Error(\n `[mionVitePlugin] middleware mode found no request handler. Start a mion platform adapter in the server ` +\n `entry, or export one of ${[...NODE_HANDLER_EXPORTS, ...FETCH_HANDLER_EXPORTS].join(', ')} from it.`,\n {cause: loadError}\n );\n}\n\nfunction handlerExportOf(source: Record<string, any>): RequestHandlers | undefined {\n const node = NODE_HANDLER_EXPORTS.map((name) => source[name]).find((fn) => typeof fn === 'function');\n if (node) return {node};\n const fetch = FETCH_HANDLER_EXPORTS.map((name) => source[name]).find((fn) => typeof fn === 'function');\n if (fetch) return {fetch};\n return undefined;\n}\n\n/** '', 'api/v1' and '/api/v1/' all normalize to the prefix route paths actually carry ('/api/v1'). */\nfunction normalizeMountPath(basePath: unknown): string {\n if (typeof basePath !== 'string' || !basePath) return '';\n const withLeading = basePath.startsWith('/') ? basePath : `/${basePath}`;\n return withLeading.endsWith('/') ? withLeading.slice(0, -1) : withLeading;\n}\n\n/** Boundary-aware prefix match: '/api' must not swallow '/apidocs'. */\nfunction isUnderMountPath(url: string, mountPath: string): boolean {\n if (!url.startsWith(mountPath)) return false;\n const rest = url.slice(mountPath.length);\n return rest === '' || rest.startsWith('/') || rest.startsWith('?');\n}\n\n/** With a basePath the prefix decides. Without one mion serves at the root, so vite's own internals\n * and static assets are what must be let through instead. */\nfunction matches(url: string, mountPath: string, exclude: RegExp[]): boolean {\n if (mountPath) return isUnderMountPath(url, mountPath);\n return !exclude.some((pattern) => pattern.test(url));\n}\n\n/** Resolves symlinks, falling back to the given spelling for paths that no longer exist. */\nfunction safeRealpath(p: string): string {\n try {\n return fs.realpathSync(p);\n } catch {\n return p;\n }\n}\n\n/** 503 with the real cause — a dev server that answers \"something went wrong\" is a wasted round. */\nfunction fail(res: ServerResponse, err: Error): void {\n res.statusCode = 503;\n res.setHeader('content-type', 'text/plain; charset=utf-8');\n res.end(`mion API failed to initialize:\\n${stripVTControlCharacters(err.message)}`);\n}\n\n/** Whether the dev server itself is on https, so bridged Requests carry the right scheme. */\nfunction isSecure(server: ViteDevServer): boolean {\n return !!server.config.server?.https;\n}\n"]}
|
|
@@ -17,7 +17,6 @@ export interface MionPluginOptions extends MionPresetOptions {
|
|
|
17
17
|
}
|
|
18
18
|
export declare function createBatchTransportSignals(invalidate: (files: string[]) => void): {
|
|
19
19
|
onGenerate: (info: GenerateInfo) => void;
|
|
20
|
-
batchesModuleOf: () => string;
|
|
21
20
|
};
|
|
22
21
|
export declare function mionVitePlugin(options?: MionPluginOptions): PluginOption[];
|
|
23
22
|
//# sourceMappingURL=mionVitePlugin.d.ts.map
|
|
@@ -8,7 +8,6 @@ export function createBatchTransportSignals(invalidate) {
|
|
|
8
8
|
let firstGenerateDone = false;
|
|
9
9
|
let batchesModule = '';
|
|
10
10
|
return {
|
|
11
|
-
batchesModuleOf: () => batchesModule,
|
|
12
11
|
onGenerate: (info) => {
|
|
13
12
|
const presenceChanged = (info.batchesModule !== '') !== (batchesModule !== '');
|
|
14
13
|
batchesModule = info.batchesModule;
|
|
@@ -20,7 +19,11 @@ export function createBatchTransportSignals(invalidate) {
|
|
|
20
19
|
}
|
|
21
20
|
export function mionVitePlugin(options = {}) {
|
|
22
21
|
const rt = options.runTypes ?? {};
|
|
23
|
-
|
|
22
|
+
let markApiStale = () => { };
|
|
23
|
+
const transport = createBatchTransportSignals((files) => {
|
|
24
|
+
invalidateFiles(files);
|
|
25
|
+
markApiStale();
|
|
26
|
+
});
|
|
24
27
|
const virtualSites = createVirtualSiteMap();
|
|
25
28
|
let devServer;
|
|
26
29
|
const invalidateStaleSites = (siteFiles) => {
|
|
@@ -67,11 +70,9 @@ export function mionVitePlugin(options = {}) {
|
|
|
67
70
|
if (typeof server.entry !== 'string' || !server.entry) {
|
|
68
71
|
throw new Error('[mionVitePlugin] server.entry must name the server entry file.');
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
batchesModuleOf: transport.batchesModuleOf,
|
|
74
|
-
}));
|
|
73
|
+
const middleware = mionMiddlewarePlugin(server, { onReady: () => { }, onError: () => { } });
|
|
74
|
+
markApiStale = middleware.markStale;
|
|
75
|
+
extraPlugins.unshift(middleware);
|
|
75
76
|
if (server.build)
|
|
76
77
|
extraPlugins.unshift(serverBundlePlugin(server, server.build));
|
|
77
78
|
}
|
|
@@ -93,7 +94,20 @@ function serverBundlePlugin(server, build) {
|
|
|
93
94
|
name: 'mion-server-bundle',
|
|
94
95
|
config: {
|
|
95
96
|
order: 'post',
|
|
96
|
-
handler(userConfig) {
|
|
97
|
+
handler(userConfig, env) {
|
|
98
|
+
if (env.command === 'build') {
|
|
99
|
+
const fix = 'Remove `server.build` and build the API with its own vite config.';
|
|
100
|
+
if (userConfig.build?.ssr) {
|
|
101
|
+
throw new Error(`[mionVitePlugin] server.build cannot run in an SSR build: this vite run already builds a server ` +
|
|
102
|
+
`bundle (build.ssr is set), and the API bundle would replace it. ${fix}`);
|
|
103
|
+
}
|
|
104
|
+
const ssrBuild = userConfig.environments?.ssr?.build;
|
|
105
|
+
const taken = [ssrBuild?.rolldownOptions?.input, ssrBuild?.rollupOptions?.input, ssrBuild?.ssr].find(namesEntry);
|
|
106
|
+
if (taken) {
|
|
107
|
+
throw new Error(`[mionVitePlugin] server.build would replace the ssr environment's input ${JSON.stringify(taken)} ` +
|
|
108
|
+
`with server.entry. ${fix}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
97
111
|
const root = path.resolve(userConfig.root ?? process.cwd());
|
|
98
112
|
return {
|
|
99
113
|
builder: { sharedConfigBuild: true, sharedPlugins: true },
|
|
@@ -103,6 +117,7 @@ function serverBundlePlugin(server, build) {
|
|
|
103
117
|
build: {
|
|
104
118
|
outDir: build.outDir ?? 'dist-server',
|
|
105
119
|
emptyOutDir: true,
|
|
120
|
+
copyPublicDir: false,
|
|
106
121
|
rollupOptions: { input: path.resolve(root, server.entry) },
|
|
107
122
|
},
|
|
108
123
|
},
|
|
@@ -112,4 +127,9 @@ function serverBundlePlugin(server, build) {
|
|
|
112
127
|
},
|
|
113
128
|
};
|
|
114
129
|
}
|
|
130
|
+
function namesEntry(input) {
|
|
131
|
+
if (typeof input === 'string')
|
|
132
|
+
return input !== '';
|
|
133
|
+
return typeof input === 'object' && input !== null && Object.keys(input).length > 0;
|
|
134
|
+
}
|
|
115
135
|
//# sourceMappingURL=mionVitePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mionVitePlugin.js","sourceRoot":"","sources":["../../src/vite/mionVitePlugin.ts"],"names":[],"mappings":"AAOA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAC,oBAAoB,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAIvE,OAAO,EACL,eAAe,EACf,iBAAiB,GAIlB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAC,eAAe,EAAC,CAAC;AA2DzB,MAAM,UAAU,2BAA2B,CAAC,UAAqC;IAI/E,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,OAAO;QACL,eAAe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,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACjH,IAAI,KAAK,EAAE,CAAC;wBACV,MAAM,IAAI,KAAK,CACb,2EAA2E,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG;4BACjG,sBAAsB,GAAG,EAAE,CAC9B,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAED,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;gBAC5D,OAAO;oBACL,OAAO,EAAE,EAAC,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAC;oBACvD,YAAY,EAAE;wBACZ,GAAG,EAAE;4BAEH,OAAO,EAAE,EAAC,UAAU,EAAE,CAAC,WAAW,CAAC,EAAC;4BACpC,KAAK,EAAE;gCACL,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,aAAa;gCACrC,WAAW,EAAE,IAAI;gCAEjB,aAAa,EAAE,KAAK;gCACpB,aAAa,EAAE,EAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,EAAC;6BACzD;yBACF;qBACF;iBACF,CAAC;YACJ,CAAC;SACF;KACe,CAAC;AACrB,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,KAAK,EAAE,CAAC;IACnD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACtF,CAAC","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 path from 'node:path';\nimport tsRuntypes from '../runtypes/vite.ts';\nimport {mionMiddlewarePlugin} from './middlewareMode.ts';\nimport {createVirtualSiteMap, mionSfcPlugins} from './sfcTransform.ts';\nimport type {GenerateInfo, PluginOptions as TsRuntypesPluginOptions} from '../core/unplugin.ts';\nimport type {Plugin, PluginOption} from 'vite';\nimport {\n resolveRtBinary,\n toRunTypesOptions,\n type MionClientOptions,\n type MionPresetOptions,\n type MionRunTypesOptions,\n} from '../options.ts';\n\nexport {resolveRtBinary};\nexport type {MionClientOptions, MionRunTypesOptions};\n\n// ############# mion vite plugin #############\n// A thin preset over the runtypes core, adding mion's own choices: the in-process API, the server bundle,\n// and the batch transport's module-graph wiring.\n\n/** The mion API behind this vite run: ONE program, ONE process. In dev it is mounted as middleware with no\n * port of its own, so a test that needs a real socket starts the API itself in its globalSetup. */\nexport interface MionServerOptions {\n /** Path to the server entry (absolute, or relative to the vite root): SSR-loaded in dev, the server bundle's\n * input when `build` is set. */\n entry: string;\n /** Opt in to the SERVER bundle: `vite build` then emits BOTH the client files and the API, from this one\n * config. Off by default, so a `build.lib` project is untouched. */\n build?: MionServerBuildOptions;\n /** DEV + no router `basePath`: paths NOT served by mion, so vite's internals and static assets still work.\n * With a basePath the router's prefix decides what reaches mion. */\n exclude?: RegExp[];\n /** DEV: re-load the API on source change (default true), a fresh copy with `@mionjs/*`; requests wait for it. */\n hotReload?: boolean;\n}\n\n/** The SERVER half of a two-bundle build (`server.build`). */\nexport interface MionServerBuildOptions {\n /** Where the server bundle lands, relative to the vite root (default 'dist-server'). The client bundle\n * keeps `build.outDir`, so the two never share a directory. */\n outDir?: string;\n}\n\n// No batch config: the SERVER build's resolver does it in the transform; this preset only wires vite's module graph.\n// The wire carries only the batch id, so the server runs exactly the batches and mappers its own build baked in.\n\n/** Options for the unified mion vite plugin. */\nexport interface MionPluginOptions extends MionPresetOptions {\n /** The mion API this run hosts: mounted inside the dev server, and optionally emitted as a second\n * bundle by `vite build`. One program, one process. */\n server?: MionServerOptions;\n}\n\n/**\n * Creates the mion Vite plugin (mion powered).\n *\n * @example\n * ```ts\n * // vitest.config.ts / vite.config.ts\n * import {mionVitePlugin} from '@mionjs/devtools/vite';\n *\n * export default defineConfig({\n * plugins: [mionVitePlugin({server: {entry: 'src/server.ts'}})],\n * });\n * ```\n */\n/** A batch table APPEARING or VANISHING invalidates the router-init modules: they hold the opposite import.\n * Never on the FIRST generate, nothing is transformed yet. Exported for its spec; the preset is its only other caller. */\nexport function createBatchTransportSignals(invalidate: (files: string[]) => void): {\n onGenerate: (info: GenerateInfo) => void;\n} {\n let firstGenerateDone = false;\n let batchesModule = '';\n return {\n onGenerate: (info) => {\n const presenceChanged = (info.batchesModule !== '') !== (batchesModule !== '');\n batchesModule = info.batchesModule;\n if (presenceChanged && firstGenerateDone) invalidate(info.routerInitFiles);\n firstGenerateDone = true;\n },\n };\n}\n\nexport function mionVitePlugin(options: MionPluginOptions = {}): PluginOption[] {\n const rt = options.runTypes ?? {};\n // The batch table appearing or vanishing changes what the API runs, and no watcher event reports it in time.\n let markApiStale = (): void => {};\n const transport = createBatchTransportSignals((files) => {\n invalidateFiles(files);\n markApiStale();\n });\n // Vue SFC scripts are registered with the resolver under a VIRTUAL path (`Comp.vue.ts`) while vite serves\n // `Comp.vue`, and stale site files are reported by the path the resolver knows, so they need translating\n // before invalidating. Built here because the mion plugin and the SFC pass are both constructed below.\n const virtualSites = createVirtualSiteMap();\n let devServer: {moduleGraph?: {getModuleById?: (id: string) => unknown; invalidateModule?: (mod: unknown) => void}} | undefined;\n\n /** Re-transforms the files whose compiled fns just changed, after a type edit elsewhere. */\n const invalidateStaleSites = (siteFiles: string[]): void => {\n const graph = devServer?.moduleGraph;\n if (!graph?.getModuleById || !graph.invalidateModule) return;\n for (const siteFile of siteFiles) {\n // A virtual site file resolves to the real .vue module; a real one is already the id.\n const id = virtualSites.resolve(siteFile) ?? siteFile;\n const mod = graph.getModuleById(id);\n if (mod) graph.invalidateModule(mod);\n }\n };\n\n /** Invalidates the modules of `files` in every environment graph (the API entry is loaded through\n * the ssr environment under vite 8, which the mixed legacy graph no longer reaches). */\n const invalidateFiles = (files: string[]): void => {\n const server = devServer as any;\n if (!server) return;\n const graphs = server.environments\n ? Object.values(server.environments).map((env: any) => env.moduleGraph)\n : [server.moduleGraph];\n for (const file of files) {\n for (const graph of graphs) {\n for (const mod of graph?.getModulesByFile?.(file) ?? []) graph.invalidateModule(mod);\n }\n }\n };\n\n const rtPluginOptions: TsRuntypesPluginOptions = {\n ...toRunTypesOptions(options),\n onGenerate: transport.onGenerate,\n // A type edit in ANOTHER file comes through an erased import vite cannot follow; the resolver names the stale files.\n onSiteFilesChanged: invalidateStaleSites,\n };\n const plugins = tsRuntypes(rtPluginOptions);\n const extraPlugins: Plugin[] = [];\n // The mion plugin only transforms plain TS/JS ids, so an SFC's <script> is handed to it under a virtual\n // path, wired off the SAME plugin instance: one resolver, one program, one generated tree.\n extraPlugins.push(...mionSfcPlugins(findRtPlugin(plugins), rt.sfc !== false, virtualSites));\n // Captures the dev server so invalidateStaleSites can reach the module graph. Build lanes never call\n // configureServer, and their single transform pass makes staleness impossible anyway.\n extraPlugins.push({\n name: 'mion-rt-invalidate',\n configureServer(server) {\n devServer = server as unknown as typeof devServer;\n },\n } satisfies Plugin);\n if (options.server) {\n const server = options.server;\n if (typeof server.entry !== 'string' || !server.entry) {\n throw new Error('[mionVitePlugin] server.entry must name the server entry file.');\n }\n // In-process, `vite dev` only. `onReady`/`onError` only feed the 503 path, no promise leaves this preset.\n const middleware = mionMiddlewarePlugin(server, {onReady: () => {}, onError: () => {}});\n markApiStale = middleware.markStale;\n extraPlugins.unshift(middleware);\n if (server.build) extraPlugins.unshift(serverBundlePlugin(server, server.build));\n }\n return [...extraPlugins, plugins];\n}\n\n/** The SFC pass delegates to this plugin's transform, so it must be the very instance vite runs: a second one\n * would mean a second resolver process and a second program scan. */\nfunction findRtPlugin(created: unknown): Plugin | undefined {\n const queue: unknown[] = [created];\n while (queue.length) {\n const next = queue.shift();\n if (Array.isArray(next)) queue.push(...(next as unknown[]));\n else if (typeof (next as Plugin | undefined)?.transform === 'function') return next as Plugin;\n }\n return undefined;\n}\n\n// ############# server bundle (`server.build`) #############\n\n/** The SERVER half of a two-bundle build, so one `vite build` emits the client files AND the API. It uses\n * vite's built-in `ssr` environment, already `consumer: 'server'`, rather than a third one: `buildApp()`\n * builds EVERY environment in the config, so a third named one would emit three bundles. `builder` is what\n * switches `vite build` off its legacy single-environment path onto `buildApp()`, and its two shared flags\n * keep the run to ONE resolver: without `sharedConfigBuild` vite re-resolves the config FILE per\n * environment, calling `mionVitePlugin()` again and spawning a second resolver that is never closed. */\nfunction serverBundlePlugin(server: MionServerOptions, build: MionServerBuildOptions): Plugin {\n return {\n name: 'mion-server-bundle',\n // Late, so a root another plugin's config hook sets is already in userConfig.\n config: {\n order: 'post',\n handler(userConfig, env) {\n // The API bundle takes over vite's ssr environment, silently replacing a server build the config sets.\n // Dev only mounts the API as middleware, so nothing gets replaced.\n if (env.command === 'build') {\n const fix = 'Remove `server.build` and build the API with its own vite config.';\n if (userConfig.build?.ssr) {\n throw new Error(\n `[mionVitePlugin] server.build cannot run in an SSR build: this vite run already builds a server ` +\n `bundle (build.ssr is set), and the API bundle would replace it. ${fix}`\n );\n }\n const ssrBuild = userConfig.environments?.ssr?.build;\n // `build.ssr: true` names no entry: vite then reads the input, which is ours.\n const taken = [ssrBuild?.rolldownOptions?.input, ssrBuild?.rollupOptions?.input, ssrBuild?.ssr].find(namesEntry);\n if (taken) {\n throw new Error(\n `[mionVitePlugin] server.build would replace the ssr environment's input ${JSON.stringify(taken)} ` +\n `with server.entry. ${fix}`\n );\n }\n }\n // vite resolves only its own defaults against root, rollupOptions.input is taken as written.\n const root = path.resolve(userConfig.root ?? process.cwd());\n return {\n builder: {sharedConfigBuild: true, sharedPlugins: true},\n environments: {\n ssr: {\n // One @mionjs instance across both bundles: two copies mean two route registries.\n resolve: {noExternal: [/@mionjs\\//]},\n build: {\n outDir: build.outDir ?? 'dist-server',\n emptyOutDir: true,\n // vite copies its static folder into every outDir; those files belong to the client only.\n copyPublicDir: false,\n rollupOptions: {input: path.resolve(root, server.entry)},\n },\n },\n },\n };\n },\n },\n } satisfies Plugin;\n}\n\nfunction namesEntry(input: unknown): boolean {\n if (typeof input === 'string') return input !== '';\n return typeof input === 'object' && input !== null && Object.keys(input).length > 0;\n}\n"]}
|