@module-federation/enhanced 0.0.0-feat-node-support-1702930274546 → 0.0.0-feat-node-support-1703050615268
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/package.json +4 -4
- package/src/declarations/plugins/container/ModuleFederationPlugin.d.js.map +1 -1
- package/src/lib/container/ContainerEntryModule.js +3 -3
- package/src/lib/container/ContainerEntryModule.js.map +1 -1
- package/src/lib/container/ContainerPlugin.js +6 -2
- package/src/lib/container/ContainerPlugin.js.map +1 -1
- package/src/lib/container/ContainerReferencePlugin.js +3 -1
- package/src/lib/container/ContainerReferencePlugin.js.map +1 -1
- package/src/lib/container/FallbackModule.js +2 -2
- package/src/lib/container/FallbackModule.js.map +1 -1
- package/src/lib/container/RemoteModule.js +2 -2
- package/src/lib/container/RemoteModule.js.map +1 -1
- package/src/lib/container/RemoteRuntimeModule.js +1 -1
- package/src/lib/container/RemoteRuntimeModule.js.map +1 -1
- package/src/lib/container/runtime/FederationRuntimePlugin.js +5 -5
- package/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -1
- package/src/lib/container/runtime/utils.js +7 -5
- package/src/lib/container/runtime/utils.js.map +1 -1
- package/src/lib/sharing/ConsumeSharedModule.js +3 -3
- package/src/lib/sharing/ConsumeSharedModule.js.map +1 -1
- package/src/lib/sharing/ProvideSharedModule.js +2 -2
- package/src/lib/sharing/ProvideSharedModule.js.map +1 -1
- package/src/lib/sharing/ShareRuntimeModule.js +1 -1
- package/src/lib/sharing/ShareRuntimeModule.js.map +1 -1
- package/src/schemas/container/ContainerReferencePlugin.check.d.ts +7 -0
- package/src/schemas/container/ContainerReferencePlugin.check.js +895 -0
- package/src/schemas/container/ContainerReferencePlugin.check.js.map +1 -0
- package/src/schemas/container/ContainerReferencePlugin.d.ts +92 -0
- package/src/schemas/container/ContainerReferencePlugin.js +151 -0
- package/src/schemas/container/ContainerReferencePlugin.js.map +1 -0
- package/src/schemas/container/ModuleFederationPlugin.check.d.js +8 -0
- package/src/schemas/container/ModuleFederationPlugin.check.d.js.map +1 -0
- package/src/schemas/container/ModuleFederationPlugin.check.js +42 -8
- package/src/schemas/container/ModuleFederationPlugin.check.js.map +1 -1
- package/src/schemas/container/ModuleFederationPlugin.d.ts +5 -0
- package/src/schemas/container/ModuleFederationPlugin.js +5 -0
- package/src/schemas/container/ModuleFederationPlugin.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/enhanced",
|
|
3
|
-
"version": "0.0.0-feat-node-support-
|
|
3
|
+
"version": "0.0.0-feat-node-support-1703050615268",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"semver": "7.5.4",
|
|
15
15
|
"tapable": "2.2.1",
|
|
16
16
|
"webpack-sources": "3.2.3",
|
|
17
|
-
"@module-federation/runtime": "0.0.0-feat-node-support-
|
|
18
|
-
"@module-federation/sdk": "0.0.0-feat-node-support-
|
|
19
|
-
"@module-federation/webpack-bundler-runtime": "0.0.0-feat-node-support-
|
|
17
|
+
"@module-federation/runtime": "0.0.0-feat-node-support-1703050615268",
|
|
18
|
+
"@module-federation/sdk": "0.0.0-feat-node-support-1703050615268",
|
|
19
|
+
"@module-federation/webpack-bundler-runtime": "0.0.0-feat-node-support-1703050615268"
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/enhanced/src/declarations/plugins/container/ModuleFederationPlugin.d.ts"],"sourcesContent":["/*\n * This file was automatically generated.\n * DO NOT MODIFY BY HAND.\n * Run `yarn special-lint-fix` to update\n */\n\n/**\n * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.\n */\nexport type Exposes = (ExposesItem | ExposesObject)[] | ExposesObject;\n/**\n * Module that should be exposed by this container.\n */\nexport type ExposesItem = string;\n/**\n * Modules that should be exposed by this container.\n */\nexport type ExposesItems = ExposesItem[];\n/**\n * Add a container for define/require functions in the AMD module.\n */\nexport type AmdContainer = string;\n/**\n * Add a comment in the UMD wrapper.\n */\nexport type AuxiliaryComment = string | LibraryCustomUmdCommentObject;\n/**\n * Specify which export should be exposed as library.\n */\nexport type LibraryExport = string[] | string;\n/**\n * The name of the library (some types allow unnamed libraries too).\n */\nexport type LibraryName = string[] | string | LibraryCustomUmdObject;\n/**\n * Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).\n */\nexport type LibraryType =\n | (\n | 'var'\n | 'module'\n | 'assign'\n | 'assign-properties'\n | 'this'\n | 'window'\n | 'self'\n | 'global'\n | 'commonjs'\n | 'commonjs2'\n | 'commonjs-module'\n | 'commonjs-static'\n | 'amd'\n | 'amd-require'\n | 'umd'\n | 'umd2'\n | 'jsonp'\n | 'system'\n )\n | string;\n/**\n * If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.\n */\nexport type UmdNamedDefine = boolean;\n/**\n * Specifies the default type of externals ('amd*', 'umd*', 'system' and 'jsonp' depend on output.libraryTarget set to the same value).\n */\nexport type ExternalsType =\n | 'var'\n | 'module'\n | 'assign'\n | 'this'\n | 'window'\n | 'self'\n | 'global'\n | 'commonjs'\n | 'commonjs2'\n | 'commonjs-module'\n | 'commonjs-static'\n | 'amd'\n | 'amd-require'\n | 'umd'\n | 'umd2'\n | 'jsonp'\n | 'system'\n | 'promise'\n | 'import'\n | 'script'\n | 'node-commonjs';\n/**\n * Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.\n */\nexport type Remotes = (RemotesItem | RemotesObject)[] | RemotesObject;\n/**\n * Container location from which modules should be resolved and loaded at runtime.\n */\nexport type RemotesItem = string;\n/**\n * Container locations from which modules should be resolved and loaded at runtime.\n */\nexport type RemotesItems = RemotesItem[];\n/**\n * The name of the runtime chunk. If set a runtime chunk with this name is created or an existing entrypoint is used as runtime.\n */\nexport type EntryRuntime = false | string;\n/**\n * Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.\n */\nexport type Shared = (SharedItem | SharedObject)[] | SharedObject;\n/**\n * A module that should be shared in the share scope.\n */\nexport type SharedItem = string;\n\nexport interface ModuleFederationPluginOptions {\n /**\n * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.\n */\n exposes?: Exposes;\n /**\n * The filename of the container as relative path inside the `output.path` directory.\n */\n filename?: string;\n /**\n * Options for library.\n */\n library?: LibraryOptions;\n /**\n * The name of the container.\n */\n name?: string;\n /**\n * The external type of the remote containers.\n */\n remoteType?: ExternalsType;\n /**\n * Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.\n */\n remotes?: Remotes;\n /**\n * The name of the runtime chunk. If set a runtime chunk with this name is created or an existing entrypoint is used as runtime.\n */\n runtime?: EntryRuntime;\n /**\n * Share scope name used for all shared modules (defaults to 'default').\n */\n shareScope?: string;\n /**\n * Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.\n */\n shared?: Shared;\n /**\n * Runtime plugin file paths or package name.\n */\n runtimePlugins?: string[];\n}\n/**\n * Modules that should be exposed by this container. Property names are used as public paths.\n */\nexport interface ExposesObject {\n /**\n * Modules that should be exposed by this container.\n */\n [k: string]: ExposesConfig | ExposesItem | ExposesItems;\n}\n/**\n * Advanced configuration for modules that should be exposed by this container.\n */\nexport interface ExposesConfig {\n /**\n * Request to a module that should be exposed by this container.\n */\n import: ExposesItem | ExposesItems;\n /**\n * Custom chunk name for the exposed module.\n */\n name?: string;\n}\n/**\n * Options for library.\n */\nexport interface LibraryOptions {\n /**\n * Add a container for define/require functions in the AMD module.\n */\n amdContainer?: AmdContainer;\n /**\n * Add a comment in the UMD wrapper.\n */\n auxiliaryComment?: AuxiliaryComment;\n /**\n * Specify which export should be exposed as library.\n */\n export?: LibraryExport;\n /**\n * The name of the library (some types allow unnamed libraries too).\n */\n name?: LibraryName;\n /**\n * Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).\n */\n type: LibraryType;\n /**\n * If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.\n */\n umdNamedDefine?: UmdNamedDefine;\n}\n/**\n * Set explicit comments for `commonjs`, `commonjs2`, `amd`, and `root`.\n */\nexport interface LibraryCustomUmdCommentObject {\n /**\n * Set comment for `amd` section in UMD.\n */\n amd?: string;\n /**\n * Set comment for `commonjs` (exports) section in UMD.\n */\n commonjs?: string;\n /**\n * Set comment for `commonjs2` (module.exports) section in UMD.\n */\n commonjs2?: string;\n /**\n * Set comment for `root` (global variable) section in UMD.\n */\n root?: string;\n}\n/**\n * Description object for all UMD variants of the library name.\n */\nexport interface LibraryCustomUmdObject {\n /**\n * Name of the exposed AMD library in the UMD.\n */\n amd?: string;\n /**\n * Name of the exposed commonjs export in the UMD.\n */\n commonjs?: string;\n /**\n * Name of the property exposed globally by a UMD library.\n */\n root?: string[] | string;\n}\n/**\n * Container locations from which modules should be resolved and loaded at runtime. Property names are used as request scopes.\n */\nexport interface RemotesObject {\n /**\n * Container locations from which modules should be resolved and loaded at runtime.\n */\n [k: string]: RemotesConfig | RemotesItem | RemotesItems;\n}\n/**\n * Advanced configuration for container locations from which modules should be resolved and loaded at runtime.\n */\nexport interface RemotesConfig {\n /**\n * Container locations from which modules should be resolved and loaded at runtime.\n */\n external: RemotesItem | RemotesItems;\n /**\n * The name of the share scope shared with this remote.\n */\n shareScope?: string;\n}\n/**\n * Modules that should be shared in the share scope. Property names are used to match requested modules in this compilation. Relative requests are resolved, module requests are matched unresolved, absolute paths will match resolved requests. A trailing slash will match all requests with this prefix. In this case shareKey must also have a trailing slash.\n */\nexport interface SharedObject {\n /**\n * Modules that should be shared in the share scope.\n */\n [k: string]: SharedConfig | SharedItem;\n}\n/**\n * Advanced configuration for modules that should be shared in the share scope.\n */\nexport interface SharedConfig {\n /**\n * Include the provided and fallback module directly instead behind an async request. This allows to use this shared module in initial load too. All possible shared modules need to be eager too.\n */\n eager?: boolean;\n /**\n * Provided module that should be provided to share scope. Also acts as fallback module if no shared module is found in share scope or version isn't valid. Defaults to the property name.\n */\n import?: false | SharedItem;\n /**\n * Package name to determine required version from description file. This is only needed when package name can't be automatically determined from request.\n */\n packageName?: string;\n /**\n * Version requirement from module in share scope.\n */\n requiredVersion?: false | string;\n /**\n * Module is looked up under this key from the share scope.\n */\n shareKey?: string;\n /**\n * Share scope name.\n */\n shareScope?: string;\n /**\n * Allow only a single version of the shared module in share scope (disabled by default).\n */\n singleton?: boolean;\n /**\n * Do not accept shared module if version is not valid (defaults to yes, if local fallback module is available and shared module is not a singleton, otherwise no, has no effect if there is no required version specified).\n */\n strictVersion?: boolean;\n /**\n * Version of the provided module. Will replace lower matching versions, but not higher.\n */\n version?: false | string;\n}\n"],"names":[],"mappings":"AAAA;;;;CAIC,GAED;;CAEC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/enhanced/src/declarations/plugins/container/ModuleFederationPlugin.d.ts"],"sourcesContent":["/*\n * This file was automatically generated.\n * DO NOT MODIFY BY HAND.\n * Run `yarn special-lint-fix` to update\n */\n\n/**\n * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.\n */\nexport type Exposes = (ExposesItem | ExposesObject)[] | ExposesObject;\n/**\n * Module that should be exposed by this container.\n */\nexport type ExposesItem = string;\n/**\n * Modules that should be exposed by this container.\n */\nexport type ExposesItems = ExposesItem[];\n/**\n * Add a container for define/require functions in the AMD module.\n */\nexport type AmdContainer = string;\n/**\n * Add a comment in the UMD wrapper.\n */\nexport type AuxiliaryComment = string | LibraryCustomUmdCommentObject;\n/**\n * Specify which export should be exposed as library.\n */\nexport type LibraryExport = string[] | string;\n/**\n * The name of the library (some types allow unnamed libraries too).\n */\nexport type LibraryName = string[] | string | LibraryCustomUmdObject;\n/**\n * Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).\n */\nexport type LibraryType =\n | (\n | 'var'\n | 'module'\n | 'assign'\n | 'assign-properties'\n | 'this'\n | 'window'\n | 'self'\n | 'global'\n | 'commonjs'\n | 'commonjs2'\n | 'commonjs-module'\n | 'commonjs-static'\n | 'amd'\n | 'amd-require'\n | 'umd'\n | 'umd2'\n | 'jsonp'\n | 'system'\n )\n | string;\n/**\n * If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.\n */\nexport type UmdNamedDefine = boolean;\n/**\n * Specifies the default type of externals ('amd*', 'umd*', 'system' and 'jsonp' depend on output.libraryTarget set to the same value).\n */\nexport type ExternalsType =\n | 'var'\n | 'module'\n | 'assign'\n | 'this'\n | 'window'\n | 'self'\n | 'global'\n | 'commonjs'\n | 'commonjs2'\n | 'commonjs-module'\n | 'commonjs-static'\n | 'amd'\n | 'amd-require'\n | 'umd'\n | 'umd2'\n | 'jsonp'\n | 'system'\n | 'promise'\n | 'import'\n | 'script'\n | 'node-commonjs';\n/**\n * Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.\n */\nexport type Remotes = (RemotesItem | RemotesObject)[] | RemotesObject;\n/**\n * Container location from which modules should be resolved and loaded at runtime.\n */\nexport type RemotesItem = string;\n/**\n * Container locations from which modules should be resolved and loaded at runtime.\n */\nexport type RemotesItems = RemotesItem[];\n/**\n * The name of the runtime chunk. If set a runtime chunk with this name is created or an existing entrypoint is used as runtime.\n */\nexport type EntryRuntime = false | string;\n/**\n * Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.\n */\nexport type Shared = (SharedItem | SharedObject)[] | SharedObject;\n/**\n * A module that should be shared in the share scope.\n */\nexport type SharedItem = string;\n\nexport interface ModuleFederationPluginOptions {\n /**\n * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.\n */\n exposes?: Exposes;\n /**\n * The filename of the container as relative path inside the `output.path` directory.\n */\n filename?: string;\n /**\n * Options for library.\n */\n library?: LibraryOptions;\n /**\n * The name of the container.\n */\n name?: string;\n /**\n * The external type of the remote containers.\n */\n remoteType?: ExternalsType;\n /**\n * Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.\n */\n remotes?: Remotes;\n /**\n * The name of the runtime chunk. If set a runtime chunk with this name is created or an existing entrypoint is used as runtime.\n */\n runtime?: EntryRuntime;\n /**\n * Share scope name used for all shared modules (defaults to 'default').\n */\n shareScope?: string;\n /**\n * Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.\n */\n shared?: Shared;\n /**\n * Runtime plugin file paths or package name.\n */\n runtimePlugins?: string[];\n}\n/**\n * Modules that should be exposed by this container. Property names are used as public paths.\n */\nexport interface ExposesObject {\n /**\n * Modules that should be exposed by this container.\n */\n [k: string]: ExposesConfig | ExposesItem | ExposesItems;\n}\n/**\n * Advanced configuration for modules that should be exposed by this container.\n */\nexport interface ExposesConfig {\n /**\n * Request to a module that should be exposed by this container.\n */\n import: ExposesItem | ExposesItems;\n /**\n * Custom chunk name for the exposed module.\n */\n name?: string;\n}\n/**\n * Options for library.\n */\nexport interface LibraryOptions {\n /**\n * Add a container for define/require functions in the AMD module.\n */\n amdContainer?: AmdContainer;\n /**\n * Add a comment in the UMD wrapper.\n */\n auxiliaryComment?: AuxiliaryComment;\n /**\n * Specify which export should be exposed as library.\n */\n export?: LibraryExport;\n /**\n * The name of the library (some types allow unnamed libraries too).\n */\n name?: LibraryName;\n /**\n * Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).\n */\n type: LibraryType;\n /**\n * If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.\n */\n umdNamedDefine?: UmdNamedDefine;\n}\n/**\n * Set explicit comments for `commonjs`, `commonjs2`, `amd`, and `root`.\n */\nexport interface LibraryCustomUmdCommentObject {\n /**\n * Set comment for `amd` section in UMD.\n */\n amd?: string;\n /**\n * Set comment for `commonjs` (exports) section in UMD.\n */\n commonjs?: string;\n /**\n * Set comment for `commonjs2` (module.exports) section in UMD.\n */\n commonjs2?: string;\n /**\n * Set comment for `root` (global variable) section in UMD.\n */\n root?: string;\n}\n/**\n * Description object for all UMD variants of the library name.\n */\nexport interface LibraryCustomUmdObject {\n /**\n * Name of the exposed AMD library in the UMD.\n */\n amd?: string;\n /**\n * Name of the exposed commonjs export in the UMD.\n */\n commonjs?: string;\n /**\n * Name of the property exposed globally by a UMD library.\n */\n root?: string[] | string;\n}\n/**\n * Container locations from which modules should be resolved and loaded at runtime. Property names are used as request scopes.\n */\nexport interface RemotesObject {\n /**\n * Container locations from which modules should be resolved and loaded at runtime.\n */\n [k: string]: RemotesConfig | RemotesItem | RemotesItems;\n}\n/**\n * Advanced configuration for container locations from which modules should be resolved and loaded at runtime.\n */\nexport interface RemotesConfig {\n /**\n * Container locations from which modules should be resolved and loaded at runtime.\n */\n external: RemotesItem | RemotesItems;\n /**\n * The name of the share scope shared with this remote.\n */\n shareScope?: string;\n /**\n * The name of the remote instance name.\n */\n name?: string;\n}\n/**\n * Modules that should be shared in the share scope. Property names are used to match requested modules in this compilation. Relative requests are resolved, module requests are matched unresolved, absolute paths will match resolved requests. A trailing slash will match all requests with this prefix. In this case shareKey must also have a trailing slash.\n */\nexport interface SharedObject {\n /**\n * Modules that should be shared in the share scope.\n */\n [k: string]: SharedConfig | SharedItem;\n}\n/**\n * Advanced configuration for modules that should be shared in the share scope.\n */\nexport interface SharedConfig {\n /**\n * Include the provided and fallback module directly instead behind an async request. This allows to use this shared module in initial load too. All possible shared modules need to be eager too.\n */\n eager?: boolean;\n /**\n * Provided module that should be provided to share scope. Also acts as fallback module if no shared module is found in share scope or version isn't valid. Defaults to the property name.\n */\n import?: false | SharedItem;\n /**\n * Package name to determine required version from description file. This is only needed when package name can't be automatically determined from request.\n */\n packageName?: string;\n /**\n * Version requirement from module in share scope.\n */\n requiredVersion?: false | string;\n /**\n * Module is looked up under this key from the share scope.\n */\n shareKey?: string;\n /**\n * Share scope name.\n */\n shareScope?: string;\n /**\n * Allow only a single version of the shared module in share scope (disabled by default).\n */\n singleton?: boolean;\n /**\n * Do not accept shared module if version is not valid (defaults to yes, if local fallback module is available and shared module is not a singleton, otherwise no, has no effect if there is no required version specified).\n */\n strictVersion?: boolean;\n /**\n * Version of the provided module. Will replace lower matching versions, but not higher.\n */\n version?: false | string;\n}\n"],"names":[],"mappings":"AAAA;;;;CAIC,GAED;;CAEC"}
|
|
@@ -15,6 +15,7 @@ const _normalizewebpackpath = require("@module-federation/sdk/normalize-webpack-
|
|
|
15
15
|
const _ContainerExposedDependency = /*#__PURE__*/ _interop_require_default(require("./ContainerExposedDependency"));
|
|
16
16
|
const _FederationRuntimePlugin = /*#__PURE__*/ _interop_require_default(require("./runtime/FederationRuntimePlugin"));
|
|
17
17
|
const _utils = require("./runtime/utils");
|
|
18
|
+
const _Constants = require("../Constants");
|
|
18
19
|
function _interop_require_default(obj) {
|
|
19
20
|
return obj && obj.__esModule ? obj : {
|
|
20
21
|
default: obj
|
|
@@ -23,7 +24,6 @@ function _interop_require_default(obj) {
|
|
|
23
24
|
const makeSerializable = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/util/makeSerializable'));
|
|
24
25
|
const { sources: webpackSources } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack'));
|
|
25
26
|
const { AsyncDependenciesBlock, Template, Module, RuntimeGlobals } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack'));
|
|
26
|
-
const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/ModuleTypeConstants'));
|
|
27
27
|
const StaticExportsDependency = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/dependencies/StaticExportsDependency'));
|
|
28
28
|
const EntryDependency = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/dependencies/EntryDependency'));
|
|
29
29
|
const SOURCE_TYPES = new Set([
|
|
@@ -174,7 +174,7 @@ let ContainerEntryModule = class ContainerEntryModule extends Module {
|
|
|
174
174
|
weak: false,
|
|
175
175
|
runtimeRequirements
|
|
176
176
|
});
|
|
177
|
-
const federationGlobal = (0, _utils.getFederationGlobalScope)(RuntimeGlobals);
|
|
177
|
+
const federationGlobal = (0, _utils.getFederationGlobalScope)(RuntimeGlobals || {});
|
|
178
178
|
const source = Template.asString([
|
|
179
179
|
`var moduleMap = {`,
|
|
180
180
|
Template.indent(getters.join(',\n')),
|
|
@@ -240,7 +240,7 @@ let ContainerEntryModule = class ContainerEntryModule extends Module {
|
|
|
240
240
|
* @param {[string, ExposeOptions][]} exposes list of exposed modules
|
|
241
241
|
* @param {string} shareScope name of the share scope
|
|
242
242
|
*/ constructor(name, exposes, shareScope, runtimePlugins){
|
|
243
|
-
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
|
243
|
+
super(_Constants.JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
|
244
244
|
this._name = name;
|
|
245
245
|
this._exposes = exposes;
|
|
246
246
|
this._shareScope = shareScope;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/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 type { Dependency, Compilation } from 'webpack';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport type {\n LibIdentOptions,\n NeedBuildContext,\n RequestShortener,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n WebpackOptions,\n InputFileSystem,\n ResolverWithOptions,\n} from 'webpack/lib/Module';\nimport type WebpackError from 'webpack/lib/WebpackError';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport { getFederationGlobalScope } from './runtime/utils';\n\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { AsyncDependenciesBlock, Template, Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require(\n normalizeWebpackPath('webpack/lib/ModuleTypeConstants'),\n) as typeof import('webpack/lib/ModuleTypeConstants');\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;\n private _runtimePlugins: string[];\n /**\n * @param {string} name container entry name\n * @param {[string, ExposeOptions][]} exposes list of exposed modules\n * @param {string} shareScope name of the share scope\n */\n constructor(\n name: string,\n exposes: [string, ExposeOptions][],\n shareScope: string,\n runtimePlugins: string[],\n ) {\n super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);\n this._name = name;\n this._exposes = exposes;\n this._shareScope = shareScope;\n this._runtimePlugins = runtimePlugins;\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 //@ts-ignore\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 return `container entry (${this._shareScope}) ${JSON.stringify(\n this._exposes,\n )}`;\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 // @ts-ignore typeof webpack/lib !== typeof webpack/types\n override needBuild(\n context: NeedBuildContext,\n callback: (\n arg0: (WebpackError | null) | undefined,\n arg1: boolean | undefined,\n ) => void,\n ): void {\n const baseContext = context as NeedBuildContext;\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 // @ts-ignore typeof webpack/lib !== typeof webpack/types\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 //@ts-ignore\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 //@ts-ignore\n block.addDependency(dep);\n }\n //@ts-ignore\n this.addBlock(block);\n }\n //@ts-ignore\n this.addDependency(\n //@ts-ignore\n new StaticExportsDependency(\n ['get', 'init'],\n false,\n ) as unknown as Dependency,\n );\n\n this.addDependency(\n // @ts-ignore\n new EntryDependency(\n FederationRuntimePlugin.getFilePath(this._name, this._runtimePlugins),\n ),\n );\n\n callback();\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n //@ts-ignore\n override codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }) {\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 str = runtimeTemplate.throwMissingModuleErrorBlock({\n request: modules.map((m) => m.request).join(', '),\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 //@ts-ignore\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\n const initRuntimeDep = this.dependencies[1];\n const initRuntimeModuleGetter = runtimeTemplate.moduleRaw({\n module: moduleGraph.getModule(initRuntimeDep),\n chunkGraph,\n // @ts-expect-error\n request: initRuntimeDep.userRequest,\n weak: false,\n runtimeRequirements,\n });\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals);\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('shareScope, initScope', [\n `return ${federationGlobal}.bundlerRuntime.initContainerEntry({${Template.indent(\n [\n `webpackRequire: ${RuntimeGlobals.require},`,\n `shareScope: shareScope,`,\n `initScope: initScope,`,\n `shareScopeKey: ${JSON.stringify(this._shareScope)}`,\n ],\n )}`,\n '})',\n ])};`,\n `${initRuntimeModuleGetter}`,\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._runtimePlugins);\n super.serialize(context);\n }\n}\nmakeSerializable(\n ContainerEntryModule,\n 'enhanced/lib/container/ContainerEntryModule',\n);\n\nexport default ContainerEntryModule;\n"],"names":["makeSerializable","require","normalizeWebpackPath","sources","webpackSources","AsyncDependenciesBlock","Template","Module","RuntimeGlobals","JAVASCRIPT_MODULE_TYPE_DYNAMIC","StaticExportsDependency","EntryDependency","SOURCE_TYPES","Set","ContainerEntryModule","deserialize","context","read","obj","getSourceTypes","identifier","_shareScope","JSON","stringify","_exposes","readableIdentifier","requestShortener","libIdent","options","layer","_name","needBuild","callback","baseContext","buildMeta","build","compilation","resolver","fs","buildInfo","strict","topLevelDeclarations","exportsType","clearDependenciesAndBlocks","name","block","import","length","idx","request","dep","ContainerExposedDependency","loc","index","addDependency","addBlock","FederationRuntimePlugin","getFilePath","_runtimePlugins","codeGeneration","moduleGraph","chunkGraph","runtimeTemplate","Map","runtimeRequirements","definePropertyGetters","hasOwnProperty","exports","getters","blocks","dependencies","modules","map","dependency","exposedName","module","getModule","userRequest","str","some","m","throwMissingModuleErrorBlock","join","blockPromise","message","returningFunction","moduleRaw","weak","push","basicFunction","initRuntimeDep","initRuntimeModuleGetter","federationGlobal","getFederationGlobalScope","source","asString","indent","currentRemoteGetScope","set","useSourceMap","useSimpleSourceMap","OriginalSource","RawSource","size","type","serialize","write","const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|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/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 type { Dependency, Compilation } from 'webpack';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport type {\n LibIdentOptions,\n NeedBuildContext,\n RequestShortener,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n WebpackOptions,\n InputFileSystem,\n ResolverWithOptions,\n} from 'webpack/lib/Module';\nimport type WebpackError from 'webpack/lib/WebpackError';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport { getFederationGlobalScope } from './runtime/utils';\nimport { JAVASCRIPT_MODULE_TYPE_DYNAMIC } from '../Constants';\n\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { AsyncDependenciesBlock, Template, Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) 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;\n private _runtimePlugins: string[];\n /**\n * @param {string} name container entry name\n * @param {[string, ExposeOptions][]} exposes list of exposed modules\n * @param {string} shareScope name of the share scope\n */\n constructor(\n name: string,\n exposes: [string, ExposeOptions][],\n shareScope: string,\n runtimePlugins: string[],\n ) {\n super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);\n this._name = name;\n this._exposes = exposes;\n this._shareScope = shareScope;\n this._runtimePlugins = runtimePlugins;\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 //@ts-ignore\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 return `container entry (${this._shareScope}) ${JSON.stringify(\n this._exposes,\n )}`;\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 // @ts-ignore typeof webpack/lib !== typeof webpack/types\n override needBuild(\n context: NeedBuildContext,\n callback: (\n arg0: (WebpackError | null) | undefined,\n arg1: boolean | undefined,\n ) => void,\n ): void {\n const baseContext = context as NeedBuildContext;\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 // @ts-ignore typeof webpack/lib !== typeof webpack/types\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 //@ts-ignore\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 //@ts-ignore\n block.addDependency(dep);\n }\n //@ts-ignore\n this.addBlock(block);\n }\n //@ts-ignore\n this.addDependency(\n //@ts-ignore\n new StaticExportsDependency(\n ['get', 'init'],\n false,\n ) as unknown as Dependency,\n );\n\n this.addDependency(\n // @ts-ignore\n new EntryDependency(\n FederationRuntimePlugin.getFilePath(this._name, this._runtimePlugins),\n ),\n );\n\n callback();\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n //@ts-ignore\n override codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }) {\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 str = runtimeTemplate.throwMissingModuleErrorBlock({\n request: modules.map((m) => m.request).join(', '),\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 //@ts-ignore\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\n const initRuntimeDep = this.dependencies[1];\n const initRuntimeModuleGetter = runtimeTemplate.moduleRaw({\n module: moduleGraph.getModule(initRuntimeDep),\n chunkGraph,\n // @ts-expect-error\n request: initRuntimeDep.userRequest,\n weak: false,\n runtimeRequirements,\n });\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\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('shareScope, initScope', [\n `return ${federationGlobal}.bundlerRuntime.initContainerEntry({${Template.indent(\n [\n `webpackRequire: ${RuntimeGlobals.require},`,\n `shareScope: shareScope,`,\n `initScope: initScope,`,\n `shareScopeKey: ${JSON.stringify(this._shareScope)}`,\n ],\n )}`,\n '})',\n ])};`,\n `${initRuntimeModuleGetter}`,\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._runtimePlugins);\n super.serialize(context);\n }\n}\nmakeSerializable(\n ContainerEntryModule,\n 'enhanced/lib/container/ContainerEntryModule',\n);\n\nexport default ContainerEntryModule;\n"],"names":["makeSerializable","require","normalizeWebpackPath","sources","webpackSources","AsyncDependenciesBlock","Template","Module","RuntimeGlobals","StaticExportsDependency","EntryDependency","SOURCE_TYPES","Set","ContainerEntryModule","deserialize","context","read","obj","getSourceTypes","identifier","_shareScope","JSON","stringify","_exposes","readableIdentifier","requestShortener","libIdent","options","layer","_name","needBuild","callback","baseContext","buildMeta","build","compilation","resolver","fs","buildInfo","strict","topLevelDeclarations","exportsType","clearDependenciesAndBlocks","name","block","import","length","idx","request","dep","ContainerExposedDependency","loc","index","addDependency","addBlock","FederationRuntimePlugin","getFilePath","_runtimePlugins","codeGeneration","moduleGraph","chunkGraph","runtimeTemplate","Map","runtimeRequirements","definePropertyGetters","hasOwnProperty","exports","getters","blocks","dependencies","modules","map","dependency","exposedName","module","getModule","userRequest","str","some","m","throwMissingModuleErrorBlock","join","blockPromise","message","returningFunction","moduleRaw","weak","push","basicFunction","initRuntimeDep","initRuntimeModuleGetter","federationGlobal","getFederationGlobalScope","source","asString","indent","currentRemoteGetScope","set","useSourceMap","useSimpleSourceMap","OriginalSource","RawSource","size","type","serialize","write","constructor","exposes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Plugin = class ContainerPlugin {
|
|
|
112
112
|
compiler.options.output.enabledLibraryTypes.push(library.type);
|
|
113
113
|
}
|
|
114
114
|
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback)=>{
|
|
115
|
+
var _compilation_options_optimization, _compilation_options;
|
|
115
116
|
const dep = new _ContainerEntryDependency.default(name, //@ts-ignore
|
|
116
117
|
exposes, shareScope, runtimePlugins);
|
|
118
|
+
const hasSingleRuntimeChunk = (_compilation_options = compilation.options) == null ? void 0 : (_compilation_options_optimization = _compilation_options.optimization) == null ? void 0 : _compilation_options_optimization.runtimeChunk;
|
|
117
119
|
dep.loc = {
|
|
118
120
|
name
|
|
119
121
|
};
|
|
@@ -121,14 +123,16 @@ let ContainerPlugin = class ContainerPlugin {
|
|
|
121
123
|
dep, {
|
|
122
124
|
name,
|
|
123
125
|
filename,
|
|
124
|
-
runtime,
|
|
126
|
+
runtime: hasSingleRuntimeChunk ? false : runtime,
|
|
125
127
|
library
|
|
126
128
|
}, (error)=>{
|
|
127
129
|
if (error) return callback(error);
|
|
128
|
-
if (
|
|
130
|
+
if (hasSingleRuntimeChunk) {
|
|
129
131
|
// Add to single runtime chunk as well.
|
|
130
132
|
// Allows for singleton runtime graph with all needed runtime modules for federation
|
|
131
133
|
addEntryToSingleRuntimeChunk();
|
|
134
|
+
} else {
|
|
135
|
+
callback();
|
|
132
136
|
}
|
|
133
137
|
});
|
|
134
138
|
// Function to add entry for undefined runtime
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/ContainerPlugin.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*/\nimport {\n getWebpackPath,\n normalizeWebpackPath,\n} from '@module-federation/sdk/normalize-webpack-path';\nimport ContainerEntryDependency from './ContainerEntryDependency';\nimport ContainerEntryModuleFactory from './ContainerEntryModuleFactory';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport { parseOptions } from './options';\nimport type { optimize, Compiler, Compilation } from 'webpack';\nimport type { ContainerPluginOptions } from '../../declarations/plugins/container/ContainerPlugin';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport checkOptions from '../../schemas/container/ContainerPlugin.check';\nimport schema from '../../schemas/container/ContainerPlugin';\n\ntype ExcludeUndefined<T> = T extends undefined ? never : T;\ntype NonUndefined<T> = ExcludeUndefined<T>;\n\ntype OptimizationSplitChunksOptions = NonUndefined<\n ConstructorParameters<typeof optimize.SplitChunksPlugin>[0]\n>;\n\ntype CacheGroups = OptimizationSplitChunksOptions['cacheGroups'];\ntype CacheGroup = NonUndefined<CacheGroups>[string];\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\nconst validate = createSchemaValidation(checkOptions, () => schema, {\n name: 'Container Plugin',\n baseDataPath: 'options',\n});\n\nconst PLUGIN_NAME = 'ContainerPlugin';\n\nclass ContainerPlugin {\n _options: ContainerPluginOptions;\n name: string;\n /**\n * @param {ContainerPluginOptions} options options\n */\n constructor(options: ContainerPluginOptions) {\n validate(options);\n this.name = PLUGIN_NAME;\n this._options = {\n name: options.name,\n shareScope: options.shareScope || 'default',\n library: options.library || {\n type: 'var',\n name: options.name,\n },\n runtime: options.runtime,\n filename: options.filename || undefined,\n //@ts-ignore\n exposes: parseOptions(\n options.exposes,\n (item) => ({\n import: Array.isArray(item) ? item : [item],\n name: undefined,\n }),\n (item) => ({\n import: Array.isArray(item.import) ? item.import : [item.import],\n name: item.name || undefined,\n }),\n ),\n runtimePlugins: options.runtimePlugins,\n };\n }\n\n // container should not be affected by splitChunks\n static patchChunkSplit(compiler: Compiler, name: string): void {\n const { splitChunks } = compiler.options.optimization;\n const patchChunkSplit = (cacheGroup: CacheGroup) => {\n switch (typeof cacheGroup) {\n case 'boolean':\n case 'string':\n case 'function':\n break;\n // cacheGroup.chunks 会继承 splitChunks.chunks ,因此只需要对单独设置了 chunks 的 做修改\n case 'object':\n {\n if (cacheGroup instanceof RegExp) {\n break;\n }\n if (!cacheGroup.chunks) {\n break;\n }\n if (typeof cacheGroup.chunks === 'function') {\n const prevChunks = cacheGroup.chunks;\n cacheGroup.chunks = (chunk) => {\n if (chunk.name && chunk.name === name) {\n return false;\n }\n return prevChunks(chunk);\n };\n break;\n }\n\n if (cacheGroup.chunks === 'all') {\n cacheGroup.chunks = (chunk) => {\n if (chunk.name && chunk.name === name) {\n return false;\n }\n return true;\n };\n break;\n }\n if (cacheGroup.chunks === 'initial') {\n cacheGroup.chunks = (chunk) => {\n if (chunk.name && chunk.name === name) {\n return false;\n }\n return chunk.isOnlyInitial();\n };\n break;\n }\n }\n break;\n }\n };\n\n if (!splitChunks) {\n return;\n }\n // 修改 splitChunk.chunks\n patchChunkSplit(splitChunks);\n\n const cacheGroups = splitChunks.cacheGroups;\n if (!cacheGroups) {\n return;\n }\n\n // 修改 splitChunk.cacheGroups[key].chunks\n Object.keys(cacheGroups).forEach((cacheGroupKey) => {\n patchChunkSplit(cacheGroups[cacheGroupKey]);\n });\n }\n\n apply(compiler: Compiler): void {\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] || getWebpackPath(compiler);\n const useModuleFederationPlugin = compiler.options.plugins.find((p) => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ModuleFederationPlugin';\n });\n\n if (!useModuleFederationPlugin) {\n ContainerPlugin.patchChunkSplit(compiler, this._options.name);\n }\n\n new FederationRuntimePlugin().apply(compiler);\n\n const {\n name,\n exposes,\n shareScope,\n filename,\n library,\n runtime,\n runtimePlugins,\n } = this._options;\n\n if (\n library &&\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(PLUGIN_NAME, (compilation, callback) => {\n const dep = new ContainerEntryDependency(\n name,\n //@ts-ignore\n exposes,\n shareScope,\n runtimePlugins,\n );\n\n dep.loc = { name };\n compilation.addEntry(\n compilation.options.context || '',\n //@ts-ignore\n dep,\n {\n name,\n filename,\n runtime,\n library,\n },\n (error: WebpackError | null | undefined) => {\n if (error) return callback(error);\n if (compilation.options.optimization.runtimeChunk) {\n // Add to single runtime chunk as well.\n // Allows for singleton runtime graph with all needed runtime modules for federation\n addEntryToSingleRuntimeChunk();\n }\n },\n );\n\n // Function to add entry for undefined runtime\n const addEntryToSingleRuntimeChunk = () => {\n compilation.addEntry(\n compilation.options.context || '',\n //@ts-ignore\n dep,\n {\n name: name ? name + '_partial' : undefined, // give unique name name\n runtime: undefined,\n library,\n },\n (error: WebpackError | null | undefined) => {\n if (error) return callback(error);\n callback();\n },\n );\n };\n });\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n ContainerEntryDependency,\n //@ts-ignore\n new ContainerEntryModuleFactory(),\n );\n\n compilation.dependencyFactories.set(\n //@ts-ignore\n ContainerExposedDependency,\n normalModuleFactory,\n );\n },\n );\n }\n}\n\nexport default ContainerPlugin;\n"],"names":["createSchemaValidation","require","normalizeWebpackPath","validate","checkOptions","schema","name","baseDataPath","PLUGIN_NAME","ContainerPlugin","patchChunkSplit","compiler","splitChunks","options","optimization","cacheGroup","RegExp","chunks","prevChunks","chunk","isOnlyInitial","cacheGroups","Object","keys","forEach","cacheGroupKey","apply","process","env","getWebpackPath","useModuleFederationPlugin","plugins","find","p","_options","FederationRuntimePlugin","exposes","shareScope","filename","library","runtime","runtimePlugins","output","enabledLibraryTypes","includes","type","push","hooks","make","tapAsync","compilation","callback","dep","ContainerEntryDependency","loc","addEntry","context","error","runtimeChunk","addEntryToSingleRuntimeChunk","undefined","thisCompilation","tap","normalModuleFactory","dependencyFactories","set","ContainerEntryModuleFactory","ContainerExposedDependency","constructor","parseOptions","item","import","Array","isArray"],"mappings":"AAAA;;;AAGA;;;;+BAmPA;;;eAAA;;;sCA/OO;iFAC8B;oFACG;mFACD;yBACV;gFAGO;6EACX;wEACN;;;;;;AAYnB,MAAMA,yBAAyBC,QAC7BC,IAAAA,0CAAoB,EAAC;AAGvB,MAAMC,WAAWH,uBAAuBI,6BAAY,EAAE,IAAMC,wBAAM,EAAE;IAClEC,MAAM;IACNC,cAAc;AAChB;AAEA,MAAMC,cAAc;AAEpB,IAAA,AAAMC,kBAAN,MAAMA;IAkCJ,kDAAkD;IAClD,OAAOC,gBAAgBC,QAAkB,EAAEL,IAAY,EAAQ;QAC7D,MAAM,EAAEM,WAAW,EAAE,GAAGD,SAASE,OAAO,CAACC,YAAY;QACrD,MAAMJ,kBAAkB,CAACK;YACvB,OAAQ,OAAOA;gBACb,KAAK;gBACL,KAAK;gBACL,KAAK;oBACH;gBACF,sEAAsE;gBACtE,KAAK;oBACH;wBACE,IAAIA,sBAAsBC,QAAQ;4BAChC;wBACF;wBACA,IAAI,CAACD,WAAWE,MAAM,EAAE;4BACtB;wBACF;wBACA,IAAI,OAAOF,WAAWE,MAAM,KAAK,YAAY;4BAC3C,MAAMC,aAAaH,WAAWE,MAAM;4BACpCF,WAAWE,MAAM,GAAG,CAACE;gCACnB,IAAIA,MAAMb,IAAI,IAAIa,MAAMb,IAAI,KAAKA,MAAM;oCACrC,OAAO;gCACT;gCACA,OAAOY,WAAWC;4BACpB;4BACA;wBACF;wBAEA,IAAIJ,WAAWE,MAAM,KAAK,OAAO;4BAC/BF,WAAWE,MAAM,GAAG,CAACE;gCACnB,IAAIA,MAAMb,IAAI,IAAIa,MAAMb,IAAI,KAAKA,MAAM;oCACrC,OAAO;gCACT;gCACA,OAAO;4BACT;4BACA;wBACF;wBACA,IAAIS,WAAWE,MAAM,KAAK,WAAW;4BACnCF,WAAWE,MAAM,GAAG,CAACE;gCACnB,IAAIA,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,QAAQ0B,OAAO,IAAI;gBAC1BM,MAAM;gBACNvC,MAAMO,QAAQP,IAAI;YACpB;YACAkC,SAAS3B,QAAQ2B,OAAO;YACxBF,UAAUzB,QAAQyB,QAAQ,IAAIsB;YAC9B,YAAY;YACZxB,SAASiC,IAAAA,qBAAY,EACnBxD,QAAQuB,OAAO,EACf,CAACkC,OAAU,CAAA;oBACTC,QAAQC,MAAMC,OAAO,CAACH,QAAQA,OAAO;wBAACA;qBAAK;oBAC3ChE,MAAMsD;gBACR,CAAA,GACA,CAACU,OAAU,CAAA;oBACTC,QAAQC,MAAMC,OAAO,CAACH,KAAKC,MAAM,IAAID,KAAKC,MAAM,GAAG;wBAACD,KAAKC,MAAM;qBAAC;oBAChEjE,MAAMgE,KAAKhE,IAAI,IAAIsD;gBACrB,CAAA;YAEFnB,gBAAgB5B,QAAQ4B,cAAc;QACxC;IACF;AA6KF;MAEA,WAAehC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/ContainerPlugin.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*/\nimport {\n getWebpackPath,\n normalizeWebpackPath,\n} from '@module-federation/sdk/normalize-webpack-path';\nimport ContainerEntryDependency from './ContainerEntryDependency';\nimport ContainerEntryModuleFactory from './ContainerEntryModuleFactory';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport { parseOptions } from './options';\nimport type { optimize, Compiler, Compilation } from 'webpack';\nimport type { ContainerPluginOptions } from '../../declarations/plugins/container/ContainerPlugin';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport checkOptions from '../../schemas/container/ContainerPlugin.check';\nimport schema from '../../schemas/container/ContainerPlugin';\n\ntype ExcludeUndefined<T> = T extends undefined ? never : T;\ntype NonUndefined<T> = ExcludeUndefined<T>;\n\ntype OptimizationSplitChunksOptions = NonUndefined<\n ConstructorParameters<typeof optimize.SplitChunksPlugin>[0]\n>;\n\ntype CacheGroups = OptimizationSplitChunksOptions['cacheGroups'];\ntype CacheGroup = NonUndefined<CacheGroups>[string];\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\nconst validate = createSchemaValidation(checkOptions, () => schema, {\n name: 'Container Plugin',\n baseDataPath: 'options',\n});\n\nconst PLUGIN_NAME = 'ContainerPlugin';\n\nclass ContainerPlugin {\n _options: ContainerPluginOptions;\n name: string;\n /**\n * @param {ContainerPluginOptions} options options\n */\n constructor(options: ContainerPluginOptions) {\n validate(options);\n this.name = PLUGIN_NAME;\n this._options = {\n name: options.name,\n shareScope: options.shareScope || 'default',\n library: options.library || {\n type: 'var',\n name: options.name,\n },\n runtime: options.runtime,\n filename: options.filename || undefined,\n //@ts-ignore\n exposes: parseOptions(\n options.exposes,\n (item) => ({\n import: Array.isArray(item) ? item : [item],\n name: undefined,\n }),\n (item) => ({\n import: Array.isArray(item.import) ? item.import : [item.import],\n name: item.name || undefined,\n }),\n ),\n runtimePlugins: options.runtimePlugins,\n };\n }\n\n // container should not be affected by splitChunks\n static patchChunkSplit(compiler: Compiler, name: string): void {\n const { splitChunks } = compiler.options.optimization;\n const patchChunkSplit = (cacheGroup: CacheGroup) => {\n switch (typeof cacheGroup) {\n case 'boolean':\n case 'string':\n case 'function':\n break;\n // cacheGroup.chunks 会继承 splitChunks.chunks ,因此只需要对单独设置了 chunks 的 做修改\n case 'object':\n {\n if (cacheGroup instanceof RegExp) {\n break;\n }\n if (!cacheGroup.chunks) {\n break;\n }\n if (typeof cacheGroup.chunks === 'function') {\n const prevChunks = cacheGroup.chunks;\n cacheGroup.chunks = (chunk) => {\n if (chunk.name && chunk.name === name) {\n return false;\n }\n return prevChunks(chunk);\n };\n break;\n }\n\n if (cacheGroup.chunks === 'all') {\n cacheGroup.chunks = (chunk) => {\n if (chunk.name && chunk.name === name) {\n return false;\n }\n return true;\n };\n break;\n }\n if (cacheGroup.chunks === 'initial') {\n cacheGroup.chunks = (chunk) => {\n if (chunk.name && chunk.name === name) {\n return false;\n }\n return chunk.isOnlyInitial();\n };\n break;\n }\n }\n break;\n }\n };\n\n if (!splitChunks) {\n return;\n }\n // 修改 splitChunk.chunks\n patchChunkSplit(splitChunks);\n\n const cacheGroups = splitChunks.cacheGroups;\n if (!cacheGroups) {\n return;\n }\n\n // 修改 splitChunk.cacheGroups[key].chunks\n Object.keys(cacheGroups).forEach((cacheGroupKey) => {\n patchChunkSplit(cacheGroups[cacheGroupKey]);\n });\n }\n\n apply(compiler: Compiler): void {\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] || getWebpackPath(compiler);\n const useModuleFederationPlugin = compiler.options.plugins.find((p) => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ModuleFederationPlugin';\n });\n\n if (!useModuleFederationPlugin) {\n ContainerPlugin.patchChunkSplit(compiler, this._options.name);\n }\n\n new FederationRuntimePlugin().apply(compiler);\n\n const {\n name,\n exposes,\n shareScope,\n filename,\n library,\n runtime,\n runtimePlugins,\n } = this._options;\n\n if (\n library &&\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(PLUGIN_NAME, (compilation, callback) => {\n const dep = new ContainerEntryDependency(\n name,\n //@ts-ignore\n exposes,\n shareScope,\n runtimePlugins,\n );\n const hasSingleRuntimeChunk =\n compilation.options?.optimization?.runtimeChunk;\n dep.loc = { name };\n compilation.addEntry(\n compilation.options.context || '',\n //@ts-ignore\n dep,\n {\n name,\n filename,\n runtime: hasSingleRuntimeChunk ? false : runtime,\n library,\n },\n (error: WebpackError | null | undefined) => {\n if (error) return callback(error);\n if (hasSingleRuntimeChunk) {\n // Add to single runtime chunk as well.\n // Allows for singleton runtime graph with all needed runtime modules for federation\n addEntryToSingleRuntimeChunk();\n } else {\n callback();\n }\n },\n );\n\n // Function to add entry for undefined runtime\n const addEntryToSingleRuntimeChunk = () => {\n compilation.addEntry(\n compilation.options.context || '',\n //@ts-ignore\n dep,\n {\n name: name ? name + '_partial' : undefined, // give unique name name\n runtime: undefined,\n library,\n },\n (error: WebpackError | null | undefined) => {\n if (error) return callback(error);\n callback();\n },\n );\n };\n });\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n ContainerEntryDependency,\n //@ts-ignore\n new ContainerEntryModuleFactory(),\n );\n\n compilation.dependencyFactories.set(\n //@ts-ignore\n ContainerExposedDependency,\n normalModuleFactory,\n );\n },\n );\n }\n}\n\nexport default ContainerPlugin;\n"],"names":["createSchemaValidation","require","normalizeWebpackPath","validate","checkOptions","schema","name","baseDataPath","PLUGIN_NAME","ContainerPlugin","patchChunkSplit","compiler","splitChunks","options","optimization","cacheGroup","RegExp","chunks","prevChunks","chunk","isOnlyInitial","cacheGroups","Object","keys","forEach","cacheGroupKey","apply","process","env","getWebpackPath","useModuleFederationPlugin","plugins","find","p","_options","FederationRuntimePlugin","exposes","shareScope","filename","library","runtime","runtimePlugins","output","enabledLibraryTypes","includes","type","push","hooks","make","tapAsync","compilation","callback","dep","ContainerEntryDependency","hasSingleRuntimeChunk","runtimeChunk","loc","addEntry","context","error","addEntryToSingleRuntimeChunk","undefined","thisCompilation","tap","normalModuleFactory","dependencyFactories","set","ContainerEntryModuleFactory","ContainerExposedDependency","constructor","parseOptions","item","import","Array","isArray"],"mappings":"AAAA;;;AAGA;;;;+BAsPA;;;eAAA;;;sCAlPO;iFAC8B;oFACG;mFACD;yBACV;gFAGO;6EACX;wEACN;;;;;;AAYnB,MAAMA,yBAAyBC,QAC7BC,IAAAA,0CAAoB,EAAC;AAGvB,MAAMC,WAAWH,uBAAuBI,6BA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,IAAIuB;YAC9B,YAAY;YACZzB,SAASkC,IAAAA,qBAAY,EACnBzD,QAAQuB,OAAO,EACf,CAACmC,OAAU,CAAA;oBACTC,QAAQC,MAAMC,OAAO,CAACH,QAAQA,OAAO;wBAACA;qBAAK;oBAC3CjE,MAAMuD;gBACR,CAAA,GACA,CAACU,OAAU,CAAA;oBACTC,QAAQC,MAAMC,OAAO,CAACH,KAAKC,MAAM,IAAID,KAAKC,MAAM,GAAG;wBAACD,KAAKC,MAAM;qBAAC;oBAChElE,MAAMiE,KAAKjE,IAAI,IAAIuD;gBACrB,CAAA;YAEFpB,gBAAgB5B,QAAQ4B,cAAc;QACxC;IACF;AAgLF;MAEA,WAAehC"}
|
|
@@ -20,6 +20,8 @@ const _RemoteRuntimeModule = /*#__PURE__*/ _interop_require_default(require("./R
|
|
|
20
20
|
const _RemoteToExternalDependency = /*#__PURE__*/ _interop_require_default(require("./RemoteToExternalDependency"));
|
|
21
21
|
const _options = require("./options");
|
|
22
22
|
const _FederationRuntimePlugin = /*#__PURE__*/ _interop_require_default(require("./runtime/FederationRuntimePlugin"));
|
|
23
|
+
const _ContainerReferencePlugin = /*#__PURE__*/ _interop_require_default(require("../../schemas/container/ContainerReferencePlugin"));
|
|
24
|
+
const _ContainerReferencePlugincheck = /*#__PURE__*/ _interop_require_default(require("../../schemas/container/ContainerReferencePlugin.check"));
|
|
23
25
|
function _interop_require_default(obj) {
|
|
24
26
|
return obj && obj.__esModule ? obj : {
|
|
25
27
|
default: obj
|
|
@@ -28,7 +30,7 @@ function _interop_require_default(obj) {
|
|
|
28
30
|
const { ExternalsPlugin } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack'));
|
|
29
31
|
const createSchemaValidation = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/util/create-schema-validation'));
|
|
30
32
|
const validate = createSchemaValidation(//eslint-disable-next-line
|
|
31
|
-
|
|
33
|
+
_ContainerReferencePlugincheck.default, ()=>_ContainerReferencePlugin.default, {
|
|
32
34
|
name: 'Container Reference Plugin',
|
|
33
35
|
baseDataPath: 'options'
|
|
34
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/ContainerReferencePlugin.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\nimport type { Compiler } from 'webpack';\nimport {\n getWebpackPath,\n normalizeWebpackPath,\n} from '@module-federation/sdk/normalize-webpack-path';\n\n// import * as RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport FallbackDependency from './FallbackDependency';\nimport FallbackItemDependency from './FallbackItemDependency';\nimport FallbackModuleFactory from './FallbackModuleFactory';\nimport RemoteModule from './RemoteModule';\nimport RemoteRuntimeModule from './RemoteRuntimeModule';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport { parseOptions } from './options';\nimport {\n ExternalsType,\n ContainerReferencePluginOptions,\n RemotesConfig,\n} from '../../declarations/plugins/container/ContainerReferencePlugin';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\n\nconst { ExternalsPlugin } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\nconst validate = createSchemaValidation(\n //eslint-disable-next-line\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/ContainerReferencePlugin.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\nimport type { Compiler } from 'webpack';\nimport {\n getWebpackPath,\n normalizeWebpackPath,\n} from '@module-federation/sdk/normalize-webpack-path';\n\n// import * as RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport FallbackDependency from './FallbackDependency';\nimport FallbackItemDependency from './FallbackItemDependency';\nimport FallbackModuleFactory from './FallbackModuleFactory';\nimport RemoteModule from './RemoteModule';\nimport RemoteRuntimeModule from './RemoteRuntimeModule';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport { parseOptions } from './options';\nimport {\n ExternalsType,\n ContainerReferencePluginOptions,\n RemotesConfig,\n} from '../../declarations/plugins/container/ContainerReferencePlugin';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport schema from '../../schemas/container/ContainerReferencePlugin';\nimport checkOptions from '../../schemas/container/ContainerReferencePlugin.check';\n\nconst { ExternalsPlugin } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\nconst validate = createSchemaValidation(\n //eslint-disable-next-line\n checkOptions,\n () => schema,\n {\n name: 'Container Reference Plugin',\n baseDataPath: 'options',\n },\n);\n\nconst slashCode = '/'.charCodeAt(0);\n\nclass ContainerReferencePlugin {\n private _remoteType: ExternalsType;\n private _remotes: [string, RemotesConfig][];\n\n constructor(options: ContainerReferencePluginOptions) {\n validate(options);\n\n this._remoteType = options.remoteType;\n this._remotes = parseOptions(\n options.remotes,\n (item) => ({\n external: Array.isArray(item) ? item : [item],\n shareScope: options.shareScope || 'default',\n name: undefined,\n }),\n (item) => ({\n external: Array.isArray(item.external)\n ? item.external\n : [item.external],\n shareScope: item.shareScope || options.shareScope || 'default',\n name: item.name,\n }),\n );\n }\n\n /**\n * Apply the plugin\n * @param {Compiler} compiler the compiler instance\n * @returns {void}\n */\n apply(compiler: Compiler): void {\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] || getWebpackPath(compiler);\n\n const { _remotes: remotes, _remoteType: remoteType } = this;\n // @ts-ignore\n new FederationRuntimePlugin().apply(compiler);\n\n /** @type {Record<string, string>} */\n const remoteExternals: Record<string, string> = {};\n\n for (const [key, config] of remotes) {\n let i = 0;\n for (const external of config.external) {\n if (typeof external === 'string' && external.startsWith('internal ')) {\n continue;\n }\n remoteExternals[\n `webpack/container/reference/${key}${i ? `/fallback-${i}` : ''}`\n ] = external;\n i++;\n }\n }\n const Externals = compiler.webpack.ExternalsPlugin || ExternalsPlugin;\n new Externals(remoteType, remoteExternals).apply(compiler);\n\n compiler.hooks.compilation.tap(\n 'ContainerReferencePlugin',\n (compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n RemoteToExternalDependency,\n normalModuleFactory,\n );\n\n compilation.dependencyFactories.set(\n FallbackItemDependency,\n normalModuleFactory,\n );\n\n compilation.dependencyFactories.set(\n FallbackDependency,\n // @ts-ignore\n new FallbackModuleFactory(),\n );\n\n normalModuleFactory.hooks.factorize.tap(\n 'ContainerReferencePlugin',\n // @ts-ignore\n (data) => {\n if (!data.request.includes('!')) {\n for (const [key, config] of remotes) {\n if (\n data.request.startsWith(`${key}`) &&\n (data.request.length === key.length ||\n data.request.charCodeAt(key.length) === slashCode)\n ) {\n return new RemoteModule(\n data.request,\n //@ts-ignore\n config.external.map((external: any, i: any) =>\n external.startsWith('internal ')\n ? external.slice(9)\n : `webpack/container/reference/${key}${\n i ? `/fallback-${i}` : ''\n }`,\n ),\n `.${data.request.slice(key.length)}`,\n //@ts-ignore\n config.shareScope,\n config.name,\n );\n }\n }\n }\n },\n );\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.ensureChunkHandlers)\n .tap('ContainerReferencePlugin', (chunk, set) => {\n set.add(compiler.webpack.RuntimeGlobals.module);\n set.add(compiler.webpack.RuntimeGlobals.moduleFactoriesAddOnly);\n set.add(compiler.webpack.RuntimeGlobals.hasOwnProperty);\n set.add(compiler.webpack.RuntimeGlobals.initializeSharing);\n set.add(compiler.webpack.RuntimeGlobals.shareScopeMap);\n compilation.addRuntimeModule(chunk, new RemoteRuntimeModule());\n });\n },\n );\n }\n}\n\nexport default ContainerReferencePlugin;\n"],"names":["ExternalsPlugin","require","normalizeWebpackPath","createSchemaValidation","validate","checkOptions","schema","name","baseDataPath","slashCode","charCodeAt","ContainerReferencePlugin","apply","compiler","process","env","getWebpackPath","_remotes","remotes","_remoteType","remoteType","FederationRuntimePlugin","remoteExternals","key","config","i","external","startsWith","Externals","webpack","hooks","compilation","tap","normalModuleFactory","dependencyFactories","set","RemoteToExternalDependency","FallbackItemDependency","FallbackDependency","FallbackModuleFactory","factorize","data","request","includes","length","RemoteModule","map","slice","shareScope","runtimeRequirementInTree","for","RuntimeGlobals","ensureChunkHandlers","chunk","add","module","moduleFactoriesAddOnly","hasOwnProperty","initializeSharing","shareScopeMap","addRuntimeModule","RemoteRuntimeModule","constructor","options","parseOptions","item","Array","isArray","undefined"],"mappings":"AAAA;;;AAGA;;;;+BAsKA;;;eAAA;;;sCAjKO;2EAGwB;+EACI;8EACD;qEACT;4EACO;mFACO;yBACV;gFAMO;iFACjB;sFACM;;;;;;AAEzB,MAAM,EAAEA,eAAe,EAAE,GAAGC,QAC1BC,IAAAA,0CAAoB,EAAC;AAGvB,MAAMC,yBAAyBF,QAC7BC,IAAAA,0CAAoB,EAAC;AAGvB,MAAME,WAAWD,uBACf,0BAA0B;AAC1BE,sCAAY,EACZ,IAAMC,iCAAM,EACZ;IACEC,MAAM;IACNC,cAAc;AAChB;AAGF,MAAMC,YAAY,IAAIC,UAAU,CAAC;AAEjC,IAAA,AAAMC,2BAAN,MAAMA;IAyBJ;;;;GAIC,GACDC,MAAMC,QAAkB,EAAQ;QAC9BC,QAAQC,GAAG,CAAC,0BAA0B,GACpCD,QAAQC,GAAG,CAAC,0BAA0B,IAAIC,IAAAA,oCAAc,EAACH;QAE3D,MAAM,EAAEI,UAAUC,OAAO,EAAEC,aAAaC,UAAU,EAAE,GAAG,IAAI;QAC3D,aAAa;QACb,IAAIC,gCAAuB,GAAGT,KAAK,CAACC;QAEpC,mCAAmC,GACnC,MAAMS,kBAA0C,CAAC;Q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AAA;gBACTvC,UAAUwC,MAAMC,OAAO,CAACF,KAAKvC,QAAQ,IACjCuC,KAAKvC,QAAQ,GACb;oBAACuC,KAAKvC,QAAQ;iBAAC;gBACnBsB,YAAYiB,KAAKjB,UAAU,IAAIe,QAAQf,UAAU,IAAI;gBACrDzC,MAAM0D,KAAK1D,IAAI;YACjB,CAAA;IAEJ;AAiGF;MAEA,WAAeI"}
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "default", {
|
|
|
13
13
|
});
|
|
14
14
|
const _normalizewebpackpath = require("@module-federation/sdk/normalize-webpack-path");
|
|
15
15
|
const _FallbackItemDependency = /*#__PURE__*/ _interop_require_default(require("./FallbackItemDependency"));
|
|
16
|
+
const _Constants = require("../Constants");
|
|
16
17
|
function _interop_require_default(obj) {
|
|
17
18
|
return obj && obj.__esModule ? obj : {
|
|
18
19
|
default: obj
|
|
@@ -21,7 +22,6 @@ function _interop_require_default(obj) {
|
|
|
21
22
|
const { sources: webpackSources } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack'));
|
|
22
23
|
const { Template, Module, RuntimeGlobals } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack'));
|
|
23
24
|
const makeSerializable = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/util/makeSerializable'));
|
|
24
|
-
const { WEBPACK_MODULE_TYPE_FALLBACK } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/ModuleTypeConstants'));
|
|
25
25
|
const TYPES = new Set([
|
|
26
26
|
'javascript'
|
|
27
27
|
]);
|
|
@@ -144,7 +144,7 @@ let FallbackModule = class FallbackModule extends Module {
|
|
|
144
144
|
/**
|
|
145
145
|
* @param {string[]} requests list of requests to choose one
|
|
146
146
|
*/ constructor(requests){
|
|
147
|
-
super(WEBPACK_MODULE_TYPE_FALLBACK);
|
|
147
|
+
super(_Constants.WEBPACK_MODULE_TYPE_FALLBACK);
|
|
148
148
|
this.requests = requests;
|
|
149
149
|
this._identifier = `fallback ${this.requests.join(' ')}`;
|
|
150
150
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/FallbackModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\n\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { ChunkGraph, Chunk } from 'webpack';\nimport type {\n RequestShortener,\n LibIdentOptions,\n CodeGenerationContext,\n CodeGenerationResult,\n NeedBuildContext,\n WebpackError,\n ResolverWithOptions,\n InputFileSystem,\n Compilation,\n WebpackOptions,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n} from 'webpack/lib/Module';\nimport FallbackItemDependency from './FallbackItemDependency';\n\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { Template, Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\nconst { WEBPACK_MODULE_TYPE_FALLBACK } = require(\n normalizeWebpackPath('webpack/lib/ModuleTypeConstants'),\n) as typeof import('webpack/lib/ModuleTypeConstants');\n\nconst TYPES = new Set(['javascript']);\nconst RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);\n\nclass FallbackModule extends Module {\n public requests: string[];\n private _identifier: string;\n\n /**\n * @param {string[]} requests list of requests to choose one\n */\n constructor(requests: string[]) {\n super(WEBPACK_MODULE_TYPE_FALLBACK);\n this.requests = requests;\n this._identifier = `fallback ${this.requests.join(' ')}`;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n return this._identifier;\n }\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 this._identifier;\n }\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/fallback/${\n this.requests[0]\n }/and ${this.requests.length - 1} more`;\n }\n\n /**\n * @param {Chunk} chunk the chunk which condition should be checked\n * @param {Compilation} compilation the compilation\n * @returns {boolean} true, if the chunk is ok for the module\n */\n override chunkCondition(\n chunk: Chunk,\n { chunkGraph }: { chunkGraph: ChunkGraph },\n ): boolean {\n return chunkGraph.getNumberOfEntryModules(chunk) > 0;\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 // @ts-ignore\n override needBuild(\n context: NeedBuildContext,\n callback: (error: WebpackError | null, result?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\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 // @ts-ignore\n override build(\n options: WebpackOptions,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (error?: WebpackError) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n };\n\n this.clearDependenciesAndBlocks();\n for (const request of this.requests)\n this.addDependency(new FallbackItemDependency(request));\n\n callback();\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 this.requests.length * 5 + 42;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n // @ts-ignore\n override codeGeneration({\n runtimeTemplate,\n moduleGraph,\n chunkGraph,\n }: CodeGenerationContext): CodeGenerationResult {\n const ids = this.dependencies.map((dep) =>\n //@ts-ignore\n chunkGraph.getModuleId(moduleGraph.getModule(dep)),\n );\n const code = Template.asString([\n `var ids = ${JSON.stringify(ids)};`,\n 'var error, result, i = 0;',\n `var loop = ${runtimeTemplate.basicFunction('next', [\n 'while(i < ids.length) {',\n Template.indent([\n `try { next = ${RuntimeGlobals.require}(ids[i++]); } catch(e) { return handleError(e); }`,\n 'if(next) return next.then ? next.then(handleResult, handleError) : handleResult(next);',\n ]),\n '}',\n 'if(error) throw error;',\n ])}`,\n `var handleResult = ${runtimeTemplate.basicFunction('result', [\n 'if(result) return result;',\n 'return loop();',\n ])};`,\n `var handleError = ${runtimeTemplate.basicFunction('e', [\n 'error = e;',\n 'return loop();',\n ])};`,\n 'module.exports = loop();',\n ]);\n const sources = new Map();\n sources.set('javascript', new webpackSources.RawSource(code));\n return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS };\n }\n\n /**\n * @param {ObjectSerializerContext} context context\n */\n override serialize(context: ObjectSerializerContext): void {\n const { write } = context;\n write(this.requests);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {FallbackModule} deserialized fallback module\n */\n static deserialize(context: ObjectDeserializerContext): FallbackModule {\n const { read } = context;\n const obj = new FallbackModule(read());\n obj.deserialize(context);\n return obj;\n }\n}\n\nmakeSerializable(FallbackModule, 'enhanced/lib/container/FallbackModule');\n\nexport default FallbackModule;\n"],"names":["sources","webpackSources","require","normalizeWebpackPath","Template","Module","RuntimeGlobals","makeSerializable","WEBPACK_MODULE_TYPE_FALLBACK","TYPES","Set","RUNTIME_REQUIREMENTS","module","FallbackModule","identifier","_identifier","readableIdentifier","requestShortener","libIdent","options","layer","requests","length","chunkCondition","chunk","chunkGraph","getNumberOfEntryModules","needBuild","context","callback","buildInfo","build","compilation","resolver","fs","buildMeta","strict","clearDependenciesAndBlocks","request","addDependency","FallbackItemDependency","size","type","getSourceTypes","codeGeneration","runtimeTemplate","moduleGraph","ids","dependencies","map","dep","getModuleId","getModule","code","asString","JSON","stringify","basicFunction","indent","Map","set","RawSource","runtimeRequirements","serialize","write","deserialize","read","obj","constructor","join"],"mappings":"AAAA;;;AAGA,GAEA;;;;+BA8MA;;;eAAA;;;sCA5MqC;+EAgBF;;;;;;AAEnC,MAAM,EAAEA,SAASC,cAAc,EAAE,GAAGC,QAClCC,IAAAA,0CAAoB,EAAC;AAEvB,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,cAAc,EAAE,GAAGJ,QAC3CC,IAAAA,0CAAoB,EAAC;AAEvB,MAAMI,mBAAmBL,QACvBC,IAAAA,0CAAoB,EAAC;AAEvB,MAAM,EAAEK,4BAA4B,EAAE,GAAGN,QACvCC,IAAAA,0CAAoB,EAAC;AAGvB,MAAMM,QAAQ,IAAIC,IAAI;IAAC;CAAa;AACpC,MAAMC,uBAAuB,IAAID,IAAI;IAACJ,eAAeM,MAAM;CAAC;AAE5D,IAAA,AAAMC,iBAAN,MAAMA,uBAAuBR;IAa3B;;GAEC,GACD,AAASS,aAAqB;QAC5B,OAAO,IAAI,CAACC,WAAW;IACzB;IAEA;;;GAGC,GACD,AAASC,mBAAmBC,gBAAkC,EAAU;QACtE,OAAO,IAAI,CAACF,WAAW;IACzB;IAEA;;;GAGC,GACD,AAASG,SAASC,OAAwB,EAAiB;QACzD,OAAO,CAAC,EAAE,IAAI,CAACC,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,CAACA,KAAK,CAAC,EAAE,CAAC,GAAG,GAAG,2BAA2B,EACxE,IAAI,CAACC,QAAQ,CAAC,EAAE,CACjB,KAAK,EAAE,IAAI,CAACA,QAAQ,CAACC,MAAM,GAAG,EAAE,KAAK,CAAC;IACzC;IAEA;;;;GAIC,GACD,AAASC,eACPC,KAAY,EACZ,EAAEC,UAAU,EAA8B,EACjC;QACT,OAAOA,WAAWC,uBAAuB,CAACF,SAAS;IACrD;IAEA;;;;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EAAEZ,gBAAgBY,aAAa,CAAC,KAAK;gBACtD;gBACA;aACD,EAAE,CAAC,CAAC;YACL;SACD;QACD,MAAMzD,UAAU,IAAI2D;QACpB3D,QAAQ4D,GAAG,CAAC,cAAc,IAAI3D,eAAe4D,SAAS,CAACR;QACvD,OAAO;YAAErD;YAAS8D,qBAAqBnD;QAAqB;IAC9D;IAEA;;GAEC,GACD,AAASoD,UAAUnC,OAAgC,EAAQ;QACzD,MAAM,EAAEoC,KAAK,EAAE,GAAGpC;QAClBoC,MAAM,IAAI,CAAC3C,QAAQ;QACnB,KAAK,CAAC0C,UAAUnC;IAClB;IAEA;;;GAGC,GACD,OAAOqC,YAAYrC,OAAkC,EAAkB;QACrE,MAAM,EAAEsC,IAAI,EAAE,GAAGtC;QACjB,MAAMuC,MAAM,IAAItD,eAAeqD;QAC/BC,IAAIF,WAAW,CAACrC;QAChB,OAAOuC;IACT;IAjKA;;GAEC,GACDC,YAAY/C,QAAkB,CAAE;QAC9B,KAAK,CAACb;QACN,IAAI,CAACa,QAAQ,GAAGA;QAChB,IAAI,CAACN,WAAW,GAAG,CAAC,SAAS,EAAE,IAAI,CAACM,QAAQ,CAACgD,IAAI,CAAC,KAAK,CAAC;IAC1D;AA2JF;AAEA9D,iBAAiBM,gBAAgB;MAEjC,WAAeA"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/FallbackModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\n\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { ChunkGraph, Chunk } from 'webpack';\nimport type {\n RequestShortener,\n LibIdentOptions,\n CodeGenerationContext,\n CodeGenerationResult,\n NeedBuildContext,\n WebpackError,\n ResolverWithOptions,\n InputFileSystem,\n Compilation,\n WebpackOptions,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n} from 'webpack/lib/Module';\nimport FallbackItemDependency from './FallbackItemDependency';\nimport { WEBPACK_MODULE_TYPE_FALLBACK } from '../Constants';\n\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { Template, Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\n\nconst TYPES = new Set(['javascript']);\nconst RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);\n\nclass FallbackModule extends Module {\n public requests: string[];\n private _identifier: string;\n\n /**\n * @param {string[]} requests list of requests to choose one\n */\n constructor(requests: string[]) {\n super(WEBPACK_MODULE_TYPE_FALLBACK);\n this.requests = requests;\n this._identifier = `fallback ${this.requests.join(' ')}`;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n return this._identifier;\n }\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 this._identifier;\n }\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/fallback/${\n this.requests[0]\n }/and ${this.requests.length - 1} more`;\n }\n\n /**\n * @param {Chunk} chunk the chunk which condition should be checked\n * @param {Compilation} compilation the compilation\n * @returns {boolean} true, if the chunk is ok for the module\n */\n override chunkCondition(\n chunk: Chunk,\n { chunkGraph }: { chunkGraph: ChunkGraph },\n ): boolean {\n return chunkGraph.getNumberOfEntryModules(chunk) > 0;\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 // @ts-ignore\n override needBuild(\n context: NeedBuildContext,\n callback: (error: WebpackError | null, result?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\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 // @ts-ignore\n override build(\n options: WebpackOptions,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (error?: WebpackError) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n };\n\n this.clearDependenciesAndBlocks();\n for (const request of this.requests)\n this.addDependency(new FallbackItemDependency(request));\n\n callback();\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 this.requests.length * 5 + 42;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n // @ts-ignore\n override codeGeneration({\n runtimeTemplate,\n moduleGraph,\n chunkGraph,\n }: CodeGenerationContext): CodeGenerationResult {\n const ids = this.dependencies.map((dep) =>\n //@ts-ignore\n chunkGraph.getModuleId(moduleGraph.getModule(dep)),\n );\n const code = Template.asString([\n `var ids = ${JSON.stringify(ids)};`,\n 'var error, result, i = 0;',\n `var loop = ${runtimeTemplate.basicFunction('next', [\n 'while(i < ids.length) {',\n Template.indent([\n `try { next = ${RuntimeGlobals.require}(ids[i++]); } catch(e) { return handleError(e); }`,\n 'if(next) return next.then ? next.then(handleResult, handleError) : handleResult(next);',\n ]),\n '}',\n 'if(error) throw error;',\n ])}`,\n `var handleResult = ${runtimeTemplate.basicFunction('result', [\n 'if(result) return result;',\n 'return loop();',\n ])};`,\n `var handleError = ${runtimeTemplate.basicFunction('e', [\n 'error = e;',\n 'return loop();',\n ])};`,\n 'module.exports = loop();',\n ]);\n const sources = new Map();\n sources.set('javascript', new webpackSources.RawSource(code));\n return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS };\n }\n\n /**\n * @param {ObjectSerializerContext} context context\n */\n override serialize(context: ObjectSerializerContext): void {\n const { write } = context;\n write(this.requests);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {FallbackModule} deserialized fallback module\n */\n static deserialize(context: ObjectDeserializerContext): FallbackModule {\n const { read } = context;\n const obj = new FallbackModule(read());\n obj.deserialize(context);\n return obj;\n }\n}\n\nmakeSerializable(FallbackModule, 'enhanced/lib/container/FallbackModule');\n\nexport default FallbackModule;\n"],"names":["sources","webpackSources","require","normalizeWebpackPath","Template","Module","RuntimeGlobals","makeSerializable","TYPES","Set","RUNTIME_REQUIREMENTS","module","FallbackModule","identifier","_identifier","readableIdentifier","requestShortener","libIdent","options","layer","requests","length","chunkCondition","chunk","chunkGraph","getNumberOfEntryModules","needBuild","context","callback","buildInfo","build","compilation","resolver","fs","buildMeta","strict","clearDependenciesAndBlocks","request","addDependency","FallbackItemDependency","size","type","getSourceTypes","codeGeneration","runtimeTemplate","moduleGraph","ids","dependencies","map","dep","getModuleId","getModule","code","asString","JSON","stringify","basicFunction","indent","Map","set","RawSource","runtimeRequirements","serialize","write","deserialize","read","obj","constructor","WEBPACK_MODULE_TYPE_FALLBACK","join"],"mappings":"AAAA;;;AAGA,GAEA;;;;+BA4MA;;;eAAA;;;sCA1MqC;+EAgBF;2BACU;;;;;;AAE7C,MAAM,EAAEA,SAASC,cAAc,EAAE,GAAGC,QAClCC,IAAAA,0CAAoB,EAAC;AAEvB,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,cAAc,EAAE,GAAGJ,QAC3CC,IAAAA,0CAAoB,EAAC;AAEvB,MAAMI,mBAAmBL,QACvBC,IAAAA,0CAAoB,EAAC;AAGvB,MAAMK,QAAQ,IAAIC,IAAI;IAAC;CAAa;AACpC,MAAMC,uBAAuB,IAAID,IAAI;IAACH,eAAeK,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AC9B,KAAK,CAACgD,uCAA4B;QAClC,IAAI,CAAChD,QAAQ,GAAGA;QAChB,IAAI,CAACN,WAAW,GAAG,CAAC,SAAS,EAAE,IAAI,CAACM,QAAQ,CAACiD,IAAI,CAAC,KAAK,CAAC;IAC1D;AA2JF;AAEA9D,iBAAiBK,gBAAgB;MAEjC,WAAeA"}
|
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "default", {
|
|
|
14
14
|
const _normalizewebpackpath = require("@module-federation/sdk/normalize-webpack-path");
|
|
15
15
|
const _FallbackDependency = /*#__PURE__*/ _interop_require_default(require("./FallbackDependency"));
|
|
16
16
|
const _RemoteToExternalDependency = /*#__PURE__*/ _interop_require_default(require("./RemoteToExternalDependency"));
|
|
17
|
+
const _Constants = require("../Constants");
|
|
17
18
|
function _interop_require_default(obj) {
|
|
18
19
|
return obj && obj.__esModule ? obj : {
|
|
19
20
|
default: obj
|
|
@@ -21,7 +22,6 @@ function _interop_require_default(obj) {
|
|
|
21
22
|
}
|
|
22
23
|
const { sources: webpackSources } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack'));
|
|
23
24
|
const { Module, RuntimeGlobals } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack'));
|
|
24
|
-
const { WEBPACK_MODULE_TYPE_REMOTE } = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/ModuleTypeConstants'));
|
|
25
25
|
const makeSerializable = require((0, _normalizewebpackpath.normalizeWebpackPath)('webpack/lib/util/makeSerializable'));
|
|
26
26
|
const TYPES = new Set([
|
|
27
27
|
'remote',
|
|
@@ -143,7 +143,7 @@ let RemoteModule = class RemoteModule extends Module {
|
|
|
143
143
|
* @param {string} shareScope the used share scope name
|
|
144
144
|
* @param {string} remoteName The name of remote instance
|
|
145
145
|
*/ constructor(request, externalRequests, internalRequest, shareScope, remoteName){
|
|
146
|
-
super(WEBPACK_MODULE_TYPE_REMOTE);
|
|
146
|
+
super(_Constants.WEBPACK_MODULE_TYPE_REMOTE);
|
|
147
147
|
this.request = request;
|
|
148
148
|
this.externalRequests = externalRequests;
|
|
149
149
|
this.internalRequest = internalRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/RemoteModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compilation, WebpackOptionsNormalized } from 'webpack';\nimport type {\n CodeGenerationContext,\n CodeGenerationResult,\n LibIdentOptions,\n NeedBuildContext,\n WebpackError,\n} from 'webpack/lib/Module';\nimport FallbackDependency from './FallbackDependency';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport type { ResolverWithOptions } from 'webpack/lib/ResolverFactory';\nimport type { InputFileSystem } from 'webpack/lib/FileSystemInfo';\nimport type { RequestShortener } from 'webpack/lib/RuntimeModule';\nimport type { ObjectDeserializerContext } from 'webpack/lib/serialization/ObjectMiddleware';\n\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { WEBPACK_MODULE_TYPE_REMOTE } = require(\n normalizeWebpackPath('webpack/lib/ModuleTypeConstants'),\n) as typeof import('webpack/lib/ModuleTypeConstants');\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\n\nconst TYPES: Set<string> = new Set(['remote', 'share-init']);\nconst RUNTIME_REQUIREMENTS: Set<string> = new Set([RuntimeGlobals.module]);\n\nclass RemoteModule extends Module {\n private _identifier: string;\n public request: string;\n public externalRequests: string[];\n public internalRequest: string;\n public shareScope: string;\n public remoteName: string;\n\n /**\n * @param {string} request request string\n * @param {string[]} externalRequests list of external requests to containers\n * @param {string} internalRequest name of exposed module in container\n * @param {string} shareScope the used share scope name\n * @param {string} remoteName The name of remote instance\n */\n constructor(\n request: string,\n externalRequests: string[],\n internalRequest: string,\n shareScope: string,\n remoteName: string,\n ) {\n super(WEBPACK_MODULE_TYPE_REMOTE);\n this.request = request;\n this.externalRequests = externalRequests;\n this.internalRequest = internalRequest;\n this.shareScope = shareScope;\n this._identifier = `remote (${shareScope}) ${this.externalRequests.join(\n ' ',\n )} ${this.internalRequest}`;\n this.remoteName = remoteName;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n return this._identifier;\n }\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 `remote ${this.request}`;\n }\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/remote/${\n this.request\n }`;\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 // @ts-ignore\n override needBuild(\n context: NeedBuildContext,\n callback: (err: WebpackError | null, needsRebuild?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\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 // @ts-ignore\n override build(\n options: WebpackOptionsNormalized,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (err?: WebpackError | undefined) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n };\n\n this.clearDependenciesAndBlocks();\n if (this.externalRequests.length === 1) {\n this.addDependency(\n new RemoteToExternalDependency(this.externalRequests[0]),\n );\n } else {\n this.addDependency(new FallbackDependency(this.externalRequests));\n }\n\n callback();\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 6;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n /**\n * @returns {string | null} absolute path which should be used for condition matching (usually the resource path)\n */\n override nameForCondition(): string | null {\n return this.request;\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n // @ts-ignore\n override codeGeneration(\n context: CodeGenerationContext,\n ): CodeGenerationResult {\n const { runtimeTemplate, moduleGraph, chunkGraph } = context;\n // @ts-ignore\n const module = moduleGraph.getModule(this.dependencies[0]);\n const id = module && chunkGraph.getModuleId(module);\n const sources = new Map();\n sources.set('remote', new webpackSources.RawSource(''));\n const data = new Map();\n data.set('share-init', [\n {\n shareScope: this.shareScope,\n initStage: 20,\n init: id === undefined ? '' : `initExternal(${JSON.stringify(id)});`,\n },\n ]);\n return { sources, data, runtimeRequirements: RUNTIME_REQUIREMENTS };\n }\n override serialize(context: any) {\n const { write } = context;\n write(this.request);\n write(this.externalRequests);\n write(this.internalRequest);\n write(this.shareScope);\n write(this.remoteName);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {RemoteModule} deserialized module\n */\n static deserialize(context: ObjectDeserializerContext): RemoteModule {\n const { read } = context;\n const obj = new RemoteModule(read(), read(), read(), read(), read());\n obj.deserialize(context);\n return obj;\n }\n}\n\nmakeSerializable(RemoteModule, 'enhanced/lib/container/RemoteModule');\n\nexport default RemoteModule;\n"],"names":["sources","webpackSources","require","normalizeWebpackPath","Module","RuntimeGlobals","WEBPACK_MODULE_TYPE_REMOTE","makeSerializable","TYPES","Set","RUNTIME_REQUIREMENTS","module","RemoteModule","identifier","_identifier","readableIdentifier","requestShortener","request","libIdent","options","layer","needBuild","context","callback","buildInfo","build","compilation","resolver","fs","buildMeta","strict","clearDependenciesAndBlocks","externalRequests","length","addDependency","RemoteToExternalDependency","FallbackDependency","size","type","getSourceTypes","nameForCondition","codeGeneration","runtimeTemplate","moduleGraph","chunkGraph","getModule","dependencies","id","getModuleId","Map","set","RawSource","data","shareScope","initStage","init","undefined","JSON","stringify","runtimeRequirements","serialize","write","internalRequest","remoteName","deserialize","read","obj","constructor","join"],"mappings":"AAAA;;;AAGA;;;;+BA+MA;;;eAAA;;;sCA9MqC;2EASN;mFACQ;;;;;;AAMvC,MAAM,EAAEA,SAASC,cAAc,EAAE,GAAGC,QAClCC,IAAAA,0CAAoB,EAAC;AAEvB,MAAM,EAAEC,MAAM,EAAEC,cAAc,EAAE,GAAGH,QACjCC,IAAAA,0CAAoB,EAAC;AAEvB,MAAM,EAAEG,0BAA0B,EAAE,GAAGJ,QACrCC,IAAAA,0CAAoB,EAAC;AAEvB,MAAMI,mBAAmBL,QACvBC,IAAAA,0CAAoB,EAAC;AAGvB,MAAMK,QAAqB,IAAIC,IAAI;IAAC;IAAU;CAAa;AAC3D,MAAMC,uBAAoC,IAAID,IAAI;IAACJ,eAAeM,MAAM;CAAC;AAEzE,IAAA,AAAMC,eAAN,MAAMA,qBAAqBR;IAiCzB;;GAEC,GACD,AAASS,aAAqB;QAC5B,OAAO,IAAI,CAACC,WAAW;IACzB;IAEA;;;GAGC,GACD,AAASC,mBAAmBC,gBAAkC,EAAU;QACtE,OAAO,CAAC,OAAO,EAAE,IAAI,CAACC,OAAO,CAAC,CAAC;IACjC;IAEA;;;GAGC,GACD,AAASC,SAASC,OAAwB,EAAiB;QACzD,OAAO,CAAC,EAAE,IAAI,CAACC,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,CAACA,KAAK,CAAC,EAAE,CAAC,GAAG,GAAG,yBAAyB,EACtE,IAAI,CAACH,OAAO,CACb,CAAC;IACJ;IAEA;;;;GAIC,GACD,aAAa;IACJI,UACPC,OAAyB,EACzBC,QAAoE,EAC9D;QACNA,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E,CAAC;YACtE;SACD;QACD,OAAO;YAAE/C;YAASoD;YAAMO,qBAAqBjD;QAAqB;IACpE;IACSkD,UAAUtC,OAAY,EAAE;QAC/B,MAAM,EAAEuC,KAAK,EAAE,GAAGvC;QAClBuC,MAAM,IAAI,CAAC5C,OAAO;QAClB4C,MAAM,IAAI,CAAC7B,gBAAgB;QAC3B6B,MAAM,IAAI,CAACC,eAAe;QAC1BD,MAAM,IAAI,CAACR,UAAU;QACrBQ,MAAM,IAAI,CAACE,UAAU;QACrB,KAAK,CAACH,UAAUtC;IAClB;IAEA;;;GAGC,GACD,OAAO0C,YAAY1C,OAAkC,EAAgB;QACnE,MAAM,EAAE2C,IAAI,EAAE,GAAG3C;QACjB,MAAM4C,MAAM,IAAItD,aAAaqD,QAAQA,QAAQA,QAAQA,QAAQA;QAC7DC,IAAIF,WAAW,CAAC1C;QAChB,OAAO4C;IACT;IAjKA;;;;;;GAMC,GACDC,YACElD,OAAe,EACfe,gBAA0B,EAC1B8B,eAAuB,EACvBT,UAAkB,EAClBU,UAAkB,CAClB;QACA,KAAK,CAACzD;QACN,IAAI,CAACW,OAAO,GAAGA;QACf,IAAI,CAACe,gBAAgB,GAAGA;QACxB,IAAI,CAAC8B,eAAe,GAAGA;QACvB,IAAI,CAACT,UAAU,GAAGA;QAClB,IAAI,CAACvC,WAAW,GAAG,CAAC,QAAQ,EAAEuC,WAAW,EAAE,EAAE,IAAI,CAACrB,gBAAgB,CAACoC,IAAI,CACrE,KACA,CAAC,EAAE,IAAI,CAACN,eAAe,CAAC,CAAC;QAC3B,IAAI,CAACC,UAAU,GAAGA;IACpB;AA2IF;AAEAxD,iBAAiBK,cAAc;MAE/B,WAAeA"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/RemoteModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compilation, WebpackOptionsNormalized } from 'webpack';\nimport type {\n CodeGenerationContext,\n CodeGenerationResult,\n LibIdentOptions,\n NeedBuildContext,\n WebpackError,\n} from 'webpack/lib/Module';\nimport FallbackDependency from './FallbackDependency';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport { WEBPACK_MODULE_TYPE_REMOTE } from '../Constants';\nimport type { ResolverWithOptions } from 'webpack/lib/ResolverFactory';\nimport type { InputFileSystem } from 'webpack/lib/FileSystemInfo';\nimport type { RequestShortener } from 'webpack/lib/RuntimeModule';\nimport type { ObjectDeserializerContext } from 'webpack/lib/serialization/ObjectMiddleware';\n\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\n\nconst TYPES: Set<string> = new Set(['remote', 'share-init']);\nconst RUNTIME_REQUIREMENTS: Set<string> = new Set([RuntimeGlobals.module]);\n\nclass RemoteModule extends Module {\n private _identifier: string;\n public request: string;\n public externalRequests: string[];\n public internalRequest: string;\n public shareScope: string;\n public remoteName: string;\n\n /**\n * @param {string} request request string\n * @param {string[]} externalRequests list of external requests to containers\n * @param {string} internalRequest name of exposed module in container\n * @param {string} shareScope the used share scope name\n * @param {string} remoteName The name of remote instance\n */\n constructor(\n request: string,\n externalRequests: string[],\n internalRequest: string,\n shareScope: string,\n remoteName: string,\n ) {\n super(WEBPACK_MODULE_TYPE_REMOTE);\n this.request = request;\n this.externalRequests = externalRequests;\n this.internalRequest = internalRequest;\n this.shareScope = shareScope;\n this._identifier = `remote (${shareScope}) ${this.externalRequests.join(\n ' ',\n )} ${this.internalRequest}`;\n this.remoteName = remoteName;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n return this._identifier;\n }\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 `remote ${this.request}`;\n }\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/remote/${\n this.request\n }`;\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 // @ts-ignore\n override needBuild(\n context: NeedBuildContext,\n callback: (err: WebpackError | null, needsRebuild?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\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 // @ts-ignore\n override build(\n options: WebpackOptionsNormalized,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (err?: WebpackError | undefined) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n };\n\n this.clearDependenciesAndBlocks();\n if (this.externalRequests.length === 1) {\n this.addDependency(\n new RemoteToExternalDependency(this.externalRequests[0]),\n );\n } else {\n this.addDependency(new FallbackDependency(this.externalRequests));\n }\n\n callback();\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 6;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n /**\n * @returns {string | null} absolute path which should be used for condition matching (usually the resource path)\n */\n override nameForCondition(): string | null {\n return this.request;\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n // @ts-ignore\n override codeGeneration(\n context: CodeGenerationContext,\n ): CodeGenerationResult {\n const { runtimeTemplate, moduleGraph, chunkGraph } = context;\n // @ts-ignore\n const module = moduleGraph.getModule(this.dependencies[0]);\n const id = module && chunkGraph.getModuleId(module);\n const sources = new Map();\n sources.set('remote', new webpackSources.RawSource(''));\n const data = new Map();\n data.set('share-init', [\n {\n shareScope: this.shareScope,\n initStage: 20,\n init: id === undefined ? '' : `initExternal(${JSON.stringify(id)});`,\n },\n ]);\n return { sources, data, runtimeRequirements: RUNTIME_REQUIREMENTS };\n }\n override serialize(context: any) {\n const { write } = context;\n write(this.request);\n write(this.externalRequests);\n write(this.internalRequest);\n write(this.shareScope);\n write(this.remoteName);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {RemoteModule} deserialized module\n */\n static deserialize(context: ObjectDeserializerContext): RemoteModule {\n const { read } = context;\n const obj = new RemoteModule(read(), read(), read(), read(), read());\n obj.deserialize(context);\n return obj;\n }\n}\n\nmakeSerializable(RemoteModule, 'enhanced/lib/container/RemoteModule');\n\nexport default RemoteModule;\n"],"names":["sources","webpackSources","require","normalizeWebpackPath","Module","RuntimeGlobals","makeSerializable","TYPES","Set","RUNTIME_REQUIREMENTS","module","RemoteModule","identifier","_identifier","readableIdentifier","requestShortener","request","libIdent","options","layer","needBuild","context","callback","buildInfo","build","compilation","resolver","fs","buildMeta","strict","clearDependenciesAndBlocks","externalRequests","length","addDependency","RemoteToExternalDependency","FallbackDependency","size","type","getSourceTypes","nameForCondition","codeGeneration","runtimeTemplate","moduleGraph","chunkGraph","getModule","dependencies","id","getModuleId","Map","set","RawSource","data","shareScope","initStage","init","undefined","JSON","stringify","runtimeRequirements","serialize","write","internalRequest","remoteName","deserialize","read","obj","constructor","WEBPACK_MODULE_TYPE_REMOTE","join"],"mappings":"AAAA;;;AAGA;;;;+BA6MA;;;eAAA;;;sCA5MqC;2EASN;mFACQ;2BACI;;;;;;AAM3C,MAAM,EAAEA,SAASC,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,IAAI,EAAE,GAAG3C;QACjB,MAAM4C,MAAM,IAAItD,aAAaqD,QAAQA,QAAQA,QAAQA,QAAQA;QAC7DC,IAAIF,WAAW,CAAC1C;QAChB,OAAO4C;IACT;IAjKA;;;;;;GAMC,GACDC,YACElD,OAAe,EACfe,gBAA0B,EAC1B8B,eAAuB,EACvBT,UAAkB,EAClBU,UAAkB,CAClB;QACA,KAAK,CAACK,qCAA0B;QAChC,IAAI,CAACnD,OAAO,GAAGA;QACf,IAAI,CAACe,gBAAgB,GAAGA;QACxB,IAAI,CAAC8B,eAAe,GAAGA;QACvB,IAAI,CAACT,UAAU,GAAGA;QAClB,IAAI,CAACvC,WAAW,GAAG,CAAC,QAAQ,EAAEuC,WAAW,EAAE,EAAE,IAAI,CAACrB,gBAAgB,CAACqC,IAAI,CACrE,KACA,CAAC,EAAE,IAAI,CAACP,eAAe,CAAC,CAAC;QAC3B,IAAI,CAACC,UAAU,GAAGA;IACpB;AA2IF;AAEAxD,iBAAiBK,cAAc;MAE/B,WAAeA"}
|
|
@@ -80,7 +80,7 @@ let RemoteRuntimeModule = class RemoteRuntimeModule extends RuntimeModule {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
const federationGlobal = (0, _utils.getFederationGlobalScope)(RuntimeGlobals);
|
|
83
|
+
const federationGlobal = (0, _utils.getFederationGlobalScope)(RuntimeGlobals || {});
|
|
84
84
|
return Template.asString([
|
|
85
85
|
`var chunkMapping = ${JSON.stringify(chunkToRemotesMapping, null, '\t')};`,
|
|
86
86
|
`var idToExternalAndNameMapping = ${JSON.stringify(idToExternalAndNameMapping, null, '\t')};`,
|