vite-plugin-zephyr 0.0.0-canary-20250513234234 → 0.0.0-canary-20250522231114

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 (35) hide show
  1. package/dist/lib/internal/extract/extract_mf_plugin.d.ts +6 -0
  2. package/dist/lib/internal/extract/extract_mf_plugin.js +8 -0
  3. package/dist/lib/internal/extract/extract_mf_plugin.js.map +1 -0
  4. package/dist/lib/internal/extract/extract_vite_assets_map.js.map +1 -1
  5. package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.d.ts +11 -1
  6. package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.js +8 -10
  7. package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.js.map +1 -1
  8. package/dist/lib/internal/mf-vite-etl/load_resolved_remotes.d.ts +1 -1
  9. package/dist/lib/internal/mf-vite-etl/load_resolved_remotes.js +32 -20
  10. package/dist/lib/internal/mf-vite-etl/load_resolved_remotes.js.map +1 -1
  11. package/dist/lib/internal/mf-vite-etl/runtime_plugin.d.ts +2 -0
  12. package/dist/lib/internal/mf-vite-etl/runtime_plugin.js +42 -0
  13. package/dist/lib/internal/mf-vite-etl/runtime_plugin.js.map +1 -0
  14. package/dist/lib/internal/mf-vite-etl/runtime_plugins_parser.d.ts +6 -0
  15. package/dist/lib/internal/mf-vite-etl/runtime_plugins_parser.js +48 -0
  16. package/dist/lib/internal/mf-vite-etl/runtime_plugins_parser.js.map +1 -0
  17. package/dist/lib/vite-plugin-zephyr-partial.js +6 -16
  18. package/dist/lib/vite-plugin-zephyr-partial.js.map +1 -1
  19. package/dist/lib/vite-plugin-zephyr.d.ts +1 -9
  20. package/dist/lib/vite-plugin-zephyr.js +13 -200
  21. package/dist/lib/vite-plugin-zephyr.js.map +1 -1
  22. package/dist/package.json +1 -1
  23. package/package.json +2 -2
  24. package/dist/lib/internal/extract/extract_preload_import.d.ts +0 -0
  25. package/dist/lib/internal/extract/extract_preload_import.js +0 -18
  26. package/dist/lib/internal/extract/extract_preload_import.js.map +0 -1
  27. package/dist/lib/internal/extract/extract_vite_build_stats.d.ts +0 -16
  28. package/dist/lib/internal/extract/extract_vite_build_stats.js +0 -294
  29. package/dist/lib/internal/extract/extract_vite_build_stats.js.map +0 -1
  30. package/dist/lib/internal/mf-vite-etl/preload-imports.d.ts +0 -0
  31. package/dist/lib/internal/mf-vite-etl/preload-imports.js +0 -124
  32. package/dist/lib/internal/mf-vite-etl/preload-imports.js.map +0 -1
  33. package/dist/lib/internal/mf-vite-etl/remote_map_parser.d.ts +0 -20
  34. package/dist/lib/internal/mf-vite-etl/remote_map_parser.js +0 -120
  35. package/dist/lib/internal/mf-vite-etl/remote_map_parser.js.map +0 -1
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { ModuleFederationOptions } from '../../vite-plugin-zephyr';
3
+ export interface ViteMFPlugin {
4
+ _options: ModuleFederationOptions;
5
+ }
6
+ export declare function extract_mf_plugin(plugins: readonly Plugin[]): (Plugin<any> & ViteMFPlugin) | undefined;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extract_mf_plugin = extract_mf_plugin;
4
+ function extract_mf_plugin(plugins) {
5
+ const mfPlugin = plugins.find((plugin) => plugin.name === 'module-federation-vite');
6
+ return mfPlugin;
7
+ }
8
+ //# sourceMappingURL=extract_mf_plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract_mf_plugin.js","sourceRoot":"","sources":["../../../../src/lib/internal/extract/extract_mf_plugin.ts"],"names":[],"mappings":";;AAOA,8CAKC;AALD,SAAgB,iBAAiB,CAAC,OAA0B;IAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,wBAAwB,CAErE,CAAC;IACd,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"extract_vite_assets_map.js","sourceRoot":"","sources":["../../../../src/lib/internal/extract/extract_vite_assets_map.ts"],"names":[],"mappings":";;AAWA,0DAiBC;AA5BD,+CAMsB;AAEtB,6DAAwD;AAGjD,KAAK,UAAU,uBAAuB,CAC3C,aAA2B,EAC3B,qBAA4C;IAE5C,MAAM,eAAe,GAAG,aAAa,CAAC,eAAe,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,IAAA,qCAAgB,EAAC,qBAAqB,CAAC,CAAC;IAC7D,MAAM,eAAe,GAAG,MAAM,IAAA,iCAAkB,EAAC,eAAe,CAAC,CAAC;IAClE,MAAM,IAAA,oCAAqB,EAAC,eAAe,CAAC,CAAC;IAE7C,MAAM,cAAc,GAAG,qBAAqB,CAAC,MAAM,CAAC;IACpD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CACnC,EAAE,EACF,MAAM,EACN,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,EAAE,CAAC,EACvC,cAAc,CACf,CAAC;IACF,OAAO,IAAA,6BAAc,EAAC,eAAe,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,YAAY,CAAC,KAAgC;IACpD,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED,SAAS,aAAa,CAAC,KAAgC;IACrD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,IAAI,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;gBACrC,CAAC,CAAC,KAAK,CAAC,MAAM;gBACd,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7C;YACE,OAAO,KAAK,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"extract_vite_assets_map.js","sourceRoot":"","sources":["../../../../src/lib/internal/extract/extract_vite_assets_map.ts"],"names":[],"mappings":";;AAUA,0DAiBC;AA3BD,+CAMsB;AAEtB,6DAAwD;AAEjD,KAAK,UAAU,uBAAuB,CAC3C,aAA2B,EAC3B,qBAA4C;IAE5C,MAAM,eAAe,GAAG,aAAa,CAAC,eAAe,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,IAAA,qCAAgB,EAAC,qBAAqB,CAAC,CAAC;IAC7D,MAAM,eAAe,GAAG,MAAM,IAAA,iCAAkB,EAAC,eAAe,CAAC,CAAC;IAClE,MAAM,IAAA,oCAAqB,EAAC,eAAe,CAAC,CAAC;IAE7C,MAAM,cAAc,GAAG,qBAAqB,CAAC,MAAM,CAAC;IACpD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CACnC,EAAE,EACF,MAAM,EACN,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,EAAE,CAAC,EACvC,cAAc,CACf,CAAC;IACF,OAAO,IAAA,6BAAc,EAAC,eAAe,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,YAAY,CAAC,KAAgC;IACpD,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED,SAAS,aAAa,CAAC,KAAgC;IACrD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,IAAI,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;gBACrC,CAAC,CAAC,KAAK,CAAC,MAAM;gBACd,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7C;YACE,OAAO,KAAK,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -1,2 +1,12 @@
1
1
  import type { ZeDependencyPair } from 'zephyr-agent';
2
- export declare function extract_remotes_dependencies(root: string, code: string, id: string): ZeDependencyPair[] | undefined;
2
+ export interface RemoteObjectConfig {
3
+ type?: string;
4
+ name: string;
5
+ entry: string;
6
+ entryGlobalName?: string;
7
+ shareScope?: string;
8
+ }
9
+ export interface PartialViteMFConfig {
10
+ remotes?: Record<string, string | RemoteObjectConfig> | undefined;
11
+ }
12
+ export declare function extract_remotes_dependencies(root: string, mfConfig: PartialViteMFConfig): ZeDependencyPair[] | undefined;
@@ -2,8 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extract_remotes_dependencies = extract_remotes_dependencies;
4
4
  const zephyr_agent_1 = require("zephyr-agent");
5
- const remote_map_parser_1 = require("./remote_map_parser");
6
- function extract_remotes_dependencies(root, code, id) {
5
+ function extract_remotes_dependencies(root, mfConfig) {
7
6
  const { zephyrDependencies } = (0, zephyr_agent_1.readPackageJson)(root);
8
7
  if (zephyrDependencies) {
9
8
  return Object.entries(zephyrDependencies).map(([name, version]) => {
@@ -13,15 +12,14 @@ function extract_remotes_dependencies(root, code, id) {
13
12
  };
14
13
  });
15
14
  }
16
- const dependencyPairs = [];
17
- const extractedRemotes = (0, remote_map_parser_1.parseRemoteMapAndImportedRemotes)(code, id);
18
- if (extractedRemotes === undefined)
15
+ if (!mfConfig.remotes)
19
16
  return;
20
- const { remotesMap } = extractedRemotes;
21
- for (const remote of remotesMap) {
22
- const { name, entry: version } = remote;
23
- dependencyPairs.push({ name, version });
24
- }
17
+ const dependencyPairs = Object.entries(mfConfig.remotes).map(([name, remote]) => {
18
+ if (typeof remote === 'string') {
19
+ return { name, version: remote };
20
+ }
21
+ return { name, version: remote.entry };
22
+ });
25
23
  return dependencyPairs;
26
24
  }
27
25
  //# sourceMappingURL=extract-mf-vite-remotes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-mf-vite-remotes.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/extract-mf-vite-remotes.ts"],"names":[],"mappings":";;AAIA,oEA2BC;AA9BD,+CAA+C;AAC/C,2DAAuE;AAEvE,SAAgB,4BAA4B,CAC1C,IAAY,EACZ,IAAY,EACZ,EAAU;IAEV,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAA,8BAAe,EAAC,IAAI,CAAC,CAAC;IACrD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE;YAChE,OAAO;gBACL,IAAI;gBACJ,OAAO;aACY,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,eAAe,GAAuB,EAAE,CAAC;IAC/C,MAAM,gBAAgB,GAAG,IAAA,oDAAgC,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACpE,IAAI,gBAAgB,KAAK,SAAS;QAAE,OAAO;IAE3C,MAAM,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAAC;IAExC,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QACxC,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"extract-mf-vite-remotes.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/extract-mf-vite-remotes.ts"],"names":[],"mappings":";;AAeA,oEA0BC;AAxCD,+CAA+C;AAc/C,SAAgB,4BAA4B,CAC1C,IAAY,EACZ,QAA6B;IAE7B,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAA,8BAAe,EAAC,IAAI,CAAC,CAAC;IACrD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE;YAChE,OAAO;gBACL,IAAI;gBACJ,OAAO;aACY,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,OAAO;QAAE,OAAO;IAE9B,MAAM,eAAe,GAAuB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,CAC9E,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;QACjB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QACnC,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC,CACF,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -1,2 +1,2 @@
1
1
  import type { ZeResolvedDependency } from 'zephyr-agent';
2
- export declare function load_resolved_remotes(resolved_remotes: ZeResolvedDependency[], code: string, id: string): string | undefined;
2
+ export declare function load_resolved_remotes(resolved_remotes: ZeResolvedDependency[], code: string): string;
@@ -1,26 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.load_resolved_remotes = load_resolved_remotes;
4
- const remote_map_parser_1 = require("./remote_map_parser");
5
- function load_resolved_remotes(resolved_remotes, code, id) {
6
- const extractedRemotes = (0, remote_map_parser_1.parseRemoteMapAndImportedRemotes)(code, id);
7
- if (extractedRemotes === undefined)
8
- return;
9
- const remotes = [];
10
- const { remotesMap, startIndex, endIndex } = extractedRemotes;
11
- for (const remote of remotesMap) {
12
- const { name, entry, type } = remote;
13
- const remoteDetails = resolved_remotes.find((r) => r.name === name && r.version === entry);
14
- if (!remoteDetails)
15
- continue;
16
- const updatedUrl = (0, remote_map_parser_1.replaceProtocolAndHost)(entry, remoteDetails.remote_entry_url);
17
- remotes.push({
18
- name,
19
- type,
20
- entryGlobalName: name,
21
- entry: updatedUrl,
22
- });
4
+ const zephyr_agent_1 = require("zephyr-agent");
5
+ const runtime_plugins_parser_1 = require("./runtime_plugins_parser");
6
+ const runtime_plugin_1 = require("./runtime_plugin");
7
+ function load_resolved_remotes(resolved_remotes, code) {
8
+ const startTime = Date.now();
9
+ try {
10
+ const runtimePluginsExtraction = (0, runtime_plugins_parser_1.parseRuntimePlugin)(code);
11
+ if (!runtimePluginsExtraction)
12
+ return code;
13
+ const { pluginsArray, startIndex, endIndex } = runtimePluginsExtraction;
14
+ // Add Zephyr plugin to the array
15
+ // We need to add a Zephyr plugin to the end of the array
16
+ // The array is in format: [plugin1(), plugin2(), ...] or []
17
+ let updatedPluginsArray;
18
+ const runtimePlugin = (0, runtime_plugin_1.generateRuntimePlugin)(resolved_remotes);
19
+ if (pluginsArray === '[]') {
20
+ // Handle empty array case
21
+ updatedPluginsArray = `[${runtimePlugin}]`;
22
+ }
23
+ else {
24
+ // Handle non-empty array case
25
+ updatedPluginsArray = pluginsArray.replace(/\]$/, `, ${runtimePlugin}]`);
26
+ }
27
+ // Replace the original array with the updated one
28
+ const updatedCode = code.substring(0, startIndex) + updatedPluginsArray + code.substring(endIndex);
29
+ const endTime = Date.now();
30
+ (0, zephyr_agent_1.ze_log)(`load_resolved_remotes took ${endTime - startTime}ms`);
31
+ return updatedCode;
32
+ }
33
+ catch (error) {
34
+ (0, zephyr_agent_1.ze_log)('Error in load_resolved_remotes:', error);
35
+ return code; // Return original code in case of error
23
36
  }
24
- return code.slice(0, startIndex) + JSON.stringify(remotes) + code.slice(endIndex);
25
37
  }
26
38
  //# sourceMappingURL=load_resolved_remotes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"load_resolved_remotes.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/load_resolved_remotes.ts"],"names":[],"mappings":";;AAOA,sDA0BC;AA/BD,2DAG6B;AAE7B,SAA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CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,CAAC;QACH,MAAM,wBAAwB,GAAG,IAAA,2CAAkB,EAAC,IAAI,CAAC,CAAC;QAE1D,IAAI,CAAC,wBAAwB;YAAE,OAAO,IAAI,CAAC;QAE3C,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,wBAAwB,CAAC;QAExE,iCAAiC;QACjC,yDAAyD;QACzD,4DAA4D;QAC5D,IAAI,mBAAmB,CAAC;QACxB,MAAM,aAAa,GAAG,IAAA,sCAAqB,EAAC,gBAAgB,CAAC,CAAC;QAE9D,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,0BAA0B;YAC1B,mBAAmB,GAAG,IAAI,aAAa,GAAG,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,8BAA8B;YAC9B,mBAAmB,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,aAAa,GAAG,CAAC,CAAC;QAC3E,CAAC;QAED,kDAAkD;QAClD,MAAM,WAAW,GACf,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,mBAAmB,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAEjF,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC3B,IAAA,qBAAM,EAAC,8BAA8B,OAAO,GAAG,SAAS,IAAI,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,qBAAM,EAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,CAAC,wCAAwC;IACvD,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { ZeResolvedDependency } from 'zephyr-agent';
2
+ export declare function generateRuntimePlugin(resolved_remotes: ZeResolvedDependency[]): string;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateRuntimePlugin = generateRuntimePlugin;
4
+ function generateRuntimePlugin(resolved_remotes) {
5
+ const remoteMap = Object.fromEntries(resolved_remotes.map((remote) => [remote.name, remote]));
6
+ const runtimePlugin = {
7
+ name: 'zephyr-runtime-remote-resolver',
8
+ beforeInit: (args) => {
9
+ const resolvedRemoteMap = JSON.parse('__REMOTE_MAP__');
10
+ const _windows = typeof window !== 'undefined' ? window : globalThis;
11
+ args.userOptions.remotes.forEach((remote) => {
12
+ const resolvedRemote = resolvedRemoteMap[remote.name];
13
+ if (!resolvedRemote)
14
+ return;
15
+ const sessionEdgeURL = _windows.sessionStorage.getItem(resolvedRemote.application_uid);
16
+ const urlOverwrite = sessionEdgeURL !== null && sessionEdgeURL !== void 0 ? sessionEdgeURL : resolvedRemote.remote_entry_url;
17
+ // @ts-expect-error overwriting entry if needed
18
+ remote.entry = urlOverwrite;
19
+ });
20
+ return args;
21
+ },
22
+ };
23
+ return objectToTemplate(runtimePlugin).replace('__REMOTE_MAP__', JSON.stringify(remoteMap));
24
+ }
25
+ function objectToTemplate(obj) {
26
+ const entries = Object.entries(obj).map(([key, value]) => {
27
+ if (typeof value === 'function') {
28
+ return `${key}: ${value.toString()}`;
29
+ }
30
+ else if (typeof value === 'object' && value !== null) {
31
+ return `${key}: ${objectToTemplate(value)}`;
32
+ }
33
+ else if (typeof value === 'string') {
34
+ return `${key}: "${value}"`;
35
+ }
36
+ else {
37
+ return `${key}: ${value}`;
38
+ }
39
+ });
40
+ return `{ ${entries.join(', ')} }`;
41
+ }
42
+ //# sourceMappingURL=runtime_plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime_plugin.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/runtime_plugin.ts"],"names":[],"mappings":";;AAGA,sDA+BC;AA/BD,SAAgB,qBAAqB,CAAC,gBAAwC;IAC5E,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAClC,gBAAgB,C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GAAG,GAAG,KAAK,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;QACvC,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACvD,OAAO,GAAG,GAAG,KAAK,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,GAAG,GAAG,MAAM,KAAK,GAAG,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,GAAG,KAAK,KAAK,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACrC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface RuntimePluginsExtraction {
2
+ pluginsArray: string;
3
+ startIndex: number;
4
+ endIndex: number;
5
+ }
6
+ export declare function parseRuntimePlugin(code: string): RuntimePluginsExtraction | undefined;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRuntimePlugin = parseRuntimePlugin;
4
+ const tslib_1 = require("tslib");
5
+ const acorn_1 = tslib_1.__importDefault(require("acorn"));
6
+ const acorn_walk_1 = tslib_1.__importDefault(require("acorn-walk"));
7
+ const zephyr_agent_1 = require("zephyr-agent");
8
+ function parseRuntimePlugin(code) {
9
+ // Parse the code into an AST
10
+ const ast = acorn_1.default.parse(code, {
11
+ ecmaVersion: 'latest',
12
+ sourceType: 'module',
13
+ locations: true,
14
+ ranges: true,
15
+ });
16
+ let pluginsArrayNode;
17
+ // Find the plugins array in the runtimeInit call
18
+ acorn_walk_1.default.simple(ast, {
19
+ CallExpression(node) {
20
+ var _a, _b;
21
+ if (((_a = node.callee) === null || _a === void 0 ? void 0 : _a.name) === 'runtimeInit' && ((_b = node.arguments) === null || _b === void 0 ? void 0 : _b.length) > 0) {
22
+ const initArg = node.arguments[0];
23
+ if (initArg.type === 'ObjectExpression') {
24
+ for (const prop of initArg.properties) {
25
+ if (prop.key.type === 'Identifier' &&
26
+ prop.key.name === 'plugins' &&
27
+ prop.value.type === 'ArrayExpression') {
28
+ pluginsArrayNode = prop.value;
29
+ break;
30
+ }
31
+ }
32
+ }
33
+ }
34
+ },
35
+ });
36
+ if (!pluginsArrayNode ||
37
+ !('start' in pluginsArrayNode) ||
38
+ !('end' in pluginsArrayNode)) {
39
+ (0, zephyr_agent_1.ze_log)('Could not find plugins array in remote entry');
40
+ return undefined;
41
+ }
42
+ // Extract the plugins array
43
+ const startIndex = pluginsArrayNode.start;
44
+ const endIndex = pluginsArrayNode.end;
45
+ const pluginsArray = code.slice(startIndex, endIndex);
46
+ return { pluginsArray, startIndex, endIndex };
47
+ }
48
+ //# sourceMappingURL=runtime_plugins_parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime_plugins_parser.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/runtime_plugins_parser.ts"],"names":[],"mappings":";;AAUA,gDAgDC;;AA1DD,0DAA0B;AAC1B,oEAA8B;AAC9B,+CAAsC;AAQtC,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,6BAA6B;IAC7B,MAAM,GAAG,GAAG,eAAK,CAAC,KAAK,CAAC,IAAI,EAAE;QAC5B,WAAW,EAAE,QAAQ;QACrB,UAAU,EAAE,QAAQ;QACpB,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IAEH,IAAI,gBAAwC,CAAC;IAE7C,iDAAiD;IACjD,oBAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,cAAc,CAAC,IAAS;;YACtB,IAAI,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,MAAK,aAAa,IAAI,CAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,MAAM,IAAG,CAAC,EAAE,CAAC;gBACtE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBAElC,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;oBACxC,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;wBACtC,IACE,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY;4BAC9B,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS;4BAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,iBAAiB,EACrC,CAAC;4BACD,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC;4BAC9B,MAAM;wBACR,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,IACE,CAAC,gBAAgB;QACjB,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAC;QAC9B,CAAC,CAAC,KAAK,IAAI,gBAAgB,CAAC,EAC5B,CAAC;QACD,IAAA,qBAAM,EAAC,8CAA8C,CAAC,CAAC;QACvD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,4BAA4B;IAC5B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC;IAC1C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CAAC;IACtC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAEtD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAChD,CAAC"}
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withZephyrPartial = withZephyrPartial;
4
4
  const zephyr_agent_1 = require("zephyr-agent");
5
5
  const extract_vite_assets_map_1 = require("./internal/extract/extract_vite_assets_map");
6
- const extract_vite_build_stats_1 = require("./internal/extract/extract_vite_build_stats");
7
6
  function withZephyrPartial() {
8
7
  const { zephyr_engine_defer, zephyr_defer_create } = zephyr_agent_1.ZephyrEngine.defer_create();
9
8
  let resolve_vite_internal_options;
10
9
  const vite_internal_options_defer = new Promise((resolve) => {
11
10
  resolve_vite_internal_options = resolve;
12
11
  });
13
- let outputBundle;
14
12
  return {
15
13
  name: 'with-zephyr-partial',
16
14
  apply: 'build',
@@ -28,7 +26,6 @@ function withZephyrPartial() {
28
26
  });
29
27
  },
30
28
  writeBundle: async (options, bundle) => {
31
- outputBundle = bundle;
32
29
  const vite_internal_options = await vite_internal_options_defer;
33
30
  vite_internal_options.dir = options.dir;
34
31
  vite_internal_options.assets = bundle;
@@ -42,19 +39,12 @@ function withZephyrPartial() {
42
39
  // context import ^
43
40
  const assetsMap = await (0, extract_vite_assets_map_1.extract_vite_assets_map)(zephyr_engine, vite_internal_options);
44
41
  await (0, zephyr_agent_1.savePartialAssetMap)(application_uid, (_a = vite_internal_options.configFile) !== null && _a !== void 0 ? _a : 'partial', assetsMap);
45
- // Enable deployment for partial builds if requested
46
- await zephyr_engine.start_new_build();
47
- // Generate enhanced build stats for Vite
48
- const buildStats = await (0, extract_vite_build_stats_1.extractViteBuildStats)({
49
- zephyr_engine,
50
- bundle: outputBundle || {},
51
- root: vite_internal_options.root,
52
- });
53
- await zephyr_engine.upload_assets({
54
- assetsMap,
55
- buildStats,
56
- });
57
- await zephyr_engine.build_finished();
42
+ // todo: initially partial build doesn't have deploy, but code below could enable it if needed
43
+ // await zephyr_engine.upload_assets({
44
+ // assetsMap,
45
+ // // todo: this should be updated if we have remotes
46
+ // buildStats: await zeBuildDashData(zephyr_engine),
47
+ // });
58
48
  }
59
49
  catch (error) {
60
50
  (0, zephyr_agent_1.logFn)('error', zephyr_agent_1.ZephyrError.format(error));
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-zephyr-partial.js","sourceRoot":"","sources":["../../src/lib/vite-plugin-zephyr-partial.ts"],"names":[],"mappings":";;AAOA,8CAsEC;AA3ED,+CAAqF;AACrF,wFAAqF;AACrF,0FAAoF;AAGpF,SAAg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  import type { Plugin } from 'vite';
2
2
  import { federation } from '@module-federation/vite';
3
- export type ModuleFederationOptions = Parameters<typeof federation>[0] & {
4
- additionalShared?: Array<{
5
- libraryName: string;
6
- sharedConfig?: {
7
- singleton?: boolean;
8
- requiredVersion?: string;
9
- };
10
- }>;
11
- };
3
+ export type ModuleFederationOptions = Parameters<typeof federation>[0];
12
4
  interface VitePluginZephyrOptions {
13
5
  mfConfig?: ModuleFederationOptions;
14
6
  }
@@ -4,99 +4,34 @@ exports.withZephyr = withZephyr;
4
4
  const zephyr_agent_1 = require("zephyr-agent");
5
5
  const vite_1 = require("@module-federation/vite");
6
6
  const extract_vite_assets_map_1 = require("./internal/extract/extract_vite_assets_map");
7
- const extract_vite_build_stats_1 = require("./internal/extract/extract_vite_build_stats");
8
7
  const extract_mf_vite_remotes_1 = require("./internal/mf-vite-etl/extract-mf-vite-remotes");
9
8
  const load_resolved_remotes_1 = require("./internal/mf-vite-etl/load_resolved_remotes");
9
+ const extract_mf_plugin_1 = require("./internal/extract/extract_mf_plugin");
10
10
  function withZephyr(_options) {
11
11
  const mfConfig = _options === null || _options === void 0 ? void 0 : _options.mfConfig;
12
12
  const plugins = [];
13
13
  if (mfConfig) {
14
14
  plugins.push(...(0, vite_1.federation)(mfConfig));
15
15
  }
16
- plugins.push(zephyrPlugin(_options));
16
+ plugins.push(zephyrPlugin());
17
17
  return plugins;
18
18
  }
19
- function zephyrPlugin(_options) {
19
+ function zephyrPlugin() {
20
20
  const { zephyr_engine_defer, zephyr_defer_create } = zephyr_agent_1.ZephyrEngine.defer_create();
21
- // const mfConfig = _options?.mfConfig;
22
21
  let resolve_vite_internal_options;
23
22
  const vite_internal_options_defer = new Promise((resolve) => {
24
23
  resolve_vite_internal_options = resolve;
25
24
  });
26
25
  let root;
27
- let outputBundle;
28
- // // remote names from the mfConfig
29
- // let remoteNames: string[] = [];
30
- // if (mfConfig?.remotes) {
31
- // remoteNames = Object.entries(mfConfig.remotes)
32
- // .map(([key, remote]) => {
33
- // if (typeof remote === 'string') {
34
- // return key;
35
- // }
36
- // if (typeof remote === 'object' && 'name' in remote) {
37
- // return remote.name;
38
- // }
39
- // return key;
40
- // })
41
- // .filter(Boolean);
42
- // }
43
- // ze_log('vite.remoteNames: ', remoteNames);
44
- // Storage for tracking discovered remote imports
45
- // const consumes: ApplicationConsumes[] = [];
46
- // const processedRemotes = new Set<string>();
47
- // // Track module information for AST analysis
48
- // const moduleSourceMap = new Map<
49
- // string,
50
- // {
51
- // originalId: string;
52
- // imports: Set<string>;
53
- // dynamicImports: Set<string>;
54
- // source: Set<string>;
55
- // }
56
- // >();
57
- // // Helper function to process remote imports consistently across hooks
58
- // function processRemoteImport(importItem: {
59
- // applicationID: string;
60
- // name: string;
61
- // usedIn: UsedIn[];
62
- // consumingApplicationID?: string;
63
- // }) {
64
- // const remoteKey = `${importItem.applicationID}/${importItem.name}`;
65
- // // Get consuming application ID - if it's a remote from the mfConfig, use the remote name
66
- // let consumingApplicationID = importItem.consumingApplicationID;
67
- // if (!consumingApplicationID && mfConfig?.name) {
68
- // consumingApplicationID = mfConfig.name;
69
- // }
70
- // if (!processedRemotes.has(remoteKey)) {
71
- // processedRemotes.add(remoteKey);
72
- // consumes.push({
73
- // consumingApplicationID: consumingApplicationID || importItem.name,
74
- // applicationID: importItem.applicationID,
75
- // name: importItem.name,
76
- // usedIn: importItem.usedIn,
77
- // });
78
- // } else {
79
- // // If we've already seen this import, update the usedIn array
80
- // const existingImport = consumes.find(
81
- // (item) =>
82
- // item.applicationID === importItem.applicationID && item.name === importItem.name
83
- // );
84
- // if (existingImport) {
85
- // // Add any new usedIn locations that aren't already in the list
86
- // for (const usedInItem of importItem.usedIn) {
87
- // if (!existingImport.usedIn.some((u) => u.file === usedInItem.file)) {
88
- // existingImport.usedIn.push(usedInItem);
89
- // }
90
- // }
91
- // }
92
- // }
93
- // }
26
+ let mfPlugin;
94
27
  return {
95
28
  name: 'with-zephyr',
96
29
  enforce: 'post',
97
30
  configResolved: async (config) => {
98
- var _a;
31
+ var _a, _b;
99
32
  root = config.root;
33
+ if (config.command === 'serve')
34
+ return;
100
35
  zephyr_defer_create({
101
36
  builder: 'vite',
102
37
  context: config.root,
@@ -106,130 +41,20 @@ function zephyrPlugin(_options) {
106
41
  outDir: (_a = config.build) === null || _a === void 0 ? void 0 : _a.outDir,
107
42
  publicDir: config.publicDir,
108
43
  });
44
+ mfPlugin = (0, extract_mf_plugin_1.extract_mf_plugin)((_b = config.plugins) !== null && _b !== void 0 ? _b : []);
109
45
  },
110
- // moduleParsed: async ({
111
- // id,
112
- // ast,
113
- // code,
114
- // dynamicallyImportedIds,
115
- // isEntry,
116
- // isExternal,
117
- // }) => {
118
- // // Initialize the module info if it doesn't exist
119
- // if (!moduleSourceMap.has(id)) {
120
- // moduleSourceMap.set(id, {
121
- // originalId: id,
122
- // imports: new Set(),
123
- // dynamicImports: new Set(),
124
- // source: new Set(),
125
- // });
126
- // }
127
- // const moduleInfo = moduleSourceMap.get(id) as {
128
- // originalId: string;
129
- // imports: Set<string>;
130
- // dynamicImports: Set<string>;
131
- // source: Set<string>;
132
- // };
133
- // // Track static imports
134
- // if (ast?.body) {
135
- // for (const content of ast.body) {
136
- // if (content.type === 'ImportDeclaration' && content && isEntry !== true) {
137
- // const importSource = content.source.raw as string;
138
- // ze_log('vite.moduleParsed.id: ', id);
139
- // ze_log('vite.moduleParsed.content: ', importSource);
140
- // ze_log('vite.moduleParsed.code: ', code);
141
- // ze_log('vite.moduleParsed.isEntry: ', isEntry);
142
- // ze_log('vite.moduleParsed.isExternal: ', isExternal);
143
- // ze_log('vite.moduleParsed.dynamicallyImportedIds: ', dynamicallyImportedIds);
144
- // if (code) {
145
- // moduleInfo.source.add(code);
146
- // }
147
- // moduleInfo.imports.add(importSource);
148
- // // Check if this is a Module Federation remote import (e.g., "remote-name/component-name")
149
- // const match = /^["']([^\/]+)\/([^\/]+)["']$/.exec(importSource);
150
- // if (match) {
151
- // const remoteName = match[1];
152
- // const componentName = match[2];
153
- // ze_log('vite.moduleParsed.match: ', { remoteName, componentName });
154
- // // Only process remotes that make sense in a Module Federation context
155
- // for (const remote of remoteNames) {
156
- // if (remoteName === remote) {
157
- // ze_log('Found MF static import in moduleParsed', {
158
- // remoteName,
159
- // componentName,
160
- // id,
161
- // });
162
- // // Create a consistent usedIn entry
163
- // const usedIn = [
164
- // {
165
- // file: id,
166
- // url: id.replace(root, ''),
167
- // },
168
- // ];
169
- // ze_log('vite.moduleParsed.processRemoteImport: ', {
170
- // remoteName,
171
- // componentName,
172
- // id,
173
- // });
174
- // // Process the remote import
175
- // processRemoteImport({
176
- // applicationID: remoteName,
177
- // name: componentName,
178
- // consumingApplicationID: componentName,
179
- // usedIn,
180
- // });
181
- // }
182
- // }
183
- // }
184
- // }
185
- // }
186
- // }
187
- // // Extract __vitePreload imports for lazy-loaded components
188
- // if (ast && code) {
189
- // try {
190
- // const preloadImports = extractVitePreloadImports(ast as ProgramNode, code);
191
- // for (const preloadImport of preloadImports) {
192
- // const { remoteId, importPath } = preloadImport;
193
- // // Only process remotes that are configured in the MF config
194
- // if (remoteNames.includes(remoteId)) {
195
- // ze_log('Found MF lazy import via __vitePreload', {
196
- // remoteId,
197
- // importPath,
198
- // id,
199
- // });
200
- // // Create a consistent usedIn entry
201
- // const usedIn = [
202
- // {
203
- // file: id,
204
- // url: id.replace(root, ''),
205
- // },
206
- // ];
207
- // // Process the remote import
208
- // processRemoteImport({
209
- // applicationID: remoteId,
210
- // name: importPath,
211
- // consumingApplicationID: mfConfig?.name,
212
- // usedIn,
213
- // });
214
- // }
215
- // }
216
- // } catch (error) {
217
- // // Log but don't crash on parse errors
218
- // ze_log('Error parsing __vitePreload imports', { error, id });
219
- // }
220
- // }
221
- // },
222
46
  transform: async (code, id) => {
223
47
  try {
224
- // Handle dependency resolution
225
- const dependencyPairs = (0, extract_mf_vite_remotes_1.extract_remotes_dependencies)(root, code, id);
48
+ if (!id.includes('virtual:mf-REMOTE_ENTRY_ID') || !mfPlugin)
49
+ return code;
50
+ const dependencyPairs = (0, extract_mf_vite_remotes_1.extract_remotes_dependencies)(root, mfPlugin._options);
226
51
  if (!dependencyPairs)
227
52
  return code;
228
53
  const zephyr_engine = await zephyr_engine_defer;
229
54
  const resolved_remotes = await zephyr_engine.resolve_remote_dependencies(dependencyPairs);
230
55
  if (!resolved_remotes)
231
56
  return code;
232
- return (0, load_resolved_remotes_1.load_resolved_remotes)(resolved_remotes, code, id);
57
+ return (0, load_resolved_remotes_1.load_resolved_remotes)(resolved_remotes, code);
233
58
  }
234
59
  catch (error) {
235
60
  (0, zephyr_agent_1.logFn)('error', zephyr_agent_1.ZephyrError.format(error));
@@ -237,10 +62,6 @@ function zephyrPlugin(_options) {
237
62
  return code;
238
63
  }
239
64
  },
240
- // Capture the output bundle for build stats generation
241
- writeBundle: (_, bundle) => {
242
- outputBundle = bundle;
243
- },
244
65
  closeBundle: async () => {
245
66
  try {
246
67
  const [vite_internal_options, zephyr_engine] = await Promise.all([
@@ -249,17 +70,9 @@ function zephyrPlugin(_options) {
249
70
  ]);
250
71
  await zephyr_engine.start_new_build();
251
72
  const assetsMap = await (0, extract_vite_assets_map_1.extract_vite_assets_map)(zephyr_engine, vite_internal_options);
252
- // Generate enhanced build stats for Vite using the discovered remote imports
253
- const buildStats = await (0, extract_vite_build_stats_1.extractViteBuildStats)({
254
- zephyr_engine,
255
- bundle: outputBundle || {},
256
- mfConfig: _options === null || _options === void 0 ? void 0 : _options.mfConfig,
257
- root,
258
- });
259
- // Upload assets and build stats
260
73
  await zephyr_engine.upload_assets({
261
74
  assetsMap,
262
- buildStats,
75
+ buildStats: await (0, zephyr_agent_1.zeBuildDashData)(zephyr_engine),
263
76
  });
264
77
  await zephyr_engine.build_finished();
265
78
  }