@vetta-org/plugin-vite 0.1.0 → 0.2.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAYA,OAAO,EAGN,KAAK,mBAAmB,EAExB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AA8HD,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAC3C,OAAO,CAAC,oBAAoB,CAAC,CAoG/B","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile, stat } from \"node:fs/promises\";\nimport { createServer as createNetServer } from \"node:net\";\nimport { dirname, isAbsolute, relative, resolve } from \"node:path\";\nimport {\n\tlistPluginManifestResources,\n\tparsePluginManifest,\n\ttype PluginManifest,\n} from \"@vetta-org/plugin-sdk/manifest\";\nimport { watch } from \"chokidar\";\nimport { createServer, isCSSRequest, type ViteDevServer } from \"vite\";\nimport { VETTA_PLUGIN_DEV_ENTRY_ID } from \"./dev-vite-plugins.js\";\nimport {\n\temitVettaPluginDevEvent,\n\tsetVettaPluginDevEventListener,\n\ttype VettaPluginDevEvent,\n\tVETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n} from \"./dev-events.js\";\nimport { hasOpaqueResourceQuery } from \"./request-query.js\";\n\nexport interface VettaPluginDevServer {\n\tpluginId: string;\n\tentryUrl: string;\n\torigin: string;\n\tclose(): Promise<void>;\n}\n\nfunction debugDevServer(message: string): void {\n\tif (process.env.VETTA_PLUGIN_DEV_DEBUG === \"1\") {\n\t\tprocess.stderr.write(`[vetta-plugin dev] ${message}\\n`);\n\t}\n}\n\nasync function readManifest(rootDir: string): Promise<PluginManifest> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\treturn parsePluginManifest(raw);\n}\n\nfunction isInsidePath(candidate: string, root: string): boolean {\n\tconst pathFromRoot = relative(root, candidate);\n\treturn pathFromRoot === \"\" || (!pathFromRoot.startsWith(\"..\") && !isAbsolute(pathFromRoot));\n}\n\nfunction isPluginProjectModule(candidate: string, rootDir: string): boolean {\n\tif (!isInsidePath(candidate, rootDir)) return false;\n\tconst pathFromRoot = relative(rootDir, candidate);\n\treturn pathFromRoot.split(/[\\\\/]/u, 1)[0] !== \"node_modules\";\n}\n\nasync function collectWatchedResourceRoots(rootDir: string, manifest: PluginManifest): Promise<string[]> {\n\tconst resources = listPluginManifestResources(manifest).filter(\n\t\t(resource) => resource.field !== \"entry\" && resource.field !== \"styles\",\n\t);\n\tconst paths = [resolve(rootDir, \"plugin.json\"), resolve(rootDir, \"locales\")];\n\tfor (const resource of resources) {\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tpaths.push(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst resourceStat = await stat(resourcePath);\n\t\t\tpaths.push(resourceStat.isDirectory() ? resourcePath : dirname(resourcePath));\n\t\t} catch {\n\t\t\tpaths.push(resourcePath);\n\t\t}\n\t}\n\treturn paths;\n}\n\nasync function findAvailablePort(): Promise<number> {\n\treturn new Promise<number>((resolvePromise, reject) => {\n\t\tconst probe = createNetServer();\n\t\tprobe.once(\"error\", reject);\n\t\tprobe.listen(0, \"127.0.0.1\", () => {\n\t\t\tconst address = probe.address();\n\t\t\tif (address === null || typeof address === \"string\") {\n\t\t\t\tprobe.close();\n\t\t\t\treject(new Error(\"Could not allocate a plugin dev server port\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprobe.close((error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolvePromise(address.port);\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction resolveServerOrigin(server: ViteDevServer): string {\n\tconst localUrl = server.resolvedUrls?.local[0];\n\tif (!localUrl) throw new Error(\"Vite dev server did not expose a local URL\");\n\treturn localUrl.endsWith(\"/\") ? localUrl.slice(0, -1) : localUrl;\n}\n\nfunction resolveViteConfigFile(rootDir: string): string | undefined {\n\tfor (const fileName of [\"vite.config.ts\", \"vite.config.mts\", \"vite.config.js\", \"vite.config.mjs\"]) {\n\t\tconst configPath = resolve(rootDir, fileName);\n\t\tif (existsSync(configPath)) return configPath;\n\t}\n\treturn undefined;\n}\n\nfunction assertDevPluginsConfigured(server: ViteDevServer): void {\n\tif (!server.config.plugins.some((plugin) => plugin.name === \"vetta-plugin-dev-runtime\")) {\n\t\tthrow new Error(\"Vite config must include vettaPluginFederation() to enable the plugin development runtime\");\n\t}\n}\n\nasync function assertDevEntryAvailable(entryUrl: string): Promise<void> {\n\tconst response = await fetch(entryUrl);\n\tif (!response.ok) {\n\t\tthrow new Error(`Plugin dev entry is unavailable: ${entryUrl} returned HTTP ${response.status}`);\n\t}\n\tawait response.body?.cancel();\n}\n\nasync function assertDevModuleGraphAvailable(server: ViteDevServer, rootDir: string): Promise<void> {\n\tconst environment = server.environments.client;\n\tconst pendingUrls = [VETTA_PLUGIN_DEV_ENTRY_ID];\n\tconst transformedUrls = new Set<string>();\n\twhile (pendingUrls.length > 0) {\n\t\tconst moduleUrl = pendingUrls.pop();\n\t\tif (moduleUrl === undefined || transformedUrls.has(moduleUrl)) continue;\n\t\ttransformedUrls.add(moduleUrl);\n\t\tdebugDevServer(`transforming ${moduleUrl}`);\n\t\ttry {\n\t\t\tconst result = await environment.transformRequest(moduleUrl);\n\t\t\tif (result === null) throw new Error(\"Vite returned no transform result\");\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Plugin development module failed to transform (${moduleUrl}): ${message}`);\n\t\t}\n\t\tif (hasOpaqueResourceQuery(moduleUrl)) continue;\n\t\tconst module = await environment.moduleGraph.getModuleByUrl(moduleUrl);\n\t\tif (!module) throw new Error(`Plugin development module is missing from the Vite graph: ${moduleUrl}`);\n\t\t// A CSS transform already resolves its @imports and produces the browser\n\t\t// update module. Plugin processors such as Tailwind may attach scanned\n\t\t// source files to importedModules even though the browser never imports\n\t\t// them, so they must not become independent JavaScript probes.\n\t\tif (isCSSRequest(moduleUrl)) continue;\n\t\tfor (const importedModule of module.importedModules) {\n\t\t\tif (importedModule.file && isPluginProjectModule(importedModule.file, rootDir)) {\n\t\t\t\tpendingUrls.push(importedModule.url);\n\t\t\t}\n\t\t}\n\t}\n\tdebugDevServer(`transformed ${transformedUrls.size} plugin modules`);\n}\n\nexport async function startVettaPluginDevServer(\n\trootDir: string,\n\tonEvent: (event: VettaPluginDevEvent) => void,\n): Promise<VettaPluginDevServer> {\n\tprocess.env.VETTA_PLUGIN_DEV_SERVER = \"1\";\n\tsetVettaPluginDevEventListener(onEvent);\n\n\tlet manifest = await readManifest(rootDir);\n\tlet watchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\tconst port = await findAvailablePort();\n\tconst server = await createServer({\n\t\troot: rootDir,\n\t\tconfigFile: resolveViteConfigFile(rootDir),\n\t\tlogLevel: \"silent\",\n\t\tserver: {\n\t\t\thost: \"127.0.0.1\",\n\t\t\tport,\n\t\t\tstrictPort: true,\n\t\t\tcors: true,\n\t\t\thmr: { overlay: false },\n\t\t},\n\t});\n\tdebugDevServer(\"vite server created\");\n\tlet refreshTimer: ReturnType<typeof setTimeout> | undefined;\n\tconst resourceWatcher = watch(watchedResourceRoots, { ignoreInitial: true });\n\tresourceWatcher.on(\"error\", (error) => {\n\t\temitVettaPluginDevEvent({\n\t\t\ttype: \"error\",\n\t\t\tpluginId: manifest.id,\n\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t});\n\t});\n\tresourceWatcher.on(\"all\", (_event, changedPath) => {\n\t\tconst absolutePath = resolve(changedPath);\n\t\tif (!watchedResourceRoots.some((watchedPath) => isInsidePath(absolutePath, watchedPath))) return;\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\trefreshTimer = setTimeout(() => {\n\t\t\tvoid (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tif (absolutePath === resolve(rootDir, \"plugin.json\")) {\n\t\t\t\t\t\tmanifest = await readManifest(rootDir);\n\t\t\t\t\t\tconst nextWatchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\t\t\t\t\t\tconst removedRoots = watchedResourceRoots.filter((path) => !nextWatchedResourceRoots.includes(path));\n\t\t\t\t\t\tif (removedRoots.length > 0) await resourceWatcher.unwatch(removedRoots);\n\t\t\t\t\t\tresourceWatcher.add(nextWatchedResourceRoots);\n\t\t\t\t\t\twatchedResourceRoots = nextWatchedResourceRoots;\n\t\t\t\t\t}\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"update\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\treason: \"resource\",\n\t\t\t\t\t\tpath: relative(rootDir, absolutePath).replaceAll(\"\\\\\", \"/\"),\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t}, 80);\n\t});\n\n\tlet origin: string;\n\tlet entryUrl: string;\n\ttry {\n\t\tassertDevPluginsConfigured(server);\n\t\tdebugDevServer(\"starting vite listener\");\n\t\tawait server.listen();\n\t\tdebugDevServer(\"vite listener ready\");\n\t\torigin = resolveServerOrigin(server);\n\t\tentryUrl = `${origin}/mf-manifest.json`;\n\t\tdebugDevServer(`probing ${entryUrl}`);\n\t\tawait assertDevEntryAvailable(entryUrl);\n\t\tdebugDevServer(\"probing plugin module graph\");\n\t\tawait assertDevModuleGraphAvailable(server, rootDir);\n\t\tdebugDevServer(\"plugin entry ready\");\n\t} catch (error) {\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\tsetVettaPluginDevEventListener(undefined);\n\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\tthrow error;\n\t}\n\tconst readyEvent: VettaPluginDevEvent = {\n\t\ttype: \"ready\",\n\t\tprotocolVersion: VETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t};\n\tonEvent(readyEvent);\n\n\treturn {\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t\tasync close() {\n\t\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\t\tsetVettaPluginDevEventListener(undefined);\n\t\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAYA,OAAO,EAGN,KAAK,mBAAmB,EAExB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AA8HD,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAC3C,OAAO,CAAC,oBAAoB,CAAC,CAyG/B","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile, stat } from \"node:fs/promises\";\nimport { createServer as createNetServer } from \"node:net\";\nimport { dirname, isAbsolute, relative, resolve } from \"node:path\";\nimport {\n\tlistPluginManifestResources,\n\tparsePluginManifest,\n\ttype PluginManifest,\n} from \"@vetta-org/plugin-sdk/manifest\";\nimport { watch } from \"chokidar\";\nimport { createServer, isCSSRequest, type ViteDevServer } from \"vite\";\nimport { VETTA_PLUGIN_DEV_ENTRY_ID } from \"./dev-vite-plugins.js\";\nimport {\n\temitVettaPluginDevEvent,\n\tsetVettaPluginDevEventListener,\n\ttype VettaPluginDevEvent,\n\tVETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n} from \"./dev-events.js\";\nimport { hasOpaqueResourceQuery } from \"./request-query.js\";\n\nexport interface VettaPluginDevServer {\n\tpluginId: string;\n\tentryUrl: string;\n\torigin: string;\n\tclose(): Promise<void>;\n}\n\nfunction debugDevServer(message: string): void {\n\tif (process.env.VETTA_PLUGIN_DEV_DEBUG === \"1\") {\n\t\tprocess.stderr.write(`[vetta-plugin dev] ${message}\\n`);\n\t}\n}\n\nasync function readManifest(rootDir: string): Promise<PluginManifest> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\treturn parsePluginManifest(raw);\n}\n\nfunction isInsidePath(candidate: string, root: string): boolean {\n\tconst pathFromRoot = relative(root, candidate);\n\treturn pathFromRoot === \"\" || (!pathFromRoot.startsWith(\"..\") && !isAbsolute(pathFromRoot));\n}\n\nfunction isPluginProjectModule(candidate: string, rootDir: string): boolean {\n\tif (!isInsidePath(candidate, rootDir)) return false;\n\tconst pathFromRoot = relative(rootDir, candidate);\n\treturn pathFromRoot.split(/[\\\\/]/u, 1)[0] !== \"node_modules\";\n}\n\nasync function collectWatchedResourceRoots(rootDir: string, manifest: PluginManifest): Promise<string[]> {\n\tconst resources = listPluginManifestResources(manifest).filter(\n\t\t(resource) => resource.field !== \"entry\" && resource.field !== \"styles\",\n\t);\n\tconst paths = [resolve(rootDir, \"plugin.json\"), resolve(rootDir, \"locales\")];\n\tfor (const resource of resources) {\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tpaths.push(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst resourceStat = await stat(resourcePath);\n\t\t\tpaths.push(resourceStat.isDirectory() ? resourcePath : dirname(resourcePath));\n\t\t} catch {\n\t\t\tpaths.push(resourcePath);\n\t\t}\n\t}\n\treturn paths;\n}\n\nasync function findAvailablePort(): Promise<number> {\n\treturn new Promise<number>((resolvePromise, reject) => {\n\t\tconst probe = createNetServer();\n\t\tprobe.once(\"error\", reject);\n\t\tprobe.listen(0, \"127.0.0.1\", () => {\n\t\t\tconst address = probe.address();\n\t\t\tif (address === null || typeof address === \"string\") {\n\t\t\t\tprobe.close();\n\t\t\t\treject(new Error(\"Could not allocate a plugin dev server port\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprobe.close((error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolvePromise(address.port);\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction resolveServerOrigin(server: ViteDevServer): string {\n\tconst localUrl = server.resolvedUrls?.local[0];\n\tif (!localUrl) throw new Error(\"Vite dev server did not expose a local URL\");\n\treturn localUrl.endsWith(\"/\") ? localUrl.slice(0, -1) : localUrl;\n}\n\nfunction resolveViteConfigFile(rootDir: string): string | undefined {\n\tfor (const fileName of [\"vite.config.ts\", \"vite.config.mts\", \"vite.config.js\", \"vite.config.mjs\"]) {\n\t\tconst configPath = resolve(rootDir, fileName);\n\t\tif (existsSync(configPath)) return configPath;\n\t}\n\treturn undefined;\n}\n\nfunction assertDevPluginsConfigured(server: ViteDevServer): void {\n\tif (!server.config.plugins.some((plugin) => plugin.name === \"vetta-plugin-dev-runtime\")) {\n\t\tthrow new Error(\"Vite config must include vettaPluginFederation() to enable the plugin development runtime\");\n\t}\n}\n\nasync function assertDevEntryAvailable(entryUrl: string): Promise<void> {\n\tconst response = await fetch(entryUrl);\n\tif (!response.ok) {\n\t\tthrow new Error(`Plugin dev entry is unavailable: ${entryUrl} returned HTTP ${response.status}`);\n\t}\n\tawait response.body?.cancel();\n}\n\nasync function assertDevModuleGraphAvailable(server: ViteDevServer, rootDir: string): Promise<void> {\n\tconst environment = server.environments.client;\n\tconst pendingUrls = [VETTA_PLUGIN_DEV_ENTRY_ID];\n\tconst transformedUrls = new Set<string>();\n\twhile (pendingUrls.length > 0) {\n\t\tconst moduleUrl = pendingUrls.pop();\n\t\tif (moduleUrl === undefined || transformedUrls.has(moduleUrl)) continue;\n\t\ttransformedUrls.add(moduleUrl);\n\t\tdebugDevServer(`transforming ${moduleUrl}`);\n\t\ttry {\n\t\t\tconst result = await environment.transformRequest(moduleUrl);\n\t\t\tif (result === null) throw new Error(\"Vite returned no transform result\");\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Plugin development module failed to transform (${moduleUrl}): ${message}`);\n\t\t}\n\t\tif (hasOpaqueResourceQuery(moduleUrl)) continue;\n\t\tconst module = await environment.moduleGraph.getModuleByUrl(moduleUrl);\n\t\tif (!module) throw new Error(`Plugin development module is missing from the Vite graph: ${moduleUrl}`);\n\t\t// A CSS transform already resolves its @imports and produces the browser\n\t\t// update module. Plugin processors such as Tailwind may attach scanned\n\t\t// source files to importedModules even though the browser never imports\n\t\t// them, so they must not become independent JavaScript probes.\n\t\tif (isCSSRequest(moduleUrl)) continue;\n\t\tfor (const importedModule of module.importedModules) {\n\t\t\tif (importedModule.file && isPluginProjectModule(importedModule.file, rootDir)) {\n\t\t\t\tpendingUrls.push(importedModule.url);\n\t\t\t}\n\t\t}\n\t}\n\tdebugDevServer(`transformed ${transformedUrls.size} plugin modules`);\n}\n\nexport async function startVettaPluginDevServer(\n\trootDir: string,\n\tonEvent: (event: VettaPluginDevEvent) => void,\n): Promise<VettaPluginDevServer> {\n\tprocess.env.VETTA_PLUGIN_DEV_SERVER = \"1\";\n\tsetVettaPluginDevEventListener(onEvent);\n\n\tlet manifest = await readManifest(rootDir);\n\tlet watchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\tconst port = await findAvailablePort();\n\tconst server = await createServer({\n\t\troot: rootDir,\n\t\tconfigFile: resolveViteConfigFile(rootDir),\n\t\tlogLevel: \"silent\",\n\t\tserver: {\n\t\t\thost: \"127.0.0.1\",\n\t\t\tport,\n\t\t\tstrictPort: true,\n\t\t\t// Module Federation derives dev share/import URLs from Vite's origin.\n\t\t\t// Pin it to the same loopback endpoint we advertise to the host instead\n\t\t\t// of letting Vite infer a hostname (which can become `localhost` or a\n\t\t\t// LAN address on Windows and make the browser fetch the wrong module).\n\t\t\torigin: `http://127.0.0.1:${port}`,\n\t\t\tcors: true,\n\t\t\thmr: { overlay: false },\n\t\t},\n\t});\n\tdebugDevServer(\"vite server created\");\n\tlet refreshTimer: ReturnType<typeof setTimeout> | undefined;\n\tconst resourceWatcher = watch(watchedResourceRoots, { ignoreInitial: true });\n\tresourceWatcher.on(\"error\", (error) => {\n\t\temitVettaPluginDevEvent({\n\t\t\ttype: \"error\",\n\t\t\tpluginId: manifest.id,\n\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t});\n\t});\n\tresourceWatcher.on(\"all\", (_event, changedPath) => {\n\t\tconst absolutePath = resolve(changedPath);\n\t\tif (!watchedResourceRoots.some((watchedPath) => isInsidePath(absolutePath, watchedPath))) return;\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\trefreshTimer = setTimeout(() => {\n\t\t\tvoid (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tif (absolutePath === resolve(rootDir, \"plugin.json\")) {\n\t\t\t\t\t\tmanifest = await readManifest(rootDir);\n\t\t\t\t\t\tconst nextWatchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\t\t\t\t\t\tconst removedRoots = watchedResourceRoots.filter((path) => !nextWatchedResourceRoots.includes(path));\n\t\t\t\t\t\tif (removedRoots.length > 0) await resourceWatcher.unwatch(removedRoots);\n\t\t\t\t\t\tresourceWatcher.add(nextWatchedResourceRoots);\n\t\t\t\t\t\twatchedResourceRoots = nextWatchedResourceRoots;\n\t\t\t\t\t}\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"update\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\treason: \"resource\",\n\t\t\t\t\t\tpath: relative(rootDir, absolutePath).replaceAll(\"\\\\\", \"/\"),\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t}, 80);\n\t});\n\n\tlet origin: string;\n\tlet entryUrl: string;\n\ttry {\n\t\tassertDevPluginsConfigured(server);\n\t\tdebugDevServer(\"starting vite listener\");\n\t\tawait server.listen();\n\t\tdebugDevServer(\"vite listener ready\");\n\t\torigin = resolveServerOrigin(server);\n\t\tentryUrl = `${origin}/mf-manifest.json`;\n\t\tdebugDevServer(`probing ${entryUrl}`);\n\t\tawait assertDevEntryAvailable(entryUrl);\n\t\tdebugDevServer(\"probing plugin module graph\");\n\t\tawait assertDevModuleGraphAvailable(server, rootDir);\n\t\tdebugDevServer(\"plugin entry ready\");\n\t} catch (error) {\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\tsetVettaPluginDevEventListener(undefined);\n\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\tthrow error;\n\t}\n\tconst readyEvent: VettaPluginDevEvent = {\n\t\ttype: \"ready\",\n\t\tprotocolVersion: VETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t};\n\tonEvent(readyEvent);\n\n\treturn {\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t\tasync close() {\n\t\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\t\tsetVettaPluginDevEventListener(undefined);\n\t\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\t},\n\t};\n}\n"]}
@@ -145,6 +145,11 @@ export async function startVettaPluginDevServer(rootDir, onEvent) {
145
145
  host: "127.0.0.1",
146
146
  port,
147
147
  strictPort: true,
148
+ // Module Federation derives dev share/import URLs from Vite's origin.
149
+ // Pin it to the same loopback endpoint we advertise to the host instead
150
+ // of letting Vite infer a hostname (which can become `localhost` or a
151
+ // LAN address on Windows and make the browser fetch the wrong module).
152
+ origin: `http://127.0.0.1:${port}`,
148
153
  cors: true,
149
154
  hmr: { overlay: false },
150
155
  },
@@ -1 +1 @@
1
- {"version":3,"file":"dev-server.js","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EACN,2BAA2B,EAC3B,mBAAmB,GAEnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAsB,MAAM,MAAM,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EACN,uBAAuB,EACvB,8BAA8B,EAE9B,iCAAiC,GACjC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAS5D,SAAS,cAAc,CAAC,OAAe,EAAQ;IAC9C,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,GAAG,EA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AAQ,EAAE,CAAC,CAAC;QACtC,MAAM,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QACxC,cAAc,CAAC,6BAA6B,CAAC,CAAC;QAC9C,MAAM,6BAA6B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrD,cAAc,CAAC,oBAAoB,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,YAAY;YAAE,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,8BAA8B,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC7D,MAAM,KAAK,CAAC;IACb,CAAC;IACD,MAAM,UAAU,GAAwB;QACvC,IAAI,EAAE,OAAO;QACb,eAAe,EAAE,iCAAiC;QAClD,QAAQ,EAAE,QAAQ,CAAC,EAAE;QACrB,QAAQ;QACR,MAAM;KACN,CAAC;IACF,OAAO,CAAC,UAAU,CAAC,CAAC;IAEpB,OAAO;QACN,QAAQ,EAAE,QAAQ,CAAC,EAAE;QACrB,QAAQ;QACR,MAAM;QACN,KAAK,CAAC,KAAK,GAAG;YACb,IAAI,YAAY;gBAAE,YAAY,CAAC,YAAY,CAAC,CAAC;YAC7C,8BAA8B,CAAC,SAAS,CAAC,CAAC;YAC1C,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAAA,CAC7D;KACD,CAAC;AAAA,CACF","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile, stat } from \"node:fs/promises\";\nimport { createServer as createNetServer } from \"node:net\";\nimport { dirname, isAbsolute, relative, resolve } from \"node:path\";\nimport {\n\tlistPluginManifestResources,\n\tparsePluginManifest,\n\ttype PluginManifest,\n} from \"@vetta-org/plugin-sdk/manifest\";\nimport { watch } from \"chokidar\";\nimport { createServer, isCSSRequest, type ViteDevServer } from \"vite\";\nimport { VETTA_PLUGIN_DEV_ENTRY_ID } from \"./dev-vite-plugins.js\";\nimport {\n\temitVettaPluginDevEvent,\n\tsetVettaPluginDevEventListener,\n\ttype VettaPluginDevEvent,\n\tVETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n} from \"./dev-events.js\";\nimport { hasOpaqueResourceQuery } from \"./request-query.js\";\n\nexport interface VettaPluginDevServer {\n\tpluginId: string;\n\tentryUrl: string;\n\torigin: string;\n\tclose(): Promise<void>;\n}\n\nfunction debugDevServer(message: string): void {\n\tif (process.env.VETTA_PLUGIN_DEV_DEBUG === \"1\") {\n\t\tprocess.stderr.write(`[vetta-plugin dev] ${message}\\n`);\n\t}\n}\n\nasync function readManifest(rootDir: string): Promise<PluginManifest> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\treturn parsePluginManifest(raw);\n}\n\nfunction isInsidePath(candidate: string, root: string): boolean {\n\tconst pathFromRoot = relative(root, candidate);\n\treturn pathFromRoot === \"\" || (!pathFromRoot.startsWith(\"..\") && !isAbsolute(pathFromRoot));\n}\n\nfunction isPluginProjectModule(candidate: string, rootDir: string): boolean {\n\tif (!isInsidePath(candidate, rootDir)) return false;\n\tconst pathFromRoot = relative(rootDir, candidate);\n\treturn pathFromRoot.split(/[\\\\/]/u, 1)[0] !== \"node_modules\";\n}\n\nasync function collectWatchedResourceRoots(rootDir: string, manifest: PluginManifest): Promise<string[]> {\n\tconst resources = listPluginManifestResources(manifest).filter(\n\t\t(resource) => resource.field !== \"entry\" && resource.field !== \"styles\",\n\t);\n\tconst paths = [resolve(rootDir, \"plugin.json\"), resolve(rootDir, \"locales\")];\n\tfor (const resource of resources) {\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tpaths.push(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst resourceStat = await stat(resourcePath);\n\t\t\tpaths.push(resourceStat.isDirectory() ? resourcePath : dirname(resourcePath));\n\t\t} catch {\n\t\t\tpaths.push(resourcePath);\n\t\t}\n\t}\n\treturn paths;\n}\n\nasync function findAvailablePort(): Promise<number> {\n\treturn new Promise<number>((resolvePromise, reject) => {\n\t\tconst probe = createNetServer();\n\t\tprobe.once(\"error\", reject);\n\t\tprobe.listen(0, \"127.0.0.1\", () => {\n\t\t\tconst address = probe.address();\n\t\t\tif (address === null || typeof address === \"string\") {\n\t\t\t\tprobe.close();\n\t\t\t\treject(new Error(\"Could not allocate a plugin dev server port\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprobe.close((error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolvePromise(address.port);\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction resolveServerOrigin(server: ViteDevServer): string {\n\tconst localUrl = server.resolvedUrls?.local[0];\n\tif (!localUrl) throw new Error(\"Vite dev server did not expose a local URL\");\n\treturn localUrl.endsWith(\"/\") ? localUrl.slice(0, -1) : localUrl;\n}\n\nfunction resolveViteConfigFile(rootDir: string): string | undefined {\n\tfor (const fileName of [\"vite.config.ts\", \"vite.config.mts\", \"vite.config.js\", \"vite.config.mjs\"]) {\n\t\tconst configPath = resolve(rootDir, fileName);\n\t\tif (existsSync(configPath)) return configPath;\n\t}\n\treturn undefined;\n}\n\nfunction assertDevPluginsConfigured(server: ViteDevServer): void {\n\tif (!server.config.plugins.some((plugin) => plugin.name === \"vetta-plugin-dev-runtime\")) {\n\t\tthrow new Error(\"Vite config must include vettaPluginFederation() to enable the plugin development runtime\");\n\t}\n}\n\nasync function assertDevEntryAvailable(entryUrl: string): Promise<void> {\n\tconst response = await fetch(entryUrl);\n\tif (!response.ok) {\n\t\tthrow new Error(`Plugin dev entry is unavailable: ${entryUrl} returned HTTP ${response.status}`);\n\t}\n\tawait response.body?.cancel();\n}\n\nasync function assertDevModuleGraphAvailable(server: ViteDevServer, rootDir: string): Promise<void> {\n\tconst environment = server.environments.client;\n\tconst pendingUrls = [VETTA_PLUGIN_DEV_ENTRY_ID];\n\tconst transformedUrls = new Set<string>();\n\twhile (pendingUrls.length > 0) {\n\t\tconst moduleUrl = pendingUrls.pop();\n\t\tif (moduleUrl === undefined || transformedUrls.has(moduleUrl)) continue;\n\t\ttransformedUrls.add(moduleUrl);\n\t\tdebugDevServer(`transforming ${moduleUrl}`);\n\t\ttry {\n\t\t\tconst result = await environment.transformRequest(moduleUrl);\n\t\t\tif (result === null) throw new Error(\"Vite returned no transform result\");\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Plugin development module failed to transform (${moduleUrl}): ${message}`);\n\t\t}\n\t\tif (hasOpaqueResourceQuery(moduleUrl)) continue;\n\t\tconst module = await environment.moduleGraph.getModuleByUrl(moduleUrl);\n\t\tif (!module) throw new Error(`Plugin development module is missing from the Vite graph: ${moduleUrl}`);\n\t\t// A CSS transform already resolves its @imports and produces the browser\n\t\t// update module. Plugin processors such as Tailwind may attach scanned\n\t\t// source files to importedModules even though the browser never imports\n\t\t// them, so they must not become independent JavaScript probes.\n\t\tif (isCSSRequest(moduleUrl)) continue;\n\t\tfor (const importedModule of module.importedModules) {\n\t\t\tif (importedModule.file && isPluginProjectModule(importedModule.file, rootDir)) {\n\t\t\t\tpendingUrls.push(importedModule.url);\n\t\t\t}\n\t\t}\n\t}\n\tdebugDevServer(`transformed ${transformedUrls.size} plugin modules`);\n}\n\nexport async function startVettaPluginDevServer(\n\trootDir: string,\n\tonEvent: (event: VettaPluginDevEvent) => void,\n): Promise<VettaPluginDevServer> {\n\tprocess.env.VETTA_PLUGIN_DEV_SERVER = \"1\";\n\tsetVettaPluginDevEventListener(onEvent);\n\n\tlet manifest = await readManifest(rootDir);\n\tlet watchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\tconst port = await findAvailablePort();\n\tconst server = await createServer({\n\t\troot: rootDir,\n\t\tconfigFile: resolveViteConfigFile(rootDir),\n\t\tlogLevel: \"silent\",\n\t\tserver: {\n\t\t\thost: \"127.0.0.1\",\n\t\t\tport,\n\t\t\tstrictPort: true,\n\t\t\tcors: true,\n\t\t\thmr: { overlay: false },\n\t\t},\n\t});\n\tdebugDevServer(\"vite server created\");\n\tlet refreshTimer: ReturnType<typeof setTimeout> | undefined;\n\tconst resourceWatcher = watch(watchedResourceRoots, { ignoreInitial: true });\n\tresourceWatcher.on(\"error\", (error) => {\n\t\temitVettaPluginDevEvent({\n\t\t\ttype: \"error\",\n\t\t\tpluginId: manifest.id,\n\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t});\n\t});\n\tresourceWatcher.on(\"all\", (_event, changedPath) => {\n\t\tconst absolutePath = resolve(changedPath);\n\t\tif (!watchedResourceRoots.some((watchedPath) => isInsidePath(absolutePath, watchedPath))) return;\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\trefreshTimer = setTimeout(() => {\n\t\t\tvoid (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tif (absolutePath === resolve(rootDir, \"plugin.json\")) {\n\t\t\t\t\t\tmanifest = await readManifest(rootDir);\n\t\t\t\t\t\tconst nextWatchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\t\t\t\t\t\tconst removedRoots = watchedResourceRoots.filter((path) => !nextWatchedResourceRoots.includes(path));\n\t\t\t\t\t\tif (removedRoots.length > 0) await resourceWatcher.unwatch(removedRoots);\n\t\t\t\t\t\tresourceWatcher.add(nextWatchedResourceRoots);\n\t\t\t\t\t\twatchedResourceRoots = nextWatchedResourceRoots;\n\t\t\t\t\t}\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"update\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\treason: \"resource\",\n\t\t\t\t\t\tpath: relative(rootDir, absolutePath).replaceAll(\"\\\\\", \"/\"),\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t}, 80);\n\t});\n\n\tlet origin: string;\n\tlet entryUrl: string;\n\ttry {\n\t\tassertDevPluginsConfigured(server);\n\t\tdebugDevServer(\"starting vite listener\");\n\t\tawait server.listen();\n\t\tdebugDevServer(\"vite listener ready\");\n\t\torigin = resolveServerOrigin(server);\n\t\tentryUrl = `${origin}/mf-manifest.json`;\n\t\tdebugDevServer(`probing ${entryUrl}`);\n\t\tawait assertDevEntryAvailable(entryUrl);\n\t\tdebugDevServer(\"probing plugin module graph\");\n\t\tawait assertDevModuleGraphAvailable(server, rootDir);\n\t\tdebugDevServer(\"plugin entry ready\");\n\t} catch (error) {\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\tsetVettaPluginDevEventListener(undefined);\n\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\tthrow error;\n\t}\n\tconst readyEvent: VettaPluginDevEvent = {\n\t\ttype: \"ready\",\n\t\tprotocolVersion: VETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t};\n\tonEvent(readyEvent);\n\n\treturn {\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t\tasync close() {\n\t\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\t\tsetVettaPluginDevEventListener(undefined);\n\t\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"dev-server.js","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,E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AAC;IACD,MAAM,UAAU,GAAwB;QACvC,IAAI,EAAE,OAAO;QACb,eAAe,EAAE,iCAAiC;QAClD,QAAQ,EAAE,QAAQ,CAAC,EAAE;QACrB,QAAQ;QACR,MAAM;KACN,CAAC;IACF,OAAO,CAAC,UAAU,CAAC,CAAC;IAEpB,OAAO;QACN,QAAQ,EAAE,QAAQ,CAAC,EAAE;QACrB,QAAQ;QACR,MAAM;QACN,KAAK,CAAC,KAAK,GAAG;YACb,IAAI,YAAY;gBAAE,YAAY,CAAC,YAAY,CAAC,CAAC;YAC7C,8BAA8B,CAAC,SAAS,CAAC,CAAC;YAC1C,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAAA,CAC7D;KACD,CAAC;AAAA,CACF","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile, stat } from \"node:fs/promises\";\nimport { createServer as createNetServer } from \"node:net\";\nimport { dirname, isAbsolute, relative, resolve } from \"node:path\";\nimport {\n\tlistPluginManifestResources,\n\tparsePluginManifest,\n\ttype PluginManifest,\n} from \"@vetta-org/plugin-sdk/manifest\";\nimport { watch } from \"chokidar\";\nimport { createServer, isCSSRequest, type ViteDevServer } from \"vite\";\nimport { VETTA_PLUGIN_DEV_ENTRY_ID } from \"./dev-vite-plugins.js\";\nimport {\n\temitVettaPluginDevEvent,\n\tsetVettaPluginDevEventListener,\n\ttype VettaPluginDevEvent,\n\tVETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n} from \"./dev-events.js\";\nimport { hasOpaqueResourceQuery } from \"./request-query.js\";\n\nexport interface VettaPluginDevServer {\n\tpluginId: string;\n\tentryUrl: string;\n\torigin: string;\n\tclose(): Promise<void>;\n}\n\nfunction debugDevServer(message: string): void {\n\tif (process.env.VETTA_PLUGIN_DEV_DEBUG === \"1\") {\n\t\tprocess.stderr.write(`[vetta-plugin dev] ${message}\\n`);\n\t}\n}\n\nasync function readManifest(rootDir: string): Promise<PluginManifest> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\treturn parsePluginManifest(raw);\n}\n\nfunction isInsidePath(candidate: string, root: string): boolean {\n\tconst pathFromRoot = relative(root, candidate);\n\treturn pathFromRoot === \"\" || (!pathFromRoot.startsWith(\"..\") && !isAbsolute(pathFromRoot));\n}\n\nfunction isPluginProjectModule(candidate: string, rootDir: string): boolean {\n\tif (!isInsidePath(candidate, rootDir)) return false;\n\tconst pathFromRoot = relative(rootDir, candidate);\n\treturn pathFromRoot.split(/[\\\\/]/u, 1)[0] !== \"node_modules\";\n}\n\nasync function collectWatchedResourceRoots(rootDir: string, manifest: PluginManifest): Promise<string[]> {\n\tconst resources = listPluginManifestResources(manifest).filter(\n\t\t(resource) => resource.field !== \"entry\" && resource.field !== \"styles\",\n\t);\n\tconst paths = [resolve(rootDir, \"plugin.json\"), resolve(rootDir, \"locales\")];\n\tfor (const resource of resources) {\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tpaths.push(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst resourceStat = await stat(resourcePath);\n\t\t\tpaths.push(resourceStat.isDirectory() ? resourcePath : dirname(resourcePath));\n\t\t} catch {\n\t\t\tpaths.push(resourcePath);\n\t\t}\n\t}\n\treturn paths;\n}\n\nasync function findAvailablePort(): Promise<number> {\n\treturn new Promise<number>((resolvePromise, reject) => {\n\t\tconst probe = createNetServer();\n\t\tprobe.once(\"error\", reject);\n\t\tprobe.listen(0, \"127.0.0.1\", () => {\n\t\t\tconst address = probe.address();\n\t\t\tif (address === null || typeof address === \"string\") {\n\t\t\t\tprobe.close();\n\t\t\t\treject(new Error(\"Could not allocate a plugin dev server port\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprobe.close((error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolvePromise(address.port);\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction resolveServerOrigin(server: ViteDevServer): string {\n\tconst localUrl = server.resolvedUrls?.local[0];\n\tif (!localUrl) throw new Error(\"Vite dev server did not expose a local URL\");\n\treturn localUrl.endsWith(\"/\") ? localUrl.slice(0, -1) : localUrl;\n}\n\nfunction resolveViteConfigFile(rootDir: string): string | undefined {\n\tfor (const fileName of [\"vite.config.ts\", \"vite.config.mts\", \"vite.config.js\", \"vite.config.mjs\"]) {\n\t\tconst configPath = resolve(rootDir, fileName);\n\t\tif (existsSync(configPath)) return configPath;\n\t}\n\treturn undefined;\n}\n\nfunction assertDevPluginsConfigured(server: ViteDevServer): void {\n\tif (!server.config.plugins.some((plugin) => plugin.name === \"vetta-plugin-dev-runtime\")) {\n\t\tthrow new Error(\"Vite config must include vettaPluginFederation() to enable the plugin development runtime\");\n\t}\n}\n\nasync function assertDevEntryAvailable(entryUrl: string): Promise<void> {\n\tconst response = await fetch(entryUrl);\n\tif (!response.ok) {\n\t\tthrow new Error(`Plugin dev entry is unavailable: ${entryUrl} returned HTTP ${response.status}`);\n\t}\n\tawait response.body?.cancel();\n}\n\nasync function assertDevModuleGraphAvailable(server: ViteDevServer, rootDir: string): Promise<void> {\n\tconst environment = server.environments.client;\n\tconst pendingUrls = [VETTA_PLUGIN_DEV_ENTRY_ID];\n\tconst transformedUrls = new Set<string>();\n\twhile (pendingUrls.length > 0) {\n\t\tconst moduleUrl = pendingUrls.pop();\n\t\tif (moduleUrl === undefined || transformedUrls.has(moduleUrl)) continue;\n\t\ttransformedUrls.add(moduleUrl);\n\t\tdebugDevServer(`transforming ${moduleUrl}`);\n\t\ttry {\n\t\t\tconst result = await environment.transformRequest(moduleUrl);\n\t\t\tif (result === null) throw new Error(\"Vite returned no transform result\");\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Plugin development module failed to transform (${moduleUrl}): ${message}`);\n\t\t}\n\t\tif (hasOpaqueResourceQuery(moduleUrl)) continue;\n\t\tconst module = await environment.moduleGraph.getModuleByUrl(moduleUrl);\n\t\tif (!module) throw new Error(`Plugin development module is missing from the Vite graph: ${moduleUrl}`);\n\t\t// A CSS transform already resolves its @imports and produces the browser\n\t\t// update module. Plugin processors such as Tailwind may attach scanned\n\t\t// source files to importedModules even though the browser never imports\n\t\t// them, so they must not become independent JavaScript probes.\n\t\tif (isCSSRequest(moduleUrl)) continue;\n\t\tfor (const importedModule of module.importedModules) {\n\t\t\tif (importedModule.file && isPluginProjectModule(importedModule.file, rootDir)) {\n\t\t\t\tpendingUrls.push(importedModule.url);\n\t\t\t}\n\t\t}\n\t}\n\tdebugDevServer(`transformed ${transformedUrls.size} plugin modules`);\n}\n\nexport async function startVettaPluginDevServer(\n\trootDir: string,\n\tonEvent: (event: VettaPluginDevEvent) => void,\n): Promise<VettaPluginDevServer> {\n\tprocess.env.VETTA_PLUGIN_DEV_SERVER = \"1\";\n\tsetVettaPluginDevEventListener(onEvent);\n\n\tlet manifest = await readManifest(rootDir);\n\tlet watchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\tconst port = await findAvailablePort();\n\tconst server = await createServer({\n\t\troot: rootDir,\n\t\tconfigFile: resolveViteConfigFile(rootDir),\n\t\tlogLevel: \"silent\",\n\t\tserver: {\n\t\t\thost: \"127.0.0.1\",\n\t\t\tport,\n\t\t\tstrictPort: true,\n\t\t\t// Module Federation derives dev share/import URLs from Vite's origin.\n\t\t\t// Pin it to the same loopback endpoint we advertise to the host instead\n\t\t\t// of letting Vite infer a hostname (which can become `localhost` or a\n\t\t\t// LAN address on Windows and make the browser fetch the wrong module).\n\t\t\torigin: `http://127.0.0.1:${port}`,\n\t\t\tcors: true,\n\t\t\thmr: { overlay: false },\n\t\t},\n\t});\n\tdebugDevServer(\"vite server created\");\n\tlet refreshTimer: ReturnType<typeof setTimeout> | undefined;\n\tconst resourceWatcher = watch(watchedResourceRoots, { ignoreInitial: true });\n\tresourceWatcher.on(\"error\", (error) => {\n\t\temitVettaPluginDevEvent({\n\t\t\ttype: \"error\",\n\t\t\tpluginId: manifest.id,\n\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t});\n\t});\n\tresourceWatcher.on(\"all\", (_event, changedPath) => {\n\t\tconst absolutePath = resolve(changedPath);\n\t\tif (!watchedResourceRoots.some((watchedPath) => isInsidePath(absolutePath, watchedPath))) return;\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\trefreshTimer = setTimeout(() => {\n\t\t\tvoid (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tif (absolutePath === resolve(rootDir, \"plugin.json\")) {\n\t\t\t\t\t\tmanifest = await readManifest(rootDir);\n\t\t\t\t\t\tconst nextWatchedResourceRoots = await collectWatchedResourceRoots(rootDir, manifest);\n\t\t\t\t\t\tconst removedRoots = watchedResourceRoots.filter((path) => !nextWatchedResourceRoots.includes(path));\n\t\t\t\t\t\tif (removedRoots.length > 0) await resourceWatcher.unwatch(removedRoots);\n\t\t\t\t\t\tresourceWatcher.add(nextWatchedResourceRoots);\n\t\t\t\t\t\twatchedResourceRoots = nextWatchedResourceRoots;\n\t\t\t\t\t}\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"update\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\treason: \"resource\",\n\t\t\t\t\t\tpath: relative(rootDir, absolutePath).replaceAll(\"\\\\\", \"/\"),\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\temitVettaPluginDevEvent({\n\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\tpluginId: manifest.id,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t}, 80);\n\t});\n\n\tlet origin: string;\n\tlet entryUrl: string;\n\ttry {\n\t\tassertDevPluginsConfigured(server);\n\t\tdebugDevServer(\"starting vite listener\");\n\t\tawait server.listen();\n\t\tdebugDevServer(\"vite listener ready\");\n\t\torigin = resolveServerOrigin(server);\n\t\tentryUrl = `${origin}/mf-manifest.json`;\n\t\tdebugDevServer(`probing ${entryUrl}`);\n\t\tawait assertDevEntryAvailable(entryUrl);\n\t\tdebugDevServer(\"probing plugin module graph\");\n\t\tawait assertDevModuleGraphAvailable(server, rootDir);\n\t\tdebugDevServer(\"plugin entry ready\");\n\t} catch (error) {\n\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\tsetVettaPluginDevEventListener(undefined);\n\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\tthrow error;\n\t}\n\tconst readyEvent: VettaPluginDevEvent = {\n\t\ttype: \"ready\",\n\t\tprotocolVersion: VETTA_PLUGIN_DEV_PROTOCOL_VERSION,\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t};\n\tonEvent(readyEvent);\n\n\treturn {\n\t\tpluginId: manifest.id,\n\t\tentryUrl,\n\t\torigin,\n\t\tasync close() {\n\t\t\tif (refreshTimer) clearTimeout(refreshTimer);\n\t\t\tsetVettaPluginDevEventListener(undefined);\n\t\t\tawait Promise.all([resourceWatcher.close(), server.close()]);\n\t\t},\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AAQjD,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,WAAW,CAAC;AAQ3F,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,+BAA+B,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9G,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,4BAA4B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gFAAgF;IAChF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;CAC9C;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,4BAA4B,GAAG,uBAAuB,CAsDhH;AAyHD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,YAAY,EAAE,CAwB3F","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the narrow host UI contract exposed by `@vetta/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\"@vetta/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\"@vetta-org/plugin-sdk\", \"@vetta/ui\", \"@vetta/theme-ui/plugin-ui\"],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AAQjD,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,WAAW,CAAC;AAQ3F,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,+BAA+B,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9G,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,4BAA4B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gFAAgF;IAChF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;CAC9C;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,4BAA4B,GAAG,uBAAuB,CA6DhH;AAgID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,YAAY,EAAE,CAwB3F","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the narrow host UI contract exposed by `@vetta/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\"@vetta-org/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// 这个包 0.1.0 之前叫 @vetta/ui。名字同时是 MF 的共享键,只留新名会让按旧名\n\t\t\t// 构建的既有插件在共享域里落空、退回自己打包的那一份(两份 React 组件实例)。\n\t\t\t\"@vetta/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\n\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\",\n\t\t\t\t\t\t\t\"@vetta-org/ui\",\n\t\t\t\t\t\t\t// 旧名仍然外置:否则用旧名写的插件源码会把整个 UI 库打进产物。\n\t\t\t\t\t\t\t\"@vetta/ui\",\n\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta-org/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
package/dist/index.js CHANGED
@@ -47,6 +47,13 @@ export function createVettaPluginFederationConfig(options) {
47
47
  requiredVersion: "*",
48
48
  },
49
49
  // Host design-system primitives; runtime provided by desktop-app share scope.
50
+ "@vetta-org/ui": {
51
+ singleton: true,
52
+ import: false,
53
+ requiredVersion: "*",
54
+ },
55
+ // 这个包 0.1.0 之前叫 @vetta/ui。名字同时是 MF 的共享键,只留新名会让按旧名
56
+ // 构建的既有插件在共享域里落空、退回自己打包的那一份(两份 React 组件实例)。
50
57
  "@vetta/ui": {
51
58
  singleton: true,
52
59
  import: false,
@@ -81,7 +88,13 @@ function createBuildDefaultsPlugin(entry) {
81
88
  rollupOptions: {
82
89
  input: entry,
83
90
  // Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).
84
- external: ["@vetta-org/plugin-sdk", "@vetta/ui", "@vetta/theme-ui/plugin-ui"],
91
+ external: [
92
+ "@vetta-org/plugin-sdk",
93
+ "@vetta-org/ui",
94
+ // 旧名仍然外置:否则用旧名写的插件源码会把整个 UI 库打进产物。
95
+ "@vetta/ui",
96
+ "@vetta/theme-ui/plugin-ui",
97
+ ],
85
98
  output: {
86
99
  assetFileNames(assetInfo) {
87
100
  return assetInfo.names.some((name) => name.endsWith(".css"))
@@ -90,6 +103,7 @@ function createBuildDefaultsPlugin(entry) {
90
103
  },
91
104
  paths: {
92
105
  "@vetta-org/plugin-sdk": "vetta-host://plugin-sdk",
106
+ "@vetta-org/ui": "vetta-host://ui",
93
107
  "@vetta/ui": "vetta-host://ui",
94
108
  "@vetta/theme-ui/plugin-ui": "vetta-host://theme-ui-plugin",
95
109
  },
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EACN,2BAA2B,EAC3B,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAwC,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC3F,OA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EAAE,CAAC;IAC3C,MAAM,OAAO,GAAmB;QAC/B,8BAA8B,EAAE;QAChC,2BAA2B,EAAE;QAC7B,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,yBAAyB,CAAC,KAAK,CAAC;QAChC,qCAAqC,EAAE;QACvC,GAAG,UAAU,CAAC;YACb,GAAG,iCAAiC,CAAC,OAAO,CAAC;YAC7C,OAAO,EAAE;gBACR,CAAC,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,KAAK;aAC7E;SACD,CAAC;QACF,4BAA4B,EAAE;QAC9B,8BAA8B,EAAE;KAChC,CAAC;IACF,6EAAuC;IACvC,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,GAAG,EAAE,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the narrow host UI contract exposed by `@vetta/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\"@vetta/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\"@vetta-org/plugin-sdk\", \"@vetta/ui\", \"@vetta/theme-ui/plugin-ui\"],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EACN,2BAA2B,EAC3B,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAwC,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC3F,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,+BAA+B,GAAG,4CAA4C,CAAC;AACrF,MAAM,wCAAwC,GAAG,KAAK,+BAA+B,EAAE,CAAC;AACxF,MAAM,4BAA4B,GAAG,uCAAuC,CAAC;AAkB7E,MAAM,UAAU,iCAAiC,CAAC,OAAqC,EAA2B;IACjH,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;IAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,iBAAiB,CAAC;IACjD,OAAO;QACN,I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G,UAAU,CAAC;YACb,GAAG,iCAAiC,CAAC,OAAO,CAAC;YAC7C,OAAO,EAAE;gBACR,CAAC,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,KAAK;aAC7E;SACD,CAAC;QACF,4BAA4B,EAAE;QAC9B,8BAA8B,EAAE;KAChC,CAAC;IACF,6EAAuC;IACvC,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,GAAG,EAAE,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the narrow host UI contract exposed by `@vetta/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\"@vetta-org/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// 这个包 0.1.0 之前叫 @vetta/ui。名字同时是 MF 的共享键,只留新名会让按旧名\n\t\t\t// 构建的既有插件在共享域里落空、退回自己打包的那一份(两份 React 组件实例)。\n\t\t\t\"@vetta/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\n\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\",\n\t\t\t\t\t\t\t\"@vetta-org/ui\",\n\t\t\t\t\t\t\t// 旧名仍然外置:否则用旧名写的插件源码会把整个 UI 库打进产物。\n\t\t\t\t\t\t\t\"@vetta/ui\",\n\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta-org/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vetta-org/plugin-vite",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "postcss-selector-parser": "^7.1.4"
35
35
  },
36
36
  "peerDependencies": {
37
- "@vetta-org/plugin-sdk": ">=0.2.0 <0.3.0",
37
+ "@vetta-org/plugin-sdk": ">=0.3.0 <0.4.0",
38
38
  "vite": "^7.0.0"
39
39
  },
40
40
  "devDependencies": {