@plugmatica/plugin-build 0.0.0-stage → 0.1.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.
Files changed (128) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-APACHE +202 -0
  3. package/README.md +221 -2
  4. package/dev-target/README.md +20 -0
  5. package/dev-target/compose.yaml +119 -0
  6. package/dist/chunk-EOLUQEKQ.js +587 -0
  7. package/dist/chunk-QHTGR4ZB.js +9378 -0
  8. package/dist/chunk-TQNG5OZ3.js +3135 -0
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.js +2606 -0
  11. package/dist/index.d.ts +2144 -0
  12. package/dist/index.js +230 -0
  13. package/dist/vite-WRwB4IG8.d.ts +929 -0
  14. package/dist/vite.d.ts +3 -0
  15. package/dist/vite.js +20 -0
  16. package/package.json +94 -4
  17. package/templates/README.md +29 -0
  18. package/templates/backend-capabilities/LICENSE.txt +231 -0
  19. package/templates/backend-capabilities/backend/Cargo.toml +21 -0
  20. package/templates/backend-capabilities/backend/src/lib.rs +179 -0
  21. package/templates/backend-capabilities/backend/tests/basic.rs +174 -0
  22. package/templates/backend-capabilities/manifest.source.json +64 -0
  23. package/templates/backend-capabilities/package.json +22 -0
  24. package/templates/backend-composition/LICENSE.txt +231 -0
  25. package/templates/backend-composition/backend/Cargo.toml +21 -0
  26. package/templates/backend-composition/backend/src/lib.rs +96 -0
  27. package/templates/backend-composition/backend/tests/basic.rs +75 -0
  28. package/templates/backend-composition/manifest.source.json +26 -0
  29. package/templates/backend-composition/package.json +22 -0
  30. package/templates/backend-entities/LICENSE.txt +231 -0
  31. package/templates/backend-entities/backend/Cargo.toml +20 -0
  32. package/templates/backend-entities/backend/src/lib.rs +77 -0
  33. package/templates/backend-entities/backend/tests/basic.rs +26 -0
  34. package/templates/backend-entities/manifest.source.json +15 -0
  35. package/templates/backend-entities/package.json +22 -0
  36. package/templates/backend-minimal/LICENSE.txt +231 -0
  37. package/templates/backend-minimal/backend/Cargo.toml +21 -0
  38. package/templates/backend-minimal/backend/src/lib.rs +69 -0
  39. package/templates/backend-minimal/backend/tests/basic.rs +67 -0
  40. package/templates/backend-minimal/manifest.source.json +15 -0
  41. package/templates/backend-minimal/package.json +22 -0
  42. package/templates/backend-operations/LICENSE.txt +231 -0
  43. package/templates/backend-operations/backend/Cargo.toml +21 -0
  44. package/templates/backend-operations/backend/src/lib.rs +117 -0
  45. package/templates/backend-operations/backend/tests/basic.rs +169 -0
  46. package/templates/backend-operations/manifest.source.json +15 -0
  47. package/templates/backend-operations/package.json +22 -0
  48. package/templates/frontend-entity/LICENSE.txt +27 -0
  49. package/templates/frontend-entity/README.md +46 -0
  50. package/templates/frontend-entity/frontend/i18n/en-GB.json +5 -0
  51. package/templates/frontend-entity/frontend/package.json +32 -0
  52. package/templates/frontend-entity/frontend/src/CustomerListPage.tsx +98 -0
  53. package/templates/frontend-entity/frontend/src/model.ts +5 -0
  54. package/templates/frontend-entity/frontend/tests/entityLifecycle.test.tsx +79 -0
  55. package/templates/frontend-entity/frontend/tsconfig.json +4 -0
  56. package/templates/frontend-entity/frontend/vite.config.ts +3 -0
  57. package/templates/frontend-entity/frontend/vitest.config.ts +9 -0
  58. package/templates/frontend-entity/manifest.source.json +53 -0
  59. package/templates/frontend-entity/package.json +22 -0
  60. package/templates/frontend-entity/pnpm-workspace.yaml +2 -0
  61. package/templates/frontend-extension/LICENSE.txt +27 -0
  62. package/templates/frontend-extension/README.md +7 -0
  63. package/templates/frontend-extension/frontend/i18n/en-GB.json +4 -0
  64. package/templates/frontend-extension/frontend/package.json +25 -0
  65. package/templates/frontend-extension/frontend/src/CustomerNotes.tsx +24 -0
  66. package/templates/frontend-extension/frontend/tsconfig.json +4 -0
  67. package/templates/frontend-extension/frontend/vite.config.ts +3 -0
  68. package/templates/frontend-extension/manifest.source.json +16 -0
  69. package/templates/frontend-extension/package.json +22 -0
  70. package/templates/frontend-extension/pnpm-workspace.yaml +2 -0
  71. package/templates/frontend-minimal/LICENSE.txt +27 -0
  72. package/templates/frontend-minimal/README.md +5 -0
  73. package/templates/frontend-minimal/frontend/i18n/en-GB.json +4 -0
  74. package/templates/frontend-minimal/frontend/package.json +25 -0
  75. package/templates/frontend-minimal/frontend/src/Page.tsx +16 -0
  76. package/templates/frontend-minimal/frontend/src/entry.ts +1 -0
  77. package/templates/frontend-minimal/frontend/tsconfig.json +4 -0
  78. package/templates/frontend-minimal/frontend/vite.config.ts +3 -0
  79. package/templates/frontend-minimal/manifest.source.json +51 -0
  80. package/templates/frontend-minimal/package.json +22 -0
  81. package/templates/frontend-minimal/pnpm-workspace.yaml +2 -0
  82. package/templates/frontend-provider-event/LICENSE.txt +27 -0
  83. package/templates/frontend-provider-event/README.md +7 -0
  84. package/templates/frontend-provider-event/frontend/i18n/en-GB.json +3 -0
  85. package/templates/frontend-provider-event/frontend/package.json +25 -0
  86. package/templates/frontend-provider-event/frontend/src/CustomerBadgeProvider.ts +24 -0
  87. package/templates/frontend-provider-event/frontend/src/CustomerSavedHandler.ts +22 -0
  88. package/templates/frontend-provider-event/frontend/tsconfig.json +4 -0
  89. package/templates/frontend-provider-event/frontend/vite.config.ts +3 -0
  90. package/templates/frontend-provider-event/manifest.source.json +16 -0
  91. package/templates/frontend-provider-event/package.json +22 -0
  92. package/templates/frontend-provider-event/pnpm-workspace.yaml +2 -0
  93. package/templates/full-stack-minimal/LICENSE.txt +231 -0
  94. package/templates/full-stack-minimal/README.md +49 -0
  95. package/templates/full-stack-minimal/backend/Cargo.toml +18 -0
  96. package/templates/full-stack-minimal/backend/src/lib.rs +49 -0
  97. package/templates/full-stack-minimal/backend/tests/basic.rs +49 -0
  98. package/templates/full-stack-minimal/frontend/i18n/en-GB.json +6 -0
  99. package/templates/full-stack-minimal/frontend/package.json +25 -0
  100. package/templates/full-stack-minimal/frontend/src/Page.tsx +29 -0
  101. package/templates/full-stack-minimal/frontend/src/entry.ts +1 -0
  102. package/templates/full-stack-minimal/frontend/tsconfig.json +4 -0
  103. package/templates/full-stack-minimal/frontend/vite.config.ts +3 -0
  104. package/templates/full-stack-minimal/manifest.source.json +55 -0
  105. package/templates/full-stack-minimal/package.json +24 -0
  106. package/templates/full-stack-minimal/pnpm-workspace.yaml +2 -0
  107. package/templates/full-stack-workflow-node/LICENSE.txt +231 -0
  108. package/templates/full-stack-workflow-node/README.md +111 -0
  109. package/templates/full-stack-workflow-node/backend/Cargo.toml +12 -0
  110. package/templates/full-stack-workflow-node/backend/src/lib.rs +70 -0
  111. package/templates/full-stack-workflow-node/frontend/i18n/en-GB.json +10 -0
  112. package/templates/full-stack-workflow-node/frontend/package.json +29 -0
  113. package/templates/full-stack-workflow-node/frontend/src/editors/FormatLabelEditor.tsx +25 -0
  114. package/templates/full-stack-workflow-node/frontend/src/entry.ts +2 -0
  115. package/templates/full-stack-workflow-node/frontend/src/nodes/FormatLabel.tsx +18 -0
  116. package/templates/full-stack-workflow-node/frontend/src/presentations/FormatLabelPresentation.tsx +7 -0
  117. package/templates/full-stack-workflow-node/frontend/tsconfig.json +4 -0
  118. package/templates/full-stack-workflow-node/frontend/vite.config.ts +5 -0
  119. package/templates/full-stack-workflow-node/manifest.source.json +18 -0
  120. package/templates/full-stack-workflow-node/package.json +25 -0
  121. package/templates/full-stack-workflow-node/pnpm-workspace.yaml +2 -0
  122. package/templates/localization-fr-fr/LICENSE.txt +27 -0
  123. package/templates/localization-fr-fr/README.md +5 -0
  124. package/templates/localization-fr-fr/localization/plugmatica.customer.fr-FR.json +4 -0
  125. package/templates/localization-fr-fr/manifest.source.json +36 -0
  126. package/templates/localization-fr-fr/package.json +18 -0
  127. package/templates/starter-projection.json +448 -0
  128. package/tsconfig.plugin.json +14 -0
@@ -0,0 +1,587 @@
1
+ import {
2
+ PLUGMATICA_FRONTEND_POLICY,
3
+ compilePluginSource,
4
+ compilerPageRoutesFromManifest,
5
+ formatScanIssues,
6
+ generatePluginManifest,
7
+ transformCompiledSource
8
+ } from "./chunk-QHTGR4ZB.js";
9
+
10
+ // src/vite/manifest-plugin.ts
11
+ import fs from "fs";
12
+ import path from "path";
13
+ function plugmaticaManifestPlugin(options = {}) {
14
+ let viteRoot = process.cwd();
15
+ let viteCommand = "build";
16
+ let compiled = null;
17
+ let devtoolsArtifactPath = null;
18
+ const paths = () => {
19
+ const root = path.resolve(options.root ?? path.join(viteRoot, ".."));
20
+ return {
21
+ root,
22
+ sourceDir: path.resolve(root, options.sourceDir ?? "frontend/src"),
23
+ manifestPath: path.resolve(
24
+ root,
25
+ options.manifestPath ?? "manifest.source.json"
26
+ ),
27
+ outputPath: path.resolve(root, options.outputPath ?? "manifest.json")
28
+ };
29
+ };
30
+ const run = () => {
31
+ const resolved = paths();
32
+ const sourceManifest = JSON.parse(
33
+ fs.readFileSync(resolved.manifestPath, "utf8")
34
+ );
35
+ compiled = compilePluginSource(resolved.sourceDir, {
36
+ pageRoutes: compilerPageRoutesFromManifest(sourceManifest)
37
+ });
38
+ const result = generatePluginManifest({
39
+ sourceDir: resolved.sourceDir,
40
+ manifestPath: resolved.manifestPath,
41
+ outputPath: resolved.outputPath,
42
+ failOnWarnings: options.failOnWarnings,
43
+ backendDescriptorPath: options.backendDescriptorPath,
44
+ compilerResult: compiled,
45
+ targets: options.targets,
46
+ currentContract: options.currentContract,
47
+ devtools: options.devtools ?? { emit: viteCommand === "serve" },
48
+ docs: options.docs,
49
+ graph: options.graph,
50
+ i18n: options.i18n
51
+ });
52
+ devtoolsArtifactPath = result.devtoolsArtifactPath ?? null;
53
+ for (const issue of result.issues) {
54
+ if (issue.severity === "warning") {
55
+ console.warn(formatScanIssues([issue]));
56
+ }
57
+ }
58
+ console.info(
59
+ `[plugmatica] compiled ${result.surfaceCount} extension surface(s), ${result.compilerResult.nodes.length} semantic node(s) and ${result.i18nMessageCount} i18n reference(s) in ${result.outputPath}`
60
+ );
61
+ return resolved;
62
+ };
63
+ const ensureCurrentCompilation = (id, code) => {
64
+ const absolute = path.resolve(stripViteQuery(id));
65
+ let file = compiled?.files.find(
66
+ (candidate) => path.resolve(candidate.absoluteFile) === absolute
67
+ );
68
+ if (!file || file.sourceText !== code) {
69
+ run();
70
+ file = compiled?.files.find(
71
+ (candidate) => path.resolve(candidate.absoluteFile) === absolute
72
+ );
73
+ }
74
+ if (file && file.sourceText !== code) {
75
+ throw new Error(
76
+ `[plugmatica] source for '${absolute}' changed before the compiler transform. Plugmatica must run as an enforce:'pre' compiler so manifest and runtime metadata use the same source snapshot.`
77
+ );
78
+ }
79
+ return file ?? null;
80
+ };
81
+ return {
82
+ name: "plugmatica-frontend-compiler",
83
+ enforce: "pre",
84
+ configResolved(config) {
85
+ viteRoot = config.root;
86
+ viteCommand = config.command;
87
+ },
88
+ configureServer(server) {
89
+ server.middlewares.use((request, response, next) => {
90
+ const requestPath = request.url?.split("?", 1)[0];
91
+ if (requestPath === "/__plugmatica/devtools/extensions.json") {
92
+ try {
93
+ if (!devtoolsArtifactPath || !fs.existsSync(devtoolsArtifactPath)) {
94
+ run();
95
+ }
96
+ if (!devtoolsArtifactPath || !fs.existsSync(devtoolsArtifactPath)) {
97
+ response.statusCode = 404;
98
+ response.end();
99
+ return;
100
+ }
101
+ response.setHeader(
102
+ "Content-Type",
103
+ "application/json; charset=utf-8"
104
+ );
105
+ response.setHeader("Cache-Control", "no-store");
106
+ response.end(fs.readFileSync(devtoolsArtifactPath, "utf8"));
107
+ return;
108
+ } catch (error) {
109
+ response.statusCode = 500;
110
+ response.setHeader(
111
+ "Content-Type",
112
+ "application/json; charset=utf-8"
113
+ );
114
+ response.end(
115
+ JSON.stringify({
116
+ error: error instanceof Error ? error.message : String(error)
117
+ })
118
+ );
119
+ return;
120
+ }
121
+ }
122
+ if (requestPath === "/__plugmatica/devtools/compatibility.json") {
123
+ const compatibilityPath = path.join(
124
+ paths().root,
125
+ "frontend/generated/compatibility-report.json"
126
+ );
127
+ if (!fs.existsSync(compatibilityPath)) {
128
+ response.statusCode = 404;
129
+ response.end();
130
+ return;
131
+ }
132
+ response.setHeader("Content-Type", "application/json; charset=utf-8");
133
+ response.setHeader("Cache-Control", "no-store");
134
+ response.end(fs.readFileSync(compatibilityPath, "utf8"));
135
+ return;
136
+ }
137
+ next();
138
+ });
139
+ },
140
+ buildStart() {
141
+ run();
142
+ },
143
+ transform(code, id) {
144
+ const cleanId = stripViteQuery(id);
145
+ if (!/\.(tsx|jsx)$/.test(cleanId)) return null;
146
+ const resolved = paths();
147
+ const absolute = path.resolve(cleanId);
148
+ const relative = path.relative(resolved.sourceDir, absolute);
149
+ if (relative.startsWith("..") || path.isAbsolute(relative)) return null;
150
+ const file = ensureCurrentCompilation(cleanId, code);
151
+ if (!file || file.nodes.every((node) => !node.runtime)) return null;
152
+ return {
153
+ code: transformCompiledSource(code, file),
154
+ map: null
155
+ };
156
+ },
157
+ handleHotUpdate(context) {
158
+ const resolved = paths();
159
+ const sourceRelative = path.relative(resolved.sourceDir, context.file);
160
+ const frontendRoot = path.join(resolved.root, "frontend");
161
+ const i18nRelative = path.relative(
162
+ path.join(frontendRoot, "i18n"),
163
+ context.file
164
+ );
165
+ const fragmentsRelative = path.relative(
166
+ path.join(frontendRoot, "i18n-src"),
167
+ context.file
168
+ );
169
+ const sourceChanged = !sourceRelative.startsWith("..") && !path.isAbsolute(sourceRelative) && /\.(tsx|jsx)$/.test(context.file);
170
+ const localeChanged = [i18nRelative, fragmentsRelative].some(
171
+ (relative) => !relative.startsWith("..") && !path.isAbsolute(relative) && context.file.endsWith(".json")
172
+ );
173
+ if (sourceChanged || localeChanged) run();
174
+ }
175
+ };
176
+ }
177
+ function stripViteQuery(id) {
178
+ const index = id.indexOf("?");
179
+ return index >= 0 ? id.slice(0, index) : id;
180
+ }
181
+
182
+ // src/vite/shared.ts
183
+ var PLUGMATICA_FEDERATION_SHARED_VERSIONS = {
184
+ react: PLUGMATICA_FRONTEND_POLICY.packages["react"],
185
+ "react-dom": PLUGMATICA_FRONTEND_POLICY.packages["react-dom"],
186
+ "react-hook-form": PLUGMATICA_FRONTEND_POLICY.packages["react-hook-form"],
187
+ "@xyflow/react": PLUGMATICA_FRONTEND_POLICY.packages["@xyflow/react"],
188
+ "@tanstack/react-query": PLUGMATICA_FRONTEND_POLICY.packages["@tanstack/react-query"],
189
+ "@plugmatica/core-sdk": PLUGMATICA_FRONTEND_POLICY.packages["@plugmatica/core-sdk"],
190
+ "@plugmatica/i18n": PLUGMATICA_FRONTEND_POLICY.packages["@plugmatica/i18n"],
191
+ "@plugmatica/plugin-sdk": PLUGMATICA_FRONTEND_POLICY.packages["@plugmatica/plugin-sdk"],
192
+ "@plugmatica/ui-kit": PLUGMATICA_FRONTEND_POLICY.packages["@plugmatica/ui-kit"],
193
+ "@plugmatica/data-viz": PLUGMATICA_FRONTEND_POLICY.packages["@plugmatica/data-viz"],
194
+ "@plugmatica/graph": PLUGMATICA_FRONTEND_POLICY.packages["@plugmatica/graph"]
195
+ };
196
+ function plugmaticaFederationShared(options = {}) {
197
+ const includeReactQuery = options.includeReactQuery ?? true;
198
+ const includeDataViz = options.includeDataViz ?? true;
199
+ const config = {};
200
+ for (const [name, requiredVersion] of Object.entries(
201
+ PLUGMATICA_FEDERATION_SHARED_VERSIONS
202
+ )) {
203
+ if (name === "@tanstack/react-query" && !includeReactQuery) continue;
204
+ if (name === "@plugmatica/data-viz" && !includeDataViz) continue;
205
+ config[name] = shared(requiredVersion);
206
+ }
207
+ config["@plugmatica/ui-kit/host"] = shared(
208
+ PLUGMATICA_FEDERATION_SHARED_VERSIONS["@plugmatica/ui-kit"]
209
+ );
210
+ config["@plugmatica/ui-kit/semantic"] = shared(
211
+ PLUGMATICA_FEDERATION_SHARED_VERSIONS["@plugmatica/ui-kit"]
212
+ );
213
+ config["react/"] = shared(PLUGMATICA_FEDERATION_SHARED_VERSIONS.react);
214
+ config["react-dom/"] = shared(
215
+ PLUGMATICA_FEDERATION_SHARED_VERSIONS["react-dom"]
216
+ );
217
+ config["react-hook-form/"] = shared(
218
+ PLUGMATICA_FEDERATION_SHARED_VERSIONS["react-hook-form"]
219
+ );
220
+ return config;
221
+ }
222
+ function plugmaticaFederationDedupe(options = {}) {
223
+ const includeReactQuery = options.includeReactQuery ?? true;
224
+ const includeDataViz = options.includeDataViz ?? true;
225
+ return [
226
+ "react",
227
+ "react-dom",
228
+ "react-hook-form",
229
+ "@xyflow/react",
230
+ ...includeReactQuery ? ["@tanstack/react-query"] : [],
231
+ "@plugmatica/core-sdk",
232
+ "@plugmatica/i18n",
233
+ "@plugmatica/plugin-sdk",
234
+ "@plugmatica/ui-kit",
235
+ ...includeDataViz ? ["@plugmatica/data-viz"] : [],
236
+ "@plugmatica/graph"
237
+ ];
238
+ }
239
+ var PLUGMATICA_FEDERATION_DEDUPE = plugmaticaFederationDedupe();
240
+ function shared(requiredVersion) {
241
+ return {
242
+ singleton: true,
243
+ requiredVersion,
244
+ allowNodeModulesSuffixMatch: true
245
+ };
246
+ }
247
+
248
+ // src/vite/config.ts
249
+ import fs4 from "fs";
250
+ import path4 from "path";
251
+ import { federation } from "@module-federation/vite";
252
+ import react from "@vitejs/plugin-react";
253
+
254
+ // src/vite/remote-policy.ts
255
+ import fs2 from "fs";
256
+ import path2 from "path";
257
+ var ALWAYS_SHARED = /* @__PURE__ */ new Set(["react", "react-dom"]);
258
+ var SHARED_ALIASES = {
259
+ "react-hook-form": ["react-hook-form/"],
260
+ "@plugmatica/ui-kit": [
261
+ "@plugmatica/ui-kit/host",
262
+ "@plugmatica/ui-kit/semantic"
263
+ ]
264
+ };
265
+ function plugmaticaRemoteFederationPolicy(frontendRoot) {
266
+ const shared2 = plugmaticaFederationShared();
267
+ const dedupe = [];
268
+ for (const packageName of PLUGMATICA_FEDERATION_DEDUPE) {
269
+ const include = ALWAYS_SHARED.has(packageName) || canResolveFromFrontend(packageName, frontendRoot);
270
+ if (include) {
271
+ dedupe.push(packageName);
272
+ continue;
273
+ }
274
+ delete shared2[packageName];
275
+ for (const alias of SHARED_ALIASES[packageName] ?? []) {
276
+ delete shared2[alias];
277
+ }
278
+ }
279
+ if (shared2["@plugmatica/data-viz"]) {
280
+ shared2["@plugmatica/data-viz"] = {
281
+ ...shared2["@plugmatica/data-viz"],
282
+ import: false
283
+ };
284
+ }
285
+ return { shared: shared2, dedupe };
286
+ }
287
+ function canResolveFromFrontend(packageName, frontendRoot) {
288
+ const candidates = [
289
+ path2.join(frontendRoot, "node_modules", packageName, "package.json"),
290
+ path2.join(
291
+ path2.dirname(frontendRoot),
292
+ "node_modules",
293
+ packageName,
294
+ "package.json"
295
+ )
296
+ ];
297
+ if (candidates.some((candidate) => fs2.existsSync(candidate))) return true;
298
+ let current = frontendRoot;
299
+ for (; ; ) {
300
+ if (fs2.existsSync(
301
+ path2.join(current, "node_modules", packageName, "package.json")
302
+ )) {
303
+ return true;
304
+ }
305
+ const parent = path2.dirname(current);
306
+ if (parent === current) return false;
307
+ current = parent;
308
+ }
309
+ }
310
+
311
+ // src/vite/chart-engine-boundary.ts
312
+ import fs3 from "fs";
313
+ import path3 from "path";
314
+ function forbidDirectChartEngineImports(frontendRoot) {
315
+ const root = path3.resolve(frontendRoot);
316
+ return {
317
+ name: "plugmatica-data-viz-boundary",
318
+ enforce: "pre",
319
+ resolveId(source, importer) {
320
+ if (!importer || !path3.isAbsolute(importer)) return null;
321
+ const file = importer.split(/[?#]/, 1)[0];
322
+ const relative = path3.relative(root, file);
323
+ if (relative === ".." || relative.startsWith(`..${path3.sep}`) || path3.isAbsolute(relative)) return null;
324
+ const echarts = source === "echarts" || source.startsWith("echarts/");
325
+ const zrender = source === "zrender" || source.startsWith("zrender/");
326
+ if (echarts || zrender || source.startsWith("echarts-")) {
327
+ const owner = installedRendererOwner(root, relative, file);
328
+ if (owner === "@plugmatica/data-viz" && echarts || owner === "echarts" && (echarts || zrender) || owner === "zrender" && zrender) return null;
329
+ throw new Error(
330
+ `[plugmatica] Plugin source must not import '${source}' directly. Use the strict @plugmatica/data-viz API so chart theming, accessibility and runtime compatibility remain platform-owned. Importer: ${file}`
331
+ );
332
+ }
333
+ if (source.startsWith("@plugmatica/data-viz/") && source !== "@plugmatica/data-viz/styles.css") {
334
+ throw new Error(
335
+ `[plugmatica] Plugin source must not import private Data Viz subpath '${source}'. Import components and public types from '@plugmatica/data-viz'; only '@plugmatica/data-viz/styles.css' is a supported subpath. Importer: ${file}`
336
+ );
337
+ }
338
+ return null;
339
+ }
340
+ };
341
+ }
342
+ function installedRendererOwner(root, relative, file) {
343
+ const parts = relative.split(path3.sep);
344
+ const start = parts.lastIndexOf("node_modules") + 1;
345
+ if (!start) return void 0;
346
+ const end = start + (parts[start]?.startsWith("@") ? 2 : 1);
347
+ const owner = parts.slice(start, end).join("/");
348
+ if (owner !== "@plugmatica/data-viz" && owner !== "echarts" && owner !== "zrender") return void 0;
349
+ if (parts.length <= end) return void 0;
350
+ try {
351
+ const manifest = JSON.parse(
352
+ fs3.readFileSync(path3.join(root, ...parts.slice(0, end), "package.json"), "utf8")
353
+ );
354
+ if (manifest.name === owner && fs3.statSync(file).isFile()) return owner;
355
+ } catch {
356
+ }
357
+ return void 0;
358
+ }
359
+
360
+ // src/vite/config.ts
361
+ var VIRTUAL_ENTRY = "virtual:plugmatica-plugin-entry";
362
+ var RESOLVED_VIRTUAL_ENTRY = `\0${VIRTUAL_ENTRY}`;
363
+ var REMOTE_ENTRY = "remoteEntry.js";
364
+ var EXPECTED_ENTRY_POINT = `frontend/${REMOTE_ENTRY}`;
365
+ function definePlugmaticaPluginConfig(options = {}) {
366
+ const pluginRoot = resolvePluginRoot(options.root);
367
+ const frontendRoot = path4.join(pluginRoot, "frontend");
368
+ const manifestPath = path4.resolve(
369
+ pluginRoot,
370
+ options.manifestPath ?? "manifest.source.json"
371
+ );
372
+ const manifest = readSourceManifest(manifestPath);
373
+ const frontend = requireFrontendConfig(manifest, manifestPath);
374
+ const moduleName = requiredString(
375
+ frontend.moduleName,
376
+ "frontend.moduleName",
377
+ manifestPath
378
+ );
379
+ const entryPoint = requiredString(
380
+ frontend.entryPoint,
381
+ "frontend.entryPoint",
382
+ manifestPath
383
+ );
384
+ if (normaliseArtifactPath(entryPoint) !== EXPECTED_ENTRY_POINT) {
385
+ throw new Error(
386
+ `[plugmatica] ${manifestPath} declares frontend.entryPoint '${entryPoint}', but the supported Vite preset emits '${EXPECTED_ENTRY_POINT}'. Keep artifact identity in the manifest and let @plugmatica/plugin-build/vite own the federation filename.`
387
+ );
388
+ }
389
+ const federationPolicy = plugmaticaRemoteFederationPolicy(frontendRoot);
390
+ const exposes = resolveExposes(
391
+ frontendRoot,
392
+ frontend.exposes,
393
+ options.exposes,
394
+ manifestPath
395
+ );
396
+ return {
397
+ root: frontendRoot,
398
+ // Plugmatica remotes are Vite library-mode builds. Vite intentionally leaves
399
+ // process.env.* references untouched in library mode, but browser remotes do
400
+ // not have Node's `process` global. Inline the standard environment branch
401
+ // for all plugin code and shared-package fallback chunks.
402
+ define: {
403
+ "process.env.NODE_ENV": JSON.stringify(
404
+ process.env.NODE_ENV ?? "production"
405
+ )
406
+ },
407
+ plugins: [
408
+ plugmaticaManifestPlugin({
409
+ ...manifestPluginOptions(options),
410
+ root: pluginRoot,
411
+ manifestPath
412
+ }),
413
+ react(),
414
+ forbidDirectChartEngineImports(frontendRoot),
415
+ virtualPluginEntry(),
416
+ federation({
417
+ name: moduleName,
418
+ filename: REMOTE_ENTRY,
419
+ dts: false,
420
+ exposes,
421
+ shared: federationPolicy.shared
422
+ }),
423
+ ...options.plugins ?? []
424
+ ],
425
+ resolve: {
426
+ dedupe: federationPolicy.dedupe,
427
+ ...options.alias ? { alias: options.alias } : {}
428
+ },
429
+ ...options.server ? { server: options.server } : {},
430
+ build: {
431
+ outDir: path4.join(frontendRoot, "dist"),
432
+ target: PLUGMATICA_FRONTEND_POLICY.browserTarget,
433
+ minify: false,
434
+ cssCodeSplit: true,
435
+ sourcemap: true,
436
+ emptyOutDir: true,
437
+ lib: {
438
+ entry: VIRTUAL_ENTRY,
439
+ formats: ["es"]
440
+ },
441
+ // Vite resolves lib.entry against root as a filesystem path. An explicit
442
+ // bundler input preserves the virtual ID for virtualPluginEntry.resolveId.
443
+ rolldownOptions: {
444
+ input: VIRTUAL_ENTRY
445
+ },
446
+ ...options.build
447
+ }
448
+ };
449
+ }
450
+ function manifestPluginOptions(options) {
451
+ const {
452
+ exposes: _exposes,
453
+ plugins: _plugins,
454
+ server: _server,
455
+ alias: _alias,
456
+ build: _build,
457
+ ...manifestOptions
458
+ } = options;
459
+ return manifestOptions;
460
+ }
461
+ function resolvePluginRoot(explicit) {
462
+ if (explicit) return path4.resolve(explicit);
463
+ let current = path4.resolve(process.cwd());
464
+ for (; ; ) {
465
+ if (fs4.existsSync(path4.join(current, "manifest.source.json")))
466
+ return current;
467
+ const parent = path4.dirname(current);
468
+ if (parent === current) break;
469
+ current = parent;
470
+ }
471
+ throw new Error(
472
+ "[plugmatica] Could not find manifest.source.json from the current directory. Run Vite from the plugin/frontend directory or pass { root }."
473
+ );
474
+ }
475
+ function readSourceManifest(file) {
476
+ if (!fs4.existsSync(file)) {
477
+ throw new Error(`[plugmatica] Missing plugin source manifest: ${file}.`);
478
+ }
479
+ try {
480
+ return JSON.parse(fs4.readFileSync(file, "utf8"));
481
+ } catch (error) {
482
+ throw new Error(
483
+ `[plugmatica] Failed to parse ${file}: ${error instanceof Error ? error.message : String(error)}`,
484
+ { cause: error }
485
+ );
486
+ }
487
+ }
488
+ function requireFrontendConfig(manifest, file) {
489
+ if (!manifest.frontend || typeof manifest.frontend !== "object") {
490
+ throw new Error(
491
+ `[plugmatica] ${file} has no frontend configuration. The Vite plugin preset is only for plugins that publish a frontend bundle.`
492
+ );
493
+ }
494
+ return manifest.frontend;
495
+ }
496
+ function requiredString(value, field, file) {
497
+ if (typeof value !== "string" || !value.trim()) {
498
+ throw new Error(`[plugmatica] ${file} must declare non-empty ${field}.`);
499
+ }
500
+ return value.trim();
501
+ }
502
+ function resolveExposes(frontendRoot, rawExposes, overrides, manifestPath) {
503
+ if (!Array.isArray(rawExposes) || rawExposes.length === 0) {
504
+ throw new Error(
505
+ `[plugmatica] ${manifestPath} must declare at least one frontend.exposes entry for a federated frontend plugin.`
506
+ );
507
+ }
508
+ const declared = rawExposes.map((value) => {
509
+ if (typeof value !== "string" || !/^\.\/[A-Za-z0-9_./-]+$/.test(value)) {
510
+ throw new Error(
511
+ `[plugmatica] Invalid frontend.exposes value '${String(value)}' in ${manifestPath}. Exposes must look like './CustomerPage'.`
512
+ );
513
+ }
514
+ return value;
515
+ });
516
+ const declaredSet = new Set(declared);
517
+ for (const key of Object.keys(overrides ?? {})) {
518
+ if (!declaredSet.has(key)) {
519
+ throw new Error(
520
+ `[plugmatica] Vite expose override '${key}' is not declared in manifest.frontend.exposes. The manifest is the source of federation identity.`
521
+ );
522
+ }
523
+ }
524
+ return Object.fromEntries(
525
+ declared.map((expose) => [
526
+ expose,
527
+ overrides?.[expose] ? resolveExplicitExpose(frontendRoot, expose, overrides[expose]) : inferExpose(frontendRoot, expose)
528
+ ])
529
+ );
530
+ }
531
+ function resolveExplicitExpose(frontendRoot, expose, configured) {
532
+ const resolved = path4.resolve(frontendRoot, configured);
533
+ if (!fs4.existsSync(resolved) || !fs4.statSync(resolved).isFile()) {
534
+ throw new Error(
535
+ `[plugmatica] Explicit source for '${expose}' does not exist: ${resolved}.`
536
+ );
537
+ }
538
+ return resolved;
539
+ }
540
+ function inferExpose(frontendRoot, expose) {
541
+ const relative = expose.slice(2);
542
+ const source = path4.join(frontendRoot, "src", relative);
543
+ const candidates = [
544
+ `${source}.tsx`,
545
+ `${source}.ts`,
546
+ `${source}.jsx`,
547
+ `${source}.js`,
548
+ path4.join(source, "index.tsx"),
549
+ path4.join(source, "index.ts"),
550
+ path4.join(source, "index.jsx"),
551
+ path4.join(source, "index.js")
552
+ ].filter(
553
+ (candidate) => fs4.existsSync(candidate) && fs4.statSync(candidate).isFile()
554
+ );
555
+ if (candidates.length === 1) return candidates[0];
556
+ if (candidates.length > 1) {
557
+ throw new Error(
558
+ `[plugmatica] Expose '${expose}' is ambiguous. Found ${candidates.map((item) => path4.relative(frontendRoot, item)).join(", ")}. Keep only one conventional module or pass an explicit exposes override.`
559
+ );
560
+ }
561
+ throw new Error(
562
+ `[plugmatica] Could not infer a source module for '${expose}'. Expected frontend/src/${relative}.{tsx,ts,jsx,js} or frontend/src/${relative}/index.*. For an unusual layout use definePlugmaticaPluginConfig({ exposes: { "${expose}": "./src/path/to/module.tsx" } }).`
563
+ );
564
+ }
565
+ function virtualPluginEntry() {
566
+ return {
567
+ name: "plugmatica-virtual-plugin-entry",
568
+ resolveId(id) {
569
+ return id === VIRTUAL_ENTRY ? RESOLVED_VIRTUAL_ENTRY : null;
570
+ },
571
+ load(id) {
572
+ return id === RESOLVED_VIRTUAL_ENTRY ? "// Plugmatica build entry; federated exposes are the real public modules.\nexport {};\n" : null;
573
+ }
574
+ };
575
+ }
576
+ function normaliseArtifactPath(value) {
577
+ return value.replace(/\\/g, "/").replace(/^\.\//, "");
578
+ }
579
+
580
+ export {
581
+ plugmaticaManifestPlugin,
582
+ PLUGMATICA_FEDERATION_SHARED_VERSIONS,
583
+ plugmaticaFederationShared,
584
+ plugmaticaFederationDedupe,
585
+ PLUGMATICA_FEDERATION_DEDUPE,
586
+ definePlugmaticaPluginConfig
587
+ };