@module-federation/nextjs-mf 8.8.58 → 8.8.59

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["setOptions","logger","CopyFederationPlugin","ModuleFederationPlugin","validateCompilerOptions","validatePluginOptions","retrieveDefaultShared","exposeNextjsPages"],"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';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js',\n );\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.js',\n );\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\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,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\n filePath: isServer ? '' : '/static/chunks',\n },\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\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,iCAKA,QAAQ,QACN,2EACD;AAEP,MAAM,wBAKA,QAAQ,QACN,2DACD;AAEP,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,aAAK,QAC3B,QAAQ,QAAQ,uCAAuC,CACxD;AAED,QAAO,QAAQ,QACb,aAAK,KACH,iBAGI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6CAAsB,SAAS;AAEnC,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,GAAG,KAAK,SAAS;IAClB;GACD,UAAU;IACR,GAAI,KAAK,SAAS,YAAY,EAAE;IAChC,UAAU,WAAW,KAAK;IAC3B;GAED,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"],"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';\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\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,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\n filePath: isServer ? '' : '/static/chunks',\n },\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":";;;;;;;;;;;;;;;;;;;;;;;AAkCA,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,iB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,OAAO,MAAM,KAAK;GACjC,eAAe;GACf,OAAO;GACR,CAAC;AAEF,wCAAe,UAAU,KAAK,UAAU,KAAK,cAAc;AAC3D,MAAI,KAAK,cAAc,MACrB,UAAS,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;AAEnC,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,GAAG,KAAK,SAAS;IAClB;GACD,UAAU;IACR,GAAI,KAAK,SAAS,YAAY,EAAE;IAChC,UAAU,WAAW,KAAK;IAC3B;GAED,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
@@ -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';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js',\n );\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.js',\n );\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\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,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\n filePath: isServer ? '' : '/static/chunks',\n },\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\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,2CAEQ,QACN,4EACD;AAKP,MAAM,kCAEQ,QACN,4DACD;AAKP,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,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,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAG,KAAK,SAAS;IAClB;GACD,UAAU;IACR,GAAI,KAAK,SAAS,YAAY,EAAE;IAChC,UAAU,WAAW,KAAK;IAC3B;GAED,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.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';\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\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,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\n filePath: isServer ? '' : '/static/chunks',\n },\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":";;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,2CAEQ,QAAQ,4EAA4E;AAGlG,MAAM,kCAEQ,QAAQ,4DAA4D;AAGlF,MAAM,qCAA6C;C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;;CAInE,AAAQ,iCACN,UACA,UACsD;EACtD,MAAM,gBAAgB,KAAK,cAAc,2BACrC,EAAE,GACF,sBAAsB,SAAS;AAEnC,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,GAAG,KAAK,SAAS;IAClB;GACD,UAAU;IACR,GAAI,KAAK,SAAS,YAAY,EAAE;IAChC,UAAU,WAAW,KAAK;IAC3B;GAED,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
@@ -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(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js',\n );\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js',\n );\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,kCAKA,QAAQ,QACN,kEACD;AAEP,MAAM,gCAKA,QAAQ,QACN,gEACD;;;;;;AAMP,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,YA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_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.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginEx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ACT,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(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js',\n );\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js',\n );\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,QACN,mEACD;AAKP,MAAM,0CAEQ,QACN,iEACD;;;;;;AASP,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;AAC9C,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;GAC7C,MAAM,YAAY;AAElB,OACE,QAAQ,wBACR,UAAU,WAAW,oBAAoB,CAEzC,kBAAiB,WAAW,EAC1B,QAAQ,2BAA2B,EACpC,CAAC;AAGJ,OAAI,QAAQ,sBAAsB,UAAU,WAAW,aAAa,CAClE,kBAAiB,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
+ {"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;AAC9C,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;GAC7C,MAAM,YAAY;AAElB,OACE,QAAQ,wBACR,UAAU,WAAW,oBAAoB,CAEzC,kBAAiB,WAAW,EAC1B,QAAQ,2BAA2B,EACpC,CAAC;AAGJ,OAAI,QAAQ,sBAAsB,UAAU,WAAW,aAAa,CAClE,kBAAiB,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/nextjs-mf",
3
- "version": "8.8.58",
3
+ "version": "8.8.59",
4
4
  "license": "MIT",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/src/index.mjs",
@@ -58,11 +58,11 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "fast-glob": "^3.2.11",
61
- "@module-federation/runtime": "2.2.0",
62
- "@module-federation/enhanced": "2.2.0",
63
- "@module-federation/node": "2.7.34",
64
- "@module-federation/webpack-bundler-runtime": "2.2.0",
65
- "@module-federation/sdk": "2.2.0"
61
+ "@module-federation/runtime": "2.2.1",
62
+ "@module-federation/sdk": "2.2.1",
63
+ "@module-federation/webpack-bundler-runtime": "2.2.1",
64
+ "@module-federation/enhanced": "2.2.1",
65
+ "@module-federation/node": "2.7.35"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/btoa": "^1.2.5",