@module-federation/enhanced 0.0.0-canary-1701764602388
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/global.d.js +14 -0
- package/global.d.js.map +1 -0
- package/package.json +19 -0
- package/src/declarations/plugins/container/AsyncDependenciesBlock.d.js +14 -0
- package/src/declarations/plugins/container/AsyncDependenciesBlock.d.js.map +1 -0
- package/src/declarations/plugins/container/ContainerPlugin.d.js +12 -0
- package/src/declarations/plugins/container/ContainerPlugin.d.js.map +1 -0
- package/src/declarations/plugins/container/ContainerReferencePlugin.d.js +12 -0
- package/src/declarations/plugins/container/ContainerReferencePlugin.d.js.map +1 -0
- package/src/declarations/plugins/container/Dependency.d.js +14 -0
- package/src/declarations/plugins/container/Dependency.d.js.map +1 -0
- package/src/declarations/plugins/container/Module.d.js +3 -0
- package/src/declarations/plugins/container/Module.d.js.map +1 -0
- package/src/declarations/plugins/container/ModuleFactory.d.js +3 -0
- package/src/declarations/plugins/container/ModuleFactory.d.js.map +1 -0
- package/src/declarations/plugins/container/ModuleFederationPlugin.d.js +12 -0
- package/src/declarations/plugins/container/ModuleFederationPlugin.d.js.map +1 -0
- package/src/declarations/plugins/container/ObjectDeserializerContext.d.js +6 -0
- package/src/declarations/plugins/container/ObjectDeserializerContext.d.js.map +1 -0
- package/src/declarations/plugins/container/StaticExportsDependency.d.js +14 -0
- package/src/declarations/plugins/container/StaticExportsDependency.d.js.map +1 -0
- package/src/declarations/plugins/container/Template.d.js +4 -0
- package/src/declarations/plugins/container/Template.d.js.map +1 -0
- package/src/declarations/plugins/container/WebpackError.d.js +3 -0
- package/src/declarations/plugins/container/WebpackError.d.js.map +1 -0
- package/src/declarations/plugins/container/WebpackOptions.d.js +6 -0
- package/src/declarations/plugins/container/WebpackOptions.d.js.map +1 -0
- package/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.js +12 -0
- package/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.js.map +1 -0
- package/src/declarations/plugins/sharing/ProvideSharedPlugin.d.js +12 -0
- package/src/declarations/plugins/sharing/ProvideSharedPlugin.d.js.map +1 -0
- package/src/declarations/plugins/sharing/SharePlugin.d.js +12 -0
- package/src/declarations/plugins/sharing/SharePlugin.d.js.map +1 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +43 -0
- package/src/index.js.map +1 -0
- package/src/lib/Constants.d.ts +117 -0
- package/src/lib/Constants.js +103 -0
- package/src/lib/Constants.js.map +1 -0
- package/src/lib/RuntimeGlobals.d.ts +0 -0
- package/src/lib/RuntimeGlobals.js +246 -0
- package/src/lib/RuntimeGlobals.js.map +1 -0
- package/src/lib/container/AsyncBoundaryPlugin.d.ts +21 -0
- package/src/lib/container/AsyncBoundaryPlugin.js +180 -0
- package/src/lib/container/AsyncBoundaryPlugin.js.map +1 -0
- package/src/lib/container/ContainerEntryDependency.d.js +4 -0
- package/src/lib/container/ContainerEntryDependency.d.js.map +1 -0
- package/src/lib/container/ContainerEntryDependency.d.ts +22 -0
- package/src/lib/container/ContainerEntryDependency.js +45 -0
- package/src/lib/container/ContainerEntryDependency.js.map +1 -0
- package/src/lib/container/ContainerEntryModule.d.js +14 -0
- package/src/lib/container/ContainerEntryModule.d.js.map +1 -0
- package/src/lib/container/ContainerEntryModule.d.ts +86 -0
- package/src/lib/container/ContainerEntryModule.js +260 -0
- package/src/lib/container/ContainerEntryModule.js.map +1 -0
- package/src/lib/container/ContainerEntryModuleFactory.d.js +4 -0
- package/src/lib/container/ContainerEntryModuleFactory.d.js.map +1 -0
- package/src/lib/container/ContainerEntryModuleFactory.d.ts +10 -0
- package/src/lib/container/ContainerEntryModuleFactory.js +32 -0
- package/src/lib/container/ContainerEntryModuleFactory.js.map +1 -0
- package/src/lib/container/ContainerExposedDependency.d.js +4 -0
- package/src/lib/container/ContainerExposedDependency.d.js.map +1 -0
- package/src/lib/container/ContainerExposedDependency.d.ts +26 -0
- package/src/lib/container/ContainerExposedDependency.js +53 -0
- package/src/lib/container/ContainerExposedDependency.js.map +1 -0
- package/src/lib/container/ContainerPlugin.d.js +4 -0
- package/src/lib/container/ContainerPlugin.d.js.map +1 -0
- package/src/lib/container/ContainerPlugin.d.ts +13 -0
- package/src/lib/container/ContainerPlugin.js +167 -0
- package/src/lib/container/ContainerPlugin.js.map +1 -0
- package/src/lib/container/ContainerReferencePlugin.d.js +4 -0
- package/src/lib/container/ContainerReferencePlugin.d.js.map +1 -0
- package/src/lib/container/ContainerReferencePlugin.d.ts +14 -0
- package/src/lib/container/ContainerReferencePlugin.js +102 -0
- package/src/lib/container/ContainerReferencePlugin.js.map +1 -0
- package/src/lib/container/FallbackDependency.d.js +14 -0
- package/src/lib/container/FallbackDependency.d.js.map +1 -0
- package/src/lib/container/FallbackDependency.d.ts +25 -0
- package/src/lib/container/FallbackDependency.js +55 -0
- package/src/lib/container/FallbackDependency.js.map +1 -0
- package/src/lib/container/FallbackItemDependency.d.js +4 -0
- package/src/lib/container/FallbackItemDependency.d.js.map +1 -0
- package/src/lib/container/FallbackItemDependency.d.ts +10 -0
- package/src/lib/container/FallbackItemDependency.js +33 -0
- package/src/lib/container/FallbackItemDependency.js.map +1 -0
- package/src/lib/container/FallbackModule.d.js +4 -0
- package/src/lib/container/FallbackModule.d.js.map +1 -0
- package/src/lib/container/FallbackModule.d.ts +73 -0
- package/src/lib/container/FallbackModule.js +149 -0
- package/src/lib/container/FallbackModule.js.map +1 -0
- package/src/lib/container/FallbackModuleFactory.d.js +4 -0
- package/src/lib/container/FallbackModuleFactory.d.js.map +1 -0
- package/src/lib/container/FallbackModuleFactory.d.ts +10 -0
- package/src/lib/container/FallbackModuleFactory.js +30 -0
- package/src/lib/container/FallbackModuleFactory.js.map +1 -0
- package/src/lib/container/HoistContainerReferencesPlugin.d.ts +19 -0
- package/src/lib/container/HoistContainerReferencesPlugin.js +78 -0
- package/src/lib/container/HoistContainerReferencesPlugin.js.map +1 -0
- package/src/lib/container/ModuleFederationPlugin.d.js +4 -0
- package/src/lib/container/ModuleFederationPlugin.d.js.map +1 -0
- package/src/lib/container/ModuleFederationPlugin.d.ts +17 -0
- package/src/lib/container/ModuleFederationPlugin.js +93 -0
- package/src/lib/container/ModuleFederationPlugin.js.map +1 -0
- package/src/lib/container/ModuleFederationPluginTypes.d.js +12 -0
- package/src/lib/container/ModuleFederationPluginTypes.d.js.map +1 -0
- package/src/lib/container/RemoteModule.d.js +13 -0
- package/src/lib/container/RemoteModule.d.js.map +1 -0
- package/src/lib/container/RemoteModule.d.ts +78 -0
- package/src/lib/container/RemoteModule.js +150 -0
- package/src/lib/container/RemoteModule.js.map +1 -0
- package/src/lib/container/RemoteRuntimeModule.d.js +13 -0
- package/src/lib/container/RemoteRuntimeModule.d.js.map +1 -0
- package/src/lib/container/RemoteRuntimeModule.d.ts +9 -0
- package/src/lib/container/RemoteRuntimeModule.js +98 -0
- package/src/lib/container/RemoteRuntimeModule.js.map +1 -0
- package/src/lib/container/RemoteToExternalDependency.d.js +15 -0
- package/src/lib/container/RemoteToExternalDependency.d.js.map +1 -0
- package/src/lib/container/RemoteToExternalDependency.d.ts +10 -0
- package/src/lib/container/RemoteToExternalDependency.js +33 -0
- package/src/lib/container/RemoteToExternalDependency.js.map +1 -0
- package/src/lib/container/constant.d.ts +3 -0
- package/src/lib/container/constant.js +26 -0
- package/src/lib/container/constant.js.map +1 -0
- package/src/lib/container/options.d.js +6 -0
- package/src/lib/container/options.d.js.map +1 -0
- package/src/lib/container/options.d.ts +18 -0
- package/src/lib/container/options.js +91 -0
- package/src/lib/container/options.js.map +1 -0
- package/src/lib/container/runtime/FederationRuntimeEntryDependency.d.ts +7 -0
- package/src/lib/container/runtime/FederationRuntimeEntryDependency.js +37 -0
- package/src/lib/container/runtime/FederationRuntimeEntryDependency.js.map +1 -0
- package/src/lib/container/runtime/FederationRuntimeModule.d.ts +13 -0
- package/src/lib/container/runtime/FederationRuntimeModule.js +31 -0
- package/src/lib/container/runtime/FederationRuntimeModule.js.map +1 -0
- package/src/lib/container/runtime/FederationRuntimePlugin.d.ts +17 -0
- package/src/lib/container/runtime/FederationRuntimePlugin.js +223 -0
- package/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -0
- package/src/lib/container/runtime/InitializeRemoteEntryRuntimePlugin.d.ts +6 -0
- package/src/lib/container/runtime/InitializeRemoteEntryRuntimePlugin.js +26 -0
- package/src/lib/container/runtime/InitializeRemoteEntryRuntimePlugin.js.map +1 -0
- package/src/lib/container/runtime/getFederationGlobal.d.ts +5 -0
- package/src/lib/container/runtime/getFederationGlobal.js +42 -0
- package/src/lib/container/runtime/getFederationGlobal.js.map +1 -0
- package/src/lib/container/runtime/utils.d.ts +15 -0
- package/src/lib/container/runtime/utils.js +95 -0
- package/src/lib/container/runtime/utils.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedFallbackDependency.d.js +4 -0
- package/src/lib/sharing/ConsumeSharedFallbackDependency.d.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedFallbackDependency.d.ts +10 -0
- package/src/lib/sharing/ConsumeSharedFallbackDependency.js +33 -0
- package/src/lib/sharing/ConsumeSharedFallbackDependency.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedModule.d.js +4 -0
- package/src/lib/sharing/ConsumeSharedModule.d.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedModule.d.ts +106 -0
- package/src/lib/sharing/ConsumeSharedModule.js +195 -0
- package/src/lib/sharing/ConsumeSharedModule.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedPlugin.d.js +4 -0
- package/src/lib/sharing/ConsumeSharedPlugin.d.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedPlugin.d.ts +8 -0
- package/src/lib/sharing/ConsumeSharedPlugin.js +225 -0
- package/src/lib/sharing/ConsumeSharedPlugin.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedRuntimeModule.d.js +4 -0
- package/src/lib/sharing/ConsumeSharedRuntimeModule.d.js.map +1 -0
- package/src/lib/sharing/ConsumeSharedRuntimeModule.d.ts +13 -0
- package/src/lib/sharing/ConsumeSharedRuntimeModule.js +310 -0
- package/src/lib/sharing/ConsumeSharedRuntimeModule.js.map +1 -0
- package/src/lib/sharing/ProvideForSharedDependency.d.js +4 -0
- package/src/lib/sharing/ProvideForSharedDependency.d.js.map +1 -0
- package/src/lib/sharing/ProvideForSharedDependency.d.ts +11 -0
- package/src/lib/sharing/ProvideForSharedDependency.js +34 -0
- package/src/lib/sharing/ProvideForSharedDependency.js.map +1 -0
- package/src/lib/sharing/ProvideSharedDependency.d.js +14 -0
- package/src/lib/sharing/ProvideSharedDependency.d.js.map +1 -0
- package/src/lib/sharing/ProvideSharedDependency.d.ts +32 -0
- package/src/lib/sharing/ProvideSharedDependency.js +65 -0
- package/src/lib/sharing/ProvideSharedDependency.js.map +1 -0
- package/src/lib/sharing/ProvideSharedModule.d.js +4 -0
- package/src/lib/sharing/ProvideSharedModule.d.js.map +1 -0
- package/src/lib/sharing/ProvideSharedModule.d.ts +79 -0
- package/src/lib/sharing/ProvideSharedModule.js +169 -0
- package/src/lib/sharing/ProvideSharedModule.js.map +1 -0
- package/src/lib/sharing/ProvideSharedModuleFactory.d.js +4 -0
- package/src/lib/sharing/ProvideSharedModuleFactory.d.js.map +1 -0
- package/src/lib/sharing/ProvideSharedModuleFactory.d.ts +11 -0
- package/src/lib/sharing/ProvideSharedModuleFactory.js +32 -0
- package/src/lib/sharing/ProvideSharedModuleFactory.js.map +1 -0
- package/src/lib/sharing/ProvideSharedPlugin.d.js +4 -0
- package/src/lib/sharing/ProvideSharedPlugin.d.js.map +1 -0
- package/src/lib/sharing/ProvideSharedPlugin.d.ts +34 -0
- package/src/lib/sharing/ProvideSharedPlugin.js +168 -0
- package/src/lib/sharing/ProvideSharedPlugin.js.map +1 -0
- package/src/lib/sharing/SharePlugin.d.js +4 -0
- package/src/lib/sharing/SharePlugin.d.js.map +1 -0
- package/src/lib/sharing/SharePlugin.d.ts +15 -0
- package/src/lib/sharing/SharePlugin.js +73 -0
- package/src/lib/sharing/SharePlugin.js.map +1 -0
- package/src/lib/sharing/ShareRuntimeModule.d.js +4 -0
- package/src/lib/sharing/ShareRuntimeModule.d.js.map +1 -0
- package/src/lib/sharing/ShareRuntimeModule.d.ts +9 -0
- package/src/lib/sharing/ShareRuntimeModule.js +95 -0
- package/src/lib/sharing/ShareRuntimeModule.js.map +1 -0
- package/src/lib/sharing/resolveMatchedConfigs.d.js +6 -0
- package/src/lib/sharing/resolveMatchedConfigs.d.js.map +1 -0
- package/src/lib/sharing/resolveMatchedConfigs.d.ts +8 -0
- package/src/lib/sharing/resolveMatchedConfigs.js +69 -0
- package/src/lib/sharing/resolveMatchedConfigs.js.map +1 -0
- package/src/lib/sharing/utils.d.js +6 -0
- package/src/lib/sharing/utils.d.js.map +1 -0
- package/src/lib/sharing/utils.d.ts +45 -0
- package/src/lib/sharing/utils.js +348 -0
- package/src/lib/sharing/utils.js.map +1 -0
- package/src/runtime/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
- package/src/runtime/AddRuntimeRequirementToPromiseExternalPlugin.js +34 -0
- package/src/runtime/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
- package/src/runtime/ModuleInfoRuntimeModule.d.ts +16 -0
- package/src/runtime/ModuleInfoRuntimeModule.js +88 -0
- package/src/runtime/ModuleInfoRuntimeModule.js.map +1 -0
- package/src/runtime/ModuleInfoRuntimePlugin.d.ts +5 -0
- package/src/runtime/ModuleInfoRuntimePlugin.js +29 -0
- package/src/runtime/ModuleInfoRuntimePlugin.js.map +1 -0
- package/src/schemas/container/ContainerPlugin.check.d.ts +7 -0
- package/src/schemas/container/ContainerPlugin.check.js +2229 -0
- package/src/schemas/container/ContainerPlugin.check.js.map +1 -0
- package/src/schemas/container/ContainerPlugin.d.ts +268 -0
- package/src/schemas/container/ContainerPlugin.js +324 -0
- package/src/schemas/container/ContainerPlugin.js.map +1 -0
- package/src/schemas/container/ModuleFederationPlugin.check.d.ts +7 -0
- package/src/schemas/container/ModuleFederationPlugin.check.js +3818 -0
- package/src/schemas/container/ModuleFederationPlugin.check.js.map +1 -0
- package/src/schemas/container/ModuleFederationPlugin.d.ts +441 -0
- package/src/schemas/container/ModuleFederationPlugin.js +556 -0
- package/src/schemas/container/ModuleFederationPlugin.js.map +1 -0
- package/src/types/runtime.d.ts +7 -0
- package/src/types/runtime.js +6 -0
- package/src/types/runtime.js.map +1 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { CodeGenerationContext, CodeGenerationResult, LibIdentOptions, NeedBuildContext, WebpackError } from 'webpack/lib/Module';
|
|
2
|
+
import Module from 'webpack/lib/Module';
|
|
3
|
+
import type Compilation from 'webpack/lib/Compilation';
|
|
4
|
+
import type { ResolverWithOptions } from 'webpack/lib/ResolverFactory';
|
|
5
|
+
import type { InputFileSystem } from 'webpack/lib/FileSystemInfo';
|
|
6
|
+
import type { RequestShortener } from 'webpack/lib/RuntimeModule';
|
|
7
|
+
import type { WebpackOptionsNormalized } from 'webpack/lib/WebpackOptionsDefaulter';
|
|
8
|
+
import type { ObjectDeserializerContext } from 'webpack/lib/serialization/ObjectMiddleware';
|
|
9
|
+
declare class RemoteModule extends Module {
|
|
10
|
+
private _identifier;
|
|
11
|
+
request: string;
|
|
12
|
+
externalRequests: string[];
|
|
13
|
+
internalRequest: string;
|
|
14
|
+
shareScope: string;
|
|
15
|
+
remoteName: string;
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} request request string
|
|
18
|
+
* @param {string[]} externalRequests list of external requests to containers
|
|
19
|
+
* @param {string} internalRequest name of exposed module in container
|
|
20
|
+
* @param {string} shareScope the used share scope name
|
|
21
|
+
* @param {string} remoteName The name of remote instance
|
|
22
|
+
*/
|
|
23
|
+
constructor(request: string, externalRequests: string[], internalRequest: string, shareScope: string, remoteName: string);
|
|
24
|
+
/**
|
|
25
|
+
* @returns {string} a unique identifier of the module
|
|
26
|
+
*/
|
|
27
|
+
identifier(): string;
|
|
28
|
+
/**
|
|
29
|
+
* @param {RequestShortener} requestShortener the request shortener
|
|
30
|
+
* @returns {string} a user readable identifier of the module
|
|
31
|
+
*/
|
|
32
|
+
readableIdentifier(requestShortener: RequestShortener): string;
|
|
33
|
+
/**
|
|
34
|
+
* @param {LibIdentOptions} options options
|
|
35
|
+
* @returns {string | null} an identifier for library inclusion
|
|
36
|
+
*/
|
|
37
|
+
libIdent(options: LibIdentOptions): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* @param {NeedBuildContext} context context info
|
|
40
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
|
41
|
+
* @returns {void}
|
|
42
|
+
*/
|
|
43
|
+
needBuild(context: NeedBuildContext, callback: (err: WebpackError | null, needsRebuild?: boolean) => void): void;
|
|
44
|
+
/**
|
|
45
|
+
* @param {WebpackOptions} options webpack options
|
|
46
|
+
* @param {Compilation} compilation the compilation
|
|
47
|
+
* @param {ResolverWithOptions} resolver the resolver
|
|
48
|
+
* @param {InputFileSystem} fs the file system
|
|
49
|
+
* @param {function(WebpackError=): void} callback callback function
|
|
50
|
+
* @returns {void}
|
|
51
|
+
*/
|
|
52
|
+
build(options: WebpackOptionsNormalized, compilation: Compilation, resolver: ResolverWithOptions, fs: InputFileSystem, callback: (err?: WebpackError | undefined) => void): void;
|
|
53
|
+
/**
|
|
54
|
+
* @param {string=} type the source type for which the size should be estimated
|
|
55
|
+
* @returns {number} the estimated size of the module (must be non-zero)
|
|
56
|
+
*/
|
|
57
|
+
size(type?: string): number;
|
|
58
|
+
/**
|
|
59
|
+
* @returns {Set<string>} types available (do not mutate)
|
|
60
|
+
*/
|
|
61
|
+
getSourceTypes(): Set<string>;
|
|
62
|
+
/**
|
|
63
|
+
* @returns {string | null} absolute path which should be used for condition matching (usually the resource path)
|
|
64
|
+
*/
|
|
65
|
+
nameForCondition(): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* @param {CodeGenerationContext} context context for code generation
|
|
68
|
+
* @returns {CodeGenerationResult} result
|
|
69
|
+
*/
|
|
70
|
+
codeGeneration(context: CodeGenerationContext): CodeGenerationResult;
|
|
71
|
+
serialize(context: any): void;
|
|
72
|
+
/**
|
|
73
|
+
* @param {ObjectDeserializerContext} context context
|
|
74
|
+
* @returns {RemoteModule} deserialized module
|
|
75
|
+
*/
|
|
76
|
+
static deserialize(context: ObjectDeserializerContext): RemoteModule;
|
|
77
|
+
}
|
|
78
|
+
export default RemoteModule;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return _default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
15
|
+
const _webpacksources = require("webpack-sources");
|
|
16
|
+
const _Module = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/Module"));
|
|
17
|
+
const _RuntimeGlobals = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/RuntimeGlobals"));
|
|
18
|
+
const _makeSerializable = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/util/makeSerializable"));
|
|
19
|
+
const _FallbackDependency = /*#__PURE__*/ _interop_require_default._(require("./FallbackDependency"));
|
|
20
|
+
const _RemoteToExternalDependency = /*#__PURE__*/ _interop_require_default._(require("./RemoteToExternalDependency"));
|
|
21
|
+
const _ModuleTypeConstants = require("webpack/lib/ModuleTypeConstants");
|
|
22
|
+
const TYPES = new Set([
|
|
23
|
+
'remote',
|
|
24
|
+
'share-init'
|
|
25
|
+
]);
|
|
26
|
+
const RUNTIME_REQUIREMENTS = new Set([
|
|
27
|
+
_RuntimeGlobals.default.module
|
|
28
|
+
]);
|
|
29
|
+
let RemoteModule = class RemoteModule extends _Module.default {
|
|
30
|
+
/**
|
|
31
|
+
* @returns {string} a unique identifier of the module
|
|
32
|
+
*/ identifier() {
|
|
33
|
+
return this._identifier;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @param {RequestShortener} requestShortener the request shortener
|
|
37
|
+
* @returns {string} a user readable identifier of the module
|
|
38
|
+
*/ readableIdentifier(requestShortener) {
|
|
39
|
+
return `remote ${this.request}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @param {LibIdentOptions} options options
|
|
43
|
+
* @returns {string | null} an identifier for library inclusion
|
|
44
|
+
*/ libIdent(options) {
|
|
45
|
+
return `${this.layer ? `(${this.layer})/` : ''}webpack/container/remote/${this.request}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @param {NeedBuildContext} context context info
|
|
49
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
|
50
|
+
* @returns {void}
|
|
51
|
+
*/ needBuild(context, callback) {
|
|
52
|
+
callback(null, !this.buildInfo);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @param {WebpackOptions} options webpack options
|
|
56
|
+
* @param {Compilation} compilation the compilation
|
|
57
|
+
* @param {ResolverWithOptions} resolver the resolver
|
|
58
|
+
* @param {InputFileSystem} fs the file system
|
|
59
|
+
* @param {function(WebpackError=): void} callback callback function
|
|
60
|
+
* @returns {void}
|
|
61
|
+
*/ build(options, compilation, resolver, fs, callback) {
|
|
62
|
+
this.buildMeta = {};
|
|
63
|
+
this.buildInfo = {
|
|
64
|
+
strict: true
|
|
65
|
+
};
|
|
66
|
+
this.clearDependenciesAndBlocks();
|
|
67
|
+
if (this.externalRequests.length === 1) {
|
|
68
|
+
this.addDependency(new _RemoteToExternalDependency.default(this.externalRequests[0]));
|
|
69
|
+
} else {
|
|
70
|
+
this.addDependency(new _FallbackDependency.default(this.externalRequests));
|
|
71
|
+
}
|
|
72
|
+
callback();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @param {string=} type the source type for which the size should be estimated
|
|
76
|
+
* @returns {number} the estimated size of the module (must be non-zero)
|
|
77
|
+
*/ size(type) {
|
|
78
|
+
return 6;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @returns {Set<string>} types available (do not mutate)
|
|
82
|
+
*/ getSourceTypes() {
|
|
83
|
+
return TYPES;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @returns {string | null} absolute path which should be used for condition matching (usually the resource path)
|
|
87
|
+
*/ nameForCondition() {
|
|
88
|
+
return this.request;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @param {CodeGenerationContext} context context for code generation
|
|
92
|
+
* @returns {CodeGenerationResult} result
|
|
93
|
+
*/ codeGeneration(context) {
|
|
94
|
+
const { runtimeTemplate, moduleGraph, chunkGraph } = context;
|
|
95
|
+
const module = moduleGraph.getModule(this.dependencies[0]);
|
|
96
|
+
const id = module && chunkGraph.getModuleId(module);
|
|
97
|
+
const sources = new Map();
|
|
98
|
+
sources.set('remote', new _webpacksources.RawSource(''));
|
|
99
|
+
const data = new Map();
|
|
100
|
+
data.set('share-init', [
|
|
101
|
+
{
|
|
102
|
+
shareScope: this.shareScope,
|
|
103
|
+
initStage: 20,
|
|
104
|
+
init: id === undefined ? '' : `initExternal(${JSON.stringify(id)});`
|
|
105
|
+
}
|
|
106
|
+
]);
|
|
107
|
+
return {
|
|
108
|
+
sources,
|
|
109
|
+
data,
|
|
110
|
+
runtimeRequirements: RUNTIME_REQUIREMENTS
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
serialize(context) {
|
|
114
|
+
const { write } = context;
|
|
115
|
+
write(this.request);
|
|
116
|
+
write(this.externalRequests);
|
|
117
|
+
write(this.internalRequest);
|
|
118
|
+
write(this.shareScope);
|
|
119
|
+
write(this.remoteName);
|
|
120
|
+
super.serialize(context);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @param {ObjectDeserializerContext} context context
|
|
124
|
+
* @returns {RemoteModule} deserialized module
|
|
125
|
+
*/ static deserialize(context) {
|
|
126
|
+
const { read } = context;
|
|
127
|
+
const obj = new RemoteModule(read(), read(), read(), read(), read());
|
|
128
|
+
obj.deserialize(context);
|
|
129
|
+
return obj;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @param {string} request request string
|
|
133
|
+
* @param {string[]} externalRequests list of external requests to containers
|
|
134
|
+
* @param {string} internalRequest name of exposed module in container
|
|
135
|
+
* @param {string} shareScope the used share scope name
|
|
136
|
+
* @param {string} remoteName The name of remote instance
|
|
137
|
+
*/ constructor(request, externalRequests, internalRequest, shareScope, remoteName){
|
|
138
|
+
super(_ModuleTypeConstants.WEBPACK_MODULE_TYPE_REMOTE);
|
|
139
|
+
this.request = request;
|
|
140
|
+
this.externalRequests = externalRequests;
|
|
141
|
+
this.internalRequest = internalRequest;
|
|
142
|
+
this.shareScope = shareScope;
|
|
143
|
+
this._identifier = `remote (${shareScope}) ${this.externalRequests.join(' ')} ${this.internalRequest}`;
|
|
144
|
+
this.remoteName = remoteName;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
(0, _makeSerializable.default)(RemoteModule, 'enhanced/lib/container/RemoteModule');
|
|
148
|
+
const _default = RemoteModule;
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=RemoteModule.js.map
|
|
@@ -0,0 +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*/\n\nimport { RawSource } from 'webpack-sources';\nimport type {\n CodeGenerationContext,\n CodeGenerationResult,\n LibIdentOptions,\n NeedBuildContext,\n WebpackError,\n} from 'webpack/lib/Module';\nimport Module from 'webpack/lib/Module';\nimport RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport makeSerializable from 'webpack/lib/util/makeSerializable';\nimport FallbackDependency from './FallbackDependency';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport type Compilation from 'webpack/lib/Compilation';\nimport type { ResolverWithOptions } from 'webpack/lib/ResolverFactory';\nimport type { InputFileSystem } from 'webpack/lib/FileSystemInfo';\nimport type { RequestShortener } from 'webpack/lib/RuntimeModule';\nimport { WEBPACK_MODULE_TYPE_REMOTE } from 'webpack/lib/ModuleTypeConstants';\nimport type { WebpackOptionsNormalized } from 'webpack/lib/WebpackOptionsDefaulter';\nimport type { ObjectDeserializerContext } from 'webpack/lib/serialization/ObjectMiddleware';\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 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 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 override codeGeneration(\n context: CodeGenerationContext,\n ): CodeGenerationResult {\n const { runtimeTemplate, moduleGraph, chunkGraph } = context;\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 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":["TYPES","Set","RUNTIME_REQUIREMENTS","RuntimeGlobals","module","RemoteModule","Module","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","sources","Map","set","RawSource","data","shareScope","initStage","init","undefined","JSON","stringify","runtimeRequirements","serialize","write","internalRequest","remoteName","deserialize","read","obj","constructor","WEBPACK_MODULE_TYPE_REMOTE","join","makeSerializable"],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _default = RemoteRuntimeModule;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=RemoteRuntimeModule.d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/RemoteRuntimeModule.d.ts"],"sourcesContent":["export default RemoteRuntimeModule;\n/** @typedef {import(\"webpack/lib/Chunk\")} Chunk */\n/** @typedef {import(\"./RemoteModule\")} RemoteModule */\ndeclare class RemoteRuntimeModule extends RuntimeModule {\n constructor();\n}\ndeclare namespace RemoteRuntimeModule {\n export { Chunk, RemoteModule };\n}\nimport RuntimeModule = require('webpack/lib/RuntimeModule');\ntype Chunk = import('webpack/lib/Chunk');\ntype RemoteModule = import('./RemoteModule');\n"],"names":["RemoteRuntimeModule"],"mappings":";;;;+BAAA;;;eAAA;;;MAAA,WAAeA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return _default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
15
|
+
const _RuntimeGlobals = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/RuntimeGlobals"));
|
|
16
|
+
const _RuntimeModule = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/RuntimeModule"));
|
|
17
|
+
const _Template = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/Template"));
|
|
18
|
+
const _utils = require("./runtime/utils");
|
|
19
|
+
let RemoteRuntimeModule = class RemoteRuntimeModule extends _RuntimeModule.default {
|
|
20
|
+
/**
|
|
21
|
+
* @returns {string | null} runtime code
|
|
22
|
+
*/ generate() {
|
|
23
|
+
var _this_chunk;
|
|
24
|
+
const { compilation, chunkGraph } = this;
|
|
25
|
+
const { runtimeTemplate, moduleGraph } = compilation;
|
|
26
|
+
const chunkToRemotesMapping = {};
|
|
27
|
+
const idToExternalAndNameMapping = {};
|
|
28
|
+
const idToRemoteMap = {};
|
|
29
|
+
const allChunks = [
|
|
30
|
+
...Array.from(((_this_chunk = this.chunk) == null ? void 0 : _this_chunk.getAllReferencedChunks()) || [])
|
|
31
|
+
];
|
|
32
|
+
for (const chunk of allChunks){
|
|
33
|
+
const modules = chunkGraph == null ? void 0 : chunkGraph.getChunkModulesIterableBySourceType(chunk, 'remote');
|
|
34
|
+
if (!modules) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
const remotes = chunkToRemotesMapping[chunk.id] = [];
|
|
39
|
+
for (const m of modules){
|
|
40
|
+
const module = m;
|
|
41
|
+
const name = module.internalRequest;
|
|
42
|
+
const remoteName = module.remoteName;
|
|
43
|
+
const id = chunkGraph ? chunkGraph.getModuleId(module) : undefined;
|
|
44
|
+
const { shareScope } = module;
|
|
45
|
+
const dep = module.dependencies[0];
|
|
46
|
+
const externalModule = moduleGraph.getModule(dep);
|
|
47
|
+
const externalModuleId = chunkGraph && externalModule ? chunkGraph.getModuleId(externalModule) : undefined;
|
|
48
|
+
if (id !== undefined) {
|
|
49
|
+
//@ts-ignore
|
|
50
|
+
remotes.push(id);
|
|
51
|
+
idToExternalAndNameMapping[id] = [
|
|
52
|
+
shareScope,
|
|
53
|
+
name,
|
|
54
|
+
externalModuleId
|
|
55
|
+
];
|
|
56
|
+
const remoteModules = [];
|
|
57
|
+
// FallbackModule has requests
|
|
58
|
+
if ('requests' in externalModule && externalModule.requests) {
|
|
59
|
+
externalModule.dependencies.forEach((dependency)=>{
|
|
60
|
+
const remoteModule = moduleGraph.getModule(dependency);
|
|
61
|
+
if (remoteModule) {
|
|
62
|
+
remoteModules.push(remoteModule);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
remoteModules.push(externalModule);
|
|
67
|
+
}
|
|
68
|
+
idToRemoteMap[id] = [];
|
|
69
|
+
remoteModules.forEach((remoteModule)=>{
|
|
70
|
+
const externalModuleId = chunkGraph && remoteModule && chunkGraph.getModuleId(remoteModule);
|
|
71
|
+
idToRemoteMap[id].push({
|
|
72
|
+
externalType: remoteModule.externalType,
|
|
73
|
+
request: remoteModule.request,
|
|
74
|
+
remoteName,
|
|
75
|
+
externalModuleId
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const federationGlobal = (0, _utils.getFederationGlobalScope)(_RuntimeGlobals.default || {});
|
|
82
|
+
return _Template.default.asString([
|
|
83
|
+
`var chunkMapping = ${JSON.stringify(chunkToRemotesMapping, null, '\t')};`,
|
|
84
|
+
`var idToExternalAndNameMapping = ${JSON.stringify(idToExternalAndNameMapping, null, '\t')};`,
|
|
85
|
+
`var idToRemoteMap = ${JSON.stringify(idToRemoteMap, null, '\t')};`,
|
|
86
|
+
`${federationGlobal}.bundlerRuntimeOptions.remotes = {idToRemoteMap,chunkMapping, idToExternalAndNameMapping, webpackRequire:${_RuntimeGlobals.default.require}};`,
|
|
87
|
+
`${_RuntimeGlobals.default.ensureChunkHandlers}.remotes = ${runtimeTemplate.basicFunction('chunkId, promises', [
|
|
88
|
+
`${federationGlobal}.bundlerRuntime.remotes({idToRemoteMap,chunkMapping, idToExternalAndNameMapping, chunkId, promises, webpackRequire:${_RuntimeGlobals.default.require}});`
|
|
89
|
+
])}`
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
constructor(){
|
|
93
|
+
super('remotes loading');
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const _default = RemoteRuntimeModule;
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=RemoteRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/RemoteRuntimeModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\nimport RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport type Compilation from 'webpack/lib/Compilation';\nimport RemoteModule from './RemoteModule';\nimport RuntimeModule from 'webpack/lib/RuntimeModule';\nimport Template from 'webpack/lib/Template';\nimport extractUrlAndGlobal from 'webpack/lib/util/extractUrlAndGlobal';\nimport { FEDERATION_SUPPORTED_TYPES } from './constant';\nimport { getFederationGlobalScope } from './runtime/utils';\nimport type ExternalModule from 'webpack/lib/ExternalModule';\nimport type FallbackModule from './FallbackModule';\nimport type { RemotesOptions } from '@module-federation/webpack-bundler-runtime';\n\nclass RemoteRuntimeModule extends RuntimeModule {\n constructor() {\n super('remotes loading');\n }\n\n /**\n * @returns {string | null} runtime code\n */\n override generate(): string | null {\n const { compilation, chunkGraph } = this;\n const { runtimeTemplate, moduleGraph } = compilation as Compilation;\n const chunkToRemotesMapping: Record<string, any> = {};\n const idToExternalAndNameMapping: Record<string | number, any> = {};\n const idToRemoteMap: RemotesOptions['idToRemoteMap'] = {};\n\n const allChunks = [\n ...Array.from(this.chunk?.getAllReferencedChunks() || []),\n ];\n\n for (const chunk of allChunks) {\n const modules = chunkGraph?.getChunkModulesIterableBySourceType(\n chunk,\n 'remote',\n );\n if (!modules) {\n continue;\n }\n // @ts-ignore\n const remotes = (chunkToRemotesMapping[chunk.id] = []);\n for (const m of modules) {\n const module: RemoteModule = m as RemoteModule;\n const name = module.internalRequest;\n const remoteName = module.remoteName;\n const id = chunkGraph ? chunkGraph.getModuleId(module) : undefined;\n const { shareScope } = module;\n const dep = module.dependencies[0];\n const externalModule = moduleGraph.getModule(dep) as\n | ExternalModule\n | FallbackModule;\n const externalModuleId =\n chunkGraph && externalModule\n ? chunkGraph.getModuleId(externalModule)\n : undefined;\n if (id !== undefined) {\n //@ts-ignore\n remotes.push(id);\n\n idToExternalAndNameMapping[id] = [shareScope, name, externalModuleId];\n const remoteModules: ExternalModule[] = [];\n // FallbackModule has requests\n if ('requests' in externalModule && externalModule.requests) {\n externalModule.dependencies.forEach((dependency) => {\n const remoteModule = moduleGraph.getModule(dependency);\n if (remoteModule) {\n remoteModules.push(remoteModule as ExternalModule);\n }\n });\n } else {\n remoteModules.push(externalModule as ExternalModule);\n }\n\n idToRemoteMap[id] = [];\n remoteModules.forEach((remoteModule) => {\n const externalModuleId =\n chunkGraph &&\n remoteModule &&\n chunkGraph.getModuleId(remoteModule);\n idToRemoteMap[id].push({\n externalType: remoteModule.externalType,\n request: remoteModule.request as string,\n remoteName,\n externalModuleId,\n });\n });\n }\n }\n }\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\n\n return Template.asString([\n `var chunkMapping = ${JSON.stringify(\n chunkToRemotesMapping,\n null,\n '\\t',\n )};`,\n `var idToExternalAndNameMapping = ${JSON.stringify(\n idToExternalAndNameMapping,\n null,\n '\\t',\n )};`,\n `var idToRemoteMap = ${JSON.stringify(idToRemoteMap, null, '\\t')};`,\n `${federationGlobal}.bundlerRuntimeOptions.remotes = {idToRemoteMap,chunkMapping, idToExternalAndNameMapping, webpackRequire:${RuntimeGlobals.require}};`,\n `${\n RuntimeGlobals.ensureChunkHandlers\n }.remotes = ${runtimeTemplate.basicFunction('chunkId, promises', [\n `${federationGlobal}.bundlerRuntime.remotes({idToRemoteMap,chunkMapping, idToExternalAndNameMapping, chunkId, promises, webpackRequire:${RuntimeGlobals.require}});`,\n // `if(${RuntimeGlobals.hasOwnProperty}(chunkMapping, chunkId)) {`,\n // Template.indent([\n // `chunkMapping[chunkId].forEach(${runtimeTemplate.basicFunction('id', [\n // `var getScope = ${RuntimeGlobals.currentRemoteGetScope};`,\n // 'if(!getScope) getScope = [];',\n // 'var data = idToExternalAndNameMapping[id];',\n // 'if(getScope.indexOf(data) >= 0) return;',\n // 'getScope.push(data);',\n // `if(data.p) return promises.push(data.p);`,\n // `var onError = ${runtimeTemplate.basicFunction('error', [\n // 'if(!error) error = new Error(\"Container missing\");',\n // 'if(typeof error.message === \"string\")',\n // Template.indent(\n // `error.message += '\\\\nwhile loading \"' + data[1] + '\" from ' + data[2];`,\n // ),\n // `${\n // RuntimeGlobals.moduleFactories\n // }[id] = ${runtimeTemplate.basicFunction('', ['throw error;'])}`,\n // 'data.p = 0;',\n // ])};`,\n // `var handleFunction = ${runtimeTemplate.basicFunction(\n // 'fn, arg1, arg2, d, next, first',\n // [\n // 'try {',\n // Template.indent([\n // 'var promise = fn(arg1, arg2);',\n // 'if(promise && promise.then) {',\n // Template.indent([\n // `var p = promise.then(${runtimeTemplate.returningFunction(\n // 'next(result, d)',\n // 'result',\n // )}, onError);`,\n // `if(first) promises.push(data.p = p); else return p;`,\n // ]),\n // '} else {',\n // Template.indent(['return next(promise, d, first);']),\n // '}',\n // ]),\n // '} catch(error) {',\n // Template.indent(['onError(error);']),\n // '}',\n // ],\n // )}`,\n // `var onExternal = ${runtimeTemplate.returningFunction(\n // `external ? handleFunction(${RuntimeGlobals.initializeSharing}, data[0], 0, external, onInitialized, first) : onError()`,\n // 'external, _, first',\n // )};`,\n // `var onInitialized = ${runtimeTemplate.returningFunction(\n // `handleFunction(external.get, data[1], getScope, 0, onFactory, first)`,\n // '_, external, first',\n // )};`,\n // `var onFactory = ${runtimeTemplate.basicFunction('factory', [\n // 'data.p = 1;',\n // `${\n // RuntimeGlobals.moduleFactories\n // }[id] = ${runtimeTemplate.basicFunction('module', [\n // 'module.exports = factory();',\n // ])}`,\n // ])};`,\n // `handleFunction(${RuntimeGlobals.require}, data[2], 0, 0, onExternal, 1);`,\n // ])});`,\n // ]),\n // '}',\n ])}`,\n ]);\n }\n}\n\nexport default RemoteRuntimeModule;\n"],"names":["RemoteRuntimeModule","RuntimeModule","generate","compilation","chunkGraph","runtimeTemplate","moduleGraph","chunkToRemotesMapping","idToExternalAndNameMapping","idToRemoteMap","allChunks","Array","from","chunk","getAllReferencedChunks","modules","getChunkModulesIterableBySourceType","remotes","id","m","module","name","internalRequest","remoteName","getModuleId","undefined","shareScope","dep","dependencies","externalModule","getModule","externalModuleId","push","remoteModules","requests","forEach","dependency","remoteModule","externalType","request","federationGlobal","getFederationGlobalScope","RuntimeGlobals","Template","asString","JSON","stringify","require","ensureChunkHandlers","basicFunction","constructor"],"mappings":"AAAA;;;AAGA;;;;+BAiLA;;;eAAA;;;;yEAhL2B;wEAGD;mEACL;uBAGoB;AAKzC,IAAA,AAAMA,sBAAN,MAAMA,4BAA4BC,sBAAa;IAK7C;;GAEC,GACD,AAASC,WAA0B;YAQjB;QAPhB,MAAM,EAAEC,WAAW,EAAEC,UAAU,EAAE,GAAG,IAAI;QACxC,MAAM,EAAEC,eAAe,EAAEC,WAAW,EAAE,GAAGH;QACzC,MAAMI,wBAA6C,CAAC;QACpD,MAAMC,6BAA2D,CAAC;QAClE,MAAMC,gBAAiD,CAAC;QAExD,MAAMC,YAAY;eACbC,MAAMC,IAAI,CAAC,EAAA,cAAA,IAAI,CAACC,KAAK,qBAAV,YAAYC,sBAAsB,OAAM,EAAE;SACzD;QAED,KAAK,MAAMD,SAASH,UAAW;YAC7B,MAAMK,UAAUX,8BAAAA,WAAYY,mCAAmC,CAC7DH,OACA;YAEF,IAAI,CAACE,SAAS;gBACZ;YACF;YACA,aAAa;YACb,MAAME,UAAWV,qBAAqB,CAACM,MAAMK,EAAE,CAAC,GAAG,EAAE;YACrD,KAAK,MAAMC,KAAKJ,QAAS;gBACvB,MAAMK,SAAuBD;gBAC7B,MAAME,OAAOD,OAAOE,eAAe;gBACnC,MAAMC,aAAaH,OAAOG,UAAU;gBACpC,MAAML,KAAKd,aAAaA,WAAWoB,WAAW,CAACJ,UAAUK;gBACzD,MAAM,EAAEC,UAAU,EAAE,GAAGN;gBACvB,MAAMO,MAAMP,OAAOQ,YAAY,CAAC,EAAE;gBAClC,MAAMC,iBAAiBvB,YAAYwB,SAAS,CAACH;gBAG7C,MAAMI,mBACJ3B,cAAcyB,iBACVzB,WAAWoB,WAAW,CAACK,kBACvBJ;gBACN,IAAIP,OAAOO,WAAW;oBACpB,YAAY;oBACZR,QAAQe,IAAI,CAACd;oBAEbV,0BAA0B,CAACU,GAAG,GAAG;wBAACQ;wBAAYL;wBAAMU;qBAAiB;oBACrE,MAAME,gBAAkC,EAAE;oBAC1C,8BAA8B;oBAC9B,IAAI,cAAcJ,kBAAkBA,eAAeK,QAAQ,EAAE;wBAC3DL,eAAeD,YAAY,CAACO,OAAO,CAAC,CAACC;4BACnC,MAAMC,eAAe/B,YAAYwB,SAAS,CAACM;4BAC3C,IAAIC,cAAc;gCAChBJ,cAAcD,IAAI,CAACK;4BACrB;wBACF;oBACF,OAAO;wBACLJ,cAAcD,IAAI,CAACH;oBACrB;oBAEApB,aAAa,CAACS,GAAG,GAAG,EAAE;oBACtBe,cAAcE,OAAO,CAAC,CAACE;wBACrB,MAAMN,mBACJ3B,cACAiC,gBACAjC,WAAWoB,WAAW,CAACa;wBACzB5B,aAAa,CAACS,GAAG,CAACc,IAAI,CAAC;4BACrBM,cAAcD,aAAaC,YAAY;4BACvCC,SAASF,aAAaE,OAAO;4BAC7BhB;4BACAQ;wBACF;oBACF;gBACF;YACF;QACF;QACA,MAAMS,mBAAmBC,IAAAA,+BAAwB,EAACC,uBAAc,IAAI,CAAC;QAErE,OAAOC,iBAAQ,CAACC,QAAQ,CAAC;YACvB,CAAC,mBAAmB,EAAEC,KAAKC,SAAS,CAClCvC,uBACA,MACA,MACA,CAAC,CAAC;YACJ,CAAC,iCAAiC,EAAEsC,KAAKC,SAAS,CAChDtC,4BACA,MACA,MACA,CAAC,CAAC;YACJ,CAAC,oBAAoB,EAAEqC,KAAKC,SAAS,CAACrC,eAAe,MAAM,MAAM,CAAC,CAAC;YACnE,CAAC,EAAE+B,iBAAiB,yGAAyG,EAAEE,uBAAc,CAACK,OAAO,CAAC,EAAE,CAAC;YACzJ,CAAC,EACCL,uBAAc,CAACM,mBAAmB,CACnC,WAAW,EAAE3C,gBAAgB4C,aAAa,CAAC,qBAAqB;gBAC/D,CAAC,EAAET,iBAAiB,mHAAmH,EAAEE,uBAAc,CAACK,OAAO,CAAC,GAAG,CAAC;aAgErK,EAAE,CAAC;SACL;IACH;IAhKAG,aAAc;QACZ,KAAK,CAAC;IACR;AA+JF;MAEA,WAAelD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
|
+
const _ModuleDependency = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/dependencies/ModuleDependency"));
|
|
13
|
+
const _default = RemoteToExternalDependency;
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=RemoteToExternalDependency.d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/RemoteToExternalDependency.d.ts"],"sourcesContent":["export default RemoteToExternalDependency;\ndeclare class RemoteToExternalDependency extends ModuleDependency {}\nimport ModuleDependency from 'webpack/lib/dependencies/ModuleDependency';\n"],"names":["RemoteToExternalDependency"],"mappings":";;;;+BAAA;;;eAAA;;;;2EAE6B;MAF7B,WAAeA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ModuleDependency from 'webpack/lib/dependencies/ModuleDependency';
|
|
2
|
+
declare class RemoteToExternalDependency extends ModuleDependency {
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} request request
|
|
5
|
+
*/
|
|
6
|
+
constructor(request: string);
|
|
7
|
+
get type(): string;
|
|
8
|
+
get category(): string;
|
|
9
|
+
}
|
|
10
|
+
export default RemoteToExternalDependency;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
|
|
4
|
+
*/ 'use strict';
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return _default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
15
|
+
const _ModuleDependency = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/dependencies/ModuleDependency"));
|
|
16
|
+
const _makeSerializable = /*#__PURE__*/ _interop_require_default._(require("webpack/lib/util/makeSerializable"));
|
|
17
|
+
let RemoteToExternalDependency = class RemoteToExternalDependency extends _ModuleDependency.default {
|
|
18
|
+
get type() {
|
|
19
|
+
return 'remote to external';
|
|
20
|
+
}
|
|
21
|
+
get category() {
|
|
22
|
+
return 'esm';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} request request
|
|
26
|
+
*/ constructor(request){
|
|
27
|
+
super(request);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
(0, _makeSerializable.default)(RemoteToExternalDependency, 'enhanced/lib/container/RemoteToExternalDependency');
|
|
31
|
+
const _default = RemoteToExternalDependency;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=RemoteToExternalDependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/RemoteToExternalDependency.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\n\nimport ModuleDependency from 'webpack/lib/dependencies/ModuleDependency';\nimport makeSerializable from 'webpack/lib/util/makeSerializable';\n\nclass RemoteToExternalDependency extends ModuleDependency {\n /**\n * @param {string} request request\n */\n constructor(request: string) {\n super(request);\n }\n override get type() {\n return 'remote to external';\n }\n\n override get category() {\n return 'esm';\n }\n}\n\nmakeSerializable(\n RemoteToExternalDependency,\n 'enhanced/lib/container/RemoteToExternalDependency',\n);\n\nexport default RemoteToExternalDependency;\n"],"names":["RemoteToExternalDependency","ModuleDependency","type","category","constructor","request","makeSerializable"],"mappings":"AAAA;;;AAGA,GAEA;;;;+BA0BA;;;eAAA;;;;2EAxB6B;2EACA;AAE7B,IAAA,AAAMA,6BAAN,MAAMA,mCAAmCC,yBAAgB;IAOvD,IAAaC,OAAO;QAClB,OAAO;IACT;IAEA,IAAaC,WAAW;QACtB,OAAO;IACT;IAZA;;GAEC,GACDC,YAAYC,OAAe,CAAE;QAC3B,KAAK,CAACA;IACR;AAQF;AAEAC,IAAAA,yBAAgB,EACdN,4BACA;MAGF,WAAeA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
FEDERATION_SUPPORTED_TYPES: function() {
|
|
13
|
+
return FEDERATION_SUPPORTED_TYPES;
|
|
14
|
+
},
|
|
15
|
+
TEMP_DIR: function() {
|
|
16
|
+
return TEMP_DIR;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
+
const _path = /*#__PURE__*/ _interop_require_default._(require("path"));
|
|
21
|
+
const FEDERATION_SUPPORTED_TYPES = [
|
|
22
|
+
'script'
|
|
23
|
+
];
|
|
24
|
+
const TEMP_DIR = _path.default.join(`${process.cwd()}/node_modules`, `.federation`);
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/constant.ts"],"sourcesContent":["import path from 'path';\n\nconst FEDERATION_SUPPORTED_TYPES = ['script'];\nconst TEMP_DIR = path.join(`${process.cwd()}/node_modules`, `.federation`);\n\nexport { FEDERATION_SUPPORTED_TYPES, TEMP_DIR };\n"],"names":["FEDERATION_SUPPORTED_TYPES","TEMP_DIR","path","join","process","cwd"],"mappings":";;;;;;;;;;;IAKSA,0BAA0B;eAA1BA;;IAA4BC,QAAQ;eAARA;;;;+DALpB;AAEjB,MAAMD,6BAA6B;IAAC;CAAS;AAC7C,MAAMC,WAAWC,aAAI,CAACC,IAAI,CAAC,CAAC,EAAEC,QAAQC,GAAG,GAAG,aAAa,CAAC,EAAE,CAAC,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/options.d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ContainerOptionsFormat<T> = (string | Record<string, string | string[] | T>)[] | Record<string, string | string[] | T>;
|
|
2
|
+
/**
|
|
3
|
+
* @template T
|
|
4
|
+
* @template R
|
|
5
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
6
|
+
* @param {function(string | string[], string) : R} normalizeSimple normalize a simple item
|
|
7
|
+
* @param {function(T, string) : R} normalizeOptions normalize a complex item
|
|
8
|
+
* @returns {[string, R][]} parsed options
|
|
9
|
+
*/
|
|
10
|
+
declare const parseOptions: <T, R>(options: ContainerOptionsFormat<T>, normalizeSimple: (item: string | string[], name: string) => R, normalizeOptions: (item: T, name: string) => R) => [string, R][];
|
|
11
|
+
/**
|
|
12
|
+
* @template T
|
|
13
|
+
* @param {string} scope scope name
|
|
14
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
15
|
+
* @returns {Record<string, string | string[] | T>} options to spread or pass
|
|
16
|
+
*/
|
|
17
|
+
declare const scope: <T>(scope: string, options: ContainerOptionsFormat<T>) => Record<string, string | string[] | T>;
|
|
18
|
+
export { parseOptions, scope };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
function _export(target, all) {
|
|
9
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: all[name]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
_export(exports, {
|
|
15
|
+
parseOptions: function() {
|
|
16
|
+
return parseOptions;
|
|
17
|
+
},
|
|
18
|
+
scope: function() {
|
|
19
|
+
return scope;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
/** @template T @typedef {(string | Record<string, string | string[] | T>)[] | Record<string, string | string[] | T>} ContainerOptionsFormat */ /**
|
|
23
|
+
* @template T
|
|
24
|
+
* @template N
|
|
25
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
26
|
+
* @param {function(string | string[], string) : N} normalizeSimple normalize a simple item
|
|
27
|
+
* @param {function(T, string) : N} normalizeOptions normalize a complex item
|
|
28
|
+
* @param {function(string, N): void} fn processing function
|
|
29
|
+
* @returns {void}
|
|
30
|
+
*/ const process = (options, normalizeSimple, normalizeOptions, fn)=>{
|
|
31
|
+
const array = (items)=>{
|
|
32
|
+
for (const item of items){
|
|
33
|
+
if (typeof item === 'string') {
|
|
34
|
+
fn(item, normalizeSimple(item, item));
|
|
35
|
+
} else if (item && typeof item === 'object') {
|
|
36
|
+
object(item);
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error('Unexpected options format');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const object = (obj)=>{
|
|
43
|
+
for (const [key, value] of Object.entries(obj)){
|
|
44
|
+
if (typeof value === 'string' || Array.isArray(value)) {
|
|
45
|
+
fn(key, normalizeSimple(value, key));
|
|
46
|
+
} else {
|
|
47
|
+
fn(key, normalizeOptions(value, key));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (!options) {
|
|
52
|
+
return;
|
|
53
|
+
} else if (Array.isArray(options)) {
|
|
54
|
+
array(options);
|
|
55
|
+
} else if (typeof options === 'object') {
|
|
56
|
+
object(options);
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error('Unexpected options format');
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* @template T
|
|
63
|
+
* @template R
|
|
64
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
65
|
+
* @param {function(string | string[], string) : R} normalizeSimple normalize a simple item
|
|
66
|
+
* @param {function(T, string) : R} normalizeOptions normalize a complex item
|
|
67
|
+
* @returns {[string, R][]} parsed options
|
|
68
|
+
*/ const parseOptions = (options, normalizeSimple, normalizeOptions)=>{
|
|
69
|
+
const items = [];
|
|
70
|
+
process(options, normalizeSimple, normalizeOptions, (key, value)=>{
|
|
71
|
+
items.push([
|
|
72
|
+
key,
|
|
73
|
+
value
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
76
|
+
return items;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* @template T
|
|
80
|
+
* @param {string} scope scope name
|
|
81
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
82
|
+
* @returns {Record<string, string | string[] | T>} options to spread or pass
|
|
83
|
+
*/ const scope = (scope, options)=>{
|
|
84
|
+
const obj = {};
|
|
85
|
+
process(options, (item)=>item, (item)=>item, (key, value)=>{
|
|
86
|
+
obj[key.startsWith('./') ? `${scope}${key.slice(1)}` : `${scope}/${key}`] = value;
|
|
87
|
+
});
|
|
88
|
+
return obj;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=options.js.map
|