@module-federation/sdk 2.0.1 → 2.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 (113) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +19 -0
  2. package/dist/_virtual/_rolldown/runtime.js +18 -0
  3. package/dist/constant.cjs +70 -0
  4. package/dist/constant.cjs.map +1 -0
  5. package/dist/constant.d.ts +53 -0
  6. package/dist/constant.js +55 -0
  7. package/dist/constant.js.map +1 -0
  8. package/dist/createModuleFederationConfig.cjs +9 -0
  9. package/dist/createModuleFederationConfig.cjs.map +1 -0
  10. package/dist/createModuleFederationConfig.d.ts +8 -0
  11. package/dist/createModuleFederationConfig.js +8 -0
  12. package/dist/createModuleFederationConfig.js.map +1 -0
  13. package/dist/dom.cjs +166 -0
  14. package/dist/dom.cjs.map +1 -0
  15. package/dist/dom.d.ts +35 -0
  16. package/dist/dom.js +162 -0
  17. package/dist/dom.js.map +1 -0
  18. package/dist/env.cjs +32 -0
  19. package/dist/env.cjs.map +1 -0
  20. package/dist/{src/env.d.ts → env.d.ts} +5 -2
  21. package/dist/env.js +29 -0
  22. package/dist/env.js.map +1 -0
  23. package/dist/generateSnapshotFromManifest.cjs +138 -0
  24. package/dist/generateSnapshotFromManifest.cjs.map +1 -0
  25. package/dist/generateSnapshotFromManifest.d.ts +22 -0
  26. package/dist/generateSnapshotFromManifest.js +134 -0
  27. package/dist/generateSnapshotFromManifest.js.map +1 -0
  28. package/dist/index.cjs +89 -0
  29. package/dist/index.d.ts +20 -1
  30. package/dist/index.js +15 -0
  31. package/dist/logger.cjs +129 -0
  32. package/dist/logger.cjs.map +1 -0
  33. package/dist/logger.d.ts +34 -0
  34. package/dist/logger.js +125 -0
  35. package/dist/logger.js.map +1 -0
  36. package/dist/node.cjs +122 -0
  37. package/dist/node.cjs.map +1 -0
  38. package/dist/node.d.ts +17 -0
  39. package/dist/node.js +120 -0
  40. package/dist/node.js.map +1 -0
  41. package/dist/normalize-webpack-path.cjs +28 -0
  42. package/dist/normalize-webpack-path.cjs.map +1 -0
  43. package/dist/normalize-webpack-path.d.ts +10 -1
  44. package/dist/normalize-webpack-path.js +26 -0
  45. package/dist/normalize-webpack-path.js.map +1 -0
  46. package/dist/normalizeOptions.cjs +19 -0
  47. package/dist/normalizeOptions.cjs.map +1 -0
  48. package/dist/normalizeOptions.d.ts +5 -0
  49. package/dist/normalizeOptions.js +18 -0
  50. package/dist/normalizeOptions.js.map +1 -0
  51. package/dist/types/common.d.ts +14 -0
  52. package/dist/types/hooks.d.ts +16 -0
  53. package/dist/types/index.d.ts +10 -0
  54. package/dist/types/manifest.d.ts +34 -0
  55. package/dist/types/plugins/ContainerPlugin.cjs +13 -0
  56. package/dist/types/plugins/ContainerPlugin.cjs.map +1 -0
  57. package/dist/types/plugins/ContainerPlugin.d.ts +40 -0
  58. package/dist/types/plugins/ContainerPlugin.js +8 -0
  59. package/dist/types/plugins/ContainerPlugin.js.map +1 -0
  60. package/dist/types/plugins/ContainerReferencePlugin.cjs +13 -0
  61. package/dist/types/plugins/ContainerReferencePlugin.cjs.map +1 -0
  62. package/dist/types/plugins/ContainerReferencePlugin.d.ts +23 -0
  63. package/dist/types/plugins/ContainerReferencePlugin.js +8 -0
  64. package/dist/types/plugins/ContainerReferencePlugin.js.map +1 -0
  65. package/dist/types/plugins/ModuleFederationPlugin.cjs +13 -0
  66. package/dist/types/plugins/ModuleFederationPlugin.cjs.map +1 -0
  67. package/dist/types/plugins/ModuleFederationPlugin.d.ts +432 -0
  68. package/dist/types/plugins/ModuleFederationPlugin.js +8 -0
  69. package/dist/types/plugins/ModuleFederationPlugin.js.map +1 -0
  70. package/dist/types/plugins/SharePlugin.cjs +13 -0
  71. package/dist/types/plugins/SharePlugin.cjs.map +1 -0
  72. package/dist/types/plugins/SharePlugin.d.ts +29 -0
  73. package/dist/types/plugins/SharePlugin.js +8 -0
  74. package/dist/types/plugins/SharePlugin.js.map +1 -0
  75. package/dist/types/plugins/index.d.ts +4 -0
  76. package/dist/types/snapshot.d.ts +81 -0
  77. package/dist/types/stats.d.ts +101 -0
  78. package/dist/utils.cjs +127 -0
  79. package/dist/utils.cjs.map +1 -0
  80. package/dist/{src/utils.d.ts → utils.d.ts} +9 -3
  81. package/dist/utils.js +116 -0
  82. package/dist/utils.js.map +1 -0
  83. package/package.json +7 -7
  84. package/dist/index.cjs.cjs +0 -1032
  85. package/dist/index.cjs.cjs.map +0 -1
  86. package/dist/index.cjs.d.ts +0 -1
  87. package/dist/index.esm.js +0 -978
  88. package/dist/index.esm.js.map +0 -1
  89. package/dist/normalize-webpack-path.cjs.cjs +0 -42
  90. package/dist/normalize-webpack-path.cjs.cjs.map +0 -1
  91. package/dist/normalize-webpack-path.cjs.d.ts +0 -1
  92. package/dist/normalize-webpack-path.esm.js +0 -39
  93. package/dist/normalize-webpack-path.esm.js.map +0 -1
  94. package/dist/src/constant.d.ts +0 -49
  95. package/dist/src/createModuleFederationConfig.d.ts +0 -2
  96. package/dist/src/dom.d.ts +0 -29
  97. package/dist/src/generateSnapshotFromManifest.d.ts +0 -15
  98. package/dist/src/index.d.ts +0 -11
  99. package/dist/src/logger.d.ts +0 -32
  100. package/dist/src/node.d.ts +0 -11
  101. package/dist/src/normalize-webpack-path.d.ts +0 -5
  102. package/dist/src/normalizeOptions.d.ts +0 -1
  103. package/dist/src/types/common.d.ts +0 -10
  104. package/dist/src/types/hooks.d.ts +0 -12
  105. package/dist/src/types/index.d.ts +0 -6
  106. package/dist/src/types/manifest.d.ts +0 -29
  107. package/dist/src/types/plugins/ContainerPlugin.d.ts +0 -32
  108. package/dist/src/types/plugins/ContainerReferencePlugin.d.ts +0 -15
  109. package/dist/src/types/plugins/ModuleFederationPlugin.d.ts +0 -425
  110. package/dist/src/types/plugins/SharePlugin.d.ts +0 -21
  111. package/dist/src/types/plugins/index.d.ts +0 -4
  112. package/dist/src/types/snapshot.d.ts +0 -77
  113. package/dist/src/types/stats.d.ts +0 -97
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { CreateScriptHookDom, CreateScriptHookReturnDom } from './types';\nimport { warn } from './utils';\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function safeWrapper<T extends (...args: Array<any>) => any>(\n callback: T,\n disableWarn?: boolean,\n): Promise<ReturnType<T> | undefined> {\n try {\n const res = await callback();\n return res;\n } catch (e) {\n !disableWarn && warn(e);\n return;\n }\n}\n\nexport function isStaticResourcesEqual(url1: string, url2: string): boolean {\n const REG_EXP = /^(https?:)?\\/\\//i;\n // Transform url1 and url2 into relative paths\n const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\\/$/, '');\n const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\\/$/, '');\n // Check if the relative paths are identical\n return relativeUrl1 === relativeUrl2;\n}\n\nexport function createScript(info: {\n url: string;\n cb?: (value: void | PromiseLike<void>) => void;\n onErrorCallback?: (error: Error) => void;\n attrs?: Record<string, any>;\n needDeleteScript?: boolean;\n createScriptHook?: CreateScriptHookDom;\n}): { script: HTMLScriptElement; needAttach: boolean } {\n // Retrieve the existing script element by its src attribute\n let script: HTMLScriptElement | null = null;\n let needAttach = true;\n let timeout = 20000;\n let timeoutId: NodeJS.Timeout;\n const scripts = document.getElementsByTagName('script');\n\n for (let i = 0; i < scripts.length; i++) {\n const s = scripts[i];\n const scriptSrc = s.getAttribute('src');\n if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {\n script = s;\n needAttach = false;\n break;\n }\n }\n\n if (!script) {\n const attrs = info.attrs;\n script = document.createElement('script');\n script.type = attrs?.['type'] === 'module' ? 'module' : 'text/javascript';\n let createScriptRes: CreateScriptHookReturnDom = undefined;\n if (info.createScriptHook) {\n createScriptRes = info.createScriptHook(info.url, info.attrs);\n\n if (createScriptRes instanceof HTMLScriptElement) {\n script = createScriptRes;\n } else if (typeof createScriptRes === 'object') {\n if ('script' in createScriptRes && createScriptRes.script) {\n script = createScriptRes.script;\n }\n if ('timeout' in createScriptRes && createScriptRes.timeout) {\n timeout = createScriptRes.timeout;\n }\n }\n }\n if (!script.src) {\n script.src = info.url;\n }\n if (attrs && !createScriptRes) {\n Object.keys(attrs).forEach((name) => {\n if (script) {\n if (name === 'async' || name === 'defer') {\n script[name] = attrs[name];\n // Attributes that do not exist are considered overridden\n } else if (!script.getAttribute(name)) {\n script.setAttribute(name, attrs[name]);\n }\n }\n });\n }\n }\n\n const onScriptComplete = async (\n prev: OnErrorEventHandler | GlobalEventHandlers['onload'] | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event: any,\n ): Promise<void> => {\n clearTimeout(timeoutId);\n const onScriptCompleteCallback = () => {\n if (event?.type === 'error') {\n info?.onErrorCallback && info?.onErrorCallback(event);\n } else {\n info?.cb && info?.cb();\n }\n };\n\n // Prevent memory leaks in IE.\n if (script) {\n script.onerror = null;\n script.onload = null;\n safeWrapper(() => {\n const { needDeleteScript = true } = info;\n if (needDeleteScript) {\n script?.parentNode && script.parentNode.removeChild(script);\n }\n });\n if (prev && typeof prev === 'function') {\n const result = (prev as any)(event);\n if (result instanceof Promise) {\n const res = await result;\n onScriptCompleteCallback();\n return res;\n }\n onScriptCompleteCallback();\n return result;\n }\n }\n onScriptCompleteCallback();\n };\n\n script.onerror = onScriptComplete.bind(null, script.onerror);\n script.onload = onScriptComplete.bind(null, script.onload);\n\n timeoutId = setTimeout(() => {\n onScriptComplete(\n null,\n new Error(`Remote script \"${info.url}\" time-outed.`),\n );\n }, timeout);\n\n return { script, needAttach };\n}\n\nexport function createLink(info: {\n url: string;\n cb?: (value: void | PromiseLike<void>) => void;\n onErrorCallback?: (error: Error) => void;\n attrs: Record<string, string>;\n needDeleteLink?: boolean;\n createLinkHook?: (\n url: string,\n attrs?: Record<string, any>,\n ) => HTMLLinkElement | void;\n}) {\n // <link rel=\"preload\" href=\"script.js\" as=\"script\">\n\n // Retrieve the existing script element by its src attribute\n let link: HTMLLinkElement | null = null;\n let needAttach = true;\n const links = document.getElementsByTagName('link');\n for (let i = 0; i < links.length; i++) {\n const l = links[i];\n const linkHref = l.getAttribute('href');\n const linkRel = l.getAttribute('rel');\n if (\n linkHref &&\n isStaticResourcesEqual(linkHref, info.url) &&\n linkRel === info.attrs['rel']\n ) {\n link = l;\n needAttach = false;\n break;\n }\n }\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('href', info.url);\n\n let createLinkRes: void | HTMLLinkElement = undefined;\n const attrs = info.attrs;\n\n if (info.createLinkHook) {\n createLinkRes = info.createLinkHook(info.url, attrs);\n if (createLinkRes instanceof HTMLLinkElement) {\n link = createLinkRes;\n }\n }\n\n if (attrs && !createLinkRes) {\n Object.keys(attrs).forEach((name) => {\n if (link && !link.getAttribute(name)) {\n link.setAttribute(name, attrs[name]);\n }\n });\n }\n }\n\n const onLinkComplete = (\n prev: OnErrorEventHandler | GlobalEventHandlers['onload'] | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event: any,\n ): void => {\n const onLinkCompleteCallback = () => {\n if (event?.type === 'error') {\n info?.onErrorCallback && info?.onErrorCallback(event);\n } else {\n info?.cb && info?.cb();\n }\n };\n // Prevent memory leaks in IE.\n if (link) {\n link.onerror = null;\n link.onload = null;\n safeWrapper(() => {\n const { needDeleteLink = true } = info;\n if (needDeleteLink) {\n link?.parentNode && link.parentNode.removeChild(link);\n }\n });\n if (prev) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const res = (prev as any)(event);\n onLinkCompleteCallback();\n return res;\n }\n }\n onLinkCompleteCallback();\n };\n\n link.onerror = onLinkComplete.bind(null, link.onerror);\n link.onload = onLinkComplete.bind(null, link.onload);\n\n return { link, needAttach };\n}\n\nexport function loadScript(\n url: string,\n info: {\n attrs?: Record<string, any>;\n createScriptHook?: CreateScriptHookDom;\n },\n) {\n const { attrs = {}, createScriptHook } = info;\n return new Promise<void>((resolve, reject) => {\n const { script, needAttach } = createScript({\n url,\n cb: resolve,\n onErrorCallback: reject,\n attrs: {\n fetchpriority: 'high',\n ...attrs,\n },\n createScriptHook,\n needDeleteScript: true,\n });\n needAttach && document.head.appendChild(script);\n });\n}\n"],"mappings":";;;AAGA,eAAsB,YACpB,UACA,aACoC;AACpC,KAAI;AAEF,SADY,MAAM,UAAU;UAErB,GAAG;AACV,GAAC,eAAe,KAAK,EAAE;AACvB;;;AAIJ,SAAgB,uBAAuB,MAAc,MAAuB;CAC1E,MAAM,UAAU;AAKhB,QAHqB,KAAK,QAAQ,SAAS,GAAG,CAAC,QAAQ,OAAO,GAAG,KAC5C,KAAK,QAAQ,SAAS,GAAG,CAAC,QAAQ,OAAO,GAAG;;AAKnE,SAAgB,aAAa,MAO0B;CAErD,IAAI,SAAmC;CACvC,IAAI,aAAa;CACjB,IAAI,UAAU;CACd,IAAI;CACJ,MAAM,UAAU,SAAS,qBAAqB,SAAS;AAEvD,MAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,IAAI,QAAQ;EAClB,MAAM,YAAY,EAAE,aAAa,MAAM;AACvC,MAAI,aAAa,uBAAuB,WAAW,KAAK,IAAI,EAAE;AAC5D,YAAS;AACT,gBAAa;AACb;;;AAIJ,KAAI,CAAC,QAAQ;EACX,MAAM,QAAQ,KAAK;AACnB,WAAS,SAAS,cAAc,SAAS;AACzC,SAAO,OAAO,QAAQ,YAAY,WAAW,WAAW;EACxD,IAAI,kBAA6C;AACjD,MAAI,KAAK,kBAAkB;AACzB,qBAAkB,KAAK,iBAAiB,KAAK,KAAK,KAAK,MAAM;AAE7D,OAAI,2BAA2B,kBAC7B,UAAS;YACA,OAAO,oBAAoB,UAAU;AAC9C,QAAI,YAAY,mBAAmB,gBAAgB,OACjD,UAAS,gBAAgB;AAE3B,QAAI,aAAa,mBAAmB,gBAAgB,QAClD,WAAU,gBAAgB;;;AAIhC,MAAI,CAAC,OAAO,IACV,QAAO,MAAM,KAAK;AAEpB,MAAI,SAAS,CAAC,gBACZ,QAA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B;GACnB,CAAC;AACF,gBAAc,SAAS,KAAK,YAAY,OAAO;GAC/C"}
package/dist/env.cjs ADDED
@@ -0,0 +1,32 @@
1
+ const require_constant = require('./constant.cjs');
2
+
3
+ //#region src/env.ts
4
+ function isBrowserEnv() {
5
+ return typeof window !== "undefined" && typeof window.document !== "undefined";
6
+ }
7
+ function isReactNativeEnv() {
8
+ return typeof navigator !== "undefined" && navigator?.product === "ReactNative";
9
+ }
10
+ function isBrowserDebug() {
11
+ try {
12
+ if (isBrowserEnv() && window.localStorage) return Boolean(localStorage.getItem(require_constant.BROWSER_LOG_KEY));
13
+ } catch (error) {
14
+ return false;
15
+ }
16
+ return false;
17
+ }
18
+ function isDebugMode() {
19
+ if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) return Boolean(process.env["FEDERATION_DEBUG"]);
20
+ if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) return true;
21
+ return isBrowserDebug();
22
+ }
23
+ const getProcessEnv = function() {
24
+ return typeof process !== "undefined" && process.env ? process.env : {};
25
+ };
26
+
27
+ //#endregion
28
+ exports.getProcessEnv = getProcessEnv;
29
+ exports.isBrowserEnv = isBrowserEnv;
30
+ exports.isDebugMode = isDebugMode;
31
+ exports.isReactNativeEnv = isReactNativeEnv;
32
+ //# sourceMappingURL=env.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.cjs","names":["BROWSER_LOG_KEY"],"sources":["../src/env.ts"],"sourcesContent":["import { BROWSER_LOG_KEY } from './constant';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var FEDERATION_DEBUG: string | undefined;\n}\n\nfunction isBrowserEnv(): boolean {\n return (\n typeof window !== 'undefined' && typeof window.document !== 'undefined'\n );\n}\n\nfunction isReactNativeEnv(): boolean {\n return (\n typeof navigator !== 'undefined' && navigator?.product === 'ReactNative'\n );\n}\n\nfunction isBrowserDebug() {\n try {\n if (isBrowserEnv() && window.localStorage) {\n return Boolean(localStorage.getItem(BROWSER_LOG_KEY));\n }\n } catch (error) {\n return false;\n }\n return false;\n}\n\nfunction isDebugMode(): boolean {\n if (\n typeof process !== 'undefined' &&\n process.env &&\n process.env['FEDERATION_DEBUG']\n ) {\n return Boolean(process.env['FEDERATION_DEBUG']);\n }\n\n if (typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG)) {\n return true;\n }\n\n return isBrowserDebug();\n}\n\nconst getProcessEnv = function (): Record<string, string | undefined> {\n return typeof process !== 'undefined' && process.env ? process.env : {};\n};\n\nexport { isBrowserEnv, isReactNativeEnv, isDebugMode, getProcessEnv };\n"],"mappings":";;;AAOA,SAAS,eAAwB;AAC/B,QACE,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;;AAIhE,SAAS,mBAA4B;AACnC,QACE,OAAO,cAAc,eAAe,WAAW,YAAY;;AAI/D,SAAS,iBAAiB;AACxB,KAAI;AACF,MAAI,cAAc,IAAI,OAAO,aAC3B,QAAO,QAAQ,aAAa,QAAQA,iCAAgB,CAAC;UAEhD,OAAO;AACd,SAAO;;AAET,QAAO;;AAGT,SAAS,cAAuB;AAC9B,KACE,OAAO,YAAY,eACnB,QAAQ,OACR,QAAQ,IAAI,oBAEZ,QAAO,QAAQ,QAAQ,IAAI,oBAAoB;AAGjD,KAAI,OAAO,qBAAqB,eAAe,QAAQ,iBAAiB,CACtE,QAAO;AAGT,QAAO,gBAAgB;;AAGzB,MAAM,gBAAgB,WAAgD;AACpE,QAAO,OAAO,YAAY,eAAe,QAAQ,MAAM,QAAQ,MAAM,EAAE"}
@@ -1,8 +1,11 @@
1
+ //#region src/env.d.ts
1
2
  declare global {
2
- var FEDERATION_DEBUG: string | undefined;
3
+ var FEDERATION_DEBUG: string | undefined;
3
4
  }
4
5
  declare function isBrowserEnv(): boolean;
5
6
  declare function isReactNativeEnv(): boolean;
6
7
  declare function isDebugMode(): boolean;
7
8
  declare const getProcessEnv: () => Record<string, string | undefined>;
8
- export { isBrowserEnv, isReactNativeEnv, isDebugMode, getProcessEnv };
9
+ //#endregion
10
+ export { getProcessEnv, isBrowserEnv, isDebugMode, isReactNativeEnv };
11
+ //# sourceMappingURL=env.d.ts.map
package/dist/env.js ADDED
@@ -0,0 +1,29 @@
1
+ import { BROWSER_LOG_KEY } from "./constant.js";
2
+
3
+ //#region src/env.ts
4
+ function isBrowserEnv() {
5
+ return typeof window !== "undefined" && typeof window.document !== "undefined";
6
+ }
7
+ function isReactNativeEnv() {
8
+ return typeof navigator !== "undefined" && navigator?.product === "ReactNative";
9
+ }
10
+ function isBrowserDebug() {
11
+ try {
12
+ if (isBrowserEnv() && window.localStorage) return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
13
+ } catch (error) {
14
+ return false;
15
+ }
16
+ return false;
17
+ }
18
+ function isDebugMode() {
19
+ if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) return Boolean(process.env["FEDERATION_DEBUG"]);
20
+ if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) return true;
21
+ return isBrowserDebug();
22
+ }
23
+ const getProcessEnv = function() {
24
+ return typeof process !== "undefined" && process.env ? process.env : {};
25
+ };
26
+
27
+ //#endregion
28
+ export { getProcessEnv, isBrowserEnv, isDebugMode, isReactNativeEnv };
29
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","names":[],"sources":["../src/env.ts"],"sourcesContent":["import { BROWSER_LOG_KEY } from './constant';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var FEDERATION_DEBUG: string | undefined;\n}\n\nfunction isBrowserEnv(): boolean {\n return (\n typeof window !== 'undefined' && typeof window.document !== 'undefined'\n );\n}\n\nfunction isReactNativeEnv(): boolean {\n return (\n typeof navigator !== 'undefined' && navigator?.product === 'ReactNative'\n );\n}\n\nfunction isBrowserDebug() {\n try {\n if (isBrowserEnv() && window.localStorage) {\n return Boolean(localStorage.getItem(BROWSER_LOG_KEY));\n }\n } catch (error) {\n return false;\n }\n return false;\n}\n\nfunction isDebugMode(): boolean {\n if (\n typeof process !== 'undefined' &&\n process.env &&\n process.env['FEDERATION_DEBUG']\n ) {\n return Boolean(process.env['FEDERATION_DEBUG']);\n }\n\n if (typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG)) {\n return true;\n }\n\n return isBrowserDebug();\n}\n\nconst getProcessEnv = function (): Record<string, string | undefined> {\n return typeof process !== 'undefined' && process.env ? process.env : {};\n};\n\nexport { isBrowserEnv, isReactNativeEnv, isDebugMode, getProcessEnv };\n"],"mappings":";;;AAOA,SAAS,eAAwB;AAC/B,QACE,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;;AAIhE,SAAS,mBAA4B;AACnC,QACE,OAAO,cAAc,eAAe,WAAW,YAAY;;AAI/D,SAAS,iBAAiB;AACxB,KAAI;AACF,MAAI,cAAc,IAAI,OAAO,aAC3B,QAAO,QAAQ,aAAa,QAAQ,gBAAgB,CAAC;UAEhD,OAAO;AACd,SAAO;;AAET,QAAO;;AAGT,SAAS,cAAuB;AAC9B,KACE,OAAO,YAAY,eACnB,QAAQ,OACR,QAAQ,IAAI,oBAEZ,QAAO,QAAQ,QAAQ,IAAI,oBAAoB;AAGjD,KAAI,OAAO,qBAAqB,eAAe,QAAQ,iBAAiB,CACtE,QAAO;AAGT,QAAO,gBAAgB;;AAGzB,MAAM,gBAAgB,WAAgD;AACpE,QAAO,OAAO,YAAY,eAAe,QAAQ,MAAM,QAAQ,MAAM,EAAE"}
@@ -0,0 +1,138 @@
1
+ const require_constant = require('./constant.cjs');
2
+
3
+ //#region src/generateSnapshotFromManifest.ts
4
+ const simpleJoinRemoteEntry = (rPath, rName) => {
5
+ if (!rPath) return rName;
6
+ const transformPath = (str) => {
7
+ if (str === ".") return "";
8
+ if (str.startsWith("./")) return str.replace("./", "");
9
+ if (str.startsWith("/")) {
10
+ const strWithoutSlash = str.slice(1);
11
+ if (strWithoutSlash.endsWith("/")) return strWithoutSlash.slice(0, -1);
12
+ return strWithoutSlash;
13
+ }
14
+ return str;
15
+ };
16
+ const transformedPath = transformPath(rPath);
17
+ if (!transformedPath) return rName;
18
+ if (transformedPath.endsWith("/")) return `${transformedPath}${rName}`;
19
+ return `${transformedPath}/${rName}`;
20
+ };
21
+ function inferAutoPublicPath(url) {
22
+ return url.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
23
+ }
24
+ function generateSnapshotFromManifest(manifest, options = {}) {
25
+ const { remotes = {}, overrides = {}, version } = options;
26
+ let remoteSnapshot;
27
+ const getPublicPath = () => {
28
+ if ("publicPath" in manifest.metaData) {
29
+ if ((manifest.metaData.publicPath === "auto" || manifest.metaData.publicPath === "") && version) return inferAutoPublicPath(version);
30
+ return manifest.metaData.publicPath;
31
+ } else return manifest.metaData.getPublicPath;
32
+ };
33
+ const overridesKeys = Object.keys(overrides);
34
+ let remotesInfo = {};
35
+ if (!Object.keys(remotes).length) remotesInfo = manifest.remotes?.reduce((res, next) => {
36
+ let matchedVersion;
37
+ const name = next.federationContainerName;
38
+ if (overridesKeys.includes(name)) matchedVersion = overrides[name];
39
+ else if ("version" in next) matchedVersion = next.version;
40
+ else matchedVersion = next.entry;
41
+ res[name] = { matchedVersion };
42
+ return res;
43
+ }, {}) || {};
44
+ Object.keys(remotes).forEach((key) => remotesInfo[key] = { matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key] });
45
+ const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes = {
46
+ path: "",
47
+ name: "",
48
+ zip: "",
49
+ api: ""
50
+ }, buildInfo: { buildVersion }, globalName, ssrRemoteEntry } = manifest.metaData;
51
+ const { exposes } = manifest;
52
+ let basicRemoteSnapshot = {
53
+ version: version ? version : "",
54
+ buildVersion,
55
+ globalName,
56
+ remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
57
+ remoteEntryType,
58
+ remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
59
+ remoteTypesZip: remoteTypes.zip || "",
60
+ remoteTypesAPI: remoteTypes.api || "",
61
+ remotesInfo,
62
+ shared: manifest?.shared.map((item) => ({
63
+ assets: item.assets,
64
+ sharedName: item.name,
65
+ version: item.version,
66
+ usedExports: item.referenceExports || []
67
+ })),
68
+ modules: exposes?.map((expose) => ({
69
+ moduleName: expose.name,
70
+ modulePath: expose.path,
71
+ assets: expose.assets
72
+ }))
73
+ };
74
+ if (manifest.metaData?.prefetchInterface) {
75
+ const prefetchInterface = manifest.metaData.prefetchInterface;
76
+ basicRemoteSnapshot = {
77
+ ...basicRemoteSnapshot,
78
+ prefetchInterface
79
+ };
80
+ }
81
+ if (manifest.metaData?.prefetchEntry) {
82
+ const { path, name, type } = manifest.metaData.prefetchEntry;
83
+ basicRemoteSnapshot = {
84
+ ...basicRemoteSnapshot,
85
+ prefetchEntry: simpleJoinRemoteEntry(path, name),
86
+ prefetchEntryType: type
87
+ };
88
+ }
89
+ if ("publicPath" in manifest.metaData) {
90
+ remoteSnapshot = {
91
+ ...basicRemoteSnapshot,
92
+ publicPath: getPublicPath()
93
+ };
94
+ if (typeof manifest.metaData.ssrPublicPath === "string") remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;
95
+ } else remoteSnapshot = {
96
+ ...basicRemoteSnapshot,
97
+ getPublicPath: getPublicPath()
98
+ };
99
+ if (ssrRemoteEntry) {
100
+ const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
101
+ remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
102
+ remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || "commonjs-module";
103
+ }
104
+ return remoteSnapshot;
105
+ }
106
+ function isManifestProvider(moduleInfo) {
107
+ if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(require_constant.MANIFEST_EXT)) return true;
108
+ else return false;
109
+ }
110
+ function getManifestFileName(manifestOptions) {
111
+ if (!manifestOptions) return {
112
+ statsFileName: require_constant.StatsFileName,
113
+ manifestFileName: require_constant.ManifestFileName
114
+ };
115
+ let filePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
116
+ let fileName = typeof manifestOptions === "boolean" ? "" : manifestOptions.fileName || "";
117
+ const JSON_EXT = ".json";
118
+ const addExt = (name) => {
119
+ if (name.endsWith(JSON_EXT)) return name;
120
+ return `${name}${JSON_EXT}`;
121
+ };
122
+ const insertSuffix = (name, suffix) => {
123
+ return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
124
+ };
125
+ const manifestFileName = fileName ? addExt(fileName) : require_constant.ManifestFileName;
126
+ return {
127
+ statsFileName: simpleJoinRemoteEntry(filePath, fileName ? insertSuffix(manifestFileName, "-stats") : require_constant.StatsFileName),
128
+ manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
129
+ };
130
+ }
131
+
132
+ //#endregion
133
+ exports.generateSnapshotFromManifest = generateSnapshotFromManifest;
134
+ exports.getManifestFileName = getManifestFileName;
135
+ exports.inferAutoPublicPath = inferAutoPublicPath;
136
+ exports.isManifestProvider = isManifestProvider;
137
+ exports.simpleJoinRemoteEntry = simpleJoinRemoteEntry;
138
+ //# sourceMappingURL=generateSnapshotFromManifest.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateSnapshotFromManifest.cjs","names":["MANIFEST_EXT","StatsFileName","ManifestFileName"],"sources":["../src/generateSnapshotFromManifest.ts"],"sourcesContent":["import {\n Manifest,\n ProviderModuleInfo,\n ModuleInfo,\n BasicProviderModuleInfo,\n ConsumerModuleInfo,\n ManifestProvider,\n moduleFederationPlugin,\n} from './types';\nimport { MANIFEST_EXT, ManifestFileName, StatsFileName } from './constant';\n\ninterface IOptions {\n remotes?: Record<string, string>;\n overrides?: Record<string, string>;\n version?: string;\n}\n\nexport const simpleJoinRemoteEntry = (rPath: string, rName: string): string => {\n if (!rPath) {\n return rName;\n }\n const transformPath = (str: string) => {\n if (str === '.') {\n return '';\n }\n if (str.startsWith('./')) {\n return str.replace('./', '');\n }\n if (str.startsWith('/')) {\n const strWithoutSlash = str.slice(1);\n if (strWithoutSlash.endsWith('/')) {\n return strWithoutSlash.slice(0, -1);\n }\n return strWithoutSlash;\n }\n return str;\n };\n\n const transformedPath = transformPath(rPath);\n\n if (!transformedPath) {\n return rName;\n }\n\n if (transformedPath.endsWith('/')) {\n return `${transformedPath}${rName}`;\n }\n\n return `${transformedPath}/${rName}`;\n};\n\nexport function inferAutoPublicPath(url: string): string {\n return url\n .replace(/#.*$/, '')\n .replace(/\\?.*$/, '')\n .replace(/\\/[^\\/]+$/, '/');\n}\n\n// Priority: overrides > remotes\n// eslint-disable-next-line max-lines-per-function\nexport function generateSnapshotFromManifest(\n manifest: Manifest,\n options: IOptions = {},\n): ProviderModuleInfo {\n const { remotes = {}, overrides = {}, version } = options;\n let remoteSnapshot: ProviderModuleInfo;\n\n const getPublicPath = (): string => {\n if ('publicPath' in manifest.metaData) {\n if (\n (manifest.metaData.publicPath === 'auto' ||\n manifest.metaData.publicPath === '') &&\n version\n ) {\n // use same implementation as publicPath auto runtime module implements\n return inferAutoPublicPath(version);\n }\n return manifest.metaData.publicPath;\n } else {\n return manifest.metaData.getPublicPath;\n }\n };\n\n const overridesKeys = Object.keys(overrides);\n\n let remotesInfo: ConsumerModuleInfo['remotesInfo'] = {};\n\n // If remotes are not provided, only the remotes in the manifest will be read\n if (!Object.keys(remotes).length) {\n remotesInfo =\n manifest.remotes?.reduce(\n (res, next) => {\n let matchedVersion: string;\n const name = next.federationContainerName;\n // overrides have higher priority\n if (overridesKeys.includes(name)) {\n matchedVersion = overrides[name];\n } else {\n if ('version' in next) {\n matchedVersion = next.version;\n } else {\n matchedVersion = next.entry;\n }\n }\n res[name] = {\n matchedVersion,\n };\n return res;\n },\n {} as ConsumerModuleInfo['remotesInfo'],\n ) || {};\n }\n\n // If remotes (deploy scenario) are specified, they need to be traversed again\n Object.keys(remotes).forEach(\n (key) =>\n (remotesInfo[key] = {\n // overrides will override dependencies\n matchedVersion: overridesKeys.includes(key)\n ? overrides[key]\n : remotes[key],\n }),\n );\n\n const {\n remoteEntry: {\n path: remoteEntryPath,\n name: remoteEntryName,\n type: remoteEntryType,\n },\n types: remoteTypes = { path: '', name: '', zip: '', api: '' },\n buildInfo: { buildVersion },\n globalName,\n ssrRemoteEntry,\n } = manifest.metaData;\n const { exposes } = manifest;\n\n let basicRemoteSnapshot: BasicProviderModuleInfo = {\n version: version ? version : '',\n buildVersion,\n globalName,\n remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),\n remoteEntryType,\n remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),\n remoteTypesZip: remoteTypes.zip || '',\n remoteTypesAPI: remoteTypes.api || '',\n remotesInfo,\n shared: manifest?.shared.map((item) => ({\n assets: item.assets,\n sharedName: item.name,\n version: item.version,\n // @ts-ignore\n usedExports: item.referenceExports || [],\n })),\n modules: exposes?.map((expose) => ({\n moduleName: expose.name,\n modulePath: expose.path,\n assets: expose.assets,\n })),\n };\n\n if (manifest.metaData?.prefetchInterface) {\n const prefetchInterface = manifest.metaData.prefetchInterface;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchInterface,\n };\n }\n\n if (manifest.metaData?.prefetchEntry) {\n const { path, name, type } = manifest.metaData.prefetchEntry;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchEntry: simpleJoinRemoteEntry(path, name),\n prefetchEntryType: type,\n };\n }\n\n if ('publicPath' in manifest.metaData) {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n publicPath: getPublicPath(),\n };\n if (typeof manifest.metaData.ssrPublicPath === 'string') {\n remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;\n }\n } else {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n getPublicPath: getPublicPath(),\n };\n }\n\n if (ssrRemoteEntry) {\n const fullSSRRemoteEntry = simpleJoinRemoteEntry(\n ssrRemoteEntry.path,\n ssrRemoteEntry.name,\n );\n remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;\n remoteSnapshot.ssrRemoteEntryType =\n ssrRemoteEntry.type || 'commonjs-module';\n }\n\n return remoteSnapshot;\n}\n\nexport function isManifestProvider(\n moduleInfo: ModuleInfo | ManifestProvider,\n): moduleInfo is ManifestProvider {\n if (\n 'remoteEntry' in moduleInfo &&\n moduleInfo.remoteEntry.includes(MANIFEST_EXT)\n ) {\n return true;\n } else {\n return false;\n }\n}\n\nexport function getManifestFileName(\n manifestOptions?: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'],\n): {\n statsFileName: string;\n manifestFileName: string;\n} {\n if (!manifestOptions) {\n return {\n statsFileName: StatsFileName,\n manifestFileName: ManifestFileName,\n };\n }\n\n let filePath =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.filePath || '';\n let fileName =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.fileName || '';\n\n const JSON_EXT = '.json';\n const addExt = (name: string): string => {\n if (name.endsWith(JSON_EXT)) {\n return name;\n }\n return `${name}${JSON_EXT}`;\n };\n const insertSuffix = (name: string, suffix: string): string => {\n return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);\n };\n const manifestFileName = fileName ? addExt(fileName) : ManifestFileName;\n const statsFileName = fileName\n ? insertSuffix(manifestFileName, '-stats')\n : StatsFileName;\n\n return {\n statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),\n manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName),\n };\n}\n"],"mappings":";;;AAiBA,MAAa,yBAAyB,OAAe,UAA0B;AAC7E,KAAI,CAAC,MACH,QAAO;CAET,MAAM,iBAAiB,QAAgB;AACrC,MAAI,QAAQ,IACV,QAAO;AAET,MAAI,IAAI,WAAW,KAAK,CACtB,QAAO,IAAI,QAAQ,MAAM,GAAG;AAE9B,MAAI,IAAI,WAAW,IAAI,EAAE;GACvB,MAAM,kBAAkB,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iB,cACjB,WAAW,YAAY,SAASA,8BAAa,CAE7C,QAAO;KAEP,QAAO;;AAIX,SAAgB,oBACd,iBAIA;AACA,KAAI,CAAC,gBACH,QAAO;EACL,eAAeC;EACf,kBAAkBC;EACnB;CAGH,IAAI,WACF,OAAO,oBAAoB,YAAY,KAAK,gBAAgB,YAAY;CAC1E,IAAI,WACF,OAAO,oBAAoB,YAAY,KAAK,gBAAgB,YAAY;CAE1E,MAAM,WAAW;CACjB,MAAM,UAAU,SAAyB;AACvC,MAAI,KAAK,SAAS,SAAS,CACzB,QAAO;AAET,SAAO,GAAG,OAAO;;CAEnB,MAAM,gBAAgB,MAAc,WAA2B;AAC7D,SAAO,KAAK,QAAQ,UAAU,GAAG,SAAS,WAAW;;CAEvD,MAAM,mBAAmB,WAAW,OAAO,SAAS,GAAGA;AAKvD,QAAO;EACL,eAAe,sBAAsB,UALjB,WAClB,aAAa,kBAAkB,SAAS,GACxCD,+BAG2D;EAC7D,kBAAkB,sBAAsB,UAAU,iBAAiB;EACpE"}
@@ -0,0 +1,22 @@
1
+ import { Manifest } from "./types/manifest.js";
2
+ import { ManifestProvider, ModuleInfo, ProviderModuleInfo } from "./types/snapshot.js";
3
+ import { ModuleFederationPluginOptions } from "./types/plugins/ModuleFederationPlugin.js";
4
+ import "./types/index.js";
5
+
6
+ //#region src/generateSnapshotFromManifest.d.ts
7
+ interface IOptions {
8
+ remotes?: Record<string, string>;
9
+ overrides?: Record<string, string>;
10
+ version?: string;
11
+ }
12
+ declare const simpleJoinRemoteEntry: (rPath: string, rName: string) => string;
13
+ declare function inferAutoPublicPath(url: string): string;
14
+ declare function generateSnapshotFromManifest(manifest: Manifest, options?: IOptions): ProviderModuleInfo;
15
+ declare function isManifestProvider(moduleInfo: ModuleInfo | ManifestProvider): moduleInfo is ManifestProvider;
16
+ declare function getManifestFileName(manifestOptions?: ModuleFederationPluginOptions['manifest']): {
17
+ statsFileName: string;
18
+ manifestFileName: string;
19
+ };
20
+ //#endregion
21
+ export { generateSnapshotFromManifest, getManifestFileName, inferAutoPublicPath, isManifestProvider, simpleJoinRemoteEntry };
22
+ //# sourceMappingURL=generateSnapshotFromManifest.d.ts.map
@@ -0,0 +1,134 @@
1
+ import { MANIFEST_EXT, ManifestFileName, StatsFileName } from "./constant.js";
2
+
3
+ //#region src/generateSnapshotFromManifest.ts
4
+ const simpleJoinRemoteEntry = (rPath, rName) => {
5
+ if (!rPath) return rName;
6
+ const transformPath = (str) => {
7
+ if (str === ".") return "";
8
+ if (str.startsWith("./")) return str.replace("./", "");
9
+ if (str.startsWith("/")) {
10
+ const strWithoutSlash = str.slice(1);
11
+ if (strWithoutSlash.endsWith("/")) return strWithoutSlash.slice(0, -1);
12
+ return strWithoutSlash;
13
+ }
14
+ return str;
15
+ };
16
+ const transformedPath = transformPath(rPath);
17
+ if (!transformedPath) return rName;
18
+ if (transformedPath.endsWith("/")) return `${transformedPath}${rName}`;
19
+ return `${transformedPath}/${rName}`;
20
+ };
21
+ function inferAutoPublicPath(url) {
22
+ return url.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
23
+ }
24
+ function generateSnapshotFromManifest(manifest, options = {}) {
25
+ const { remotes = {}, overrides = {}, version } = options;
26
+ let remoteSnapshot;
27
+ const getPublicPath = () => {
28
+ if ("publicPath" in manifest.metaData) {
29
+ if ((manifest.metaData.publicPath === "auto" || manifest.metaData.publicPath === "") && version) return inferAutoPublicPath(version);
30
+ return manifest.metaData.publicPath;
31
+ } else return manifest.metaData.getPublicPath;
32
+ };
33
+ const overridesKeys = Object.keys(overrides);
34
+ let remotesInfo = {};
35
+ if (!Object.keys(remotes).length) remotesInfo = manifest.remotes?.reduce((res, next) => {
36
+ let matchedVersion;
37
+ const name = next.federationContainerName;
38
+ if (overridesKeys.includes(name)) matchedVersion = overrides[name];
39
+ else if ("version" in next) matchedVersion = next.version;
40
+ else matchedVersion = next.entry;
41
+ res[name] = { matchedVersion };
42
+ return res;
43
+ }, {}) || {};
44
+ Object.keys(remotes).forEach((key) => remotesInfo[key] = { matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key] });
45
+ const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes = {
46
+ path: "",
47
+ name: "",
48
+ zip: "",
49
+ api: ""
50
+ }, buildInfo: { buildVersion }, globalName, ssrRemoteEntry } = manifest.metaData;
51
+ const { exposes } = manifest;
52
+ let basicRemoteSnapshot = {
53
+ version: version ? version : "",
54
+ buildVersion,
55
+ globalName,
56
+ remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
57
+ remoteEntryType,
58
+ remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
59
+ remoteTypesZip: remoteTypes.zip || "",
60
+ remoteTypesAPI: remoteTypes.api || "",
61
+ remotesInfo,
62
+ shared: manifest?.shared.map((item) => ({
63
+ assets: item.assets,
64
+ sharedName: item.name,
65
+ version: item.version,
66
+ usedExports: item.referenceExports || []
67
+ })),
68
+ modules: exposes?.map((expose) => ({
69
+ moduleName: expose.name,
70
+ modulePath: expose.path,
71
+ assets: expose.assets
72
+ }))
73
+ };
74
+ if (manifest.metaData?.prefetchInterface) {
75
+ const prefetchInterface = manifest.metaData.prefetchInterface;
76
+ basicRemoteSnapshot = {
77
+ ...basicRemoteSnapshot,
78
+ prefetchInterface
79
+ };
80
+ }
81
+ if (manifest.metaData?.prefetchEntry) {
82
+ const { path, name, type } = manifest.metaData.prefetchEntry;
83
+ basicRemoteSnapshot = {
84
+ ...basicRemoteSnapshot,
85
+ prefetchEntry: simpleJoinRemoteEntry(path, name),
86
+ prefetchEntryType: type
87
+ };
88
+ }
89
+ if ("publicPath" in manifest.metaData) {
90
+ remoteSnapshot = {
91
+ ...basicRemoteSnapshot,
92
+ publicPath: getPublicPath()
93
+ };
94
+ if (typeof manifest.metaData.ssrPublicPath === "string") remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;
95
+ } else remoteSnapshot = {
96
+ ...basicRemoteSnapshot,
97
+ getPublicPath: getPublicPath()
98
+ };
99
+ if (ssrRemoteEntry) {
100
+ const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
101
+ remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
102
+ remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || "commonjs-module";
103
+ }
104
+ return remoteSnapshot;
105
+ }
106
+ function isManifestProvider(moduleInfo) {
107
+ if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) return true;
108
+ else return false;
109
+ }
110
+ function getManifestFileName(manifestOptions) {
111
+ if (!manifestOptions) return {
112
+ statsFileName: StatsFileName,
113
+ manifestFileName: ManifestFileName
114
+ };
115
+ let filePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
116
+ let fileName = typeof manifestOptions === "boolean" ? "" : manifestOptions.fileName || "";
117
+ const JSON_EXT = ".json";
118
+ const addExt = (name) => {
119
+ if (name.endsWith(JSON_EXT)) return name;
120
+ return `${name}${JSON_EXT}`;
121
+ };
122
+ const insertSuffix = (name, suffix) => {
123
+ return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
124
+ };
125
+ const manifestFileName = fileName ? addExt(fileName) : ManifestFileName;
126
+ return {
127
+ statsFileName: simpleJoinRemoteEntry(filePath, fileName ? insertSuffix(manifestFileName, "-stats") : StatsFileName),
128
+ manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
129
+ };
130
+ }
131
+
132
+ //#endregion
133
+ export { generateSnapshotFromManifest, getManifestFileName, inferAutoPublicPath, isManifestProvider, simpleJoinRemoteEntry };
134
+ //# sourceMappingURL=generateSnapshotFromManifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateSnapshotFromManifest.js","names":[],"sources":["../src/generateSnapshotFromManifest.ts"],"sourcesContent":["import {\n Manifest,\n ProviderModuleInfo,\n ModuleInfo,\n BasicProviderModuleInfo,\n ConsumerModuleInfo,\n ManifestProvider,\n moduleFederationPlugin,\n} from './types';\nimport { MANIFEST_EXT, ManifestFileName, StatsFileName } from './constant';\n\ninterface IOptions {\n remotes?: Record<string, string>;\n overrides?: Record<string, string>;\n version?: string;\n}\n\nexport const simpleJoinRemoteEntry = (rPath: string, rName: string): string => {\n if (!rPath) {\n return rName;\n }\n const transformPath = (str: string) => {\n if (str === '.') {\n return '';\n }\n if (str.startsWith('./')) {\n return str.replace('./', '');\n }\n if (str.startsWith('/')) {\n const strWithoutSlash = str.slice(1);\n if (strWithoutSlash.endsWith('/')) {\n return strWithoutSlash.slice(0, -1);\n }\n return strWithoutSlash;\n }\n return str;\n };\n\n const transformedPath = transformPath(rPath);\n\n if (!transformedPath) {\n return rName;\n }\n\n if (transformedPath.endsWith('/')) {\n return `${transformedPath}${rName}`;\n }\n\n return `${transformedPath}/${rName}`;\n};\n\nexport function inferAutoPublicPath(url: string): string {\n return url\n .replace(/#.*$/, '')\n .replace(/\\?.*$/, '')\n .replace(/\\/[^\\/]+$/, '/');\n}\n\n// Priority: overrides > remotes\n// eslint-disable-next-line max-lines-per-function\nexport function generateSnapshotFromManifest(\n manifest: Manifest,\n options: IOptions = {},\n): ProviderModuleInfo {\n const { remotes = {}, overrides = {}, version } = options;\n let remoteSnapshot: ProviderModuleInfo;\n\n const getPublicPath = (): string => {\n if ('publicPath' in manifest.metaData) {\n if (\n (manifest.metaData.publicPath === 'auto' ||\n manifest.metaData.publicPath === '') &&\n version\n ) {\n // use same implementation as publicPath auto runtime module implements\n return inferAutoPublicPath(version);\n }\n return manifest.metaData.publicPath;\n } else {\n return manifest.metaData.getPublicPath;\n }\n };\n\n const overridesKeys = Object.keys(overrides);\n\n let remotesInfo: ConsumerModuleInfo['remotesInfo'] = {};\n\n // If remotes are not provided, only the remotes in the manifest will be read\n if (!Object.keys(remotes).length) {\n remotesInfo =\n manifest.remotes?.reduce(\n (res, next) => {\n let matchedVersion: string;\n const name = next.federationContainerName;\n // overrides have higher priority\n if (overridesKeys.includes(name)) {\n matchedVersion = overrides[name];\n } else {\n if ('version' in next) {\n matchedVersion = next.version;\n } else {\n matchedVersion = next.entry;\n }\n }\n res[name] = {\n matchedVersion,\n };\n return res;\n },\n {} as ConsumerModuleInfo['remotesInfo'],\n ) || {};\n }\n\n // If remotes (deploy scenario) are specified, they need to be traversed again\n Object.keys(remotes).forEach(\n (key) =>\n (remotesInfo[key] = {\n // overrides will override dependencies\n matchedVersion: overridesKeys.includes(key)\n ? overrides[key]\n : remotes[key],\n }),\n );\n\n const {\n remoteEntry: {\n path: remoteEntryPath,\n name: remoteEntryName,\n type: remoteEntryType,\n },\n types: remoteTypes = { path: '', name: '', zip: '', api: '' },\n buildInfo: { buildVersion },\n globalName,\n ssrRemoteEntry,\n } = manifest.metaData;\n const { exposes } = manifest;\n\n let basicRemoteSnapshot: BasicProviderModuleInfo = {\n version: version ? version : '',\n buildVersion,\n globalName,\n remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),\n remoteEntryType,\n remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),\n remoteTypesZip: remoteTypes.zip || '',\n remoteTypesAPI: remoteTypes.api || '',\n remotesInfo,\n shared: manifest?.shared.map((item) => ({\n assets: item.assets,\n sharedName: item.name,\n version: item.version,\n // @ts-ignore\n usedExports: item.referenceExports || [],\n })),\n modules: exposes?.map((expose) => ({\n moduleName: expose.name,\n modulePath: expose.path,\n assets: expose.assets,\n })),\n };\n\n if (manifest.metaData?.prefetchInterface) {\n const prefetchInterface = manifest.metaData.prefetchInterface;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchInterface,\n };\n }\n\n if (manifest.metaData?.prefetchEntry) {\n const { path, name, type } = manifest.metaData.prefetchEntry;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchEntry: simpleJoinRemoteEntry(path, name),\n prefetchEntryType: type,\n };\n }\n\n if ('publicPath' in manifest.metaData) {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n publicPath: getPublicPath(),\n };\n if (typeof manifest.metaData.ssrPublicPath === 'string') {\n remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;\n }\n } else {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n getPublicPath: getPublicPath(),\n };\n }\n\n if (ssrRemoteEntry) {\n const fullSSRRemoteEntry = simpleJoinRemoteEntry(\n ssrRemoteEntry.path,\n ssrRemoteEntry.name,\n );\n remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;\n remoteSnapshot.ssrRemoteEntryType =\n ssrRemoteEntry.type || 'commonjs-module';\n }\n\n return remoteSnapshot;\n}\n\nexport function isManifestProvider(\n moduleInfo: ModuleInfo | ManifestProvider,\n): moduleInfo is ManifestProvider {\n if (\n 'remoteEntry' in moduleInfo &&\n moduleInfo.remoteEntry.includes(MANIFEST_EXT)\n ) {\n return true;\n } else {\n return false;\n }\n}\n\nexport function getManifestFileName(\n manifestOptions?: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'],\n): {\n statsFileName: string;\n manifestFileName: string;\n} {\n if (!manifestOptions) {\n return {\n statsFileName: StatsFileName,\n manifestFileName: ManifestFileName,\n };\n }\n\n let filePath =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.filePath || '';\n let fileName =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.fileName || '';\n\n const JSON_EXT = '.json';\n const addExt = (name: string): string => {\n if (name.endsWith(JSON_EXT)) {\n return name;\n }\n return `${name}${JSON_EXT}`;\n };\n const insertSuffix = (name: string, suffix: string): string => {\n return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);\n };\n const manifestFileName = fileName ? addExt(fileName) : ManifestFileName;\n const statsFileName = fileName\n ? insertSuffix(manifestFileName, '-stats')\n : StatsFileName;\n\n return {\n statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),\n manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName),\n };\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7C,gBAAe,gBAAgB,SAAS,SAAS;OAGnD,kBAAiB;EACf,GAAG;EACH,eAAe,eAAe;EAC/B;AAGH,KAAI,gBAAgB;EAClB,MAAM,qBAAqB,sBACzB,eAAe,MACf,eAAe,KAChB;AACD,iBAAe,iBAAiB;AAChC,iBAAe,qBACb,eAAe,QAAQ;;AAG3B,QAAO;;AAGT,SAAgB,mBACd,YACgC;AAChC,KACE,iBAAiB,cACjB,WAAW,YAAY,SAAS,aAAa,CAE7C,QAAO;KAEP,QAAO;;AAIX,SAAgB,oBACd,iBAIA;AACA,KAAI,CAAC,gBACH,QAAO;EACL,eAAe;EACf,kBAAkB;EACnB;CAGH,IAAI,WACF,OAAO,oBAAoB,YAAY,KAAK,gBAAgB,YAAY;CAC1E,IAAI,WACF,OAAO,oBAAoB,YAAY,KAAK,gBAAgB,YAAY;CAE1E,MAAM,WAAW;CACjB,MAAM,UAAU,SAAyB;AACvC,MAAI,KAAK,SAAS,SAAS,CACzB,QAAO;AAET,SAAO,GAAG,OAAO;;CAEnB,MAAM,gBAAgB,MAAc,WAA2B;AAC7D,SAAO,KAAK,QAAQ,UAAU,GAAG,SAAS,WAAW;;CAEvD,MAAM,mBAAmB,WAAW,OAAO,SAAS,GAAG;AAKvD,QAAO;EACL,eAAe,sBAAsB,UALjB,WAClB,aAAa,kBAAkB,SAAS,GACxC,cAG2D;EAC7D,kBAAkB,sBAAsB,UAAU,iBAAiB;EACpE"}
package/dist/index.cjs ADDED
@@ -0,0 +1,89 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_constant = require('./constant.cjs');
3
+ const require_ContainerPlugin = require('./types/plugins/ContainerPlugin.cjs');
4
+ const require_ContainerReferencePlugin = require('./types/plugins/ContainerReferencePlugin.cjs');
5
+ const require_ModuleFederationPlugin = require('./types/plugins/ModuleFederationPlugin.cjs');
6
+ const require_SharePlugin = require('./types/plugins/SharePlugin.cjs');
7
+ const require_env = require('./env.cjs');
8
+ const require_utils = require('./utils.cjs');
9
+ const require_generateSnapshotFromManifest = require('./generateSnapshotFromManifest.cjs');
10
+ const require_logger = require('./logger.cjs');
11
+ const require_dom = require('./dom.cjs');
12
+ const require_node = require('./node.cjs');
13
+ const require_normalizeOptions = require('./normalizeOptions.cjs');
14
+ const require_createModuleFederationConfig = require('./createModuleFederationConfig.cjs');
15
+
16
+ exports.BROWSER_LOG_KEY = require_constant.BROWSER_LOG_KEY;
17
+ exports.ENCODE_NAME_PREFIX = require_constant.ENCODE_NAME_PREFIX;
18
+ exports.EncodedNameTransformMap = require_constant.EncodedNameTransformMap;
19
+ exports.FederationModuleManifest = require_constant.FederationModuleManifest;
20
+ exports.MANIFEST_EXT = require_constant.MANIFEST_EXT;
21
+ exports.MFModuleType = require_constant.MFModuleType;
22
+ exports.MFPrefetchCommon = require_constant.MFPrefetchCommon;
23
+ exports.MODULE_DEVTOOL_IDENTIFIER = require_constant.MODULE_DEVTOOL_IDENTIFIER;
24
+ exports.ManifestFileName = require_constant.ManifestFileName;
25
+ exports.NameTransformMap = require_constant.NameTransformMap;
26
+ exports.NameTransformSymbol = require_constant.NameTransformSymbol;
27
+ exports.SEPARATOR = require_constant.SEPARATOR;
28
+ exports.StatsFileName = require_constant.StatsFileName;
29
+ exports.TEMP_DIR = require_constant.TEMP_DIR;
30
+ exports.TreeShakingStatus = require_constant.TreeShakingStatus;
31
+ exports.assert = require_utils.assert;
32
+ exports.bindLoggerToCompiler = require_logger.bindLoggerToCompiler;
33
+ exports.composeKeyWithSeparator = require_utils.composeKeyWithSeparator;
34
+ Object.defineProperty(exports, 'containerPlugin', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return require_ContainerPlugin.ContainerPlugin_exports;
38
+ }
39
+ });
40
+ Object.defineProperty(exports, 'containerReferencePlugin', {
41
+ enumerable: true,
42
+ get: function () {
43
+ return require_ContainerReferencePlugin.ContainerReferencePlugin_exports;
44
+ }
45
+ });
46
+ exports.createInfrastructureLogger = require_logger.createInfrastructureLogger;
47
+ exports.createLink = require_dom.createLink;
48
+ exports.createLogger = require_logger.createLogger;
49
+ exports.createModuleFederationConfig = require_createModuleFederationConfig.createModuleFederationConfig;
50
+ exports.createScript = require_dom.createScript;
51
+ exports.createScriptNode = require_node.createScriptNode;
52
+ exports.decodeName = require_utils.decodeName;
53
+ exports.encodeName = require_utils.encodeName;
54
+ exports.error = require_utils.error;
55
+ exports.generateExposeFilename = require_utils.generateExposeFilename;
56
+ exports.generateShareFilename = require_utils.generateShareFilename;
57
+ exports.generateSnapshotFromManifest = require_generateSnapshotFromManifest.generateSnapshotFromManifest;
58
+ exports.getManifestFileName = require_generateSnapshotFromManifest.getManifestFileName;
59
+ exports.getProcessEnv = require_env.getProcessEnv;
60
+ exports.getResourceUrl = require_utils.getResourceUrl;
61
+ exports.inferAutoPublicPath = require_generateSnapshotFromManifest.inferAutoPublicPath;
62
+ exports.infrastructureLogger = require_logger.infrastructureLogger;
63
+ exports.isBrowserEnv = require_env.isBrowserEnv;
64
+ exports.isDebugMode = require_env.isDebugMode;
65
+ exports.isManifestProvider = require_generateSnapshotFromManifest.isManifestProvider;
66
+ exports.isReactNativeEnv = require_env.isReactNativeEnv;
67
+ exports.isRequiredVersion = require_utils.isRequiredVersion;
68
+ exports.isStaticResourcesEqual = require_dom.isStaticResourcesEqual;
69
+ exports.loadScript = require_dom.loadScript;
70
+ exports.loadScriptNode = require_node.loadScriptNode;
71
+ exports.logger = require_logger.logger;
72
+ Object.defineProperty(exports, 'moduleFederationPlugin', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return require_ModuleFederationPlugin.ModuleFederationPlugin_exports;
76
+ }
77
+ });
78
+ exports.normalizeOptions = require_normalizeOptions.normalizeOptions;
79
+ exports.parseEntry = require_utils.parseEntry;
80
+ exports.safeToString = require_utils.safeToString;
81
+ exports.safeWrapper = require_dom.safeWrapper;
82
+ Object.defineProperty(exports, 'sharePlugin', {
83
+ enumerable: true,
84
+ get: function () {
85
+ return require_SharePlugin.SharePlugin_exports;
86
+ }
87
+ });
88
+ exports.simpleJoinRemoteEntry = require_generateSnapshotFromManifest.simpleJoinRemoteEntry;
89
+ exports.warn = require_utils.warn;
package/dist/index.d.ts CHANGED
@@ -1 +1,20 @@
1
- export * from "./src/index";
1
+ import { BROWSER_LOG_KEY, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, MANIFEST_EXT, MFModuleType, MFPrefetchCommon, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, TEMP_DIR, TreeShakingStatus } from "./constant.js";
2
+ import { Module, RemoteEntryInfo, RemoteWithEntry, RemoteWithVersion } from "./types/common.js";
3
+ import { BasicStatsMetaData, ManifestModuleInfos, MetaDataTypes, RemoteEntryType, ResourceInfo, Stats, StatsAssets, StatsBuildInfo, StatsExpose, StatsMetaData, StatsMetaDataWithGetPublicPath, StatsMetaDataWithPublicPath, StatsModuleInfo, StatsRemote, StatsRemoteVal, StatsRemoteWithEntry, StatsRemoteWithVersion, StatsShared } from "./types/stats.js";
4
+ import { Manifest, ManifestExpose, ManifestRemote, ManifestRemoteCommonInfo, ManifestShared } from "./types/manifest.js";
5
+ import { BasicProviderModuleInfo, ConsumerModuleInfo, ConsumerModuleInfoWithPublicPath, GlobalModuleInfo, ManifestProvider, ModuleInfo, ProviderModuleInfo, PureConsumerModuleInfo, PureEntryProvider } from "./types/snapshot.js";
6
+ import { ModuleFederationPlugin_d_exports } from "./types/plugins/ModuleFederationPlugin.js";
7
+ import { ContainerPlugin_d_exports } from "./types/plugins/ContainerPlugin.js";
8
+ import { ContainerReferencePlugin_d_exports } from "./types/plugins/ContainerReferencePlugin.js";
9
+ import { SharePlugin_d_exports } from "./types/plugins/SharePlugin.js";
10
+ import { CreateScriptHook, CreateScriptHookDom, CreateScriptHookNode, CreateScriptHookReturn, CreateScriptHookReturnDom, CreateScriptHookReturnNode, FetchHook } from "./types/hooks.js";
11
+ import "./types/index.js";
12
+ import { assert, composeKeyWithSeparator, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, getResourceUrl, isRequiredVersion, parseEntry, safeToString, warn } from "./utils.js";
13
+ import { generateSnapshotFromManifest, getManifestFileName, inferAutoPublicPath, isManifestProvider, simpleJoinRemoteEntry } from "./generateSnapshotFromManifest.js";
14
+ import { InfrastructureLogger, Logger, bindLoggerToCompiler, createInfrastructureLogger, createLogger, infrastructureLogger, logger } from "./logger.js";
15
+ import { getProcessEnv, isBrowserEnv, isDebugMode, isReactNativeEnv } from "./env.js";
16
+ import { createLink, createScript, isStaticResourcesEqual, loadScript, safeWrapper } from "./dom.js";
17
+ import { createScriptNode, loadScriptNode } from "./node.js";
18
+ import { normalizeOptions } from "./normalizeOptions.js";
19
+ import { createModuleFederationConfig } from "./createModuleFederationConfig.js";
20
+ export { BROWSER_LOG_KEY, BasicProviderModuleInfo, BasicStatsMetaData, ConsumerModuleInfo, ConsumerModuleInfoWithPublicPath, CreateScriptHook, CreateScriptHookDom, CreateScriptHookNode, CreateScriptHookReturn, CreateScriptHookReturnDom, CreateScriptHookReturnNode, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, FetchHook, GlobalModuleInfo, type InfrastructureLogger, type Logger, MANIFEST_EXT, MFModuleType, MFPrefetchCommon, MODULE_DEVTOOL_IDENTIFIER, Manifest, ManifestExpose, ManifestFileName, ManifestModuleInfos, ManifestProvider, ManifestRemote, ManifestRemoteCommonInfo, ManifestShared, MetaDataTypes, Module, ModuleInfo, NameTransformMap, NameTransformSymbol, ProviderModuleInfo, PureConsumerModuleInfo, PureEntryProvider, RemoteEntryInfo, RemoteEntryType, RemoteWithEntry, RemoteWithVersion, ResourceInfo, SEPARATOR, Stats, StatsAssets, StatsBuildInfo, StatsExpose, StatsFileName, StatsMetaData, StatsMetaDataWithGetPublicPath, StatsMetaDataWithPublicPath, StatsModuleInfo, StatsRemote, StatsRemoteVal, StatsRemoteWithEntry, StatsRemoteWithVersion, StatsShared, TEMP_DIR, TreeShakingStatus, assert, bindLoggerToCompiler, composeKeyWithSeparator, ContainerPlugin_d_exports as containerPlugin, ContainerReferencePlugin_d_exports as containerReferencePlugin, createInfrastructureLogger, createLink, createLogger, createModuleFederationConfig, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getManifestFileName, getProcessEnv, getResourceUrl, inferAutoPublicPath, infrastructureLogger, isBrowserEnv, isDebugMode, isManifestProvider, isReactNativeEnv, isRequiredVersion, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin_d_exports as moduleFederationPlugin, normalizeOptions, parseEntry, safeToString, safeWrapper, SharePlugin_d_exports as sharePlugin, simpleJoinRemoteEntry, warn };
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { BROWSER_LOG_KEY, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, MANIFEST_EXT, MFModuleType, MFPrefetchCommon, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, TEMP_DIR, TreeShakingStatus } from "./constant.js";
2
+ import { ContainerPlugin_exports } from "./types/plugins/ContainerPlugin.js";
3
+ import { ContainerReferencePlugin_exports } from "./types/plugins/ContainerReferencePlugin.js";
4
+ import { ModuleFederationPlugin_exports } from "./types/plugins/ModuleFederationPlugin.js";
5
+ import { SharePlugin_exports } from "./types/plugins/SharePlugin.js";
6
+ import { getProcessEnv, isBrowserEnv, isDebugMode, isReactNativeEnv } from "./env.js";
7
+ import { assert, composeKeyWithSeparator, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, getResourceUrl, isRequiredVersion, parseEntry, safeToString, warn } from "./utils.js";
8
+ import { generateSnapshotFromManifest, getManifestFileName, inferAutoPublicPath, isManifestProvider, simpleJoinRemoteEntry } from "./generateSnapshotFromManifest.js";
9
+ import { bindLoggerToCompiler, createInfrastructureLogger, createLogger, infrastructureLogger, logger } from "./logger.js";
10
+ import { createLink, createScript, isStaticResourcesEqual, loadScript, safeWrapper } from "./dom.js";
11
+ import { createScriptNode, loadScriptNode } from "./node.js";
12
+ import { normalizeOptions } from "./normalizeOptions.js";
13
+ import { createModuleFederationConfig } from "./createModuleFederationConfig.js";
14
+
15
+ export { BROWSER_LOG_KEY, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, MANIFEST_EXT, MFModuleType, MFPrefetchCommon, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, TEMP_DIR, TreeShakingStatus, assert, bindLoggerToCompiler, composeKeyWithSeparator, ContainerPlugin_exports as containerPlugin, ContainerReferencePlugin_exports as containerReferencePlugin, createInfrastructureLogger, createLink, createLogger, createModuleFederationConfig, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getManifestFileName, getProcessEnv, getResourceUrl, inferAutoPublicPath, infrastructureLogger, isBrowserEnv, isDebugMode, isManifestProvider, isReactNativeEnv, isRequiredVersion, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin_exports as moduleFederationPlugin, normalizeOptions, parseEntry, safeToString, safeWrapper, SharePlugin_exports as sharePlugin, simpleJoinRemoteEntry, warn };