@module-federation/enhanced 2.9.1 → 2.9.2
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.
- package/dist/CHANGELOG.md +21 -0
- package/dist/src/lib/container/ContainerEntryModule.js +12 -6
- package/dist/src/lib/container/ContainerEntryModule.js.map +1 -1
- package/dist/src/lib/container/ModuleFederationPlugin.js +2 -2
- package/dist/src/lib/sharing/ConsumeSharedPlugin.js +2 -2
- package/dist/src/lib/sharing/ProvideSharedPlugin.js +2 -2
- package/dist/src/lib/sharing/SharePlugin.js +2 -2
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.js +2 -5
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.js.map +1 -1
- package/package.json +12 -12
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @module-federation/enhanced
|
|
2
2
|
|
|
3
|
+
## 2.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 412f62e: Restore BUILD-001 logging and diagnostic context when an expose cannot resolve. Webpack still reports the build error, and `container.get()` rejects the missing expose.
|
|
8
|
+
- c130946: An exposed module that fails to resolve no longer exits the Node process during code generation. The build finishes with webpack's "Module not found" error in `compilation.errors`, and the container's `get()` for that expose throws `MODULE_NOT_FOUND`, as in upstream webpack. Watch mode and dev servers keep running.
|
|
9
|
+
- 923b55d: Fix the tree-shaking shared entry build finishing its `make` phase before the shared entry module tree was built. Large shared packages with a filesystem cache could crash in `createModuleAssets` or emit a fallback bundle with missing modules, and an entry error was thrown instead of reported.
|
|
10
|
+
- Updated dependencies [000f3fa]
|
|
11
|
+
- Updated dependencies [7f0ac8b]
|
|
12
|
+
- @module-federation/dts-plugin@2.9.2
|
|
13
|
+
- @module-federation/cli@2.9.2
|
|
14
|
+
- @module-federation/manifest@2.9.2
|
|
15
|
+
- @module-federation/rspack@2.9.2
|
|
16
|
+
- @module-federation/runtime-tools@2.9.2
|
|
17
|
+
- @module-federation/webpack-bundler-runtime@2.9.2
|
|
18
|
+
- @module-federation/inject-external-runtime-core-plugin@2.9.2
|
|
19
|
+
- @module-federation/sdk@2.9.2
|
|
20
|
+
- @module-federation/managers@2.9.2
|
|
21
|
+
- @module-federation/bridge-react-webpack-plugin@2.9.2
|
|
22
|
+
- @module-federation/error-codes@2.9.2
|
|
23
|
+
|
|
3
24
|
## 2.9.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -125,18 +125,24 @@ var ContainerEntryModule = class ContainerEntryModule extends Module {
|
|
|
125
125
|
const getters = [];
|
|
126
126
|
for (const block of this.blocks) {
|
|
127
127
|
const { dependencies } = block;
|
|
128
|
-
const modules =
|
|
128
|
+
const modules = [];
|
|
129
|
+
let missingModules;
|
|
130
|
+
let requests = "";
|
|
131
|
+
for (const dependency of dependencies) {
|
|
129
132
|
const dep = dependency;
|
|
130
|
-
|
|
133
|
+
const exposedModule = {
|
|
131
134
|
name: dep.exposedName,
|
|
132
135
|
module: moduleGraph.getModule(dep),
|
|
133
136
|
request: dep.userRequest
|
|
134
137
|
};
|
|
135
|
-
|
|
138
|
+
modules.push(exposedModule);
|
|
139
|
+
if (!exposedModule.module) (missingModules ??= []).push(exposedModule);
|
|
140
|
+
requests += `${modules.length > 1 ? ", " : ""}${dep.userRequest}`;
|
|
141
|
+
}
|
|
136
142
|
let str;
|
|
137
|
-
if (
|
|
143
|
+
if (missingModules) {
|
|
138
144
|
(0, _module_federation_error_codes_node.logAndReport)(_module_federation_error_codes.BUILD_001, _module_federation_error_codes.buildDescMap, {
|
|
139
|
-
exposeModules:
|
|
145
|
+
exposeModules: missingModules,
|
|
140
146
|
FEDERATION_WEBPACK_PATH: process.env["FEDERATION_WEBPACK_PATH"]
|
|
141
147
|
}, _module_federation_sdk.infrastructureLogger.error.bind(_module_federation_sdk.infrastructureLogger), void 0, {
|
|
142
148
|
bundler: { name: "webpack" },
|
|
@@ -145,7 +151,7 @@ var ContainerEntryModule = class ContainerEntryModule extends Module {
|
|
|
145
151
|
exposes: Object.fromEntries(this._exposes.map(([key, opts]) => [key, opts.import[opts.import.length - 1]]))
|
|
146
152
|
}
|
|
147
153
|
});
|
|
148
|
-
|
|
154
|
+
str = runtimeTemplate.throwMissingModuleErrorBlock({ request: requests });
|
|
149
155
|
} else str = `return ${runtimeTemplate.blockPromise({
|
|
150
156
|
block,
|
|
151
157
|
message: "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerEntryModule.js","names":["JAVASCRIPT_MODULE_TYPE_DYNAMIC","ContainerExposedDependency","BUILD_001","buildDescMap","logger","getFederationGlobalScope"],"sources":["../../../../src/lib/container/ContainerEntryModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { infrastructureLogger as logger } from '@module-federation/sdk';\nimport { buildDescMap, BUILD_001 } from '@module-federation/error-codes';\nimport { logAndReport } from '@module-federation/error-codes/node';\nimport type { Compilation, Dependency } from 'webpack';\nimport type {\n InputFileSystem,\n LibIdentOptions,\n NeedBuildContext,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n RequestShortener,\n ResolverWithOptions,\n WebpackOptions,\n} from 'webpack/lib/Module';\nimport type WebpackError from 'webpack/lib/WebpackError';\nimport { JAVASCRIPT_MODULE_TYPE_DYNAMIC } from '../Constants';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport { getFederationGlobalScope } from './runtime/utils';\n\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\nconst {\n sources: webpackSources,\n AsyncDependenciesBlock,\n Template,\n Module,\n RuntimeGlobals,\n} = require(normalizeWebpackPath('webpack')) as typeof import('webpack');\nconst StaticExportsDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/StaticExportsDependency'),\n) as typeof import('webpack/lib/dependencies/StaticExportsDependency');\nconst EntryDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/EntryDependency'),\n) as typeof import('webpack/lib/dependencies/EntryDependency');\n\nconst SOURCE_TYPES = new Set(['javascript']);\n\nexport type ExposeOptions = {\n /**\n * requests to exposed modules (last one is exported)\n */\n import: string[];\n /**\n * custom chunk name for the exposed module\n */\n name: string;\n};\n\nclass ContainerEntryModule extends Module {\n private _name: string;\n private _exposes: [string, ExposeOptions][];\n private _shareScope: string | string[];\n private _injectRuntimeEntry: string;\n\n /**\n * @param {string} name container entry name\n * @param {[string, ExposeOptions][]} exposes list of exposed modules\n * @param {string|string[]} shareScope name of the share scope\n * @param {string} injectRuntimeEntry the path of injectRuntime file.\n */\n constructor(\n name: string,\n exposes: [string, ExposeOptions][],\n shareScope: string | string[],\n injectRuntimeEntry: string,\n ) {\n super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);\n this._name = name;\n this._exposes = exposes;\n this._shareScope = shareScope;\n this._injectRuntimeEntry = injectRuntimeEntry;\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {ContainerEntryModule} deserialized container entry module\n */\n static deserialize(context: ObjectDeserializerContext): ContainerEntryModule {\n const { read } = context;\n const obj = new ContainerEntryModule(read(), read(), read(), read());\n obj.deserialize(context);\n return obj;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return SOURCE_TYPES;\n }\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n const scopeStr = Array.isArray(this._shareScope)\n ? this._shareScope.join('|')\n : this._shareScope;\n\n return `container entry (${scopeStr}) ${JSON.stringify(\n this._exposes,\n )} ${this._injectRuntimeEntry}`;\n }\n /**\n * @param {RequestShortener} requestShortener the request shortener\n * @returns {string} a user readable identifier of the module\n */\n override readableIdentifier(requestShortener: RequestShortener): string {\n return 'container entry';\n }\n /**\n * @param {LibIdentOptions} options options\n * @returns {string | null} an identifier for library inclusion\n */\n override libIdent(options: LibIdentOptions): string | null {\n return `${this.layer ? `(${this.layer})/` : ''}webpack/container/entry/${\n this._name\n }`;\n }\n /**\n * @param {NeedBuildContext} context context info\n * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild\n * @returns {void}\n */\n override needBuild(\n context: NeedBuildContext,\n callback: (\n arg0: (WebpackError | null) | undefined,\n arg1: boolean | undefined,\n ) => void,\n ): void {\n callback(null, !this.buildMeta);\n }\n /**\n * @param {WebpackOptions} options webpack options\n * @param {Compilation} compilation the compilation\n * @param {ResolverWithOptions} resolver the resolver\n * @param {InputFileSystem} fs the file system\n * @param {function(WebpackError): void} callback callback function\n * @returns {void}\n */\n override build(\n options: WebpackOptions,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (err?: WebpackError) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n topLevelDeclarations: new Set(['moduleMap', 'get', 'init']),\n };\n this.buildMeta.exportsType = 'namespace';\n this.clearDependenciesAndBlocks();\n\n for (const [name, options] of this._exposes) {\n const block = new AsyncDependenciesBlock(\n {\n name: options.name,\n },\n { name },\n options.import[options.import.length - 1],\n );\n let idx = 0;\n for (const request of options.import) {\n const dep = new ContainerExposedDependency(name, request);\n dep.loc = {\n name,\n index: idx++,\n };\n block.addDependency(dep);\n }\n this.addBlock(block);\n }\n this.addDependency(\n new StaticExportsDependency(\n ['get', 'init'],\n false,\n ) as unknown as Dependency,\n );\n\n this.addDependency(new EntryDependency(this._injectRuntimeEntry));\n\n callback();\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n override codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }: any) {\n const sources = new Map();\n const runtimeRequirements = new Set([\n RuntimeGlobals.definePropertyGetters,\n RuntimeGlobals.hasOwnProperty,\n RuntimeGlobals.exports,\n ]);\n const getters = [];\n for (const block of this.blocks) {\n const { dependencies } = block;\n\n const modules = dependencies.map((dependency: Dependency) => {\n const dep = dependency as unknown as ContainerExposedDependency;\n return {\n name: dep.exposedName,\n module: moduleGraph.getModule(dep),\n request: dep.userRequest,\n };\n });\n\n let str;\n if (modules.some((m) => !m.module)) {\n logAndReport(\n BUILD_001,\n buildDescMap,\n {\n exposeModules: modules.filter((m) => !m.module),\n FEDERATION_WEBPACK_PATH: process.env['FEDERATION_WEBPACK_PATH'],\n },\n logger.error.bind(logger),\n undefined,\n {\n bundler: { name: 'webpack' },\n mfConfig: {\n name: this._name,\n exposes: Object.fromEntries(\n this._exposes.map(([key, opts]) => [\n key,\n opts.import[opts.import.length - 1],\n ]),\n ),\n },\n },\n );\n process.exit(1);\n } else {\n str = `return ${runtimeTemplate.blockPromise({\n block,\n message: '',\n chunkGraph,\n runtimeRequirements,\n })}.then(${runtimeTemplate.returningFunction(\n runtimeTemplate.returningFunction(\n `(${modules\n .map(({ module, request }) =>\n runtimeTemplate.moduleRaw({\n module,\n chunkGraph,\n request,\n weak: false,\n runtimeRequirements,\n }),\n )\n .join(', ')})`,\n ),\n )});`;\n }\n\n getters.push(\n `${JSON.stringify(modules[0].name)}: ${runtimeTemplate.basicFunction(\n '',\n str,\n )}`,\n );\n }\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n const source = Template.asString([\n `var moduleMap = {`,\n Template.indent(getters.join(',\\n')),\n '};',\n `var get = ${runtimeTemplate.basicFunction('module, getScope', [\n `${RuntimeGlobals.currentRemoteGetScope} = getScope;`,\n // reusing the getScope variable to avoid creating a new var (and module is also used later)\n 'getScope = (',\n Template.indent([\n `${RuntimeGlobals.hasOwnProperty}(moduleMap, module)`,\n Template.indent([\n '? moduleMap[module]()',\n `: Promise.resolve().then(${runtimeTemplate.basicFunction(\n '',\n \"throw new Error('Module \\\"' + module + '\\\" does not exist in container.');\",\n )})`,\n ]),\n ]),\n ');',\n `${RuntimeGlobals.currentRemoteGetScope} = undefined;`,\n 'return getScope;',\n ])};`,\n `var init = ${runtimeTemplate.basicFunction(\n 'shareScope, initScope, remoteEntryInitOptions',\n [\n `return ${federationGlobal}.bundlerRuntime.initContainerEntry({${Template.indent(\n [\n `webpackRequire: ${RuntimeGlobals.require},`,\n `shareScope: shareScope,`,\n `initScope: initScope,`,\n `remoteEntryInitOptions: remoteEntryInitOptions,`,\n `shareScopeKey: ${JSON.stringify(this._shareScope)}`,\n ],\n )}`,\n '})',\n ],\n )};`,\n '// This exports getters to disallow modifications',\n `${RuntimeGlobals.definePropertyGetters}(exports, {`,\n Template.indent([\n `get: ${runtimeTemplate.returningFunction('get')},`,\n `init: ${runtimeTemplate.returningFunction('init')}`,\n ]),\n '});',\n ]);\n\n sources.set(\n 'javascript',\n this.useSourceMap || this.useSimpleSourceMap\n ? new webpackSources.OriginalSource(source, 'webpack/container-entry')\n : new webpackSources.RawSource(source),\n );\n\n return {\n sources,\n runtimeRequirements,\n };\n }\n\n /**\n * @param {string=} type the source type for which the size should be estimated\n * @returns {number} the estimated size of the module (must be non-zero)\n */\n override size(type?: string): number {\n return 42;\n }\n /**\n * @param {ObjectSerializerContext} context context\n */\n override serialize(context: ObjectSerializerContext): void {\n const { write } = context;\n write(this._name);\n write(this._exposes);\n write(this._shareScope);\n write(this._injectRuntimeEntry);\n super.serialize(context);\n }\n}\n\nmakeSerializable(\n ContainerEntryModule,\n 'enhanced/lib/container/ContainerEntryModule',\n);\n\nexport default ContainerEntryModule;\n"],"mappings":";;;;;;;;;;;;;AA0BA,MAAM,mBAAmB,gFACF,oCAAoC,CAC1D;AACD,MAAM,EACJ,SAAS,gBACT,wBACA,UACA,QACA,mBACE,gFAA6B,UAAU,CAAC;AAC5C,MAAM,0BAA0B,gFACT,mDAAmD,CACzE;AACD,MAAM,kBAAkB,gFACD,2CAA2C,CACjE;AAED,MA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B,QAAM,KAAK,SAAS;AACpB,QAAM,KAAK,YAAY;AACvB,QAAM,KAAK,oBAAoB;AAC/B,QAAM,UAAU,QAAQ;;;AAI5B,iBACE,sBACA,8CACD"}
|
|
1
|
+
{"version":3,"file":"ContainerEntryModule.js","names":["JAVASCRIPT_MODULE_TYPE_DYNAMIC","ContainerExposedDependency","BUILD_001","buildDescMap","logger","getFederationGlobalScope"],"sources":["../../../../src/lib/container/ContainerEntryModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { infrastructureLogger as logger } from '@module-federation/sdk';\nimport { buildDescMap, BUILD_001 } from '@module-federation/error-codes';\nimport { logAndReport } from '@module-federation/error-codes/node';\nimport type { Compilation, Dependency, Module as WebpackModule } from 'webpack';\nimport type {\n InputFileSystem,\n LibIdentOptions,\n NeedBuildContext,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n RequestShortener,\n ResolverWithOptions,\n WebpackOptions,\n} from 'webpack/lib/Module';\nimport type WebpackError from 'webpack/lib/WebpackError';\nimport { JAVASCRIPT_MODULE_TYPE_DYNAMIC } from '../Constants';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport { getFederationGlobalScope } from './runtime/utils';\n\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\nconst {\n sources: webpackSources,\n AsyncDependenciesBlock,\n Template,\n Module,\n RuntimeGlobals,\n} = require(normalizeWebpackPath('webpack')) as typeof import('webpack');\nconst StaticExportsDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/StaticExportsDependency'),\n) as typeof import('webpack/lib/dependencies/StaticExportsDependency');\nconst EntryDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/EntryDependency'),\n) as typeof import('webpack/lib/dependencies/EntryDependency');\n\nconst SOURCE_TYPES = new Set(['javascript']);\n\nexport type ExposeOptions = {\n /**\n * requests to exposed modules (last one is exported)\n */\n import: string[];\n /**\n * custom chunk name for the exposed module\n */\n name: string;\n};\n\nclass ContainerEntryModule extends Module {\n private _name: string;\n private _exposes: [string, ExposeOptions][];\n private _shareScope: string | string[];\n private _injectRuntimeEntry: string;\n\n /**\n * @param {string} name container entry name\n * @param {[string, ExposeOptions][]} exposes list of exposed modules\n * @param {string|string[]} shareScope name of the share scope\n * @param {string} injectRuntimeEntry the path of injectRuntime file.\n */\n constructor(\n name: string,\n exposes: [string, ExposeOptions][],\n shareScope: string | string[],\n injectRuntimeEntry: string,\n ) {\n super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);\n this._name = name;\n this._exposes = exposes;\n this._shareScope = shareScope;\n this._injectRuntimeEntry = injectRuntimeEntry;\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {ContainerEntryModule} deserialized container entry module\n */\n static deserialize(context: ObjectDeserializerContext): ContainerEntryModule {\n const { read } = context;\n const obj = new ContainerEntryModule(read(), read(), read(), read());\n obj.deserialize(context);\n return obj;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return SOURCE_TYPES;\n }\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n const scopeStr = Array.isArray(this._shareScope)\n ? this._shareScope.join('|')\n : this._shareScope;\n\n return `container entry (${scopeStr}) ${JSON.stringify(\n this._exposes,\n )} ${this._injectRuntimeEntry}`;\n }\n /**\n * @param {RequestShortener} requestShortener the request shortener\n * @returns {string} a user readable identifier of the module\n */\n override readableIdentifier(requestShortener: RequestShortener): string {\n return 'container entry';\n }\n /**\n * @param {LibIdentOptions} options options\n * @returns {string | null} an identifier for library inclusion\n */\n override libIdent(options: LibIdentOptions): string | null {\n return `${this.layer ? `(${this.layer})/` : ''}webpack/container/entry/${\n this._name\n }`;\n }\n /**\n * @param {NeedBuildContext} context context info\n * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild\n * @returns {void}\n */\n override needBuild(\n context: NeedBuildContext,\n callback: (\n arg0: (WebpackError | null) | undefined,\n arg1: boolean | undefined,\n ) => void,\n ): void {\n callback(null, !this.buildMeta);\n }\n /**\n * @param {WebpackOptions} options webpack options\n * @param {Compilation} compilation the compilation\n * @param {ResolverWithOptions} resolver the resolver\n * @param {InputFileSystem} fs the file system\n * @param {function(WebpackError): void} callback callback function\n * @returns {void}\n */\n override build(\n options: WebpackOptions,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (err?: WebpackError) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n topLevelDeclarations: new Set(['moduleMap', 'get', 'init']),\n };\n this.buildMeta.exportsType = 'namespace';\n this.clearDependenciesAndBlocks();\n\n for (const [name, options] of this._exposes) {\n const block = new AsyncDependenciesBlock(\n {\n name: options.name,\n },\n { name },\n options.import[options.import.length - 1],\n );\n let idx = 0;\n for (const request of options.import) {\n const dep = new ContainerExposedDependency(name, request);\n dep.loc = {\n name,\n index: idx++,\n };\n block.addDependency(dep);\n }\n this.addBlock(block);\n }\n this.addDependency(\n new StaticExportsDependency(\n ['get', 'init'],\n false,\n ) as unknown as Dependency,\n );\n\n this.addDependency(new EntryDependency(this._injectRuntimeEntry));\n\n callback();\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n override codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }: any) {\n const sources = new Map();\n const runtimeRequirements = new Set([\n RuntimeGlobals.definePropertyGetters,\n RuntimeGlobals.hasOwnProperty,\n RuntimeGlobals.exports,\n ]);\n const getters = [];\n for (const block of this.blocks) {\n const { dependencies } = block;\n\n const modules: {\n name: string;\n module: WebpackModule | null;\n request: string;\n }[] = [];\n let missingModules: typeof modules | undefined;\n let requests = '';\n for (const dependency of dependencies) {\n const dep = dependency as unknown as ContainerExposedDependency;\n const exposedModule = {\n name: dep.exposedName,\n module: moduleGraph.getModule(dep),\n request: dep.userRequest,\n };\n modules.push(exposedModule);\n if (!exposedModule.module) {\n (missingModules ??= []).push(exposedModule);\n }\n requests += `${modules.length > 1 ? ', ' : ''}${dep.userRequest}`;\n }\n\n let str;\n if (missingModules) {\n logAndReport(\n BUILD_001,\n buildDescMap,\n {\n exposeModules: missingModules,\n FEDERATION_WEBPACK_PATH: process.env['FEDERATION_WEBPACK_PATH'],\n },\n logger.error.bind(logger),\n undefined,\n {\n bundler: { name: 'webpack' },\n mfConfig: {\n name: this._name,\n exposes: Object.fromEntries(\n this._exposes.map(([key, opts]) => [\n key,\n opts.import[opts.import.length - 1],\n ]),\n ),\n },\n },\n );\n str = runtimeTemplate.throwMissingModuleErrorBlock({\n request: requests,\n });\n } else {\n str = `return ${runtimeTemplate.blockPromise({\n block,\n message: '',\n chunkGraph,\n runtimeRequirements,\n })}.then(${runtimeTemplate.returningFunction(\n runtimeTemplate.returningFunction(\n `(${modules\n .map(({ module, request }) =>\n runtimeTemplate.moduleRaw({\n module,\n chunkGraph,\n request,\n weak: false,\n runtimeRequirements,\n }),\n )\n .join(', ')})`,\n ),\n )});`;\n }\n\n getters.push(\n `${JSON.stringify(modules[0].name)}: ${runtimeTemplate.basicFunction(\n '',\n str,\n )}`,\n );\n }\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n const source = Template.asString([\n `var moduleMap = {`,\n Template.indent(getters.join(',\\n')),\n '};',\n `var get = ${runtimeTemplate.basicFunction('module, getScope', [\n `${RuntimeGlobals.currentRemoteGetScope} = getScope;`,\n // reusing the getScope variable to avoid creating a new var (and module is also used later)\n 'getScope = (',\n Template.indent([\n `${RuntimeGlobals.hasOwnProperty}(moduleMap, module)`,\n Template.indent([\n '? moduleMap[module]()',\n `: Promise.resolve().then(${runtimeTemplate.basicFunction(\n '',\n \"throw new Error('Module \\\"' + module + '\\\" does not exist in container.');\",\n )})`,\n ]),\n ]),\n ');',\n `${RuntimeGlobals.currentRemoteGetScope} = undefined;`,\n 'return getScope;',\n ])};`,\n `var init = ${runtimeTemplate.basicFunction(\n 'shareScope, initScope, remoteEntryInitOptions',\n [\n `return ${federationGlobal}.bundlerRuntime.initContainerEntry({${Template.indent(\n [\n `webpackRequire: ${RuntimeGlobals.require},`,\n `shareScope: shareScope,`,\n `initScope: initScope,`,\n `remoteEntryInitOptions: remoteEntryInitOptions,`,\n `shareScopeKey: ${JSON.stringify(this._shareScope)}`,\n ],\n )}`,\n '})',\n ],\n )};`,\n '// This exports getters to disallow modifications',\n `${RuntimeGlobals.definePropertyGetters}(exports, {`,\n Template.indent([\n `get: ${runtimeTemplate.returningFunction('get')},`,\n `init: ${runtimeTemplate.returningFunction('init')}`,\n ]),\n '});',\n ]);\n\n sources.set(\n 'javascript',\n this.useSourceMap || this.useSimpleSourceMap\n ? new webpackSources.OriginalSource(source, 'webpack/container-entry')\n : new webpackSources.RawSource(source),\n );\n\n return {\n sources,\n runtimeRequirements,\n };\n }\n\n /**\n * @param {string=} type the source type for which the size should be estimated\n * @returns {number} the estimated size of the module (must be non-zero)\n */\n override size(type?: string): number {\n return 42;\n }\n /**\n * @param {ObjectSerializerContext} context context\n */\n override serialize(context: ObjectSerializerContext): void {\n const { write } = context;\n write(this._name);\n write(this._exposes);\n write(this._shareScope);\n write(this._injectRuntimeEntry);\n super.serialize(context);\n }\n}\n\nmakeSerializable(\n ContainerEntryModule,\n 'enhanced/lib/container/ContainerEntryModule',\n);\n\nexport default ContainerEntryModule;\n"],"mappings":";;;;;;;;;;;;;AA0BA,MAAM,mBAAmB,gFACF,oCAAoC,CAC1D;AACD,MAAM,EACJ,SAAS,gBACT,wBACA,UACA,QACA,mBACE,gFAA6B,UAAU,CAAC;AAC5C,MAAM,0BAA0B,gFACT,mDAAmD,CACzE;AACD,MAAM,kBAAkB,gFACD,2CAA2C,CACjE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AAO,CACzC;AAED,SAAO;GACL;GACA;GACD;;;;;;CAOH,AAAS,KAAK,MAAuB;AACnC,SAAO;;;;;CAKT,AAAS,UAAU,SAAwC;EACzD,MAAM,EAAE,UAAU;AAClB,QAAM,KAAK,MAAM;AACjB,QAAM,KAAK,SAAS;AACpB,QAAM,KAAK,YAAY;AACvB,QAAM,KAAK,oBAAoB;AAC/B,QAAM,UAAU,QAAQ;;;AAI5B,iBACE,sBACA,8CACD"}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
4
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
5
|
const require_utils = require('../../utils.js');
|
|
6
|
+
const require_schemas_container_ModuleFederationPlugin_check = require('../../schemas/container/ModuleFederationPlugin.check.js');
|
|
7
|
+
const require_schemas_container_ModuleFederationPlugin = require('../../schemas/container/ModuleFederationPlugin.js');
|
|
6
8
|
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
7
9
|
const require_lib_container_runtime_FederationRuntimePlugin = require('./runtime/FederationRuntimePlugin.js');
|
|
8
10
|
const require_lib_container_ContainerPlugin = require('./ContainerPlugin.js');
|
|
@@ -10,8 +12,6 @@ const require_lib_container_ContainerReferencePlugin = require('./ContainerRefer
|
|
|
10
12
|
const require_lib_sharing_SharePlugin = require('../sharing/SharePlugin.js');
|
|
11
13
|
const require_lib_startup_MfStartupChunkDependenciesPlugin = require('../startup/MfStartupChunkDependenciesPlugin.js');
|
|
12
14
|
const require_lib_sharing_tree_shaking_TreeShakingSharedPlugin = require('../sharing/tree-shaking/TreeShakingSharedPlugin.js');
|
|
13
|
-
const require_schemas_container_ModuleFederationPlugin_check = require('../../schemas/container/ModuleFederationPlugin.check.js');
|
|
14
|
-
const require_schemas_container_ModuleFederationPlugin = require('../../schemas/container/ModuleFederationPlugin.js');
|
|
15
15
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
16
16
|
let node_path = require("node:path");
|
|
17
17
|
node_path = require_runtime.__toESM(node_path);
|
|
@@ -4,6 +4,8 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
4
4
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
5
|
const require_lib_container_options = require('../container/options.js');
|
|
6
6
|
const require_utils = require('../../utils.js');
|
|
7
|
+
const require_schemas_sharing_ConsumeSharedPlugin_check = require('../../schemas/sharing/ConsumeSharedPlugin.check.js');
|
|
8
|
+
const require_schemas_sharing_ConsumeSharedPlugin = require('../../schemas/sharing/ConsumeSharedPlugin.js');
|
|
7
9
|
const require_lib_container_runtime_FederationRuntimePlugin = require('../container/runtime/FederationRuntimePlugin.js');
|
|
8
10
|
const require_lib_sharing_resolveMatchedConfigs = require('./resolveMatchedConfigs.js');
|
|
9
11
|
const require_lib_sharing_utils = require('./utils.js');
|
|
@@ -12,8 +14,6 @@ const require_lib_sharing_ConsumeSharedModule = require('./ConsumeSharedModule.j
|
|
|
12
14
|
const require_lib_sharing_ConsumeSharedRuntimeModule = require('./ConsumeSharedRuntimeModule.js');
|
|
13
15
|
const require_lib_sharing_ProvideForSharedDependency = require('./ProvideForSharedDependency.js');
|
|
14
16
|
const require_lib_sharing_ShareRuntimeModule = require('./ShareRuntimeModule.js');
|
|
15
|
-
const require_schemas_sharing_ConsumeSharedPlugin_check = require('../../schemas/sharing/ConsumeSharedPlugin.check.js');
|
|
16
|
-
const require_schemas_sharing_ConsumeSharedPlugin = require('../../schemas/sharing/ConsumeSharedPlugin.js');
|
|
17
17
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
18
18
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
19
19
|
let path = require("path");
|
|
@@ -4,13 +4,13 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
4
4
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
5
|
const require_lib_container_options = require('../container/options.js');
|
|
6
6
|
const require_utils = require('../../utils.js');
|
|
7
|
+
const require_schemas_sharing_ProvideSharedPlugin_check = require('../../schemas/sharing/ProvideSharedPlugin.check.js');
|
|
8
|
+
const require_schemas_sharing_ProvideSharedPlugin = require('../../schemas/sharing/ProvideSharedPlugin.js');
|
|
7
9
|
const require_lib_container_runtime_FederationRuntimePlugin = require('../container/runtime/FederationRuntimePlugin.js');
|
|
8
10
|
const require_lib_sharing_utils = require('./utils.js');
|
|
9
11
|
const require_lib_sharing_ProvideForSharedDependency = require('./ProvideForSharedDependency.js');
|
|
10
12
|
const require_lib_sharing_ProvideSharedDependency = require('./ProvideSharedDependency.js');
|
|
11
13
|
const require_lib_sharing_ProvideSharedModuleFactory = require('./ProvideSharedModuleFactory.js');
|
|
12
|
-
const require_schemas_sharing_ProvideSharedPlugin_check = require('../../schemas/sharing/ProvideSharedPlugin.check.js');
|
|
13
|
-
const require_schemas_sharing_ProvideSharedPlugin = require('../../schemas/sharing/ProvideSharedPlugin.js');
|
|
14
14
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
15
15
|
|
|
16
16
|
//#region src/lib/sharing/ProvideSharedPlugin.ts
|
|
@@ -4,10 +4,10 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
4
4
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
5
|
const require_lib_container_options = require('../container/options.js');
|
|
6
6
|
const require_utils = require('../../utils.js');
|
|
7
|
-
const require_lib_sharing_ConsumeSharedPlugin = require('./ConsumeSharedPlugin.js');
|
|
8
|
-
const require_lib_sharing_ProvideSharedPlugin = require('./ProvideSharedPlugin.js');
|
|
9
7
|
const require_schemas_sharing_SharePlugin_check = require('../../schemas/sharing/SharePlugin.check.js');
|
|
10
8
|
const require_schemas_sharing_SharePlugin = require('../../schemas/sharing/SharePlugin.js');
|
|
9
|
+
const require_lib_sharing_ConsumeSharedPlugin = require('./ConsumeSharedPlugin.js');
|
|
10
|
+
const require_lib_sharing_ProvideSharedPlugin = require('./ProvideSharedPlugin.js');
|
|
11
11
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
12
12
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ var SharedContainerPlugin = class {
|
|
|
45
45
|
apply(compiler) {
|
|
46
46
|
const { library, name, request, fileName } = this._options;
|
|
47
47
|
if (library.type && compiler.options.output && compiler.options.output.enabledLibraryTypes && !compiler.options.output.enabledLibraryTypes.includes(library.type)) compiler.options.output.enabledLibraryTypes.push(library.type);
|
|
48
|
-
compiler.hooks.make.tapAsync(PLUGIN_NAME,
|
|
48
|
+
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
|
|
49
49
|
const dep = new require_lib_sharing_tree_shaking_SharedContainerPlugin_SharedEntryDependency.default(name, request);
|
|
50
50
|
dep.loc = { name };
|
|
51
51
|
compilation.addEntry(compilation.options.context || "", dep, {
|
|
@@ -55,10 +55,7 @@ var SharedContainerPlugin = class {
|
|
|
55
55
|
type: library.type,
|
|
56
56
|
name: this._globalName
|
|
57
57
|
}
|
|
58
|
-
}, (error) =>
|
|
59
|
-
if (error) throw error;
|
|
60
|
-
});
|
|
61
|
-
callback();
|
|
58
|
+
}, (error) => callback(error));
|
|
62
59
|
});
|
|
63
60
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {
|
|
64
61
|
compilation.dependencyFactories.set(require_lib_sharing_tree_shaking_SharedContainerPlugin_SharedEntryDependency.default, new require_lib_sharing_tree_shaking_SharedContainerPlugin_SharedEntryModuleFactory.default());
|
package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedContainerPlugin.js","names":["SharedEntryDependency","SharedEntryModuleFactory","SharedDependency","getFederationGlobalScope","FederationRuntimeModule"],"sources":["../../../../../../src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\nimport { assert, encodeName } from '@module-federation/sdk';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\nimport type { Compilation, Compiler, WebpackError } from 'webpack';\nimport SharedDependency from './SharedDependency';\nimport SharedEntryDependency from './SharedEntryDependency';\nimport SharedEntryModuleFactory from './SharedEntryModuleFactory';\nimport { getFederationGlobalScope } from '../../../container/runtime/utils';\nimport FederationRuntimeModule from '../../../container/runtime/FederationRuntimeModule';\n\nconst EntryDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/EntryDependency'),\n) as typeof import('webpack/lib/dependencies/EntryDependency');\n\nexport const PLUGIN_NAME = 'SharedContainerPlugin';\nconst HOT_UPDATE_SUFFIX = '.hot-update';\n\nexport type SharedContainerPluginOptions = {\n mfName: string;\n shareName: string;\n version: string;\n request: string;\n library?: moduleFederationPlugin.LibraryOptions;\n independentShareFileName?: string;\n};\n\nclass SharedContainerPlugin {\n name = PLUGIN_NAME;\n filename = '';\n _options: {\n name: string;\n request: string;\n version: string;\n fileName: string;\n library: moduleFederationPlugin.LibraryOptions;\n };\n _shareName: string;\n _globalName: string;\n\n constructor(options: SharedContainerPluginOptions) {\n const { mfName, shareName, request, library, independentShareFileName } =\n options;\n const version = options.version || '0.0.0';\n this._globalName = encodeName(`${mfName}_${shareName}_${version}`);\n const fileName = independentShareFileName || `${version}/share-entry.js`;\n this._shareName = shareName;\n this._options = {\n name: shareName,\n request: request,\n library: (library\n ? { ...library, name: this._globalName }\n : undefined) || {\n type: 'global',\n name: this._globalName,\n },\n version,\n fileName,\n };\n }\n\n getData() {\n return [this.filename, this._globalName, this._options.version];\n }\n\n apply(compiler: Compiler): void {\n const { library, name, request, fileName } = this._options;\n\n if (\n library.type &&\n compiler.options.output &&\n compiler.options.output.enabledLibraryTypes &&\n !compiler.options.output.enabledLibraryTypes.includes(library.type)\n ) {\n compiler.options.output.enabledLibraryTypes.push(library.type);\n }\n\n compiler.hooks.make.tapAsync(\n PLUGIN_NAME,\n
|
|
1
|
+
{"version":3,"file":"SharedContainerPlugin.js","names":["SharedEntryDependency","SharedEntryModuleFactory","SharedDependency","getFederationGlobalScope","FederationRuntimeModule"],"sources":["../../../../../../src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\nimport { assert, encodeName } from '@module-federation/sdk';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\nimport type { Compilation, Compiler, WebpackError } from 'webpack';\nimport SharedDependency from './SharedDependency';\nimport SharedEntryDependency from './SharedEntryDependency';\nimport SharedEntryModuleFactory from './SharedEntryModuleFactory';\nimport { getFederationGlobalScope } from '../../../container/runtime/utils';\nimport FederationRuntimeModule from '../../../container/runtime/FederationRuntimeModule';\n\nconst EntryDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/EntryDependency'),\n) as typeof import('webpack/lib/dependencies/EntryDependency');\n\nexport const PLUGIN_NAME = 'SharedContainerPlugin';\nconst HOT_UPDATE_SUFFIX = '.hot-update';\n\nexport type SharedContainerPluginOptions = {\n mfName: string;\n shareName: string;\n version: string;\n request: string;\n library?: moduleFederationPlugin.LibraryOptions;\n independentShareFileName?: string;\n};\n\nclass SharedContainerPlugin {\n name = PLUGIN_NAME;\n filename = '';\n _options: {\n name: string;\n request: string;\n version: string;\n fileName: string;\n library: moduleFederationPlugin.LibraryOptions;\n };\n _shareName: string;\n _globalName: string;\n\n constructor(options: SharedContainerPluginOptions) {\n const { mfName, shareName, request, library, independentShareFileName } =\n options;\n const version = options.version || '0.0.0';\n this._globalName = encodeName(`${mfName}_${shareName}_${version}`);\n const fileName = independentShareFileName || `${version}/share-entry.js`;\n this._shareName = shareName;\n this._options = {\n name: shareName,\n request: request,\n library: (library\n ? { ...library, name: this._globalName }\n : undefined) || {\n type: 'global',\n name: this._globalName,\n },\n version,\n fileName,\n };\n }\n\n getData() {\n return [this.filename, this._globalName, this._options.version];\n }\n\n apply(compiler: Compiler): void {\n const { library, name, request, fileName } = this._options;\n\n if (\n library.type &&\n compiler.options.output &&\n compiler.options.output.enabledLibraryTypes &&\n !compiler.options.output.enabledLibraryTypes.includes(library.type)\n ) {\n compiler.options.output.enabledLibraryTypes.push(library.type);\n }\n\n compiler.hooks.make.tapAsync(\n PLUGIN_NAME,\n (\n compilation: Compilation,\n callback: (error?: WebpackError | null | undefined) => void,\n ) => {\n const dep = new SharedEntryDependency(name, request);\n dep.loc = { name: name };\n\n compilation.addEntry(\n compilation.options.context || '',\n dep,\n {\n name: name,\n filename: fileName,\n library: {\n type: library.type!,\n name: this._globalName,\n },\n },\n (error: WebpackError | null | undefined) => callback(error),\n );\n },\n );\n\n // add the container entry module\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n SharedEntryDependency,\n new SharedEntryModuleFactory(),\n );\n\n compilation.dependencyFactories.set(\n SharedDependency,\n normalModuleFactory,\n );\n\n if (!compilation.dependencyFactories.has(EntryDependency)) {\n compilation.dependencyFactories.set(\n EntryDependency,\n normalModuleFactory,\n );\n }\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n PLUGIN_NAME,\n (chunk, set) => {\n set.add(getFederationGlobalScope(compiler.webpack.RuntimeGlobals));\n set.add(compiler.webpack.RuntimeGlobals.runtimeId);\n compilation.addRuntimeModule(\n chunk,\n new FederationRuntimeModule(set, name, { name, remotes: [] }),\n );\n },\n );\n\n compilation.hooks.processAssets.tapPromise(\n {\n name: 'getManifestFileName',\n stage:\n // @ts-ignore use runtime variable in case peer dep not installed\n compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,\n },\n async () => {\n const remoteEntryPoint = compilation.entrypoints.get(name);\n assert(remoteEntryPoint, `Can not get shared ${name} entryPoint!`);\n const remoteEntryNameChunk = compilation.namedChunks.get(name);\n assert(remoteEntryNameChunk, `Can not get shared ${name} chunk!`);\n\n const files = Array.from(\n remoteEntryNameChunk.files as Iterable<string>,\n ).filter(\n (f: string) =>\n !f.includes(HOT_UPDATE_SUFFIX) && !f.endsWith('.css'),\n );\n assert(files.length > 0, `no files found for shared ${name} chunk`);\n assert(\n files.length === 1,\n `shared ${name} chunk should not have multiple files!, current files: ${files.join(\n ',',\n )}`,\n );\n this.filename = files[0];\n },\n );\n },\n );\n }\n}\n\nexport default SharedContainerPlugin;\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,kBAAkB,gFACD,2CAA2C,CACjE;AAED,MAAa,cAAc;AAC3B,MAAM,oBAAoB;AAW1B,IAAM,wBAAN,MAA4B;CAa1B,YAAY,SAAuC;cAZ5C;kBACI;EAYT,MAAM,EAAE,QAAQ,WAAW,SAAS,SAAS,6BAC3C;EACF,MAAM,UAAU,QAAQ,WAAW;AACnC,OAAK,qDAAyB,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU;EAClE,MAAM,WAAW,4BAA4B,GAAG,QAAQ;AACxD,OAAK,aAAa;AAClB,OAAK,WAAW;GACd,MAAM;GACG;GACT,UAAU,UACN;IAAE,GAAG;IAAS,MAAM,KAAK;IAAa,GACtC,WAAc;IAChB,MAAM;IACN,MAAM,KAAK;IACZ;GACD;GACA;GACD;;CAGH,UAAU;AACR,SAAO;GAAC,KAAK;GAAU,KAAK;GAAa,KAAK,SAAS;GAAQ;;CAGjE,MAAM,UAA0B;EAC9B,MAAM,EAAE,SAAS,MAAM,SAAS,aAAa,KAAK;AAElD,MACE,QAAQ,QACR,SAAS,QAAQ,UACjB,SAAS,QAAQ,OAAO,uBACxB,CAAC,SAAS,QAAQ,OAAO,oBAAoB,SAAS,QAAQ,KAAK,CAEnE,UAAS,QAAQ,OAAO,oBAAoB,KAAK,QAAQ,K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yDAAyD,MAAM,KAC5E,IACD,GACF;AACD,SAAK,WAAW,MAAM;KAEzB;IAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/enhanced",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.2",
|
|
4
4
|
"main": "./dist/src/index.js",
|
|
5
5
|
"types": "./dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -85,17 +85,17 @@
|
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"schema-utils": "4.3.0",
|
|
87
87
|
"tapable": "2.3.0",
|
|
88
|
-
"@module-federation/webpack-bundler-runtime": "2.9.
|
|
89
|
-
"@module-federation/
|
|
90
|
-
"@module-federation/
|
|
91
|
-
"@module-federation/
|
|
92
|
-
"@module-federation/
|
|
93
|
-
"@module-federation/
|
|
94
|
-
"@module-federation/
|
|
95
|
-
"@module-federation/inject-external-runtime-core-plugin": "2.9.
|
|
96
|
-
"@module-federation/runtime-tools": "2.9.
|
|
97
|
-
"@module-federation/sdk": "2.9.
|
|
98
|
-
"@module-federation/cli": "2.9.
|
|
88
|
+
"@module-federation/webpack-bundler-runtime": "2.9.2",
|
|
89
|
+
"@module-federation/error-codes": "2.9.2",
|
|
90
|
+
"@module-federation/bridge-react-webpack-plugin": "2.9.2",
|
|
91
|
+
"@module-federation/dts-plugin": "2.9.2",
|
|
92
|
+
"@module-federation/managers": "2.9.2",
|
|
93
|
+
"@module-federation/manifest": "2.9.2",
|
|
94
|
+
"@module-federation/rspack": "2.9.2",
|
|
95
|
+
"@module-federation/inject-external-runtime-core-plugin": "2.9.2",
|
|
96
|
+
"@module-federation/runtime-tools": "2.9.2",
|
|
97
|
+
"@module-federation/sdk": "2.9.2",
|
|
98
|
+
"@module-federation/cli": "2.9.2"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
101
101
|
"generate:schema": "node src/scripts/compile-schema.js && node src/scripts/generate-sdk-types.js",
|