@module-federation/nextjs-mf 8.8.76 → 8.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,6 +105,7 @@ var NextFederationPlugin = class {
105
105
  });
106
106
  require_next_fragments.applyPathFixes(compiler, this._options, this._extraOptions);
107
107
  if (this._extraOptions.debug) compiler.options.devtool = false;
108
+ if (this._extraOptions.scriptTimeout !== void 0) new compiler.webpack.DefinePlugin({ FEDERATION_NEXTJS_SCRIPT_TIMEOUT: JSON.stringify(this._extraOptions.scriptTimeout) }).apply(compiler);
108
109
  if (isServer) {
109
110
  require_apply_server_plugins.configureServerCompilerOptions(compiler);
110
111
  require_apply_server_plugins.configureServerLibraryAndFilename(this._options);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["setOptions","logger","CopyFederationPlugin","ModuleFederationPlugin","validateCompilerOptions","validatePluginOptions","retrieveDefaultShared","exposeNextjsPages","normalizeManifestOptions"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\nimport { normalizeManifestOptions } from './manifest-options';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: normalizeManifestOptions(this._options.manifest, isServer),\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,iCAGA,QAAQ,QAAQ,2EAA2E;AAEjG,MAAM,wBAGA,QAAQ,QAAQ,2DAA2D;AAEjF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,aAAK,QAC3B,QAAQ,QAAQ,uCAAuC,CACxD;AAED,QAAO,QAAQ,QACb,aAAK,KACH,iBAGI,4BACL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,aAAa,iBAAiBA,+BAAW,QAAQ;AACzD,OAAK,WAAW;AAChB,OAAK,gBAAgB;AACrB,OAAK,OAAO;;;;;;CAOd,MAAM,UAAoB;AACxB,mDAAqBC,wBAAQ,UAAU,uBAAuB;AAC9D,UAAQ,IAAI,6BACV,QAAQ,IAAI,gGACG,UAAU,EAAE,WAAW,UAAU,CAAC;AACnD,MAAI,CAAC,KAAK,gBAAgB,SAAS,CAAE;EACrC,MAAM,WAAW,KAAK,iBAAiB,SAAS;AAChD,MAAIC,qCAAqB,SAAS,CAAC,MAAM,SAAS;EAClD,MAAM,gCAAgC,KAAK,iCACzC,UACA,SACD;AACD,OAAK,WAAW;AAChB,OAAK,wBAAwB,UAAU,SAAS;AAEhD,MAAIC,2DAAuB,8BAA8B,CAAC,MAAM,SAAS;EAEzE,MAAM,OAAO,KAAK,aAAa;AAE/B,MAAI,CAAC,KAAK,cAAc,yBACtB,UAAS,MAAM,KAAK,SAClB,yBACC,aAAa,aAAa;GACzB,MAAM,MAAM,SAAS,QAAQ,YAAY,iBACvC,MACA,OACD;AACD,eAAY,SACV,SAAS,SACT,KACA,EAAE,MAAM,QAAQ,GACf,KAAK,WAAW;AACf,QAAI,IACF,QAAO,SAAS,IAAI;AAEtB,cAAU;KAE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,QAAQ,UAAU;AAG7B,MAAI,UAAU;AACZ,+DAA+B,SAAS;AACxC,kEAAkC,KAAK,SAAS;AAChD,mDAAmB,UAAU,KAAK,SAAS;AAC3C,sDAAsB,UAAU;IAC9B,GAAG,KAAK;IACR,QAAQ;KAAE,GAAGC,6CAAsB,SAAS;KAAE,GAAG,KAAK,SAAS;KAAQ;IACxE,CAAC;QAEF,iDAAmB,UAAU,KAAK,UAAU,KAAK,cAAc;;CAInE,AAAQ,iCACN,UACA,UACsD;EACtD,MAAM,gBAAgB,KAAK,cAAc,2BACrC,EAAE,GACFA,6CAAsB,SAAS;AACnC,SAAO;GACL,GAAG,KAAK;GACR,SAAS;GACT,YAAY;GACZ,gBAAgB;IACd,GAAI,WAAW,CAAC,8BAA8B,CAAC,GAAG,EAAE;IACpD,0BAA0B;IAC1B,GAAI,KAAK,SAAS,kBAAkB,EAAE;IACvC,CAAC,KAAK,WAAW,SAAS,iBAAiB;GAE5C,SAAS;IACP,GAAG,KAAK,SAAS;IACjB,GAAI,KAAK,cAAc,cACnBC,wDAAkB,SAAS,QAAQ,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAI,KAAK,SAAS;IACnB;GACD,UAAUC,kDAAyB,KAAK,SAAS,UAAU,SAAS;GAEpE,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
1
+ {"version":3,"file":"index.js","names":["setOptions","logger","CopyFederationPlugin","ModuleFederationPlugin","validateCompilerOptions","validatePluginOptions","retrieveDefaultShared","exposeNextjsPages","normalizeManifestOptions"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\nimport { normalizeManifestOptions } from './manifest-options';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n if (this._extraOptions.scriptTimeout !== undefined) {\n new compiler.webpack.DefinePlugin({\n FEDERATION_NEXTJS_SCRIPT_TIMEOUT: JSON.stringify(\n this._extraOptions.scriptTimeout,\n ),\n }).apply(compiler);\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: normalizeManifestOptions(this._options.manifest, isServer),\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,iCAGA,QAAQ,QAAQ,2EAA2E;AAEjG,MAAM,wBAGA,QAAQ,QAAQ,2DAA2D;AAEjF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,aAAK,QAC3B,QAAQ,QAAQ,uCAAuC,CACxD;AAED,QAAO,QAAQ,QACb,aAAK,KACH,iBAGI,4BACL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,aAAa,iBAAiBA,+BAAW,QAAQ;AACzD,OAAK,WAAW;AAChB,OAAK,gBAAgB;AACrB,OAAK,OAAO;;;;;;CAOd,MAAM,UAAoB;AACxB,mDAAqBC,wBAAQ,UAAU,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WAAW,CAAC,8BAA8B,CAAC,GAAG,EAAE;IACpD,0BAA0B;IAC1B,GAAI,KAAK,SAAS,kBAAkB,EAAE;IACvC,CAAC,KAAK,WAAW,SAAS,iBAAiB;GAE5C,SAAS;IACP,GAAG,KAAK,SAAS;IACjB,GAAI,KAAK,cAAc,cACnBC,wDAAkB,SAAS,QAAQ,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAI,KAAK,SAAS;IACnB;GACD,UAAUC,kDAAyB,KAAK,SAAS,UAAU,SAAS;GAEpE,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
@@ -102,6 +102,7 @@ var NextFederationPlugin = class {
102
102
  });
103
103
  applyPathFixes(compiler, this._options, this._extraOptions);
104
104
  if (this._extraOptions.debug) compiler.options.devtool = false;
105
+ if (this._extraOptions.scriptTimeout !== void 0) new compiler.webpack.DefinePlugin({ FEDERATION_NEXTJS_SCRIPT_TIMEOUT: JSON.stringify(this._extraOptions.scriptTimeout) }).apply(compiler);
105
106
  if (isServer) {
106
107
  configureServerCompilerOptions(compiler);
107
108
  configureServerLibraryAndFilename(this._options);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["CopyFederationPlugin"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\nimport { normalizeManifestOptions } from './manifest-options';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: normalizeManifestOptions(this._options.manifest, isServer),\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,2CAEQ,QAAQ,4EAA4E;AAGlG,MAAM,kCAEQ,QAAQ,4DAA4D;AAGlF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,KAAK,kBACnB,QAAQ,uCAAuC,CACxD;AAED,kBAAe,QACb,KAAK,KACH,iBAEI,6BAEL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,aAAa,iBAAiB,WAAW,QAAQ;AACzD,OAAK,WAAW;AAChB,OAAK,gBAAgB;AACrB,OAAK,OAAO;;;;;;CAOd,MAAM,UAAoB;AACxB,uBAAqB,QAAQ,UAAU,uBAAuB;AAC9D,UAAQ,IAAI,6BACV,QAAQ,IAAI,8BACZ,eAAe,UAAU,EAAE,WAAW,UAAU,CAAC;AACnD,MAAI,CAAC,KAAK,gBAAgB,SAAS,CAAE;EACrC,MAAM,WAAW,KAAK,iBAAiB,SAAS;AAChD,MAAIA,sBAAqB,SAAS,CAAC,MAAM,SAAS;EAClD,MAAM,gCAAgC,KAAK,iCACzC,UACA,SACD;AACD,OAAK,WAAW;AAChB,OAAK,wBAAwB,UAAU,SAAS;AAEhD,MAAI,uBAAuB,8BAA8B,CAAC,MAAM,SAAS;EAEzE,MAAM,OAAO,KA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1
+ {"version":3,"file":"index.mjs","names":["CopyFederationPlugin"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\nimport { normalizeManifestOptions } from './manifest-options';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n if (this._extraOptions.scriptTimeout !== undefined) {\n new compiler.webpack.DefinePlugin({\n FEDERATION_NEXTJS_SCRIPT_TIMEOUT: JSON.stringify(\n this._extraOptions.scriptTimeout,\n ),\n }).apply(compiler);\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: normalizeManifestOptions(this._options.manifest, isServer),\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,2CAEQ,QAAQ,4EAA4E;AAGlG,MAAM,kCAEQ,QAAQ,4DAA4D;AAGlF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,KAAK,kBACnB,QAAQ,uCAAuC,CACxD;AAED,kBAAe,QACb,KAAK,KACH,iBAEI,6BAEL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,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,MAAM,gBAAgB,KAAK,cAAc,2BACrC,EAAE,GACF,sBAAsB,SAAS;AACnC,SAAO;GACL,GAAG,KAAK;GACR,SAAS;GACT,YAAY;GACZ,gBAAgB;IACd,GAAI,WAAW,CAAC,8BAA8B,CAAC,GAAG,EAAE;IACpD,0BAA0B;IAC1B,GAAI,KAAK,SAAS,kBAAkB,EAAE;IACvC,CAAC,KAAK,WAAW,SAAS,iBAAiB;GAE5C,SAAS;IACP,GAAG,KAAK,SAAS;IACjB,GAAI,KAAK,cAAc,cACnB,kBAAkB,SAAS,QAAQ,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAI,KAAK,SAAS;IACnB;GACD,UAAU,yBAAyB,KAAK,SAAS,UAAU,SAAS;GAEpE,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
@@ -14,6 +14,8 @@ export interface NextFederationPluginExtraOptions {
14
14
  skipSharingNextInternals?: boolean;
15
15
  automaticPageStitching?: boolean;
16
16
  debug?: boolean;
17
+ /** Browser remote entry timeout in milliseconds. Defaults to 8000. */
18
+ scriptTimeout?: number;
17
19
  }
18
20
  export interface NextFederationPluginOptions extends moduleFederationPlugin.ModuleFederationPluginOptions {
19
21
  extraOptions: NextFederationPluginExtraOptions;
@@ -14,6 +14,8 @@ export interface NextFederationPluginExtraOptions {
14
14
  skipSharingNextInternals?: boolean;
15
15
  automaticPageStitching?: boolean;
16
16
  debug?: boolean;
17
+ /** Browser remote entry timeout in milliseconds. Defaults to 8000. */
18
+ scriptTimeout?: number;
17
19
  }
18
20
  export interface NextFederationPluginOptions extends moduleFederationPlugin.ModuleFederationPluginOptions {
19
21
  extraOptions: NextFederationPluginExtraOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"next-fragments.js","names":["DEFAULT_SHARE_SCOPE","DEFAULT_SHARE_SCOPE_BROWSER","findLoaderForResource","hasLoader"],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js');\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js');\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.Module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iB,EACf,MAAM,yBACP;GACD,SAAS;GACT,SAAS;GACV;EAED,MAAM,WAAwB;GAC5B,GAAG;GACH,eAAe;GACf,SAAS;GACT,SAAS;GACV;EAED,MAAM,YAAY,SAAS,QAAQ,OAAO,MAAM,MAC7C,SAA8B;AAC7B,UAAO,CAAC,CAAC,QAAQ,OAAO,SAAS,YAAY,WAAW;IAE3D;AAED,MAAI,CAAC,UACH,UAAS,QAAQ,OAAO,MAAM,QAAQ,EACpC,OAAO,CAAC,qBAAqB,SAAS,EACvC,CAAC;WACO,UAAU,MACnB,WAAU,MAAM,QAAQ,qBAAqB,SAAS"}
1
+ {"version":3,"file":"next-fragments.js","names":["DEFAULT_SHARE_SCOPE","DEFAULT_SHARE_SCOPE_BROWSER","findLoaderForResource","hasLoader"],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js');\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js');\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n /** Browser remote entry timeout in milliseconds. Defaults to 8000. */\n scriptTimeout?: number;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginExtraOptions;\n}\n"],"mappings":";;;;;;;AAgBA,MAAM,kCAGA,QAAQ,QAAQ,kEAAkE;AAExF,MAAM,gCAGA,QAAQ,QAAQ,gEAAgE;;;;;;AAMtF,MAAa,yBACX,aACwC;AAGxC,KAAI,SACF,QAAOA;AAGT,QAAOC;;AAET,MAAa,kBACX,UACA,eACA,YACG;CACH,MAAM,QAAQC,sCACZ,SAAS,QAAQ,OAAO,OACxB;EACE,MAAM,aAAK,KAAK,SAAS,SAAS,sBAAsB;EACxD,aAAa;EACb,OAAO;EACR,CACF;AAED,UAAS,QAAQ,OAAO,MAAM,SAAS,SAAS;AAC9C,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;GAC7C,MAAM,YAAY;AAElB,OACE,QAAQ,wBACRC,0BAAU,WAAW,oBAAoB,CAEzC,kCAAiB,WAAW,EAC1B,QAAQ,2BAA2B,EACpC,CAAC;AAGJ,OAAI,QAAQ,sBAAsBA,0BAAU,WAAW,aAAa,CAClE,kCAAiB,WAAW,EAC1B,QAAQ,yBAAyB,EAClC,CAAC;;GAGN;AAEF,KAAI,OAAO;EACT,IAAI;AACJ,MAAI,MAAM,KAAK;AACb,eAAY,EAAE,GAAG,OAAO;AACxB,OAAI,MAAM,QAAQ,MAAM,IAAI,CAC1B,WAAU,MAAM,MAAM,IAAI,QAAQ,WAAgB;AAChD,WACE,OAAO,WAAW,YAClB,OAAO,UACP,CAAC,OAAO,OAAO,SAAS,QAAQ;KAElC;YACO,OAAO,MAAM,QAAQ,SAC9B,WAAU,MAAM,MAAM,IAAI,SAAS,QAAQ,GAAG,KAAK,MAAM;YAChD,OAAO,MAAM,QAAQ,YAAY,MAAM,QAAQ,KACxD,WAAU,MACR,MAAM,IAAI,UAAU,MAAM,IAAI,OAAO,SAAS,QAAQ,GAClD,EAAE,GACF,MAAM;QAGd,aAAY,EAAE,GAAG,OAAO;EAG1B,MAAM,sBAAmC;GACvC,GAAG;GACH,iBAAiB,EACf,MAAM,yBACP;GACD,SAAS;GACT,SAAS;GACV;EAED,MAAM,WAAwB;GAC5B,GAAG;GACH,eAAe;GACf,SAAS;GACT,SAAS;GACV;EAED,MAAM,YAAY,SAAS,QAAQ,OAAO,MAAM,MAC7C,SAA8B;AAC7B,UAAO,CAAC,CAAC,QAAQ,OAAO,SAAS,YAAY,WAAW;IAE3D;AAED,MAAI,CAAC,UACH,UAAS,QAAQ,OAAO,MAAM,QAAQ,EACpC,OAAO,CAAC,qBAAqB,SAAS,EACvC,CAAC;WACO,UAAU,MACnB,WAAU,MAAM,QAAQ,qBAAqB,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"next-fragments.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js');\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js');\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginExtraOptions;\n}\n"],"mappings":";;;;;;AAgBA,MAAM,4CAEQ,QAAQ,mEAAmE;AAGzF,MAAM,0CAEQ,QAAQ,iEAAiE;;;;;;AAOvF,MAAa,yBACX,aACwC;AAGxC,KAAI,SACF,QAAO;AAGT,QAAO;;AAET,MAAa,kBACX,UACA,eACA,YACG;CACH,MAAM,QAAQ,sBACZ,SAAS,QAAQ,OAAO,OACxB;EACE,MAAM,KAAK,KAAK,SAAS,SAAS,sBAAsB;EACxD,aAAa;EACb,OAAO;EACR,CACF;AAED,UAAS,QAAQ,OAAO,MAAM,SAAS,SAAS;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ources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js');\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js');\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n /** Browser remote entry timeout in milliseconds. Defaults to 8000. */\n scriptTimeout?: number;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: N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GACV;EAED,MAAM,WAAwB;GAC5B,GAAG;GACH,eAAe;GACf,SAAS;GACT,SAAS;GACV;EAED,MAAM,YAAY,SAAS,QAAQ,OAAO,MAAM,MAC7C,SAA8B;AAC7B,UAAO,CAAC,CAAC,QAAQ,OAAO,SAAS,YAAY,WAAW;IAE3D;AAED,MAAI,CAAC,UACH,UAAS,QAAQ,OAAO,MAAM,QAAQ,EACpC,OAAO,CAAC,qBAAqB,SAAS,EACvC,CAAC;WACO,UAAU,MACnB,WAAU,MAAM,QAAQ,qBAAqB,SAAS"}
@@ -1,4 +1,4 @@
1
- declare const RuntimeModule: typeof import("node_modules/webpack/types").RuntimeModule;
1
+ declare const RuntimeModule: typeof import("webpack").RuntimeModule;
2
2
  interface InvertedContainerRuntimeModuleOptions {
3
3
  name?: string;
4
4
  containers: Set<any>;
@@ -1,4 +1,4 @@
1
- declare const RuntimeModule: typeof import("node_modules/webpack/types").RuntimeModule;
1
+ declare const RuntimeModule: typeof import("webpack").RuntimeModule;
2
2
  interface InvertedContainerRuntimeModuleOptions {
3
3
  name?: string;
4
4
  containers: Set<any>;
@@ -17,6 +17,7 @@ function wrapCallableForChunkTracking(fn, id) {
17
17
  }
18
18
  });
19
19
  }
20
+ const DEFAULT_SCRIPT_TIMEOUT = 8e3;
20
21
  function runtimePlugin_default() {
21
22
  return {
22
23
  name: "next-internal-plugin",
@@ -30,7 +31,7 @@ function runtimePlugin_default() {
30
31
  delete attrs?.["crossorigin"];
31
32
  return {
32
33
  script,
33
- timeout: 8e3
34
+ timeout: typeof FEDERATION_NEXTJS_SCRIPT_TIMEOUT === "number" && Number.isFinite(FEDERATION_NEXTJS_SCRIPT_TIMEOUT) && FEDERATION_NEXTJS_SCRIPT_TIMEOUT > 0 ? FEDERATION_NEXTJS_SCRIPT_TIMEOUT : DEFAULT_SCRIPT_TIMEOUT
34
35
  };
35
36
  }
36
37
  },
@@ -1 +1 @@
1
- {"version":3,"file":"runtimePlugin.js","names":[],"sources":["../../../../src/plugins/container/runtimePlugin.ts"],"sourcesContent":["import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';\nimport { matchRemoteWithNameAndExpose } from '@module-federation/runtime-core';\n\nfunction wrapCallableForChunkTracking<T extends (...args: any[]) => any>(\n fn: T,\n id: string,\n): T {\n return new Proxy(fn, {\n apply(_target, thisArg, args) {\n globalThis.usedChunks.add(id);\n return Reflect.apply(fn, thisArg, args);\n },\n construct(_target, args, newTarget) {\n globalThis.usedChunks.add(id);\n return Reflect.construct(fn, args, newTarget);\n },\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'next-internal-plugin',\n createScript: function (args: {\n url: string;\n attrs?: Record<string, any>;\n }) {\n const url = args.url;\n const attrs = args.attrs;\n if (typeof window !== 'undefined') {\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n delete attrs?.['crossorigin'];\n\n return { script: script, timeout: 8000 };\n }\n return undefined;\n },\n errorLoadRemote: function (args: {\n id: string;\n error: any;\n from: string;\n origin: any;\n }) {\n const id = args.id;\n const error = args.error;\n const from = args.from;\n //@ts-ignore\n globalThis.moduleGraphDirty = true;\n console.error(id, 'offline');\n const pg = function () {\n console.error(id, 'offline', error);\n return null;\n };\n\n (pg as any).getInitialProps = function (ctx: any) {\n return {};\n };\n let mod;\n if (from === 'build') {\n mod = function () {\n return {\n __esModule: true,\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n };\n } else {\n mod = {\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n }\n\n return mod;\n },\n beforeInit: function (args) {\n if (!globalThis.usedChunks) globalThis.usedChunks = new Set();\n if (\n typeof __webpack_runtime_id__ === 'string' &&\n !__webpack_runtime_id__.startsWith('webpack')\n ) {\n return args;\n }\n\n const moduleCache = args.origin.moduleCache;\n const name = args.origin.name;\n let gs;\n try {\n gs = new Function('return globalThis')();\n } catch (e) {\n gs = globalThis; // fallback for browsers without 'unsafe-eval' CSP policy enabled\n }\n //@ts-ignore\n const attachedRemote = gs[name];\n if (attachedRemote) {\n moduleCache.set(name, attachedRemote);\n }\n\n return args;\n },\n init: function (args: any) {\n return args;\n },\n beforeRequest: function (args: any) {\n const options = args.options;\n const id = args.id;\n const match = matchRemoteWithNameAndExpose(options.remotes, id);\n if (!match) return args;\n const remote = match.remote;\n if (\n !('entry' in remote) ||\n !remote.entry ||\n /[?&]t=/.test(remote.entry)\n ) {\n return args;\n }\n remote.entry =\n remote.entry +\n (remote.entry.includes('?') ? '&' : '?') +\n 't=' +\n Date.now();\n return args;\n },\n afterResolve: function (args: any) {\n return args;\n },\n onLoad: async function (args: any) {\n const exposeModuleFactory = args.exposeModuleFactory;\n const exposeModule = args.exposeModule;\n const id = args.id;\n const moduleOrFactory = exposeModuleFactory || exposeModule;\n if (!moduleOrFactory) return args;\n\n if (typeof window === 'undefined') {\n let exposedModuleExports: any;\n try {\n exposedModuleExports = moduleOrFactory();\n } catch (e) {\n exposedModuleExports = moduleOrFactory;\n }\n\n exposedModuleExports = await exposedModuleExports;\n\n const handler: ProxyHandler<any> = {\n get: function (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver);\n if (typeof value === 'function') {\n return wrapCallableForChunkTracking(value, id);\n }\n return value;\n },\n };\n\n if (typeof exposedModuleExports === 'function') {\n exposedModuleExports = wrapCallableForChunkTracking(\n exposedModuleExports,\n id,\n );\n return function () {\n return exposedModuleExports;\n };\n }\n\n exposedModuleExports = new Proxy(exposedModuleExports, handler);\n\n if (exposeModuleFactory) {\n const wrappedExports = exposedModuleExports;\n return function () {\n return wrappedExports;\n };\n }\n\n return exposedModuleExports;\n }\n\n return args;\n },\n loadRemoteSnapshot(args) {\n const { from, remoteSnapshot, manifestUrl, manifestJson, options } = args;\n\n // ensure snapshot is loaded from manifest\n if (\n from !== 'manifest' ||\n !manifestUrl ||\n !manifestJson ||\n !('publicPath' in remoteSnapshot)\n ) {\n return args;\n }\n\n // re-assign publicPath based on remoteEntry location if in browser nextjs remote\n const { publicPath } = remoteSnapshot;\n if (options.inBrowser && publicPath.includes('/_next/')) {\n remoteSnapshot.publicPath = publicPath.substring(\n 0,\n publicPath.lastIndexOf('/_next/') + 7,\n );\n } else {\n const serverPublicPath = manifestUrl.substring(\n 0,\n manifestUrl.indexOf('mf-manifest.json'),\n );\n remoteSnapshot.publicPath = serverPublicPath;\n }\n\n if ('publicPath' in manifestJson.metaData) {\n manifestJson.metaData.publicPath = remoteSnapshot.publicPath;\n }\n\n return args;\n },\n resolveShare: function (args: any) {\n if (\n args.pkgName !== 'react' &&\n args.pkgName !== 'react-dom' &&\n !args.pkgName.startsWith('next/')\n ) {\n return args;\n }\n const shareScopeMap = args.shareScopeMap;\n const scope = args.scope;\n const pkgName = args.pkgName;\n const version = args.version;\n const GlobalFederation = args.GlobalFederation;\n const host = GlobalFederation['__INSTANCES__'][0];\n if (!host) {\n return args;\n }\n\n if (!host.options.shared[pkgName]) {\n return args;\n }\n args.resolver = function () {\n shareScopeMap[scope][pkgName][version] =\n host.options.shared[pkgName][0];\n return {\n shared: shareScopeMap[scope][pkgName][version],\n useTreesShaking: false,\n };\n };\n return args;\n },\n beforeLoadShare: async function (args: any) {\n return args;\n },\n };\n}\n"],"mappings":";;;;AAGA,SAAS,6BACP,IACA,IACG;AACH,QAAO,IAAI,MAAM,IAAI;EACnB,MAAM,SAAS,SAAS,MAAM;AAC5B,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,MAAM,IAAI,SAAS,KAAK;;EAEzC,UAAU,SAAS,MAAM,WAAW;AAClC,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,UAAU,IAAI,MAAM,UAAU;;EAE/C,IAAI,QAAQ,MAAM,UAAU;AAC1B,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;;EAE7C,CAAC;;AAGJ,iCAA0D;AACxD,QAAO;EACL,MAAM;EACN,cAAc,SAAU,MAGrB;GACD,MAAM,MAAM,K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,aAAa,WAAW,UACrC,GACA,WAAW,YAAY,UAAU,GAAG,EACrC;OAMD,gBAAe,aAJU,YAAY,UACnC,GACA,YAAY,QAAQ,mBAAmB,CACxC;AAIH,OAAI,gBAAgB,aAAa,SAC/B,cAAa,SAAS,aAAa,eAAe;AAGpD,UAAO;;EAET,cAAc,SAAU,MAAW;AACjC,OACE,KAAK,YAAY,WACjB,KAAK,YAAY,eACjB,CAAC,KAAK,QAAQ,WAAW,QAAQ,CAEjC,QAAO;GAET,MAAM,gBAAgB,KAAK;GAC3B,MAAM,QAAQ,KAAK;GACnB,MAAM,UAAU,KAAK;GACrB,MAAM,UAAU,KAAK;GAErB,MAAM,OADmB,KAAK,iBACA,iBAAiB;AAC/C,OAAI,CAAC,KACH,QAAO;AAGT,OAAI,CAAC,KAAK,QAAQ,OAAO,SACvB,QAAO;AAET,QAAK,WAAW,WAAY;AAC1B,kBAAc,OAAO,SAAS,WAC5B,KAAK,QAAQ,OAAO,SAAS;AAC/B,WAAO;KACL,QAAQ,cAAc,OAAO,SAAS;KACtC,iBAAiB;KAClB;;AAEH,UAAO;;EAET,iBAAiB,eAAgB,MAAW;AAC1C,UAAO;;EAEV"}
1
+ {"version":3,"file":"runtimePlugin.js","names":[],"sources":["../../../../src/plugins/container/runtimePlugin.ts"],"sourcesContent":["import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';\nimport { matchRemoteWithNameAndExpose } from '@module-federation/runtime-core';\n\nfunction wrapCallableForChunkTracking<T extends (...args: any[]) => any>(\n fn: T,\n id: string,\n): T {\n return new Proxy(fn, {\n apply(_target, thisArg, args) {\n globalThis.usedChunks.add(id);\n return Reflect.apply(fn, thisArg, args);\n },\n construct(_target, args, newTarget) {\n globalThis.usedChunks.add(id);\n return Reflect.construct(fn, args, newTarget);\n },\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n\ndeclare const FEDERATION_NEXTJS_SCRIPT_TIMEOUT: number;\n\nconst DEFAULT_SCRIPT_TIMEOUT = 8000;\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'next-internal-plugin',\n createScript: function (args: {\n url: string;\n attrs?: Record<string, any>;\n }) {\n const url = args.url;\n const attrs = args.attrs;\n if (typeof window !== 'undefined') {\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n delete attrs?.['crossorigin'];\n\n const timeout =\n typeof FEDERATION_NEXTJS_SCRIPT_TIMEOUT === 'number' &&\n Number.isFinite(FEDERATION_NEXTJS_SCRIPT_TIMEOUT) &&\n FEDERATION_NEXTJS_SCRIPT_TIMEOUT > 0\n ? FEDERATION_NEXTJS_SCRIPT_TIMEOUT\n : DEFAULT_SCRIPT_TIMEOUT;\n\n return { script: script, timeout };\n }\n return undefined;\n },\n errorLoadRemote: function (args: {\n id: string;\n error: any;\n from: string;\n origin: any;\n }) {\n const id = args.id;\n const error = args.error;\n const from = args.from;\n //@ts-ignore\n globalThis.moduleGraphDirty = true;\n console.error(id, 'offline');\n const pg = function () {\n console.error(id, 'offline', error);\n return null;\n };\n\n (pg as any).getInitialProps = function (ctx: any) {\n return {};\n };\n let mod;\n if (from === 'build') {\n mod = function () {\n return {\n __esModule: true,\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n };\n } else {\n mod = {\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n }\n\n return mod;\n },\n beforeInit: function (args) {\n if (!globalThis.usedChunks) globalThis.usedChunks = new Set();\n if (\n typeof __webpack_runtime_id__ === 'string' &&\n !__webpack_runtime_id__.startsWith('webpack')\n ) {\n return args;\n }\n\n const moduleCache = args.origin.moduleCache;\n const name = args.origin.name;\n let gs;\n try {\n gs = new Function('return globalThis')();\n } catch (e) {\n gs = globalThis; // fallback for browsers without 'unsafe-eval' CSP policy enabled\n }\n //@ts-ignore\n const attachedRemote = gs[name];\n if (attachedRemote) {\n moduleCache.set(name, attachedRemote);\n }\n\n return args;\n },\n init: function (args: any) {\n return args;\n },\n beforeRequest: function (args: any) {\n const options = args.options;\n const id = args.id;\n const match = matchRemoteWithNameAndExpose(options.remotes, id);\n if (!match) return args;\n const remote = match.remote;\n if (\n !('entry' in remote) ||\n !remote.entry ||\n /[?&]t=/.test(remote.entry)\n ) {\n return args;\n }\n remote.entry =\n remote.entry +\n (remote.entry.includes('?') ? '&' : '?') +\n 't=' +\n Date.now();\n return args;\n },\n afterResolve: function (args: any) {\n return args;\n },\n onLoad: async function (args: any) {\n const exposeModuleFactory = args.exposeModuleFactory;\n const exposeModule = args.exposeModule;\n const id = args.id;\n const moduleOrFactory = exposeModuleFactory || exposeModule;\n if (!moduleOrFactory) return args;\n\n if (typeof window === 'undefined') {\n let exposedModuleExports: any;\n try {\n exposedModuleExports = moduleOrFactory();\n } catch (e) {\n exposedModuleExports = moduleOrFactory;\n }\n\n exposedModuleExports = await exposedModuleExports;\n\n const handler: ProxyHandler<any> = {\n get: function (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver);\n if (typeof value === 'function') {\n return wrapCallableForChunkTracking(value, id);\n }\n return value;\n },\n };\n\n if (typeof exposedModuleExports === 'function') {\n exposedModuleExports = wrapCallableForChunkTracking(\n exposedModuleExports,\n id,\n );\n return function () {\n return exposedModuleExports;\n };\n }\n\n exposedModuleExports = new Proxy(exposedModuleExports, handler);\n\n if (exposeModuleFactory) {\n const wrappedExports = exposedModuleExports;\n return function () {\n return wrappedExports;\n };\n }\n\n return exposedModuleExports;\n }\n\n return args;\n },\n loadRemoteSnapshot(args) {\n const { from, remoteSnapshot, manifestUrl, manifestJson, options } = args;\n\n // ensure snapshot is loaded from manifest\n if (\n from !== 'manifest' ||\n !manifestUrl ||\n !manifestJson ||\n !('publicPath' in remoteSnapshot)\n ) {\n return args;\n }\n\n // re-assign publicPath based on remoteEntry location if in browser nextjs remote\n const { publicPath } = remoteSnapshot;\n if (options.inBrowser && publicPath.includes('/_next/')) {\n remoteSnapshot.publicPath = publicPath.substring(\n 0,\n publicPath.lastIndexOf('/_next/') + 7,\n );\n } else {\n const serverPublicPath = manifestUrl.substring(\n 0,\n manifestUrl.indexOf('mf-manifest.json'),\n );\n remoteSnapshot.publicPath = serverPublicPath;\n }\n\n if ('publicPath' in manifestJson.metaData) {\n manifestJson.metaData.publicPath = remoteSnapshot.publicPath;\n }\n\n return args;\n },\n resolveShare: function (args: any) {\n if (\n args.pkgName !== 'react' &&\n args.pkgName !== 'react-dom' &&\n !args.pkgName.startsWith('next/')\n ) {\n return args;\n }\n const shareScopeMap = args.shareScopeMap;\n const scope = args.scope;\n const pkgName = args.pkgName;\n const version = args.version;\n const GlobalFederation = args.GlobalFederation;\n const host = GlobalFederation['__INSTANCES__'][0];\n if (!host) {\n return args;\n }\n\n if (!host.options.shared[pkgName]) {\n return args;\n }\n args.resolver = function () {\n shareScopeMap[scope][pkgName][version] =\n host.options.shared[pkgName][0];\n return {\n shared: shareScopeMap[scope][pkgName][version],\n useTreesShaking: false,\n };\n };\n return args;\n },\n beforeLoadShare: async function (args: any) {\n return args;\n },\n };\n}\n"],"mappings":";;;;AAGA,SAAS,6BACP,IACA,IACG;AACH,QAAO,IAAI,MAAM,IAAI;EACnB,MAAM,SAAS,SAAS,MAAM;AAC5B,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,MAAM,IAAI,SAAS,KAAK;;EAEzC,UAAU,SAAS,MAAM,WAAW;AAClC,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,UAAU,IAAI,MAAM,UAAU;;EAE/C,IAAI,QAAQ,MAAM,UAAU;AAC1B,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;;EAE7C,CAAC;;AAKJ,MAAM,yBAAyB;AAE/B,iCAA0D;AACxD,QAAO;EACL,MAAM;EACN,cAAc,SAAU,MAGrB;GACD,MAAM,MAAM,KAAK;GACjB,MAAM,QAAQ,KAAK;AACnB,OAAI,OAAO,WAAW,aAAa;IACjC,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,WAAO,MAAM;AACb,WAAO,QAA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BAAe,aAJU,YAAY,UACnC,GACA,YAAY,QAAQ,mBAAmB,CACxC;AAIH,OAAI,gBAAgB,aAAa,SAC/B,cAAa,SAAS,aAAa,eAAe;AAGpD,UAAO;;EAET,cAAc,SAAU,MAAW;AACjC,OACE,KAAK,YAAY,WACjB,KAAK,YAAY,eACjB,CAAC,KAAK,QAAQ,WAAW,QAAQ,CAEjC,QAAO;GAET,MAAM,gBAAgB,KAAK;GAC3B,MAAM,QAAQ,KAAK;GACnB,MAAM,UAAU,KAAK;GACrB,MAAM,UAAU,KAAK;GAErB,MAAM,OADmB,KAAK,iBACA,iBAAiB;AAC/C,OAAI,CAAC,KACH,QAAO;AAGT,OAAI,CAAC,KAAK,QAAQ,OAAO,SACvB,QAAO;AAET,QAAK,WAAW,WAAY;AAC1B,kBAAc,OAAO,SAAS,WAC5B,KAAK,QAAQ,OAAO,SAAS;AAC/B,WAAO;KACL,QAAQ,cAAc,OAAO,SAAS;KACtC,iBAAiB;KAClB;;AAEH,UAAO;;EAET,iBAAiB,eAAgB,MAAW;AAC1C,UAAO;;EAEV"}
@@ -16,6 +16,7 @@ function wrapCallableForChunkTracking(fn, id) {
16
16
  }
17
17
  });
18
18
  }
19
+ const DEFAULT_SCRIPT_TIMEOUT = 8e3;
19
20
  function runtimePlugin_default() {
20
21
  return {
21
22
  name: "next-internal-plugin",
@@ -29,7 +30,7 @@ function runtimePlugin_default() {
29
30
  delete attrs?.["crossorigin"];
30
31
  return {
31
32
  script,
32
- timeout: 8e3
33
+ timeout: typeof FEDERATION_NEXTJS_SCRIPT_TIMEOUT === "number" && Number.isFinite(FEDERATION_NEXTJS_SCRIPT_TIMEOUT) && FEDERATION_NEXTJS_SCRIPT_TIMEOUT > 0 ? FEDERATION_NEXTJS_SCRIPT_TIMEOUT : DEFAULT_SCRIPT_TIMEOUT
33
34
  };
34
35
  }
35
36
  },
@@ -1 +1 @@
1
- {"version":3,"file":"runtimePlugin.mjs","names":[],"sources":["../../../../src/plugins/container/runtimePlugin.ts"],"sourcesContent":["import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';\nimport { matchRemoteWithNameAndExpose } from '@module-federation/runtime-core';\n\nfunction wrapCallableForChunkTracking<T extends (...args: any[]) => any>(\n fn: T,\n id: string,\n): T {\n return new Proxy(fn, {\n apply(_target, thisArg, args) {\n globalThis.usedChunks.add(id);\n return Reflect.apply(fn, thisArg, args);\n },\n construct(_target, args, newTarget) {\n globalThis.usedChunks.add(id);\n return Reflect.construct(fn, args, newTarget);\n },\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'next-internal-plugin',\n createScript: function (args: {\n url: string;\n attrs?: Record<string, any>;\n }) {\n const url = args.url;\n const attrs = args.attrs;\n if (typeof window !== 'undefined') {\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n delete attrs?.['crossorigin'];\n\n return { script: script, timeout: 8000 };\n }\n return undefined;\n },\n errorLoadRemote: function (args: {\n id: string;\n error: any;\n from: string;\n origin: any;\n }) {\n const id = args.id;\n const error = args.error;\n const from = args.from;\n //@ts-ignore\n globalThis.moduleGraphDirty = true;\n console.error(id, 'offline');\n const pg = function () {\n console.error(id, 'offline', error);\n return null;\n };\n\n (pg as any).getInitialProps = function (ctx: any) {\n return {};\n };\n let mod;\n if (from === 'build') {\n mod = function () {\n return {\n __esModule: true,\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n };\n } else {\n mod = {\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n }\n\n return mod;\n },\n beforeInit: function (args) {\n if (!globalThis.usedChunks) globalThis.usedChunks = new Set();\n if (\n typeof __webpack_runtime_id__ === 'string' &&\n !__webpack_runtime_id__.startsWith('webpack')\n ) {\n return args;\n }\n\n const moduleCache = args.origin.moduleCache;\n const name = args.origin.name;\n let gs;\n try {\n gs = new Function('return globalThis')();\n } catch (e) {\n gs = globalThis; // fallback for browsers without 'unsafe-eval' CSP policy enabled\n }\n //@ts-ignore\n const attachedRemote = gs[name];\n if (attachedRemote) {\n moduleCache.set(name, attachedRemote);\n }\n\n return args;\n },\n init: function (args: any) {\n return args;\n },\n beforeRequest: function (args: any) {\n const options = args.options;\n const id = args.id;\n const match = matchRemoteWithNameAndExpose(options.remotes, id);\n if (!match) return args;\n const remote = match.remote;\n if (\n !('entry' in remote) ||\n !remote.entry ||\n /[?&]t=/.test(remote.entry)\n ) {\n return args;\n }\n remote.entry =\n remote.entry +\n (remote.entry.includes('?') ? '&' : '?') +\n 't=' +\n Date.now();\n return args;\n },\n afterResolve: function (args: any) {\n return args;\n },\n onLoad: async function (args: any) {\n const exposeModuleFactory = args.exposeModuleFactory;\n const exposeModule = args.exposeModule;\n const id = args.id;\n const moduleOrFactory = exposeModuleFactory || exposeModule;\n if (!moduleOrFactory) return args;\n\n if (typeof window === 'undefined') {\n let exposedModuleExports: any;\n try {\n exposedModuleExports = moduleOrFactory();\n } catch (e) {\n exposedModuleExports = moduleOrFactory;\n }\n\n exposedModuleExports = await exposedModuleExports;\n\n const handler: ProxyHandler<any> = {\n get: function (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver);\n if (typeof value === 'function') {\n return wrapCallableForChunkTracking(value, id);\n }\n return value;\n },\n };\n\n if (typeof exposedModuleExports === 'function') {\n exposedModuleExports = wrapCallableForChunkTracking(\n exposedModuleExports,\n id,\n );\n return function () {\n return exposedModuleExports;\n };\n }\n\n exposedModuleExports = new Proxy(exposedModuleExports, handler);\n\n if (exposeModuleFactory) {\n const wrappedExports = exposedModuleExports;\n return function () {\n return wrappedExports;\n };\n }\n\n return exposedModuleExports;\n }\n\n return args;\n },\n loadRemoteSnapshot(args) {\n const { from, remoteSnapshot, manifestUrl, manifestJson, options } = args;\n\n // ensure snapshot is loaded from manifest\n if (\n from !== 'manifest' ||\n !manifestUrl ||\n !manifestJson ||\n !('publicPath' in remoteSnapshot)\n ) {\n return args;\n }\n\n // re-assign publicPath based on remoteEntry location if in browser nextjs remote\n const { publicPath } = remoteSnapshot;\n if (options.inBrowser && publicPath.includes('/_next/')) {\n remoteSnapshot.publicPath = publicPath.substring(\n 0,\n publicPath.lastIndexOf('/_next/') + 7,\n );\n } else {\n const serverPublicPath = manifestUrl.substring(\n 0,\n manifestUrl.indexOf('mf-manifest.json'),\n );\n remoteSnapshot.publicPath = serverPublicPath;\n }\n\n if ('publicPath' in manifestJson.metaData) {\n manifestJson.metaData.publicPath = remoteSnapshot.publicPath;\n }\n\n return args;\n },\n resolveShare: function (args: any) {\n if (\n args.pkgName !== 'react' &&\n args.pkgName !== 'react-dom' &&\n !args.pkgName.startsWith('next/')\n ) {\n return args;\n }\n const shareScopeMap = args.shareScopeMap;\n const scope = args.scope;\n const pkgName = args.pkgName;\n const version = args.version;\n const GlobalFederation = args.GlobalFederation;\n const host = GlobalFederation['__INSTANCES__'][0];\n if (!host) {\n return args;\n }\n\n if (!host.options.shared[pkgName]) {\n return args;\n }\n args.resolver = function () {\n shareScopeMap[scope][pkgName][version] =\n host.options.shared[pkgName][0];\n return {\n shared: shareScopeMap[scope][pkgName][version],\n useTreesShaking: false,\n };\n };\n return args;\n },\n beforeLoadShare: async function (args: any) {\n return args;\n },\n };\n}\n"],"mappings":";;;AAGA,SAAS,6BACP,IACA,IACG;AACH,QAAO,IAAI,MAAM,IAAI;EACnB,MAAM,SAAS,SAAS,MAAM;AAC5B,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,MAAM,IAAI,SAAS,KAAK;;EAEzC,UAAU,SAAS,MAAM,WAAW;AAClC,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,UAAU,IAAI,MAAM,UAAU;;EAE/C,IAAI,QAAQ,MAAM,UAAU;AAC1B,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;;EAE7C,CAAC;;AAGJ,iCAA0D;AACxD,QAAO;EACL,MAAM;EACN,cAAc,SAAU,MAGrB;GACD,MAAM,MAAM,KAAK;GACjB,M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a,WAAW,UACrC,GACA,WAAW,YAAY,UAAU,GAAG,EACrC;OAMD,gBAAe,aAJU,YAAY,UACnC,GACA,YAAY,QAAQ,mBAAmB,CACxC;AAIH,OAAI,gBAAgB,aAAa,SAC/B,cAAa,SAAS,aAAa,eAAe;AAGpD,UAAO;;EAET,cAAc,SAAU,MAAW;AACjC,OACE,KAAK,YAAY,WACjB,KAAK,YAAY,eACjB,CAAC,KAAK,QAAQ,WAAW,QAAQ,CAEjC,QAAO;GAET,MAAM,gBAAgB,KAAK;GAC3B,MAAM,QAAQ,KAAK;GACnB,MAAM,UAAU,KAAK;GACrB,MAAM,UAAU,KAAK;GAErB,MAAM,OADmB,KAAK,iBACA,iBAAiB;AAC/C,OAAI,CAAC,KACH,QAAO;AAGT,OAAI,CAAC,KAAK,QAAQ,OAAO,SACvB,QAAO;AAET,QAAK,WAAW,WAAY;AAC1B,kBAAc,OAAO,SAAS,WAC5B,KAAK,QAAQ,OAAO,SAAS;AAC/B,WAAO;KACL,QAAQ,cAAc,OAAO,SAAS;KACtC,iBAAiB;KAClB;;AAEH,UAAO;;EAET,iBAAiB,eAAgB,MAAW;AAC1C,UAAO;;EAEV"}
1
+ {"version":3,"file":"runtimePlugin.mjs","names":[],"sources":["../../../../src/plugins/container/runtimePlugin.ts"],"sourcesContent":["import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';\nimport { matchRemoteWithNameAndExpose } from '@module-federation/runtime-core';\n\nfunction wrapCallableForChunkTracking<T extends (...args: any[]) => any>(\n fn: T,\n id: string,\n): T {\n return new Proxy(fn, {\n apply(_target, thisArg, args) {\n globalThis.usedChunks.add(id);\n return Reflect.apply(fn, thisArg, args);\n },\n construct(_target, args, newTarget) {\n globalThis.usedChunks.add(id);\n return Reflect.construct(fn, args, newTarget);\n },\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n\ndeclare const FEDERATION_NEXTJS_SCRIPT_TIMEOUT: number;\n\nconst DEFAULT_SCRIPT_TIMEOUT = 8000;\n\nexport default function (): ModuleFederationRuntimePlugin {\n return {\n name: 'next-internal-plugin',\n createScript: function (args: {\n url: string;\n attrs?: Record<string, any>;\n }) {\n const url = args.url;\n const attrs = args.attrs;\n if (typeof window !== 'undefined') {\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n delete attrs?.['crossorigin'];\n\n const timeout =\n typeof FEDERATION_NEXTJS_SCRIPT_TIMEOUT === 'number' &&\n Number.isFinite(FEDERATION_NEXTJS_SCRIPT_TIMEOUT) &&\n FEDERATION_NEXTJS_SCRIPT_TIMEOUT > 0\n ? FEDERATION_NEXTJS_SCRIPT_TIMEOUT\n : DEFAULT_SCRIPT_TIMEOUT;\n\n return { script: script, timeout };\n }\n return undefined;\n },\n errorLoadRemote: function (args: {\n id: string;\n error: any;\n from: string;\n origin: any;\n }) {\n const id = args.id;\n const error = args.error;\n const from = args.from;\n //@ts-ignore\n globalThis.moduleGraphDirty = true;\n console.error(id, 'offline');\n const pg = function () {\n console.error(id, 'offline', error);\n return null;\n };\n\n (pg as any).getInitialProps = function (ctx: any) {\n return {};\n };\n let mod;\n if (from === 'build') {\n mod = function () {\n return {\n __esModule: true,\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n };\n } else {\n mod = {\n default: pg,\n getServerSideProps: function () {\n return { props: {} };\n },\n };\n }\n\n return mod;\n },\n beforeInit: function (args) {\n if (!globalThis.usedChunks) globalThis.usedChunks = new Set();\n if (\n typeof __webpack_runtime_id__ === 'string' &&\n !__webpack_runtime_id__.startsWith('webpack')\n ) {\n return args;\n }\n\n const moduleCache = args.origin.moduleCache;\n const name = args.origin.name;\n let gs;\n try {\n gs = new Function('return globalThis')();\n } catch (e) {\n gs = globalThis; // fallback for browsers without 'unsafe-eval' CSP policy enabled\n }\n //@ts-ignore\n const attachedRemote = gs[name];\n if (attachedRemote) {\n moduleCache.set(name, attachedRemote);\n }\n\n return args;\n },\n init: function (args: any) {\n return args;\n },\n beforeRequest: function (args: any) {\n const options = args.options;\n const id = args.id;\n const match = matchRemoteWithNameAndExpose(options.remotes, id);\n if (!match) return args;\n const remote = match.remote;\n if (\n !('entry' in remote) ||\n !remote.entry ||\n /[?&]t=/.test(remote.entry)\n ) {\n return args;\n }\n remote.entry =\n remote.entry +\n (remote.entry.includes('?') ? '&' : '?') +\n 't=' +\n Date.now();\n return args;\n },\n afterResolve: function (args: any) {\n return args;\n },\n onLoad: async function (args: any) {\n const exposeModuleFactory = args.exposeModuleFactory;\n const exposeModule = args.exposeModule;\n const id = args.id;\n const moduleOrFactory = exposeModuleFactory || exposeModule;\n if (!moduleOrFactory) return args;\n\n if (typeof window === 'undefined') {\n let exposedModuleExports: any;\n try {\n exposedModuleExports = moduleOrFactory();\n } catch (e) {\n exposedModuleExports = moduleOrFactory;\n }\n\n exposedModuleExports = await exposedModuleExports;\n\n const handler: ProxyHandler<any> = {\n get: function (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver);\n if (typeof value === 'function') {\n return wrapCallableForChunkTracking(value, id);\n }\n return value;\n },\n };\n\n if (typeof exposedModuleExports === 'function') {\n exposedModuleExports = wrapCallableForChunkTracking(\n exposedModuleExports,\n id,\n );\n return function () {\n return exposedModuleExports;\n };\n }\n\n exposedModuleExports = new Proxy(exposedModuleExports, handler);\n\n if (exposeModuleFactory) {\n const wrappedExports = exposedModuleExports;\n return function () {\n return wrappedExports;\n };\n }\n\n return exposedModuleExports;\n }\n\n return args;\n },\n loadRemoteSnapshot(args) {\n const { from, remoteSnapshot, manifestUrl, manifestJson, options } = args;\n\n // ensure snapshot is loaded from manifest\n if (\n from !== 'manifest' ||\n !manifestUrl ||\n !manifestJson ||\n !('publicPath' in remoteSnapshot)\n ) {\n return args;\n }\n\n // re-assign publicPath based on remoteEntry location if in browser nextjs remote\n const { publicPath } = remoteSnapshot;\n if (options.inBrowser && publicPath.includes('/_next/')) {\n remoteSnapshot.publicPath = publicPath.substring(\n 0,\n publicPath.lastIndexOf('/_next/') + 7,\n );\n } else {\n const serverPublicPath = manifestUrl.substring(\n 0,\n manifestUrl.indexOf('mf-manifest.json'),\n );\n remoteSnapshot.publicPath = serverPublicPath;\n }\n\n if ('publicPath' in manifestJson.metaData) {\n manifestJson.metaData.publicPath = remoteSnapshot.publicPath;\n }\n\n return args;\n },\n resolveShare: function (args: any) {\n if (\n args.pkgName !== 'react' &&\n args.pkgName !== 'react-dom' &&\n !args.pkgName.startsWith('next/')\n ) {\n return args;\n }\n const shareScopeMap = args.shareScopeMap;\n const scope = args.scope;\n const pkgName = args.pkgName;\n const version = args.version;\n const GlobalFederation = args.GlobalFederation;\n const host = GlobalFederation['__INSTANCES__'][0];\n if (!host) {\n return args;\n }\n\n if (!host.options.shared[pkgName]) {\n return args;\n }\n args.resolver = function () {\n shareScopeMap[scope][pkgName][version] =\n host.options.shared[pkgName][0];\n return {\n shared: shareScopeMap[scope][pkgName][version],\n useTreesShaking: false,\n };\n };\n return args;\n },\n beforeLoadShare: async function (args: any) {\n return args;\n },\n };\n}\n"],"mappings":";;;AAGA,SAAS,6BACP,IACA,IACG;AACH,QAAO,IAAI,MAAM,IAAI;EACnB,MAAM,SAAS,SAAS,MAAM;AAC5B,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,MAAM,IAAI,SAAS,KAAK;;EAEzC,UAAU,SAAS,MAAM,WAAW;AAClC,cAAW,WAAW,IAAI,GAAG;AAC7B,UAAO,QAAQ,UAAU,IAAI,MAAM,UAAU;;EAE/C,IAAI,QAAQ,MAAM,UAAU;AAC1B,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;;EAE7C,CAAC;;AAKJ,MAAM,yBAAyB;AAE/B,iCAA0D;AACxD,QAAO;EACL,MAAM;EACN,cAAc,SAAU,MAGrB;GACD,MAAM,MAAM,KAAK;GACjB,MAAM,QAAQ,KAAK;AACnB,OAAI,OAAO,WAAW,aAAa;IACjC,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,WAAO,MAAM;AACb,WAAO,QAAQ;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D,gBAAe,aAJU,YAAY,UACnC,GACA,YAAY,QAAQ,mBAAmB,CACxC;AAIH,OAAI,gBAAgB,aAAa,SAC/B,cAAa,SAAS,aAAa,eAAe;AAGpD,UAAO;;EAET,cAAc,SAAU,MAAW;AACjC,OACE,KAAK,YAAY,WACjB,KAAK,YAAY,eACjB,CAAC,KAAK,QAAQ,WAAW,QAAQ,CAEjC,QAAO;GAET,MAAM,gBAAgB,KAAK;GAC3B,MAAM,QAAQ,KAAK;GACnB,MAAM,UAAU,KAAK;GACrB,MAAM,UAAU,KAAK;GAErB,MAAM,OADmB,KAAK,iBACA,iBAAiB;AAC/C,OAAI,CAAC,KACH,QAAO;AAGT,OAAI,CAAC,KAAK,QAAQ,OAAO,SACvB,QAAO;AAET,QAAK,WAAW,WAAY;AAC1B,kBAAc,OAAO,SAAS,WAC5B,KAAK,QAAQ,OAAO,SAAS;AAC/B,WAAO;KACL,QAAQ,cAAc,OAAO,SAAS;KACtC,iBAAiB;KAClB;;AAEH,UAAO;;EAET,iBAAiB,eAAgB,MAAW;AAC1C,UAAO;;EAEV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/nextjs-mf",
3
- "version": "8.8.76",
3
+ "version": "8.9.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/src/index.mjs",
@@ -58,12 +58,12 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "fast-glob": "^3.2.11",
61
- "@module-federation/runtime": "2.9.2",
62
- "@module-federation/enhanced": "2.9.2",
63
- "@module-federation/runtime-core": "2.9.2",
64
- "@module-federation/sdk": "2.9.2",
65
- "@module-federation/node": "2.7.52",
66
- "@module-federation/webpack-bundler-runtime": "2.9.2"
61
+ "@module-federation/runtime": "2.9.4",
62
+ "@module-federation/sdk": "2.9.4",
63
+ "@module-federation/runtime-core": "2.9.4",
64
+ "@module-federation/enhanced": "2.9.4",
65
+ "@module-federation/node": "2.7.54",
66
+ "@module-federation/webpack-bundler-runtime": "2.9.4"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/btoa": "^1.2.5",