@module-federation/node 2.7.39 → 2.7.41

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.
@@ -2,6 +2,37 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
2
2
 
3
3
  //#region src/runtimePlugin.ts
4
4
  const nodeRuntimeImportCache = /* @__PURE__ */ new Map();
5
+ const CHUNK_PREVIEW_LENGTH = 240;
6
+ const getChunkPreview = (content) => content.slice(0, CHUNK_PREVIEW_LENGTH).replace(/\s+/g, " ").trim();
7
+ const enrichChunkExecutionError = (error, options) => {
8
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
9
+ const preview = getChunkPreview(options.content);
10
+ const details = [
11
+ `Federated chunk execution failed.`,
12
+ `chunk: ${options.chunkName}`,
13
+ `source: ${options.source}`,
14
+ `location: ${options.location}`
15
+ ];
16
+ if (options.hostName) details.push(`host: ${options.hostName}`);
17
+ if (options.resolution) {
18
+ details.push(`resolved-from: ${options.resolution.resolvedFrom}`);
19
+ if (options.resolution.remoteName) details.push(`remote: ${options.resolution.remoteName}`);
20
+ if (options.resolution.publicPath) details.push(`public-path: ${options.resolution.publicPath}`);
21
+ if (options.resolution.rootOutputDir) details.push(`root-output-dir: ${options.resolution.rootOutputDir}`);
22
+ if (options.resolution.remoteEntryUrl) details.push(`remote-entry: ${options.resolution.remoteEntryUrl}`);
23
+ }
24
+ if (preview) details.push(`preview: ${preview}`);
25
+ normalizedError.message = `${normalizedError.message}\n${details.join("\n")}`;
26
+ Object.assign(normalizedError, {
27
+ chunkName: options.chunkName,
28
+ chunkLocation: options.location,
29
+ chunkSource: options.source,
30
+ chunkPreview: preview,
31
+ chunkHostName: options.hostName,
32
+ chunkResolution: options.resolution
33
+ });
34
+ return normalizedError;
35
+ };
5
36
  function importNodeModule(name) {
6
37
  if (!name) throw new Error("import specifier is required");
7
38
  if (nodeRuntimeImportCache.has(name)) return nodeRuntimeImportCache.get(name);
@@ -46,8 +77,12 @@ const loadFromFs = (filename, callback) => {
46
77
  }).runInThisContext()(chunk, __non_webpack_require__, path.dirname(filename), filename);
47
78
  callback(null, chunk);
48
79
  } catch (e) {
49
- console.log("'runInThisContext threw'", e);
50
- callback(e, null);
80
+ callback(enrichChunkExecutionError(e, {
81
+ chunkName: path.basename(filename),
82
+ location: filename,
83
+ source: "filesystem",
84
+ content
85
+ }), null);
51
86
  }
52
87
  });
53
88
  else callback(/* @__PURE__ */ new Error(`File ${filename} does not exist`), null);
@@ -60,17 +95,32 @@ const fetchAndRun = (url, chunkName, callback, args) => {
60
95
  });
61
96
  }).then((data) => {
62
97
  const chunk = {};
98
+ const hostName = args?.origin?.options?.name || args?.origin?.name;
99
+ const resolution = url.mfMetadata;
63
100
  try {
64
101
  eval(`(function(exports, require, __dirname, __filename) {${data}\n})`)(chunk, __non_webpack_require__, url.pathname.split("/").slice(0, -1).join("/"), chunkName);
65
102
  callback(null, chunk);
66
103
  } catch (e) {
67
- callback(e, null);
104
+ callback(enrichChunkExecutionError(e, {
105
+ chunkName,
106
+ location: url.href,
107
+ source: "remote-url",
108
+ content: data,
109
+ hostName,
110
+ resolution
111
+ }), null);
68
112
  }
69
113
  }).catch((err) => callback(err, null));
70
114
  };
71
115
  const resolveUrl = (remoteName, chunkName) => {
72
116
  try {
73
- return new URL(chunkName, __webpack_require__.p);
117
+ return Object.assign(new URL(chunkName, __webpack_require__.p), { mfMetadata: {
118
+ chunkName,
119
+ publicPath: __webpack_require__.p,
120
+ remoteName,
121
+ rootOutputDir: __webpack_require__.federation.rootOutputDir || "",
122
+ resolvedFrom: "public-path"
123
+ } });
74
124
  } catch {
75
125
  const entryUrl = returnFromCache(remoteName) || returnFromGlobalInstances(remoteName);
76
126
  if (!entryUrl) return null;
@@ -81,7 +131,14 @@ const resolveUrl = (remoteName, chunkName) => {
81
131
  const directoryPath = lastSlashIndex >= 0 ? urlPath.substring(0, lastSlashIndex + 1) : "/";
82
132
  const rootDir = __webpack_require__.federation.rootOutputDir || "";
83
133
  const combinedPath = path.join(directoryPath, rootDir, chunkName).replace(/\\/g, "/");
84
- return new URL(combinedPath, url.origin);
134
+ return Object.assign(new URL(combinedPath, url.origin), { mfMetadata: {
135
+ chunkName,
136
+ publicPath: __webpack_require__.p,
137
+ remoteName,
138
+ rootOutputDir: rootDir,
139
+ resolvedFrom: "remote-entry-fallback",
140
+ remoteEntryUrl: entryUrl
141
+ } });
85
142
  }
86
143
  };
87
144
  const loadChunk = (strategy, chunkId, rootOutputDir, callback, args) => {
@@ -1 +1 @@
1
- {"version":3,"file":"runtimePlugin.js","names":[],"sources":["../../src/runtimePlugin.ts"],"sourcesContent":["import type {\n ModuleFederationRuntimePlugin,\n ModuleFederation,\n} from '@module-federation/runtime';\ntype WebpackRequire = {\n (id: string): any;\n u: (chunkId: string) => string;\n p: string;\n m: { [key: string]: any };\n o: (obj: any, prop: string) => boolean;\n C?: (chunk: any) => void;\n l: (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ) => void;\n federation: {\n runtime: {\n loadScriptNode: (\n url: string,\n options: { attrs: { globalName: string } },\n ) => Promise<any>;\n };\n instance: ModuleFederation;\n chunkMatcher?: (chunkId: string) => boolean;\n rootOutputDir?: string;\n initOptions: {\n name: string;\n remotes: any;\n };\n };\n f?: {\n require?: (chunkId: string, promises: any[]) => void;\n readFileVm?: (chunkId: string, promises: any[]) => void;\n };\n};\n\ndeclare const __webpack_require__: WebpackRequire;\ndeclare const __non_webpack_require__: (id: string) => any;\n\nexport const nodeRuntimeImportCache = new Map<string, Promise<any>>();\n\nexport function importNodeModule<T>(name: string): Promise<T> {\n if (!name) {\n throw new Error('import specifier is required');\n }\n\n // Check cache to prevent infinite recursion\n if (nodeRuntimeImportCache.has(name)) {\n return nodeRuntimeImportCache.get(name)!;\n }\n\n const importModule = new Function('name', `return import(name)`);\n const promise = importModule(name)\n .then((res: any) => res.default as T)\n .catch((error: any) => {\n console.error(`Error importing module ${name}:`, error);\n // Remove from cache on error so it can be retried\n nodeRuntimeImportCache.delete(name);\n throw error;\n });\n\n // Cache the promise to prevent recursive calls\n nodeRuntimeImportCache.set(name, promise);\n return promise;\n}\n\n// Hoisted utility function to resolve file paths for chunks\nexport const resolveFile = (rootOutputDir: string, chunkId: string): string => {\n const path = __non_webpack_require__('path');\n return path.join(__dirname, rootOutputDir + __webpack_require__.u(chunkId));\n};\n\n// Hoisted utility function to get remote entry from cache\nexport const returnFromCache = (remoteName: string): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n const moduleContainer = instance.moduleCache.get(remoteName);\n if (moduleContainer?.remoteInfo) return moduleContainer.remoteInfo.entry;\n }\n return null;\n};\n\n// Hoisted utility function to get remote entry from global instances\nexport const returnFromGlobalInstances = (\n remoteName: string,\n): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n for (const remote of instance.options.remotes) {\n if (remote.name === remoteName || remote.alias === remoteName) {\n console.log('Backup remote entry found:', remote.entry);\n return remote.entry;\n }\n }\n }\n return null;\n};\n\n// Hoisted utility function to load chunks from filesystem\nexport const loadFromFs = (\n filename: string,\n callback: (err: Error | null, chunk: any) => void,\n): void => {\n const fs = __non_webpack_require__('fs') as typeof import('fs');\n const path = __non_webpack_require__('path') as typeof import('path');\n const vm = __non_webpack_require__('vm') as typeof import('vm');\n\n if (fs.existsSync(filename)) {\n fs.readFile(filename, 'utf-8', (err, content) => {\n if (err) return callback(err, null);\n const chunk = {};\n try {\n const script = new vm.Script(\n `(function(exports, require, __dirname, __filename) {${content}\\n})`,\n {\n filename,\n importModuleDynamically:\n //@ts-ignore\n vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER ?? importNodeModule,\n },\n );\n script.runInThisContext()(\n chunk,\n __non_webpack_require__,\n path.dirname(filename),\n filename,\n );\n callback(null, chunk);\n } catch (e) {\n console.log(\"'runInThisContext threw'\", e);\n callback(e as Error, null);\n }\n });\n } else {\n callback(new Error(`File ${filename} does not exist`), null);\n }\n};\n\n// Hoisted utility function to fetch and execute chunks from remote URLs\nexport const fetchAndRun = (\n url: URL,\n chunkName: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n (typeof fetch === 'undefined'\n ? importNodeModule<typeof import('node-fetch')>('node-fetch').then(\n (mod) => mod.default,\n )\n : Promise.resolve(fetch)\n )\n .then((fetchFunction) => {\n return args.origin.loaderHook.lifecycle.fetch\n .emit(url.href, {})\n .then((res: Response | null) => {\n if (!res || !(res instanceof Response)) {\n return fetchFunction(url.href).then((response) => response.text());\n }\n return res.text();\n });\n })\n .then((data) => {\n const chunk = {};\n try {\n eval(`(function(exports, require, __dirname, __filename) {${data}\\n})`)(\n chunk,\n __non_webpack_require__,\n url.pathname.split('/').slice(0, -1).join('/'),\n chunkName,\n );\n callback(null, chunk);\n } catch (e) {\n callback(e as Error, null);\n }\n })\n .catch((err: Error) => callback(err, null));\n};\n\n// Hoisted utility function to resolve URLs for chunks\nexport const resolveUrl = (\n remoteName: string,\n chunkName: string,\n): URL | null => {\n try {\n return new URL(chunkName, __webpack_require__.p);\n } catch {\n const entryUrl =\n returnFromCache(remoteName) || returnFromGlobalInstances(remoteName);\n\n if (!entryUrl) return null;\n\n const url = new URL(entryUrl);\n const path = __non_webpack_require__('path');\n\n // Extract the directory path from the remote entry URL\n // e.g., from \"http://url/static/js/remoteEntry.js\" to \"/static/js/\"\n const urlPath = url.pathname;\n const lastSlashIndex = urlPath.lastIndexOf('/');\n const directoryPath =\n lastSlashIndex >= 0 ? urlPath.substring(0, lastSlashIndex + 1) : '/';\n\n // Get rootDir from webpack configuration\n const rootDir = __webpack_require__.federation.rootOutputDir || '';\n\n // Use path.join to combine the paths properly while handling slashes\n // Convert Windows-style paths to URL-style paths\n const combinedPath = path\n .join(directoryPath, rootDir, chunkName)\n .replace(/\\\\/g, '/');\n // Create the final URL\n return new URL(combinedPath, url.origin);\n }\n};\n\n// Hoisted utility function to load chunks based on different strategies\nexport const loadChunk = (\n strategy: string,\n chunkId: string,\n rootOutputDir: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n if (strategy === 'filesystem') {\n return loadFromFs(resolveFile(rootOutputDir, chunkId), callback);\n }\n\n const url = resolveUrl(rootOutputDir, chunkId);\n if (!url) return callback(null, { modules: {}, ids: [], runtime: null });\n\n // Using fetchAndRun directly with args\n fetchAndRun(url, chunkId, callback, args);\n};\n\n// Hoisted utility function to install a chunk into webpack\nexport const installChunk = (\n chunk: any,\n installedChunks: { [key: string]: any },\n): void => {\n for (const moduleId in chunk.modules) {\n __webpack_require__.m[moduleId] = chunk.modules[moduleId];\n }\n if (chunk.runtime) chunk.runtime(__webpack_require__);\n for (const chunkId of chunk.ids) {\n if (installedChunks[chunkId]) installedChunks[chunkId][0]();\n installedChunks[chunkId] = 0;\n }\n};\n\n// Hoisted utility function to remove a chunk on fail\nexport const deleteChunk = (\n chunkId: string,\n installedChunks: { [key: string]: any },\n): boolean => {\n delete installedChunks[chunkId];\n return true;\n};\n\n// Hoisted function to set up webpack script loader\nexport const setupScriptLoader = (): void => {\n __webpack_require__.l = (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ): void => {\n if (!key || chunkId)\n throw new Error(`__webpack_require__.l name is required for ${url}`);\n __webpack_require__.federation.runtime\n .loadScriptNode(url, { attrs: { globalName: key } })\n .then((res) => {\n const enhancedRemote =\n __webpack_require__.federation.instance.initRawContainer(\n key,\n url,\n res,\n );\n new Function('return globalThis')()[key] = enhancedRemote;\n done(enhancedRemote);\n })\n .catch(done);\n };\n};\n\n// Hoisted function to set up chunk handler\nexport const setupChunkHandler = (\n installedChunks: { [key: string]: any },\n args: any,\n): ((chunkId: string, promises: any[]) => void) => {\n return (chunkId: string, promises: any[]): void => {\n let installedChunkData = installedChunks[chunkId];\n if (installedChunkData !== 0) {\n if (installedChunkData) {\n promises.push(installedChunkData[2]);\n } else {\n const matcher = __webpack_require__.federation.chunkMatcher\n ? __webpack_require__.federation.chunkMatcher(chunkId)\n : true;\n\n if (matcher) {\n const promise = new Promise((resolve, reject) => {\n installedChunkData = installedChunks[chunkId] = [resolve, reject];\n const fs =\n typeof process !== 'undefined'\n ? __non_webpack_require__('fs')\n : false;\n const filename =\n typeof process !== 'undefined'\n ? resolveFile(\n __webpack_require__.federation.rootOutputDir || '',\n chunkId,\n )\n : false;\n\n if (fs && fs.existsSync(filename)) {\n loadChunk(\n 'filesystem',\n chunkId,\n __webpack_require__.federation.rootOutputDir || '',\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n } else {\n const chunkName = __webpack_require__.u(chunkId);\n const loadingStrategy =\n typeof process === 'undefined' ? 'http-eval' : 'http-vm';\n loadChunk(\n loadingStrategy,\n chunkName,\n __webpack_require__.federation.initOptions.name,\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n }\n });\n promises.push((installedChunkData[2] = promise));\n } else {\n installedChunks[chunkId] = 0;\n }\n }\n }\n };\n};\n\n// Hoisted function to set up webpack require patching\nexport const setupWebpackRequirePatching = (\n handle: (chunkId: string, promises: any[]) => void,\n): void => {\n if (__webpack_require__.f) {\n if (__webpack_require__.f.require) {\n console.warn(\n '\\x1b[33m%s\\x1b[0m',\n 'CAUTION: build target is not set to \"async-node\", attempting to patch additional chunk handlers. This may not work',\n );\n __webpack_require__.f.require = handle;\n }\n\n if (__webpack_require__.f.readFileVm) {\n __webpack_require__.f.readFileVm = handle;\n }\n }\n};\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'node-federation-plugin',\n beforeInit(args) {\n // Patch webpack chunk loading handlers\n (() => {\n // Create the chunk tracking object\n const installedChunks: { [key: string]: any } = {};\n\n // Set up webpack script loader\n setupScriptLoader();\n\n // Create and set up the chunk handler\n const handle = setupChunkHandler(installedChunks, args);\n\n // Patch webpack require\n setupWebpackRequirePatching(handle);\n })();\n\n return args;\n },\n };\n}\n"],"mappings":";;;AAyCA,MAAa,yCAAyB,IAAI,KAA2B;AAErE,SAAgB,iBAAoB,MAA0B;AAC5D,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,+BAA+B;AAIjD,KAAI,uBAAuB,IAAI,KAAK,CAClC,QAAO,uBAAuB,IAAI,KAAK;CAIzC,MAAM,UADe,IAAI,SAAS,QAAQ,sBAAsB,CACnC,KAAK,CAC/B,MAAM,QAAa,IAAI,QAAa,CACpC,OAAO,UAAe;AACrB,UAAQ,MAAM,0BAA0B,KAAK,IAAI,MAAM;AAEvD,yBAAuB,OAAO,KAAK;AACnC,QAAM;GACN;AAGJ,wBAAuB,IAAI,MAAM,QAAQ;AACzC,QAAO;;AAIT,MAAa,eAAe,eAAuB,YAA4B;AAE7E,QADa,wBAAwB,OAAO,CAChC,KAAK,WAAW,gBAAgB,oBAAoB,EAAE,QAAQ,CAAC;;AAI7E,MAAa,mBAAmB,eAAsC;CAEpE,MAAM,sBADgB,IAAI,SAAS,oBAAoB,EAAE,CACf,kBAAkB;AAC5D,MAAK,MAAM,YAAY,qBAAqB;EAC1C,MAAM,kBAAkB,SAAS,YAAY,IAAI,WAAW;AAC5D,MAAI,iBAAiB,WAAY,QAAO,gBAAgB,WAAW;;AAErE,QAAO;;AAIT,MAAa,6BACX,eACkB;CAElB,MAAM,sBADgB,IAAI,SAAS,oBAAoB,EAAE,CACf,kBAAkB;AAC5D,MAAK,MAAM,YAAY,oBACrB,MAAK,MAAM,UAAU,SAAS,QAAQ,QACpC,KAAI,OAAO,SAAS,cAAc,OAAO,UAAU,YAAY;AAC7D,UAAQ,IAAI,8BAA8B,OAAO,MAAM;AACvD,SAAO,OAAO;;AAIpB,QAAO;;AAIT,MAAa,cACX,UACA,aACS;CACT,MAAM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KAEH;AACF,YAAS,KAAM,mBAAmB,KAAK,QAAS;QAEhD,iBAAgB,WAAW;;;AAQrC,MAAa,+BACX,WACS;AACT,KAAI,oBAAoB,GAAG;AACzB,MAAI,oBAAoB,EAAE,SAAS;AACjC,WAAQ,KACN,qBACA,uHACD;AACD,uBAAoB,EAAE,UAAU;;AAGlC,MAAI,oBAAoB,EAAE,WACxB,qBAAoB,EAAE,aAAa;;;AAKzC,iCAA0D;AACxD,QAAO;EACL,MAAM;EACN,WAAW,MAAM;AAEf,UAAO;IAEL,MAAM,kBAA0C,EAAE;AAGlD,uBAAmB;AAMnB,gCAHe,kBAAkB,iBAAiB,KAAK,CAGpB;OACjC;AAEJ,UAAO;;EAEV"}
1
+ {"version":3,"file":"runtimePlugin.js","names":[],"sources":["../../src/runtimePlugin.ts"],"sourcesContent":["import type {\n ModuleFederationRuntimePlugin,\n ModuleFederation,\n} from '@module-federation/runtime';\ntype WebpackRequire = {\n (id: string): any;\n u: (chunkId: string) => string;\n p: string;\n m: { [key: string]: any };\n o: (obj: any, prop: string) => boolean;\n C?: (chunk: any) => void;\n l: (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ) => void;\n federation: {\n runtime: {\n loadScriptNode: (\n url: string,\n options: { attrs: { globalName: string } },\n ) => Promise<any>;\n };\n instance: ModuleFederation;\n chunkMatcher?: (chunkId: string) => boolean;\n rootOutputDir?: string;\n initOptions: {\n name: string;\n remotes: any;\n };\n };\n f?: {\n require?: (chunkId: string, promises: any[]) => void;\n readFileVm?: (chunkId: string, promises: any[]) => void;\n };\n};\n\ndeclare const __webpack_require__: WebpackRequire;\ndeclare const __non_webpack_require__: (id: string) => any;\n\nexport const nodeRuntimeImportCache = new Map<string, Promise<any>>();\nconst CHUNK_PREVIEW_LENGTH = 240;\ntype ChunkResolutionSource = 'public-path' | 'remote-entry-fallback';\ntype ChunkLocationSource = 'filesystem' | 'remote-url';\ntype ChunkUrlMetadata = {\n chunkName: string;\n publicPath?: string;\n remoteName?: string;\n rootOutputDir?: string;\n resolvedFrom: ChunkResolutionSource;\n remoteEntryUrl?: string;\n};\n\nconst getChunkPreview = (content: string): string =>\n content.slice(0, CHUNK_PREVIEW_LENGTH).replace(/\\s+/g, ' ').trim();\n\nconst enrichChunkExecutionError = (\n error: unknown,\n options: {\n chunkName: string;\n location: string;\n source: ChunkLocationSource;\n content: string;\n hostName?: string;\n resolution?: ChunkUrlMetadata;\n },\n): Error => {\n const normalizedError =\n error instanceof Error ? error : new Error(String(error));\n const preview = getChunkPreview(options.content);\n const details = [\n `Federated chunk execution failed.`,\n `chunk: ${options.chunkName}`,\n `source: ${options.source}`,\n `location: ${options.location}`,\n ];\n\n if (options.hostName) {\n details.push(`host: ${options.hostName}`);\n }\n\n if (options.resolution) {\n details.push(`resolved-from: ${options.resolution.resolvedFrom}`);\n\n if (options.resolution.remoteName) {\n details.push(`remote: ${options.resolution.remoteName}`);\n }\n\n if (options.resolution.publicPath) {\n details.push(`public-path: ${options.resolution.publicPath}`);\n }\n\n if (options.resolution.rootOutputDir) {\n details.push(`root-output-dir: ${options.resolution.rootOutputDir}`);\n }\n\n if (options.resolution.remoteEntryUrl) {\n details.push(`remote-entry: ${options.resolution.remoteEntryUrl}`);\n }\n }\n\n if (preview) {\n details.push(`preview: ${preview}`);\n }\n\n normalizedError.message = `${normalizedError.message}\\n${details.join('\\n')}`;\n\n Object.assign(normalizedError, {\n chunkName: options.chunkName,\n chunkLocation: options.location,\n chunkSource: options.source,\n chunkPreview: preview,\n chunkHostName: options.hostName,\n chunkResolution: options.resolution,\n });\n\n return normalizedError;\n};\n\nexport function importNodeModule<T>(name: string): Promise<T> {\n if (!name) {\n throw new Error('import specifier is required');\n }\n\n // Check cache to prevent infinite recursion\n if (nodeRuntimeImportCache.has(name)) {\n return nodeRuntimeImportCache.get(name)!;\n }\n\n const importModule = new Function('name', `return import(name)`);\n const promise = importModule(name)\n .then((res: any) => res.default as T)\n .catch((error: any) => {\n console.error(`Error importing module ${name}:`, error);\n // Remove from cache on error so it can be retried\n nodeRuntimeImportCache.delete(name);\n throw error;\n });\n\n // Cache the promise to prevent recursive calls\n nodeRuntimeImportCache.set(name, promise);\n return promise;\n}\n\n// Hoisted utility function to resolve file paths for chunks\nexport const resolveFile = (rootOutputDir: string, chunkId: string): string => {\n const path = __non_webpack_require__('path');\n return path.join(__dirname, rootOutputDir + __webpack_require__.u(chunkId));\n};\n\n// Hoisted utility function to get remote entry from cache\nexport const returnFromCache = (remoteName: string): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n const moduleContainer = instance.moduleCache.get(remoteName);\n if (moduleContainer?.remoteInfo) return moduleContainer.remoteInfo.entry;\n }\n return null;\n};\n\n// Hoisted utility function to get remote entry from global instances\nexport const returnFromGlobalInstances = (\n remoteName: string,\n): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n for (const remote of instance.options.remotes) {\n if (remote.name === remoteName || remote.alias === remoteName) {\n console.log('Backup remote entry found:', remote.entry);\n return remote.entry;\n }\n }\n }\n return null;\n};\n\n// Hoisted utility function to load chunks from filesystem\nexport const loadFromFs = (\n filename: string,\n callback: (err: Error | null, chunk: any) => void,\n): void => {\n const fs = __non_webpack_require__('fs') as typeof import('fs');\n const path = __non_webpack_require__('path') as typeof import('path');\n const vm = __non_webpack_require__('vm') as typeof import('vm');\n\n if (fs.existsSync(filename)) {\n fs.readFile(filename, 'utf-8', (err, content) => {\n if (err) return callback(err, null);\n const chunk = {};\n try {\n const script = new vm.Script(\n `(function(exports, require, __dirname, __filename) {${content}\\n})`,\n {\n filename,\n importModuleDynamically:\n //@ts-ignore\n vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER ?? importNodeModule,\n },\n );\n script.runInThisContext()(\n chunk,\n __non_webpack_require__,\n path.dirname(filename),\n filename,\n );\n callback(null, chunk);\n } catch (e) {\n callback(\n enrichChunkExecutionError(e, {\n chunkName: path.basename(filename),\n location: filename,\n source: 'filesystem',\n content,\n }),\n null,\n );\n }\n });\n } else {\n callback(new Error(`File ${filename} does not exist`), null);\n }\n};\n\n// Hoisted utility function to fetch and execute chunks from remote URLs\nexport const fetchAndRun = (\n url: URL,\n chunkName: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n (typeof fetch === 'undefined'\n ? importNodeModule<typeof import('node-fetch')>('node-fetch').then(\n (mod) => mod.default,\n )\n : Promise.resolve(fetch)\n )\n .then((fetchFunction) => {\n return args.origin.loaderHook.lifecycle.fetch\n .emit(url.href, {})\n .then((res: Response | null) => {\n if (!res || !(res instanceof Response)) {\n return fetchFunction(url.href).then((response) => response.text());\n }\n return res.text();\n });\n })\n .then((data) => {\n const chunk = {};\n const hostName = args?.origin?.options?.name || args?.origin?.name;\n const resolution = (url as URL & { mfMetadata?: ChunkUrlMetadata })\n .mfMetadata;\n try {\n eval(`(function(exports, require, __dirname, __filename) {${data}\\n})`)(\n chunk,\n __non_webpack_require__,\n url.pathname.split('/').slice(0, -1).join('/'),\n chunkName,\n );\n callback(null, chunk);\n } catch (e) {\n callback(\n enrichChunkExecutionError(e, {\n chunkName,\n location: url.href,\n source: 'remote-url',\n content: data,\n hostName,\n resolution,\n }),\n null,\n );\n }\n })\n .catch((err: Error) => callback(err, null));\n};\n\n// Hoisted utility function to resolve URLs for chunks\nexport const resolveUrl = (\n remoteName: string,\n chunkName: string,\n): URL | null => {\n try {\n return Object.assign(new URL(chunkName, __webpack_require__.p), {\n mfMetadata: {\n chunkName,\n publicPath: __webpack_require__.p,\n remoteName,\n rootOutputDir: __webpack_require__.federation.rootOutputDir || '',\n resolvedFrom: 'public-path' as const,\n },\n });\n } catch {\n const entryUrl =\n returnFromCache(remoteName) || returnFromGlobalInstances(remoteName);\n\n if (!entryUrl) return null;\n\n const url = new URL(entryUrl);\n const path = __non_webpack_require__('path');\n\n // Extract the directory path from the remote entry URL\n // e.g., from \"http://url/static/js/remoteEntry.js\" to \"/static/js/\"\n const urlPath = url.pathname;\n const lastSlashIndex = urlPath.lastIndexOf('/');\n const directoryPath =\n lastSlashIndex >= 0 ? urlPath.substring(0, lastSlashIndex + 1) : '/';\n\n // Get rootDir from webpack configuration\n const rootDir = __webpack_require__.federation.rootOutputDir || '';\n\n // Use path.join to combine the paths properly while handling slashes\n // Convert Windows-style paths to URL-style paths\n const combinedPath = path\n .join(directoryPath, rootDir, chunkName)\n .replace(/\\\\/g, '/');\n // Create the final URL\n return Object.assign(new URL(combinedPath, url.origin), {\n mfMetadata: {\n chunkName,\n publicPath: __webpack_require__.p,\n remoteName,\n rootOutputDir: rootDir,\n resolvedFrom: 'remote-entry-fallback' as const,\n remoteEntryUrl: entryUrl,\n },\n });\n }\n};\n\n// Hoisted utility function to load chunks based on different strategies\nexport const loadChunk = (\n strategy: string,\n chunkId: string,\n rootOutputDir: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n if (strategy === 'filesystem') {\n return loadFromFs(resolveFile(rootOutputDir, chunkId), callback);\n }\n\n const url = resolveUrl(rootOutputDir, chunkId);\n if (!url) return callback(null, { modules: {}, ids: [], runtime: null });\n\n // Using fetchAndRun directly with args\n fetchAndRun(url, chunkId, callback, args);\n};\n\n// Hoisted utility function to install a chunk into webpack\nexport const installChunk = (\n chunk: any,\n installedChunks: { [key: string]: any },\n): void => {\n for (const moduleId in chunk.modules) {\n __webpack_require__.m[moduleId] = chunk.modules[moduleId];\n }\n if (chunk.runtime) chunk.runtime(__webpack_require__);\n for (const chunkId of chunk.ids) {\n if (installedChunks[chunkId]) installedChunks[chunkId][0]();\n installedChunks[chunkId] = 0;\n }\n};\n\n// Hoisted utility function to remove a chunk on fail\nexport const deleteChunk = (\n chunkId: string,\n installedChunks: { [key: string]: any },\n): boolean => {\n delete installedChunks[chunkId];\n return true;\n};\n\n// Hoisted function to set up webpack script loader\nexport const setupScriptLoader = (): void => {\n __webpack_require__.l = (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ): void => {\n if (!key || chunkId)\n throw new Error(`__webpack_require__.l name is required for ${url}`);\n __webpack_require__.federation.runtime\n .loadScriptNode(url, { attrs: { globalName: key } })\n .then((res) => {\n const enhancedRemote =\n __webpack_require__.federation.instance.initRawContainer(\n key,\n url,\n res,\n );\n new Function('return globalThis')()[key] = enhancedRemote;\n done(enhancedRemote);\n })\n .catch(done);\n };\n};\n\n// Hoisted function to set up chunk handler\nexport const setupChunkHandler = (\n installedChunks: { [key: string]: any },\n args: any,\n): ((chunkId: string, promises: any[]) => void) => {\n return (chunkId: string, promises: any[]): void => {\n let installedChunkData = installedChunks[chunkId];\n if (installedChunkData !== 0) {\n if (installedChunkData) {\n promises.push(installedChunkData[2]);\n } else {\n const matcher = __webpack_require__.federation.chunkMatcher\n ? __webpack_require__.federation.chunkMatcher(chunkId)\n : true;\n\n if (matcher) {\n const promise = new Promise((resolve, reject) => {\n installedChunkData = installedChunks[chunkId] = [resolve, reject];\n const fs =\n typeof process !== 'undefined'\n ? __non_webpack_require__('fs')\n : false;\n const filename =\n typeof process !== 'undefined'\n ? resolveFile(\n __webpack_require__.federation.rootOutputDir || '',\n chunkId,\n )\n : false;\n\n if (fs && fs.existsSync(filename)) {\n loadChunk(\n 'filesystem',\n chunkId,\n __webpack_require__.federation.rootOutputDir || '',\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n } else {\n const chunkName = __webpack_require__.u(chunkId);\n const loadingStrategy =\n typeof process === 'undefined' ? 'http-eval' : 'http-vm';\n loadChunk(\n loadingStrategy,\n chunkName,\n __webpack_require__.federation.initOptions.name,\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n }\n });\n promises.push((installedChunkData[2] = promise));\n } else {\n installedChunks[chunkId] = 0;\n }\n }\n }\n };\n};\n\n// Hoisted function to set up webpack require patching\nexport const setupWebpackRequirePatching = (\n handle: (chunkId: string, promises: any[]) => void,\n): void => {\n if (__webpack_require__.f) {\n if (__webpack_require__.f.require) {\n console.warn(\n '\\x1b[33m%s\\x1b[0m',\n 'CAUTION: build target is not set to \"async-node\", attempting to patch additional chunk handlers. This may not work',\n );\n __webpack_require__.f.require = handle;\n }\n\n if (__webpack_require__.f.readFileVm) {\n __webpack_require__.f.readFileVm = handle;\n }\n }\n};\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'node-federation-plugin',\n beforeInit(args) {\n // Patch webpack chunk loading handlers\n (() => {\n // Create the chunk tracking object\n const installedChunks: { [key: string]: any } = {};\n\n // Set up webpack script loader\n setupScriptLoader();\n\n // Create and set up the chunk handler\n const handle = setupChunkHandler(installedChunks, args);\n\n // Patch webpack require\n setupWebpackRequirePatching(handle);\n })();\n\n return args;\n },\n };\n}\n"],"mappings":";;;AAyCA,MAAa,yCAAyB,IAAI,KAA2B;AACrE,MAAM,uBAAuB;AAY7B,MAAM,mBAAmB,YACvB,QAAQ,MAAM,GAAG,qBAAqB,CAAC,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAEpE,MAAM,6BACJ,OACA,YAQU;CACV,MAAM,kBACJ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;CAC3D,MAAM,UAAU,gBAAgB,QAAQ,QAAQ;CAChD,MAAM,UAAU;EACd;EACA,UAAU,QAAQ;EAClB,WAAW,QAAQ;EACnB,aAAa,QAAQ;EACtB;AAED,KAAI,QAAQ,SACV,SAAQ,KAAK,SAAS,QAAQ,WAAW;AAG3C,KAAI,QAAQ,YAAY;AACtB,UAAQ,KAAK,kBAAkB,QAAQ,WAAW,eAAe;AAEjE,MAAI,QAAQ,WAAW,WACrB,SAAQ,KAAK,WAAW,QAAQ,WAAW,aAAa;AAG1D,M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2
  const nodeRuntimeImportCache = /* @__PURE__ */ new Map();
3
+ const CHUNK_PREVIEW_LENGTH = 240;
4
+ const getChunkPreview = (content) => content.slice(0, CHUNK_PREVIEW_LENGTH).replace(/\s+/g, " ").trim();
5
+ const enrichChunkExecutionError = (error, options) => {
6
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
7
+ const preview = getChunkPreview(options.content);
8
+ const details = [
9
+ `Federated chunk execution failed.`,
10
+ `chunk: ${options.chunkName}`,
11
+ `source: ${options.source}`,
12
+ `location: ${options.location}`
13
+ ];
14
+ if (options.hostName) details.push(`host: ${options.hostName}`);
15
+ if (options.resolution) {
16
+ details.push(`resolved-from: ${options.resolution.resolvedFrom}`);
17
+ if (options.resolution.remoteName) details.push(`remote: ${options.resolution.remoteName}`);
18
+ if (options.resolution.publicPath) details.push(`public-path: ${options.resolution.publicPath}`);
19
+ if (options.resolution.rootOutputDir) details.push(`root-output-dir: ${options.resolution.rootOutputDir}`);
20
+ if (options.resolution.remoteEntryUrl) details.push(`remote-entry: ${options.resolution.remoteEntryUrl}`);
21
+ }
22
+ if (preview) details.push(`preview: ${preview}`);
23
+ normalizedError.message = `${normalizedError.message}\n${details.join("\n")}`;
24
+ Object.assign(normalizedError, {
25
+ chunkName: options.chunkName,
26
+ chunkLocation: options.location,
27
+ chunkSource: options.source,
28
+ chunkPreview: preview,
29
+ chunkHostName: options.hostName,
30
+ chunkResolution: options.resolution
31
+ });
32
+ return normalizedError;
33
+ };
3
34
  function importNodeModule(name) {
4
35
  if (!name) throw new Error("import specifier is required");
5
36
  if (nodeRuntimeImportCache.has(name)) return nodeRuntimeImportCache.get(name);
@@ -44,8 +75,12 @@ const loadFromFs = (filename, callback) => {
44
75
  }).runInThisContext()(chunk, __non_webpack_require__, path.dirname(filename), filename);
45
76
  callback(null, chunk);
46
77
  } catch (e) {
47
- console.log("'runInThisContext threw'", e);
48
- callback(e, null);
78
+ callback(enrichChunkExecutionError(e, {
79
+ chunkName: path.basename(filename),
80
+ location: filename,
81
+ source: "filesystem",
82
+ content
83
+ }), null);
49
84
  }
50
85
  });
51
86
  else callback(/* @__PURE__ */ new Error(`File ${filename} does not exist`), null);
@@ -58,17 +93,32 @@ const fetchAndRun = (url, chunkName, callback, args) => {
58
93
  });
59
94
  }).then((data) => {
60
95
  const chunk = {};
96
+ const hostName = args?.origin?.options?.name || args?.origin?.name;
97
+ const resolution = url.mfMetadata;
61
98
  try {
62
99
  eval(`(function(exports, require, __dirname, __filename) {${data}\n})`)(chunk, __non_webpack_require__, url.pathname.split("/").slice(0, -1).join("/"), chunkName);
63
100
  callback(null, chunk);
64
101
  } catch (e) {
65
- callback(e, null);
102
+ callback(enrichChunkExecutionError(e, {
103
+ chunkName,
104
+ location: url.href,
105
+ source: "remote-url",
106
+ content: data,
107
+ hostName,
108
+ resolution
109
+ }), null);
66
110
  }
67
111
  }).catch((err) => callback(err, null));
68
112
  };
69
113
  const resolveUrl = (remoteName, chunkName) => {
70
114
  try {
71
- return new URL(chunkName, __webpack_require__.p);
115
+ return Object.assign(new URL(chunkName, __webpack_require__.p), { mfMetadata: {
116
+ chunkName,
117
+ publicPath: __webpack_require__.p,
118
+ remoteName,
119
+ rootOutputDir: __webpack_require__.federation.rootOutputDir || "",
120
+ resolvedFrom: "public-path"
121
+ } });
72
122
  } catch {
73
123
  const entryUrl = returnFromCache(remoteName) || returnFromGlobalInstances(remoteName);
74
124
  if (!entryUrl) return null;
@@ -79,7 +129,14 @@ const resolveUrl = (remoteName, chunkName) => {
79
129
  const directoryPath = lastSlashIndex >= 0 ? urlPath.substring(0, lastSlashIndex + 1) : "/";
80
130
  const rootDir = __webpack_require__.federation.rootOutputDir || "";
81
131
  const combinedPath = path.join(directoryPath, rootDir, chunkName).replace(/\\/g, "/");
82
- return new URL(combinedPath, url.origin);
132
+ return Object.assign(new URL(combinedPath, url.origin), { mfMetadata: {
133
+ chunkName,
134
+ publicPath: __webpack_require__.p,
135
+ remoteName,
136
+ rootOutputDir: rootDir,
137
+ resolvedFrom: "remote-entry-fallback",
138
+ remoteEntryUrl: entryUrl
139
+ } });
83
140
  }
84
141
  };
85
142
  const loadChunk = (strategy, chunkId, rootOutputDir, callback, args) => {
@@ -1 +1 @@
1
- {"version":3,"file":"runtimePlugin.mjs","names":[],"sources":["../../src/runtimePlugin.ts"],"sourcesContent":["import type {\n ModuleFederationRuntimePlugin,\n ModuleFederation,\n} from '@module-federation/runtime';\ntype WebpackRequire = {\n (id: string): any;\n u: (chunkId: string) => string;\n p: string;\n m: { [key: string]: any };\n o: (obj: any, prop: string) => boolean;\n C?: (chunk: any) => void;\n l: (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ) => void;\n federation: {\n runtime: {\n loadScriptNode: (\n url: string,\n options: { attrs: { globalName: string } },\n ) => Promise<any>;\n };\n instance: ModuleFederation;\n chunkMatcher?: (chunkId: string) => boolean;\n rootOutputDir?: string;\n initOptions: {\n name: string;\n remotes: any;\n };\n };\n f?: {\n require?: (chunkId: string, promises: any[]) => void;\n readFileVm?: (chunkId: string, promises: any[]) => void;\n };\n};\n\ndeclare const __webpack_require__: WebpackRequire;\ndeclare const __non_webpack_require__: (id: string) => any;\n\nexport const nodeRuntimeImportCache = new Map<string, Promise<any>>();\n\nexport function importNodeModule<T>(name: string): Promise<T> {\n if (!name) {\n throw new Error('import specifier is required');\n }\n\n // Check cache to prevent infinite recursion\n if (nodeRuntimeImportCache.has(name)) {\n return nodeRuntimeImportCache.get(name)!;\n }\n\n const importModule = new Function('name', `return import(name)`);\n const promise = importModule(name)\n .then((res: any) => res.default as T)\n .catch((error: any) => {\n console.error(`Error importing module ${name}:`, error);\n // Remove from cache on error so it can be retried\n nodeRuntimeImportCache.delete(name);\n throw error;\n });\n\n // Cache the promise to prevent recursive calls\n nodeRuntimeImportCache.set(name, promise);\n return promise;\n}\n\n// Hoisted utility function to resolve file paths for chunks\nexport const resolveFile = (rootOutputDir: string, chunkId: string): string => {\n const path = __non_webpack_require__('path');\n return path.join(__dirname, rootOutputDir + __webpack_require__.u(chunkId));\n};\n\n// Hoisted utility function to get remote entry from cache\nexport const returnFromCache = (remoteName: string): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n const moduleContainer = instance.moduleCache.get(remoteName);\n if (moduleContainer?.remoteInfo) return moduleContainer.remoteInfo.entry;\n }\n return null;\n};\n\n// Hoisted utility function to get remote entry from global instances\nexport const returnFromGlobalInstances = (\n remoteName: string,\n): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n for (const remote of instance.options.remotes) {\n if (remote.name === remoteName || remote.alias === remoteName) {\n console.log('Backup remote entry found:', remote.entry);\n return remote.entry;\n }\n }\n }\n return null;\n};\n\n// Hoisted utility function to load chunks from filesystem\nexport const loadFromFs = (\n filename: string,\n callback: (err: Error | null, chunk: any) => void,\n): void => {\n const fs = __non_webpack_require__('fs') as typeof import('fs');\n const path = __non_webpack_require__('path') as typeof import('path');\n const vm = __non_webpack_require__('vm') as typeof import('vm');\n\n if (fs.existsSync(filename)) {\n fs.readFile(filename, 'utf-8', (err, content) => {\n if (err) return callback(err, null);\n const chunk = {};\n try {\n const script = new vm.Script(\n `(function(exports, require, __dirname, __filename) {${content}\\n})`,\n {\n filename,\n importModuleDynamically:\n //@ts-ignore\n vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER ?? importNodeModule,\n },\n );\n script.runInThisContext()(\n chunk,\n __non_webpack_require__,\n path.dirname(filename),\n filename,\n );\n callback(null, chunk);\n } catch (e) {\n console.log(\"'runInThisContext threw'\", e);\n callback(e as Error, null);\n }\n });\n } else {\n callback(new Error(`File ${filename} does not exist`), null);\n }\n};\n\n// Hoisted utility function to fetch and execute chunks from remote URLs\nexport const fetchAndRun = (\n url: URL,\n chunkName: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n (typeof fetch === 'undefined'\n ? importNodeModule<typeof import('node-fetch')>('node-fetch').then(\n (mod) => mod.default,\n )\n : Promise.resolve(fetch)\n )\n .then((fetchFunction) => {\n return args.origin.loaderHook.lifecycle.fetch\n .emit(url.href, {})\n .then((res: Response | null) => {\n if (!res || !(res instanceof Response)) {\n return fetchFunction(url.href).then((response) => response.text());\n }\n return res.text();\n });\n })\n .then((data) => {\n const chunk = {};\n try {\n eval(`(function(exports, require, __dirname, __filename) {${data}\\n})`)(\n chunk,\n __non_webpack_require__,\n url.pathname.split('/').slice(0, -1).join('/'),\n chunkName,\n );\n callback(null, chunk);\n } catch (e) {\n callback(e as Error, null);\n }\n })\n .catch((err: Error) => callback(err, null));\n};\n\n// Hoisted utility function to resolve URLs for chunks\nexport const resolveUrl = (\n remoteName: string,\n chunkName: string,\n): URL | null => {\n try {\n return new URL(chunkName, __webpack_require__.p);\n } catch {\n const entryUrl =\n returnFromCache(remoteName) || returnFromGlobalInstances(remoteName);\n\n if (!entryUrl) return null;\n\n const url = new URL(entryUrl);\n const path = __non_webpack_require__('path');\n\n // Extract the directory path from the remote entry URL\n // e.g., from \"http://url/static/js/remoteEntry.js\" to \"/static/js/\"\n const urlPath = url.pathname;\n const lastSlashIndex = urlPath.lastIndexOf('/');\n const directoryPath =\n lastSlashIndex >= 0 ? urlPath.substring(0, lastSlashIndex + 1) : '/';\n\n // Get rootDir from webpack configuration\n const rootDir = __webpack_require__.federation.rootOutputDir || '';\n\n // Use path.join to combine the paths properly while handling slashes\n // Convert Windows-style paths to URL-style paths\n const combinedPath = path\n .join(directoryPath, rootDir, chunkName)\n .replace(/\\\\/g, '/');\n // Create the final URL\n return new URL(combinedPath, url.origin);\n }\n};\n\n// Hoisted utility function to load chunks based on different strategies\nexport const loadChunk = (\n strategy: string,\n chunkId: string,\n rootOutputDir: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n if (strategy === 'filesystem') {\n return loadFromFs(resolveFile(rootOutputDir, chunkId), callback);\n }\n\n const url = resolveUrl(rootOutputDir, chunkId);\n if (!url) return callback(null, { modules: {}, ids: [], runtime: null });\n\n // Using fetchAndRun directly with args\n fetchAndRun(url, chunkId, callback, args);\n};\n\n// Hoisted utility function to install a chunk into webpack\nexport const installChunk = (\n chunk: any,\n installedChunks: { [key: string]: any },\n): void => {\n for (const moduleId in chunk.modules) {\n __webpack_require__.m[moduleId] = chunk.modules[moduleId];\n }\n if (chunk.runtime) chunk.runtime(__webpack_require__);\n for (const chunkId of chunk.ids) {\n if (installedChunks[chunkId]) installedChunks[chunkId][0]();\n installedChunks[chunkId] = 0;\n }\n};\n\n// Hoisted utility function to remove a chunk on fail\nexport const deleteChunk = (\n chunkId: string,\n installedChunks: { [key: string]: any },\n): boolean => {\n delete installedChunks[chunkId];\n return true;\n};\n\n// Hoisted function to set up webpack script loader\nexport const setupScriptLoader = (): void => {\n __webpack_require__.l = (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ): void => {\n if (!key || chunkId)\n throw new Error(`__webpack_require__.l name is required for ${url}`);\n __webpack_require__.federation.runtime\n .loadScriptNode(url, { attrs: { globalName: key } })\n .then((res) => {\n const enhancedRemote =\n __webpack_require__.federation.instance.initRawContainer(\n key,\n url,\n res,\n );\n new Function('return globalThis')()[key] = enhancedRemote;\n done(enhancedRemote);\n })\n .catch(done);\n };\n};\n\n// Hoisted function to set up chunk handler\nexport const setupChunkHandler = (\n installedChunks: { [key: string]: any },\n args: any,\n): ((chunkId: string, promises: any[]) => void) => {\n return (chunkId: string, promises: any[]): void => {\n let installedChunkData = installedChunks[chunkId];\n if (installedChunkData !== 0) {\n if (installedChunkData) {\n promises.push(installedChunkData[2]);\n } else {\n const matcher = __webpack_require__.federation.chunkMatcher\n ? __webpack_require__.federation.chunkMatcher(chunkId)\n : true;\n\n if (matcher) {\n const promise = new Promise((resolve, reject) => {\n installedChunkData = installedChunks[chunkId] = [resolve, reject];\n const fs =\n typeof process !== 'undefined'\n ? __non_webpack_require__('fs')\n : false;\n const filename =\n typeof process !== 'undefined'\n ? resolveFile(\n __webpack_require__.federation.rootOutputDir || '',\n chunkId,\n )\n : false;\n\n if (fs && fs.existsSync(filename)) {\n loadChunk(\n 'filesystem',\n chunkId,\n __webpack_require__.federation.rootOutputDir || '',\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n } else {\n const chunkName = __webpack_require__.u(chunkId);\n const loadingStrategy =\n typeof process === 'undefined' ? 'http-eval' : 'http-vm';\n loadChunk(\n loadingStrategy,\n chunkName,\n __webpack_require__.federation.initOptions.name,\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n }\n });\n promises.push((installedChunkData[2] = promise));\n } else {\n installedChunks[chunkId] = 0;\n }\n }\n }\n };\n};\n\n// Hoisted function to set up webpack require patching\nexport const setupWebpackRequirePatching = (\n handle: (chunkId: string, promises: any[]) => void,\n): void => {\n if (__webpack_require__.f) {\n if (__webpack_require__.f.require) {\n console.warn(\n '\\x1b[33m%s\\x1b[0m',\n 'CAUTION: build target is not set to \"async-node\", attempting to patch additional chunk handlers. This may not work',\n );\n __webpack_require__.f.require = handle;\n }\n\n if (__webpack_require__.f.readFileVm) {\n __webpack_require__.f.readFileVm = handle;\n }\n }\n};\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'node-federation-plugin',\n beforeInit(args) {\n // Patch webpack chunk loading handlers\n (() => {\n // Create the chunk tracking object\n const installedChunks: { [key: string]: any } = {};\n\n // Set up webpack script loader\n setupScriptLoader();\n\n // Create and set up the chunk handler\n const handle = setupChunkHandler(installedChunks, args);\n\n // Patch webpack require\n setupWebpackRequirePatching(handle);\n })();\n\n return args;\n },\n };\n}\n"],"mappings":";AAyCA,MAAa,yCAAyB,IAAI,KAA2B;AAErE,SAAgB,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;;AAGlC,MAAI,oBAAoB,EAAE,WACxB,qBAAoB,EAAE,aAAa;;;AAKzC,iCAA0D;AACxD,QAAO;EACL,MAAM;EACN,WAAW,MAAM;AAEf,UAAO;IAEL,MAAM,kBAA0C,EAAE;AAGlD,uBAAmB;AAMnB,gCAHe,kBAAkB,iBAAiB,KAAK,CAGpB;OACjC;AAEJ,UAAO;;EAEV"}
1
+ {"version":3,"file":"runtimePlugin.mjs","names":[],"sources":["../../src/runtimePlugin.ts"],"sourcesContent":["import type {\n ModuleFederationRuntimePlugin,\n ModuleFederation,\n} from '@module-federation/runtime';\ntype WebpackRequire = {\n (id: string): any;\n u: (chunkId: string) => string;\n p: string;\n m: { [key: string]: any };\n o: (obj: any, prop: string) => boolean;\n C?: (chunk: any) => void;\n l: (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ) => void;\n federation: {\n runtime: {\n loadScriptNode: (\n url: string,\n options: { attrs: { globalName: string } },\n ) => Promise<any>;\n };\n instance: ModuleFederation;\n chunkMatcher?: (chunkId: string) => boolean;\n rootOutputDir?: string;\n initOptions: {\n name: string;\n remotes: any;\n };\n };\n f?: {\n require?: (chunkId: string, promises: any[]) => void;\n readFileVm?: (chunkId: string, promises: any[]) => void;\n };\n};\n\ndeclare const __webpack_require__: WebpackRequire;\ndeclare const __non_webpack_require__: (id: string) => any;\n\nexport const nodeRuntimeImportCache = new Map<string, Promise<any>>();\nconst CHUNK_PREVIEW_LENGTH = 240;\ntype ChunkResolutionSource = 'public-path' | 'remote-entry-fallback';\ntype ChunkLocationSource = 'filesystem' | 'remote-url';\ntype ChunkUrlMetadata = {\n chunkName: string;\n publicPath?: string;\n remoteName?: string;\n rootOutputDir?: string;\n resolvedFrom: ChunkResolutionSource;\n remoteEntryUrl?: string;\n};\n\nconst getChunkPreview = (content: string): string =>\n content.slice(0, CHUNK_PREVIEW_LENGTH).replace(/\\s+/g, ' ').trim();\n\nconst enrichChunkExecutionError = (\n error: unknown,\n options: {\n chunkName: string;\n location: string;\n source: ChunkLocationSource;\n content: string;\n hostName?: string;\n resolution?: ChunkUrlMetadata;\n },\n): Error => {\n const normalizedError =\n error instanceof Error ? error : new Error(String(error));\n const preview = getChunkPreview(options.content);\n const details = [\n `Federated chunk execution failed.`,\n `chunk: ${options.chunkName}`,\n `source: ${options.source}`,\n `location: ${options.location}`,\n ];\n\n if (options.hostName) {\n details.push(`host: ${options.hostName}`);\n }\n\n if (options.resolution) {\n details.push(`resolved-from: ${options.resolution.resolvedFrom}`);\n\n if (options.resolution.remoteName) {\n details.push(`remote: ${options.resolution.remoteName}`);\n }\n\n if (options.resolution.publicPath) {\n details.push(`public-path: ${options.resolution.publicPath}`);\n }\n\n if (options.resolution.rootOutputDir) {\n details.push(`root-output-dir: ${options.resolution.rootOutputDir}`);\n }\n\n if (options.resolution.remoteEntryUrl) {\n details.push(`remote-entry: ${options.resolution.remoteEntryUrl}`);\n }\n }\n\n if (preview) {\n details.push(`preview: ${preview}`);\n }\n\n normalizedError.message = `${normalizedError.message}\\n${details.join('\\n')}`;\n\n Object.assign(normalizedError, {\n chunkName: options.chunkName,\n chunkLocation: options.location,\n chunkSource: options.source,\n chunkPreview: preview,\n chunkHostName: options.hostName,\n chunkResolution: options.resolution,\n });\n\n return normalizedError;\n};\n\nexport function importNodeModule<T>(name: string): Promise<T> {\n if (!name) {\n throw new Error('import specifier is required');\n }\n\n // Check cache to prevent infinite recursion\n if (nodeRuntimeImportCache.has(name)) {\n return nodeRuntimeImportCache.get(name)!;\n }\n\n const importModule = new Function('name', `return import(name)`);\n const promise = importModule(name)\n .then((res: any) => res.default as T)\n .catch((error: any) => {\n console.error(`Error importing module ${name}:`, error);\n // Remove from cache on error so it can be retried\n nodeRuntimeImportCache.delete(name);\n throw error;\n });\n\n // Cache the promise to prevent recursive calls\n nodeRuntimeImportCache.set(name, promise);\n return promise;\n}\n\n// Hoisted utility function to resolve file paths for chunks\nexport const resolveFile = (rootOutputDir: string, chunkId: string): string => {\n const path = __non_webpack_require__('path');\n return path.join(__dirname, rootOutputDir + __webpack_require__.u(chunkId));\n};\n\n// Hoisted utility function to get remote entry from cache\nexport const returnFromCache = (remoteName: string): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n const moduleContainer = instance.moduleCache.get(remoteName);\n if (moduleContainer?.remoteInfo) return moduleContainer.remoteInfo.entry;\n }\n return null;\n};\n\n// Hoisted utility function to get remote entry from global instances\nexport const returnFromGlobalInstances = (\n remoteName: string,\n): string | null => {\n const globalThisVal = new Function('return globalThis')();\n const federationInstances = globalThisVal['__FEDERATION__']['__INSTANCES__'];\n for (const instance of federationInstances) {\n for (const remote of instance.options.remotes) {\n if (remote.name === remoteName || remote.alias === remoteName) {\n console.log('Backup remote entry found:', remote.entry);\n return remote.entry;\n }\n }\n }\n return null;\n};\n\n// Hoisted utility function to load chunks from filesystem\nexport const loadFromFs = (\n filename: string,\n callback: (err: Error | null, chunk: any) => void,\n): void => {\n const fs = __non_webpack_require__('fs') as typeof import('fs');\n const path = __non_webpack_require__('path') as typeof import('path');\n const vm = __non_webpack_require__('vm') as typeof import('vm');\n\n if (fs.existsSync(filename)) {\n fs.readFile(filename, 'utf-8', (err, content) => {\n if (err) return callback(err, null);\n const chunk = {};\n try {\n const script = new vm.Script(\n `(function(exports, require, __dirname, __filename) {${content}\\n})`,\n {\n filename,\n importModuleDynamically:\n //@ts-ignore\n vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER ?? importNodeModule,\n },\n );\n script.runInThisContext()(\n chunk,\n __non_webpack_require__,\n path.dirname(filename),\n filename,\n );\n callback(null, chunk);\n } catch (e) {\n callback(\n enrichChunkExecutionError(e, {\n chunkName: path.basename(filename),\n location: filename,\n source: 'filesystem',\n content,\n }),\n null,\n );\n }\n });\n } else {\n callback(new Error(`File ${filename} does not exist`), null);\n }\n};\n\n// Hoisted utility function to fetch and execute chunks from remote URLs\nexport const fetchAndRun = (\n url: URL,\n chunkName: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n (typeof fetch === 'undefined'\n ? importNodeModule<typeof import('node-fetch')>('node-fetch').then(\n (mod) => mod.default,\n )\n : Promise.resolve(fetch)\n )\n .then((fetchFunction) => {\n return args.origin.loaderHook.lifecycle.fetch\n .emit(url.href, {})\n .then((res: Response | null) => {\n if (!res || !(res instanceof Response)) {\n return fetchFunction(url.href).then((response) => response.text());\n }\n return res.text();\n });\n })\n .then((data) => {\n const chunk = {};\n const hostName = args?.origin?.options?.name || args?.origin?.name;\n const resolution = (url as URL & { mfMetadata?: ChunkUrlMetadata })\n .mfMetadata;\n try {\n eval(`(function(exports, require, __dirname, __filename) {${data}\\n})`)(\n chunk,\n __non_webpack_require__,\n url.pathname.split('/').slice(0, -1).join('/'),\n chunkName,\n );\n callback(null, chunk);\n } catch (e) {\n callback(\n enrichChunkExecutionError(e, {\n chunkName,\n location: url.href,\n source: 'remote-url',\n content: data,\n hostName,\n resolution,\n }),\n null,\n );\n }\n })\n .catch((err: Error) => callback(err, null));\n};\n\n// Hoisted utility function to resolve URLs for chunks\nexport const resolveUrl = (\n remoteName: string,\n chunkName: string,\n): URL | null => {\n try {\n return Object.assign(new URL(chunkName, __webpack_require__.p), {\n mfMetadata: {\n chunkName,\n publicPath: __webpack_require__.p,\n remoteName,\n rootOutputDir: __webpack_require__.federation.rootOutputDir || '',\n resolvedFrom: 'public-path' as const,\n },\n });\n } catch {\n const entryUrl =\n returnFromCache(remoteName) || returnFromGlobalInstances(remoteName);\n\n if (!entryUrl) return null;\n\n const url = new URL(entryUrl);\n const path = __non_webpack_require__('path');\n\n // Extract the directory path from the remote entry URL\n // e.g., from \"http://url/static/js/remoteEntry.js\" to \"/static/js/\"\n const urlPath = url.pathname;\n const lastSlashIndex = urlPath.lastIndexOf('/');\n const directoryPath =\n lastSlashIndex >= 0 ? urlPath.substring(0, lastSlashIndex + 1) : '/';\n\n // Get rootDir from webpack configuration\n const rootDir = __webpack_require__.federation.rootOutputDir || '';\n\n // Use path.join to combine the paths properly while handling slashes\n // Convert Windows-style paths to URL-style paths\n const combinedPath = path\n .join(directoryPath, rootDir, chunkName)\n .replace(/\\\\/g, '/');\n // Create the final URL\n return Object.assign(new URL(combinedPath, url.origin), {\n mfMetadata: {\n chunkName,\n publicPath: __webpack_require__.p,\n remoteName,\n rootOutputDir: rootDir,\n resolvedFrom: 'remote-entry-fallback' as const,\n remoteEntryUrl: entryUrl,\n },\n });\n }\n};\n\n// Hoisted utility function to load chunks based on different strategies\nexport const loadChunk = (\n strategy: string,\n chunkId: string,\n rootOutputDir: string,\n callback: (err: Error | null, chunk: any) => void,\n args: any,\n): void => {\n if (strategy === 'filesystem') {\n return loadFromFs(resolveFile(rootOutputDir, chunkId), callback);\n }\n\n const url = resolveUrl(rootOutputDir, chunkId);\n if (!url) return callback(null, { modules: {}, ids: [], runtime: null });\n\n // Using fetchAndRun directly with args\n fetchAndRun(url, chunkId, callback, args);\n};\n\n// Hoisted utility function to install a chunk into webpack\nexport const installChunk = (\n chunk: any,\n installedChunks: { [key: string]: any },\n): void => {\n for (const moduleId in chunk.modules) {\n __webpack_require__.m[moduleId] = chunk.modules[moduleId];\n }\n if (chunk.runtime) chunk.runtime(__webpack_require__);\n for (const chunkId of chunk.ids) {\n if (installedChunks[chunkId]) installedChunks[chunkId][0]();\n installedChunks[chunkId] = 0;\n }\n};\n\n// Hoisted utility function to remove a chunk on fail\nexport const deleteChunk = (\n chunkId: string,\n installedChunks: { [key: string]: any },\n): boolean => {\n delete installedChunks[chunkId];\n return true;\n};\n\n// Hoisted function to set up webpack script loader\nexport const setupScriptLoader = (): void => {\n __webpack_require__.l = (\n url: string,\n done: (res: any) => void,\n key: string,\n chunkId: string,\n ): void => {\n if (!key || chunkId)\n throw new Error(`__webpack_require__.l name is required for ${url}`);\n __webpack_require__.federation.runtime\n .loadScriptNode(url, { attrs: { globalName: key } })\n .then((res) => {\n const enhancedRemote =\n __webpack_require__.federation.instance.initRawContainer(\n key,\n url,\n res,\n );\n new Function('return globalThis')()[key] = enhancedRemote;\n done(enhancedRemote);\n })\n .catch(done);\n };\n};\n\n// Hoisted function to set up chunk handler\nexport const setupChunkHandler = (\n installedChunks: { [key: string]: any },\n args: any,\n): ((chunkId: string, promises: any[]) => void) => {\n return (chunkId: string, promises: any[]): void => {\n let installedChunkData = installedChunks[chunkId];\n if (installedChunkData !== 0) {\n if (installedChunkData) {\n promises.push(installedChunkData[2]);\n } else {\n const matcher = __webpack_require__.federation.chunkMatcher\n ? __webpack_require__.federation.chunkMatcher(chunkId)\n : true;\n\n if (matcher) {\n const promise = new Promise((resolve, reject) => {\n installedChunkData = installedChunks[chunkId] = [resolve, reject];\n const fs =\n typeof process !== 'undefined'\n ? __non_webpack_require__('fs')\n : false;\n const filename =\n typeof process !== 'undefined'\n ? resolveFile(\n __webpack_require__.federation.rootOutputDir || '',\n chunkId,\n )\n : false;\n\n if (fs && fs.existsSync(filename)) {\n loadChunk(\n 'filesystem',\n chunkId,\n __webpack_require__.federation.rootOutputDir || '',\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n } else {\n const chunkName = __webpack_require__.u(chunkId);\n const loadingStrategy =\n typeof process === 'undefined' ? 'http-eval' : 'http-vm';\n loadChunk(\n loadingStrategy,\n chunkName,\n __webpack_require__.federation.initOptions.name,\n (err, chunk) => {\n if (err)\n return deleteChunk(chunkId, installedChunks) && reject(err);\n if (chunk) installChunk(chunk, installedChunks);\n resolve(chunk);\n },\n args,\n );\n }\n });\n promises.push((installedChunkData[2] = promise));\n } else {\n installedChunks[chunkId] = 0;\n }\n }\n }\n };\n};\n\n// Hoisted function to set up webpack require patching\nexport const setupWebpackRequirePatching = (\n handle: (chunkId: string, promises: any[]) => void,\n): void => {\n if (__webpack_require__.f) {\n if (__webpack_require__.f.require) {\n console.warn(\n '\\x1b[33m%s\\x1b[0m',\n 'CAUTION: build target is not set to \"async-node\", attempting to patch additional chunk handlers. This may not work',\n );\n __webpack_require__.f.require = handle;\n }\n\n if (__webpack_require__.f.readFileVm) {\n __webpack_require__.f.readFileVm = handle;\n }\n }\n};\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'node-federation-plugin',\n beforeInit(args) {\n // Patch webpack chunk loading handlers\n (() => {\n // Create the chunk tracking object\n const installedChunks: { [key: string]: any } = {};\n\n // Set up webpack script loader\n setupScriptLoader();\n\n // Create and set up the chunk handler\n const handle = setupChunkHandler(installedChunks, args);\n\n // Patch webpack require\n setupWebpackRequirePatching(handle);\n })();\n\n return args;\n },\n };\n}\n"],"mappings":";AAyCA,MAAa,yCAAyB,IAAI,KAA2B;AACrE,MAAM,uBAAuB;AAY7B,MAAM,mBAAmB,YACvB,QAAQ,MAAM,GAAG,qBAAqB,CAAC,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAEpE,MAAM,6BACJ,OACA,YAQU;CACV,MAAM,kBACJ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;CAC3D,MAAM,UAAU,gBAAgB,QAAQ,QAAQ;CAChD,MAAM,UAAU;EACd;EACA,UAAU,QAAQ;EAClB,WAAW,QAAQ;EACnB,aAAa,QAAQ;EACtB;AAED,KAAI,QAAQ,SACV,SAAQ,KAAK,SAAS,QAAQ,WAAW;AAG3C,KAAI,QAAQ,YAAY;AACtB,UAAQ,KAAK,kBAAkB,QAAQ,WAAW,eAAe;AAEjE,MAAI,QAAQ,WAAW,WACrB,SAAQ,KAAK,WAAW,QAAQ,WAAW,aAAa;AAG1D,MAAI,QAAQ,WAAW,WACrB,SAAQ,KAAK,gBAAgB,QAAQ,WAAW,aAAa;AAG/D,MAAI,QAAQ,WAAW,cACrB,SAAQ,KAAK,oBAAoB,QAAQ,WAAW,gBAAgB;AAGtE,MAAI,QAAQ,WAAW,eACrB,SAAQ,KAAK,iBAAiB,QAAQ,W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,oBAAoB,WAAW,iBAAiB,IAChD,QACD,GACD;AAEN,QAAI,MAAM,GAAG,WAAW,SAAS,CAC/B,WACE,cACA,SACA,oBAAoB,WAAW,iBAAiB,KAC/C,KAAK,UAAU;AACd,SAAI,IACF,QAAO,YAAY,SAAS,gBAAgB,IAAI,OAAO,IAAI;AAC7D,SAAI,MAAO,cAAa,OAAO,gBAAgB;AAC/C,aAAQ,MAAM;OAEhB,KACD;SACI;KACL,MAAM,YAAY,oBAAoB,EAAE,QAAQ;AAGhD,eADE,OAAO,YAAY,cAAc,cAAc,WAG/C,WACA,oBAAoB,WAAW,YAAY,OAC1C,KAAK,UAAU;AACd,UAAI,IACF,QAAO,YAAY,SAAS,gBAAgB,IAAI,OAAO,IAAI;AAC7D,UAAI,MAAO,cAAa,OAAO,gBAAgB;AAC/C,cAAQ,MAAM;QAEhB,KACD;;KAEH;AACF,YAAS,KAAM,mBAAmB,KAAK,QAAS;QAEhD,iBAAgB,WAAW;;;AAQrC,MAAa,+BACX,WACS;AACT,KAAI,oBAAoB,GAAG;AACzB,MAAI,oBAAoB,EAAE,SAAS;AACjC,WAAQ,KACN,qBACA,uHACD;AACD,uBAAoB,EAAE,UAAU;;AAGlC,MAAI,oBAAoB,EAAE,WACxB,qBAAoB,EAAE,aAAa;;;AAKzC,iCAA0D;AACxD,QAAO;EACL,MAAM;EACN,WAAW,MAAM;AAEf,UAAO;IAEL,MAAM,kBAA0C,EAAE;AAGlD,uBAAmB;AAMnB,gCAHe,kBAAkB,iBAAiB,KAAK,CAGpB;OACjC;AAEJ,UAAO;;EAEV"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "@module-federation/node",
4
- "version": "2.7.39",
4
+ "version": "2.7.41",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/src/index.js",
7
7
  "module": "./dist/src/index.mjs",
@@ -108,12 +108,12 @@
108
108
  "author": "Zack Jackson <zackary.l.jackson@gmail.com>",
109
109
  "license": "MIT",
110
110
  "dependencies": {
111
- "encoding": "^0.1.13",
111
+ "encoding": "0.1.13",
112
112
  "node-fetch": "2.7.0",
113
113
  "tapable": "2.3.0",
114
- "@module-federation/enhanced": "2.3.1",
115
- "@module-federation/sdk": "2.3.1",
116
- "@module-federation/runtime": "2.3.1"
114
+ "@module-federation/sdk": "2.3.3",
115
+ "@module-federation/runtime": "2.3.3",
116
+ "@module-federation/enhanced": "2.3.3"
117
117
  },
118
118
  "peerDependencies": {
119
119
  "webpack": "^5.40.0"