@module-federation/enhanced 0.2.0-canary.2 → 0.2.0-canary.4
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 +1 -1
- package/src/lib/container/AsyncBoundaryPlugin.js +14 -14
- package/src/lib/container/AsyncBoundaryPlugin.js.map +1 -1
- 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.js +3 -1
- package/src/lib/container/ModuleFederationPlugin.js.map +1 -1
- package/src/lib/container/RemoteRuntimeModule.js +2 -3
- package/src/lib/container/RemoteRuntimeModule.js.map +1 -1
- package/src/lib/sharing/ConsumeSharedRuntimeModule.js +3 -4
- package/src/lib/sharing/ConsumeSharedRuntimeModule.js.map +1 -1
- package/src/schemas/container/ModuleFederationPlugin.check.d.ts +3 -6
- package/src/schemas/container/ModuleFederationPlugin.check.js +2245 -0
- package/src/schemas/container/ModuleFederationPlugin.check.js.map +1 -0
- package/src/schemas/container/ModuleFederationPlugin.d.ts +437 -0
- package/src/schemas/container/ModuleFederationPlugin.js +552 -0
- package/src/schemas/container/ModuleFederationPlugin.js.map +1 -0
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ let AsyncEntryStartupPlugin = class AsyncEntryStartupPlugin {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
collectRuntimeChunks(compilation) {
|
|
26
|
-
compilation.hooks.beforeChunkAssets.tap('
|
|
26
|
+
compilation.hooks.beforeChunkAssets.tap('AsyncEntryStartupPlugin', ()=>{
|
|
27
27
|
for (const chunk of compilation.chunks){
|
|
28
28
|
if (chunk.hasRuntime() && chunk.id !== null) {
|
|
29
29
|
this._runtimeChunks.set(chunk.id, chunk);
|
|
@@ -39,7 +39,6 @@ let AsyncEntryStartupPlugin = class AsyncEntryStartupPlugin {
|
|
|
39
39
|
handleRenderStartup(compiler, compilation) {
|
|
40
40
|
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).renderStartup.tap('AsyncEntryStartupPlugin', (source, renderContext, upperContext)=>{
|
|
41
41
|
var _compiler_options_optimization, _compiler_options, _compiler_options_experiments, _compiler_options1, _compiler_options_experiments1, _compiler_options2;
|
|
42
|
-
// Check if this._runtimeChunks contains any runtime chunks
|
|
43
42
|
const isSingleRuntime = (_compiler_options = compiler.options) == null ? void 0 : (_compiler_options_optimization = _compiler_options.optimization) == null ? void 0 : _compiler_options_optimization.runtimeChunk;
|
|
44
43
|
if ((upperContext == null ? void 0 : upperContext.chunk.id) && isSingleRuntime) {
|
|
45
44
|
if (upperContext == null ? void 0 : upperContext.chunk.hasRuntime()) {
|
|
@@ -47,7 +46,6 @@ let AsyncEntryStartupPlugin = class AsyncEntryStartupPlugin {
|
|
|
47
46
|
return source;
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
// Check if excludeChunk is provided, use it to decide further processing
|
|
51
49
|
if (this._options.excludeChunk && this._options.excludeChunk(upperContext.chunk)) {
|
|
52
50
|
return source;
|
|
53
51
|
}
|
|
@@ -68,42 +66,44 @@ let AsyncEntryStartupPlugin = class AsyncEntryStartupPlugin {
|
|
|
68
66
|
if (runtime.size === 0) {
|
|
69
67
|
runtime.add(upperContext.chunk);
|
|
70
68
|
}
|
|
71
|
-
// Get the runtime requirements of the chunk
|
|
72
69
|
let remotes = '';
|
|
73
70
|
let shared = '';
|
|
74
71
|
for (const runtimeItem of runtime){
|
|
75
72
|
const requirements = compilation.chunkGraph.getTreeRuntimeRequirements(runtimeItem);
|
|
76
73
|
const hasRemoteModules = compilation.chunkGraph.getChunkModulesIterableBySourceType(upperContext.chunk, 'remote');
|
|
77
74
|
const consumeShares = compilation.chunkGraph.getChunkModulesIterableBySourceType(upperContext.chunk, 'consume-shared');
|
|
78
|
-
|
|
75
|
+
const entryOptions = upperContext.chunk.getEntryOptions();
|
|
76
|
+
const chunksToRef = (entryOptions == null ? void 0 : entryOptions.dependOn) ? [
|
|
77
|
+
...entryOptions.dependOn,
|
|
78
|
+
upperContext.chunk.id
|
|
79
|
+
] : [
|
|
80
|
+
upperContext.chunk.id
|
|
81
|
+
];
|
|
79
82
|
if (requirements.has(_RuntimeGlobals.default.currentRemoteGetScope) || hasRemoteModules || requirements.has('__webpack_require__.vmok')) {
|
|
80
|
-
|
|
83
|
+
for (const chunkId of chunksToRef){
|
|
84
|
+
remotes += `if(__webpack_require__.f && __webpack_require__.f.remotes) __webpack_require__.f.remotes(${JSON.stringify(chunkId)}, promiseTrack);`;
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
|
-
// Check if the chunk has share scope map or initialize sharing
|
|
83
87
|
if (requirements.has(_RuntimeGlobals.default.shareScopeMap) || requirements.has(_RuntimeGlobals.default.initializeSharing) || consumeShares) {
|
|
84
|
-
|
|
88
|
+
for (const chunkId of chunksToRef){
|
|
89
|
+
shared += `if(__webpack_require__.f && __webpack_require__.f.consumes) __webpack_require__.f.consumes(${JSON.stringify(chunkId)}, promiseTrack);`;
|
|
90
|
+
}
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
|
-
// If no remotes or shared, return the source
|
|
88
93
|
if (!remotes && !shared) {
|
|
89
94
|
return source;
|
|
90
95
|
}
|
|
91
|
-
// Get the entry modules of the chunk
|
|
92
96
|
const entryModules = compilation.chunkGraph.getChunkEntryModulesIterable(upperContext.chunk);
|
|
93
97
|
const initialEntryModules = [];
|
|
94
|
-
// Iterate over the entry modules
|
|
95
98
|
for (const entryModule of entryModules){
|
|
96
99
|
const entryModuleID = compilation.chunkGraph.getModuleId(entryModule);
|
|
97
100
|
if (entryModuleID) {
|
|
98
101
|
let shouldInclude = false;
|
|
99
|
-
// Check if eager is a function and call it
|
|
100
102
|
if (typeof this._options.eager === 'function') {
|
|
101
103
|
shouldInclude = this._options.eager(entryModule);
|
|
102
104
|
} else if (this._options.eager && this._options.eager.test(entryModule.identifier())) {
|
|
103
|
-
// Check if eager is a RegExp and test it
|
|
104
105
|
shouldInclude = true;
|
|
105
106
|
}
|
|
106
|
-
// If shouldInclude is true, push the module to initialEntryModules
|
|
107
107
|
if (shouldInclude) {
|
|
108
108
|
initialEntryModules.push(`__webpack_require__(${JSON.stringify(entryModuleID)});`);
|
|
109
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts"],"sourcesContent":["import Compiler from 'webpack/lib/Compiler';\nimport Compilation from 'webpack/lib/Compilation';\nimport Chunk from 'webpack/lib/Chunk';\nimport RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport Template from 'webpack/lib/Template';\nimport Module from 'webpack/lib/Module';\n\ninterface Options {\n eager?: RegExp | ((module: Module) => boolean);\n excludeChunk?: (chunk: Chunk) => boolean;\n}\n\nclass AsyncEntryStartupPlugin {\n private _options: Options;\n private _runtimeChunks: Map<string | number, Chunk>;\n\n constructor(options?: Options) {\n this._options = options || {};\n this._runtimeChunks = new Map<string | number, Chunk>();\n }\n\n apply(compiler: Compiler): void {\n compiler.hooks.thisCompilation.tap(\n 'AsyncEntryStartupPlugin',\n (compilation: Compilation) => {\n this.collectRuntimeChunks(compilation);\n this.handleRenderStartup(compiler, compilation);\n },\n );\n }\n\n private collectRuntimeChunks(compilation: Compilation): void {\n compilation.hooks.beforeChunkAssets.tap(\n 'CollectRuntimeChunksPlugin',\n () => {\n for (const chunk of compilation.chunks) {\n if (chunk.hasRuntime() && chunk.id !== null) {\n this._runtimeChunks.set(chunk.id, chunk);\n for (const dependentChunk of compilation.chunkGraph.getChunkEntryDependentChunksIterable(\n chunk,\n )) {\n if (dependentChunk.id !== null) {\n this._runtimeChunks.set(dependentChunk.id, dependentChunk);\n }\n }\n }\n }\n },\n );\n }\n\n private handleRenderStartup(\n compiler: Compiler,\n compilation: Compilation,\n ): void {\n compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation,\n ).renderStartup.tap(\n 'AsyncEntryStartupPlugin',\n (source: any, renderContext: Module, upperContext: { chunk: Chunk }) => {\n // Check if this._runtimeChunks contains any runtime chunks\n const isSingleRuntime = compiler.options?.optimization?.runtimeChunk;\n if (upperContext?.chunk.id && isSingleRuntime) {\n if (upperContext?.chunk.hasRuntime()) {\n this._runtimeChunks.set(upperContext.chunk.id, upperContext.chunk);\n return source;\n }\n }\n\n // Check if excludeChunk is provided, use it to decide further processing\n if (\n this._options.excludeChunk &&\n this._options.excludeChunk(upperContext.chunk)\n ) {\n return source;\n }\n\n const runtime = new Set();\n if (\n typeof upperContext.chunk.runtime === 'string' ||\n typeof upperContext.chunk.runtime === 'number'\n ) {\n if (this._runtimeChunks.has(upperContext.chunk.runtime)) {\n runtime.add(this._runtimeChunks.get(upperContext.chunk.runtime));\n } else {\n runtime.add(upperContext.chunk);\n }\n } else if (\n upperContext.chunk.runtime &&\n typeof upperContext.chunk.runtime[Symbol.iterator] === 'function'\n ) {\n for (const runtimeItem of upperContext.chunk.runtime) {\n if (this._runtimeChunks.has(runtimeItem)) {\n runtime.add(this._runtimeChunks.get(runtimeItem));\n }\n }\n }\n if (runtime.size === 0) {\n runtime.add(upperContext.chunk);\n }\n // Get the runtime requirements of the chunk\n let remotes = '';\n let shared = '';\n\n for (const runtimeItem of runtime) {\n const requirements =\n compilation.chunkGraph.getTreeRuntimeRequirements(\n runtimeItem as Chunk,\n );\n\n const hasRemoteModules =\n compilation.chunkGraph.getChunkModulesIterableBySourceType(\n upperContext.chunk,\n 'remote',\n );\n\n const consumeShares =\n compilation.chunkGraph.getChunkModulesIterableBySourceType(\n upperContext.chunk,\n 'consume-shared',\n );\n\n // Check if the chunk has remote get scope\n if (\n requirements.has(RuntimeGlobals.currentRemoteGetScope) ||\n hasRemoteModules ||\n requirements.has('__webpack_require__.vmok')\n ) {\n remotes = `if(__webpack_require__.f && __webpack_require__.f.remotes) __webpack_require__.f.remotes(${JSON.stringify(\n upperContext.chunk.id,\n )}, promiseTrack);`;\n }\n\n // Check if the chunk has share scope map or initialize sharing\n if (\n requirements.has(RuntimeGlobals.shareScopeMap) ||\n requirements.has(RuntimeGlobals.initializeSharing) ||\n consumeShares\n ) {\n shared = `if(__webpack_require__.f && __webpack_require__.f.consumes) __webpack_require__.f.consumes(${JSON.stringify(\n upperContext.chunk.id,\n )}, promiseTrack);`;\n }\n }\n\n // If no remotes or shared, return the source\n if (!remotes && !shared) {\n return source;\n }\n\n // Get the entry modules of the chunk\n const entryModules =\n compilation.chunkGraph.getChunkEntryModulesIterable(\n upperContext.chunk,\n );\n\n const initialEntryModules = [];\n\n // Iterate over the entry modules\n for (const entryModule of entryModules) {\n const entryModuleID = compilation.chunkGraph.getModuleId(entryModule);\n if (entryModuleID) {\n let shouldInclude = false;\n\n // Check if eager is a function and call it\n if (typeof this._options.eager === 'function') {\n shouldInclude = this._options.eager(entryModule);\n } else if (\n this._options.eager &&\n this._options.eager.test(entryModule.identifier())\n ) {\n // Check if eager is a RegExp and test it\n shouldInclude = true;\n }\n\n // If shouldInclude is true, push the module to initialEntryModules\n if (shouldInclude) {\n initialEntryModules.push(\n `__webpack_require__(${JSON.stringify(entryModuleID)});`,\n );\n }\n }\n }\n if (\n compiler.options?.experiments?.topLevelAwait &&\n compiler.options?.experiments?.outputModule\n ) {\n return Template.asString([\n 'var promiseTrack = [];',\n Template.asString(initialEntryModules),\n shared,\n remotes,\n 'await Promise.all(promiseTrack)',\n Template.indent(source.source()),\n ]);\n }\n return Template.asString([\n 'var promiseTrack = [];',\n Template.asString(initialEntryModules),\n shared,\n remotes,\n 'var __webpack_exports__ = Promise.all(promiseTrack).then(function() {',\n Template.indent(source.source()),\n Template.indent('return __webpack_exports__'),\n '});',\n ]);\n },\n );\n }\n}\n\nexport default AsyncEntryStartupPlugin;\n"],"names":["AsyncEntryStartupPlugin","apply","compiler","hooks","thisCompilation","tap","compilation","collectRuntimeChunks","handleRenderStartup","beforeChunkAssets","chunk","chunks","hasRuntime","id","_runtimeChunks","set","dependentChunk","chunkGraph","getChunkEntryDependentChunksIterable","webpack","javascript","JavascriptModulesPlugin","getCompilationHooks","renderStartup","source","renderContext","upperContext","isSingleRuntime","options","optimization","runtimeChunk","_options","excludeChunk","runtime","Set","has","add","get","Symbol","iterator","runtimeItem","size","remotes","shared","requirements","getTreeRuntimeRequirements","hasRemoteModules","getChunkModulesIterableBySourceType","consumeShares","RuntimeGlobals","currentRemoteGetScope","JSON","stringify","shareScopeMap","initializeSharing","entryModules","getChunkEntryModulesIterable","initialEntryModules","entryModule","entryModuleID","getModuleId","shouldInclude","eager","test","identifier","push","experiments","topLevelAwait","outputModule","Template","asString","indent","constructor","Map"],"mappings":";;;;+BAmNA;;;eAAA;;;uEAhN2B;iEACN;;;;;;AAQrB,IAAA,AAAMA,0BAAN,MAAMA;IASJC,MAAMC,QAAkB,EAAQ;QAC9BA,SAASC,KAAK,CAACC,eAAe,CAACC,GAAG,CAChC,2BACA,CAACC;YACC,IAAI,CAACC,oBAAoB,CAACD;YAC1B,IAAI,CAACE,mBAAmB,CAACN,UAAUI;QACrC;IAEJ;IAEQC,qBAAqBD,WAAwB,EAAQ;QAC3DA,YAAYH,KAAK,CAACM,iBAAiB,CAACJ,GAAG,CACrC,8BACA;YACE,KAAK,MAAMK,SAASJ,YAAYK,MAAM,CAAE;gBACtC,IAAID,MAAME,UAAU,MAAMF,MAAMG,EAAE,KAAK,MAAM;oBAC3C,IAAI,CAACC,cAAc,CAACC,GAAG,CAACL,MAAMG,EAAE,EAAEH;oBAClC,KAAK,MAAMM,kBAAkBV,YAAYW,UAAU,CAACC,oCAAoC,CACtFR,OACC;wBACD,IAAIM,eAAeH,EAAE,KAAK,MAAM;4BAC9B,IAAI,CAACC,cAAc,CAACC,GAAG,CAACC,eAAeH,EAAE,EAAEG;wBAC7C;oBACF;gBACF;YACF;QACF;IAEJ;IAEQR,oBACNN,QAAkB,EAClBI,WAAwB,EAClB;QACNJ,SAASiB,OAAO,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AAW,CAAC;QAC5B,IAAI,CAACd,cAAc,GAAG,IAAI2D;IAC5B;AA8LF;MAEA,WAAezE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts"],"sourcesContent":["import Compiler from 'webpack/lib/Compiler';\nimport Compilation from 'webpack/lib/Compilation';\nimport Chunk from 'webpack/lib/Chunk';\nimport RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport Template from 'webpack/lib/Template';\nimport Module from 'webpack/lib/Module';\n\ninterface Options {\n eager?: RegExp | ((module: Module) => boolean);\n excludeChunk?: (chunk: Chunk) => boolean;\n}\n\nclass AsyncEntryStartupPlugin {\n private _options: Options;\n private _runtimeChunks: Map<string | number, Chunk>;\n\n constructor(options?: Options) {\n this._options = options || {};\n this._runtimeChunks = new Map<string | number, Chunk>();\n }\n\n apply(compiler: Compiler): void {\n compiler.hooks.thisCompilation.tap(\n 'AsyncEntryStartupPlugin',\n (compilation: Compilation) => {\n this.collectRuntimeChunks(compilation);\n this.handleRenderStartup(compiler, compilation);\n },\n );\n }\n\n private collectRuntimeChunks(compilation: Compilation): void {\n compilation.hooks.beforeChunkAssets.tap('AsyncEntryStartupPlugin', () => {\n for (const chunk of compilation.chunks) {\n if (chunk.hasRuntime() && chunk.id !== null) {\n this._runtimeChunks.set(chunk.id, chunk);\n for (const dependentChunk of compilation.chunkGraph.getChunkEntryDependentChunksIterable(\n chunk,\n )) {\n if (dependentChunk.id !== null) {\n this._runtimeChunks.set(dependentChunk.id, dependentChunk);\n }\n }\n }\n }\n });\n }\n\n private handleRenderStartup(\n compiler: Compiler,\n compilation: Compilation,\n ): void {\n compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation,\n ).renderStartup.tap(\n 'AsyncEntryStartupPlugin',\n (source: any, renderContext: Module, upperContext: { chunk: Chunk }) => {\n const isSingleRuntime = compiler.options?.optimization?.runtimeChunk;\n if (upperContext?.chunk.id && isSingleRuntime) {\n if (upperContext?.chunk.hasRuntime()) {\n this._runtimeChunks.set(upperContext.chunk.id, upperContext.chunk);\n return source;\n }\n }\n\n if (\n this._options.excludeChunk &&\n this._options.excludeChunk(upperContext.chunk)\n ) {\n return source;\n }\n\n const runtime = new Set();\n if (\n typeof upperContext.chunk.runtime === 'string' ||\n typeof upperContext.chunk.runtime === 'number'\n ) {\n if (this._runtimeChunks.has(upperContext.chunk.runtime)) {\n runtime.add(this._runtimeChunks.get(upperContext.chunk.runtime));\n } else {\n runtime.add(upperContext.chunk);\n }\n } else if (\n upperContext.chunk.runtime &&\n typeof upperContext.chunk.runtime[Symbol.iterator] === 'function'\n ) {\n for (const runtimeItem of upperContext.chunk.runtime) {\n if (this._runtimeChunks.has(runtimeItem)) {\n runtime.add(this._runtimeChunks.get(runtimeItem));\n }\n }\n }\n if (runtime.size === 0) {\n runtime.add(upperContext.chunk);\n }\n\n let remotes = '';\n let shared = '';\n\n for (const runtimeItem of runtime) {\n const requirements =\n compilation.chunkGraph.getTreeRuntimeRequirements(\n runtimeItem as Chunk,\n );\n\n const hasRemoteModules =\n compilation.chunkGraph.getChunkModulesIterableBySourceType(\n upperContext.chunk,\n 'remote',\n );\n\n const consumeShares =\n compilation.chunkGraph.getChunkModulesIterableBySourceType(\n upperContext.chunk,\n 'consume-shared',\n );\n\n const entryOptions = upperContext.chunk.getEntryOptions();\n const chunksToRef = entryOptions?.dependOn\n ? [...entryOptions.dependOn, upperContext.chunk.id]\n : [upperContext.chunk.id];\n\n if (\n requirements.has(RuntimeGlobals.currentRemoteGetScope) ||\n hasRemoteModules ||\n requirements.has('__webpack_require__.vmok')\n ) {\n for (const chunkId of chunksToRef) {\n remotes += `if(__webpack_require__.f && __webpack_require__.f.remotes) __webpack_require__.f.remotes(${JSON.stringify(\n chunkId,\n )}, promiseTrack);`;\n }\n }\n\n if (\n requirements.has(RuntimeGlobals.shareScopeMap) ||\n requirements.has(RuntimeGlobals.initializeSharing) ||\n consumeShares\n ) {\n for (const chunkId of chunksToRef) {\n shared += `if(__webpack_require__.f && __webpack_require__.f.consumes) __webpack_require__.f.consumes(${JSON.stringify(\n chunkId,\n )}, promiseTrack);`;\n }\n }\n }\n\n if (!remotes && !shared) {\n return source;\n }\n\n const entryModules =\n compilation.chunkGraph.getChunkEntryModulesIterable(\n upperContext.chunk,\n );\n\n const initialEntryModules = [];\n\n for (const entryModule of entryModules) {\n const entryModuleID = compilation.chunkGraph.getModuleId(entryModule);\n if (entryModuleID) {\n let shouldInclude = false;\n\n if (typeof this._options.eager === 'function') {\n shouldInclude = this._options.eager(entryModule);\n } else if (\n this._options.eager &&\n this._options.eager.test(entryModule.identifier())\n ) {\n shouldInclude = true;\n }\n\n if (shouldInclude) {\n initialEntryModules.push(\n `__webpack_require__(${JSON.stringify(entryModuleID)});`,\n );\n }\n }\n }\n if (\n compiler.options?.experiments?.topLevelAwait &&\n compiler.options?.experiments?.outputModule\n ) {\n return Template.asString([\n 'var promiseTrack = [];',\n Template.asString(initialEntryModules),\n shared,\n remotes,\n 'await Promise.all(promiseTrack)',\n Template.indent(source.source()),\n ]);\n }\n return Template.asString([\n 'var promiseTrack = [];',\n Template.asString(initialEntryModules),\n shared,\n remotes,\n 'var __webpack_exports__ = Promise.all(promiseTrack).then(function() {',\n Template.indent(source.source()),\n Template.indent('return __webpack_exports__'),\n '});',\n ]);\n },\n );\n }\n}\n\nexport default AsyncEntryStartupPlugin;\n"],"names":["AsyncEntryStartupPlugin","apply","compiler","hooks","thisCompilation","tap","compilation","collectRuntimeChunks","handleRenderStartup","beforeChunkAssets","chunk","chunks","hasRuntime","id","_runtimeChunks","set","dependentChunk","chunkGraph","getChunkEntryDependentChunksIterable","webpack","javascript","JavascriptModulesPlugin","getCompilationHooks","renderStartup","source","renderContext","upperContext","isSingleRuntime","options","optimization","runtimeChunk","_options","excludeChunk","runtime","Set","has","add","get","Symbol","iterator","runtimeItem","size","remotes","shared","requirements","getTreeRuntimeRequirements","hasRemoteModules","getChunkModulesIterableBySourceType","consumeShares","entryOptions","getEntryOptions","chunksToRef","dependOn","RuntimeGlobals","currentRemoteGetScope","chunkId","JSON","stringify","shareScopeMap","initializeSharing","entryModules","getChunkEntryModulesIterable","initialEntryModules","entryModule","entryModuleID","getModuleId","shouldInclude","eager","test","identifier","push","experiments","topLevelAwait","outputModule","Template","asString","indent","constructor","Map"],"mappings":";;;;+BA+MA;;;eAAA;;;uEA5M2B;iEACN;;;;;;AAQrB,IAAA,AAAMA,0BAAN,MAAMA;IASJC,MAAMC,QAAkB,EAAQ;QAC9BA,SAASC,KAAK,CAACC,eAAe,CAACC,GAAG,CAChC,2BACA,CAACC;YACC,IAAI,CAACC,oBAAoB,CAACD;YAC1B,IAAI,CAACE,mBAAmB,CAACN,UAAUI;QACrC;IAEJ;IAEQC,qBAAqBD,WAAwB,EAAQ;QAC3DA,YAAYH,KAAK,CAACM,iBAAiB,CAACJ,GAAG,CAAC,2BAA2B;YACjE,KAAK,MAAMK,SAASJ,YAAYK,MAAM,CAAE;gBACtC,IAAID,MAAME,UAAU,MAAMF,MAAMG,EAAE,KAAK,MAAM;oBAC3C,IAAI,CAACC,cAAc,CAACC,GAAG,CAACL,MAAMG,EAAE,EAAEH;oBAClC,KAAK,MAAMM,kBAAkBV,YAAYW,UAAU,CAACC,oCAAoC,CACtFR,OACC;wBACD,IAAIM,eAAeH,EAAE,KAAK,MAAM;4BAC9B,IAAI,CAACC,cAAc,CAACC,GAAG,CAACC,eAAeH,EAAE,EAAEG;wBAC7C;oBACF;gBACF;YACF;QACF;IACF;IAEQR,oBACNN,QAAkB,EAClBI,WAAwB,EAClB;QACNJ,SAASiB,OAAO,CAACC,UAAU,CAACC,uBAAuB,CAACC,mBAAmB,CACrEhB,aACAiB,aAAa,CAAClB,GAAG,CACjB,2BACA,CAACmB,QAAaC,eAAuBC;gBACXxB,gCAAAA,mBA2HtBA,+BAAAA,oBACAA,gCAAAA;YA5HF,MAAMyB,mBAAkBzB,oBAAAA,SAAS0B,OAAO,sBAAhB1B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
/**
|
|
3
|
+
* @typedef {import("webpack").Compiler} Compiler
|
|
4
|
+
* @typedef {import("webpack").Compilation} Compilation
|
|
5
|
+
* @typedef {import("webpack").Chunk} Chunk
|
|
6
|
+
* @typedef {import("webpack").Module} Module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* This class is used to hoist container references in the code.
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
export declare class HoistContainerReferences {
|
|
13
|
+
/**
|
|
14
|
+
* @function apply
|
|
15
|
+
* @param {Compiler} compiler The webpack compiler object
|
|
16
|
+
*/
|
|
17
|
+
apply(compiler: Compiler): void;
|
|
18
|
+
}
|
|
19
|
+
export default HoistContainerReferences;
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
HoistContainerReferences: function() {
|
|
13
|
+
return HoistContainerReferences;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return _default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
let HoistContainerReferences = class HoistContainerReferences {
|
|
20
|
+
/**
|
|
21
|
+
* @function apply
|
|
22
|
+
* @param {Compiler} compiler The webpack compiler object
|
|
23
|
+
*/ apply(compiler) {
|
|
24
|
+
// Hook into the compilation process
|
|
25
|
+
compiler.hooks.thisCompilation.tap('HoistContainerReferences', (compilation)=>{
|
|
26
|
+
// After chunks are optimized, perform the hoisting
|
|
27
|
+
compilation.hooks.afterOptimizeChunks.tap('HoistContainerReferences', (chunks, chunkGroups)=>{
|
|
28
|
+
// Create a map to store chunks by their id or name
|
|
29
|
+
/** @type {Map<(string|number), Chunk>} */ const chunkSet = new Map();
|
|
30
|
+
// Create a set to store external module requests
|
|
31
|
+
/** @type {Set<Module>} */ const externalRequests = new Set();
|
|
32
|
+
// Populate the chunkSet with chunks
|
|
33
|
+
for (const chunk of chunks){
|
|
34
|
+
const ident = chunk.id || chunk.name;
|
|
35
|
+
if (ident) {
|
|
36
|
+
chunkSet.set(ident, chunk);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Iterate over chunks again to handle remote modules
|
|
40
|
+
for (const chunk of chunks){
|
|
41
|
+
// Get iterable of remote modules for the chunk
|
|
42
|
+
const remoteModules = compilation.chunkGraph.getChunkModulesIterableBySourceType(chunk, 'remote');
|
|
43
|
+
if (!remoteModules) continue;
|
|
44
|
+
// Iterate over remote modules
|
|
45
|
+
for (const remoteModule of remoteModules){
|
|
46
|
+
// Iterate over dependencies of the remote module
|
|
47
|
+
for (const dep of remoteModule.dependencies){
|
|
48
|
+
// Get the module associated with the dependency
|
|
49
|
+
const mod = compilation.moduleGraph.getModule(dep);
|
|
50
|
+
// If the module exists and the chunk has a runtime, add the module to externalRequests
|
|
51
|
+
if (mod !== null && chunk.runtime) {
|
|
52
|
+
externalRequests.add(mod);
|
|
53
|
+
// Get the runtime chunk(s) associated with the chunk
|
|
54
|
+
const runtimeChunk = typeof chunk.runtime === 'string' || typeof chunk.runtime === 'number' ? [
|
|
55
|
+
chunk.runtime
|
|
56
|
+
] : [
|
|
57
|
+
...chunk.runtime
|
|
58
|
+
];
|
|
59
|
+
// Iterate over runtime chunks
|
|
60
|
+
for (const runtimeChunkId of runtimeChunk){
|
|
61
|
+
// Get the runtime chunk from the chunkSet
|
|
62
|
+
const runtimeChunk = chunkSet.get(runtimeChunkId);
|
|
63
|
+
// If the runtime chunk exists, connect it with the module in the chunk graph
|
|
64
|
+
if (runtimeChunk) {
|
|
65
|
+
compilation.chunkGraph.connectChunkAndModule(runtimeChunk, mod);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const _default = HoistContainerReferences;
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=HoistContainerReferencesPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/HoistContainerReferencesPlugin.ts"],"sourcesContent":["import Compiler from 'webpack/lib/Compiler';\nimport Module from 'webpack/lib/Module';\nimport Chunk from 'webpack/lib/Chunk';\nimport Compilation from 'webpack/lib/Compilation';\nimport ChunkGroup from 'webpack/lib/ChunkGroup';\n\n/**\n * @typedef {import(\"webpack\").Compiler} Compiler\n * @typedef {import(\"webpack\").Compilation} Compilation\n * @typedef {import(\"webpack\").Chunk} Chunk\n * @typedef {import(\"webpack\").Module} Module\n */\n\n/**\n * This class is used to hoist container references in the code.\n * @constructor\n */\nexport class HoistContainerReferences {\n /**\n * @function apply\n * @param {Compiler} compiler The webpack compiler object\n */\n apply(compiler: Compiler): void {\n // Hook into the compilation process\n compiler.hooks.thisCompilation.tap(\n 'HoistContainerReferences',\n (compilation: Compilation) => {\n // After chunks are optimized, perform the hoisting\n compilation.hooks.afterOptimizeChunks.tap(\n 'HoistContainerReferences',\n (chunks: Iterable<Chunk>, chunkGroups: ChunkGroup[]) => {\n // Create a map to store chunks by their id or name\n /** @type {Map<(string|number), Chunk>} */\n const chunkSet = new Map<string | number, Chunk>();\n // Create a set to store external module requests\n /** @type {Set<Module>} */\n const externalRequests = new Set<Module>();\n // Populate the chunkSet with chunks\n for (const chunk of chunks) {\n const ident = chunk.id || chunk.name;\n if (ident) {\n chunkSet.set(ident, chunk);\n }\n }\n // Iterate over chunks again to handle remote modules\n for (const chunk of chunks) {\n // Get iterable of remote modules for the chunk\n const remoteModules =\n compilation.chunkGraph.getChunkModulesIterableBySourceType(\n chunk,\n 'remote',\n );\n if (!remoteModules) continue;\n // Iterate over remote modules\n for (const remoteModule of remoteModules) {\n // Iterate over dependencies of the remote module\n for (const dep of remoteModule.dependencies) {\n // Get the module associated with the dependency\n const mod = compilation.moduleGraph.getModule(dep);\n // If the module exists and the chunk has a runtime, add the module to externalRequests\n if (mod !== null && chunk.runtime) {\n externalRequests.add(mod);\n // Get the runtime chunk(s) associated with the chunk\n const runtimeChunk =\n typeof chunk.runtime === 'string' ||\n typeof chunk.runtime === 'number'\n ? [chunk.runtime]\n : [...chunk.runtime];\n // Iterate over runtime chunks\n for (const runtimeChunkId of runtimeChunk) {\n // Get the runtime chunk from the chunkSet\n const runtimeChunk = chunkSet.get(runtimeChunkId);\n // If the runtime chunk exists, connect it with the module in the chunk graph\n if (runtimeChunk) {\n compilation.chunkGraph.connectChunkAndModule(\n runtimeChunk,\n mod,\n );\n }\n }\n }\n }\n }\n }\n },\n );\n },\n );\n }\n}\nexport default HoistContainerReferences;\n"],"names":["HoistContainerReferences","apply","compiler","hooks","thisCompilation","tap","compilation","afterOptimizeChunks","chunks","chunkGroups","chunkSet","Map","externalRequests","Set","chunk","ident","id","name","set","remoteModules","chunkGraph","getChunkModulesIterableBySourceType","remoteModule","dep","dependencies","mod","moduleGraph","getModule","runtime","add","runtimeChunk","runtimeChunkId","get","connectChunkAndModule"],"mappings":";;;;;;;;;;;IAiBaA,wBAAwB;eAAxBA;;IAyEb,OAAwC;eAAxC;;;AAzEO,IAAA,AAAMA,2BAAN,MAAMA;IACX;;;GAGC,GACDC,MAAMC,QAAkB,EAAQ;QAC9B,oCAAoC;QACpCA,SAASC,KAAK,CAACC,eAAe,CAACC,GAAG,CAChC,4BACA,CAACC;YACC,mDAAmD;YACnDA,YAAYH,KAAK,CAACI,mBAAmB,CAACF,GAAG,CACvC,4BACA,CAACG,QAAyBC;gBACxB,mDAAmD;gBACnD,wCAAwC,GACxC,MAAMC,WAAW,IAAIC;gBACrB,iDAAiD;gBACjD,wBAAwB,GACxB,MAAMC,mBAAmB,IAAIC;gBAC7B,oCAAoC;gBACpC,KAAK,MAAMC,SAASN,OAAQ;oBAC1B,MAAMO,QAAQD,MAAME,EAAE,IAAIF,MAAMG,IAAI;oBACpC,IAAIF,OAAO;wBACTL,SAASQ,GAAG,CAACH,OAAOD;oBACtB;gBACF;gBACA,qDAAqD;gBACrD,KAAK,MAAMA,SAASN,OAAQ;oBAC1B,+CAA+C;oBAC/C,MAAMW,gBACJb,YAAYc,UAAU,CAACC,mCAAmC,CACxDP,OACA;oBAEJ,IAAI,CAACK,eAAe;oBACpB,8BAA8B;oBAC9B,KAAK,MAAMG,gBAAgBH,cAAe;wBACxC,iDAAiD;wBACjD,KAAK,MAAMI,OAAOD,aAAaE,YAAY,CAAE;4BAC3C,gDAAgD;4BAChD,MAAMC,MAAMnB,YAAYoB,WAAW,CAACC,SAAS,CAACJ;4BAC9C,uFAAuF;4BACvF,IAAIE,QAAQ,QAAQX,MAAMc,OAAO,EAAE;gCACjChB,iBAAiBiB,GAAG,CAACJ;gCACrB,qDAAqD;gCACrD,MAAMK,eACJ,OAAOhB,MAAMc,OAAO,KAAK,YACzB,OAAOd,MAAMc,OAAO,KAAK,WACrB;oCAACd,MAAMc,OAAO;iCAAC,GACf;uCAAId,MAAMc,OAAO;iCAAC;gCACxB,8BAA8B;gCAC9B,KAAK,MAAMG,kBAAkBD,aAAc;oCACzC,0CAA0C;oCAC1C,MAAMA,eAAepB,SAASsB,GAAG,CAACD;oCAClC,6EAA6E;oCAC7E,IAAID,cAAc;wCAChBxB,YAAYc,UAAU,CAACa,qBAAqB,CAC1CH,cACAL;oCAEJ;gCACF;4BACF;wBACF;oBACF;gBACF;YACF;QAEJ;IAEJ;AACF;MACA,WAAezB"}
|
|
@@ -16,13 +16,15 @@ const _SharePlugin = /*#__PURE__*/ _interop_require_default(require("../sharing/
|
|
|
16
16
|
const _createschemavalidation = /*#__PURE__*/ _interop_require_default(require("webpack/lib/util/create-schema-validation"));
|
|
17
17
|
const _ContainerPlugin = /*#__PURE__*/ _interop_require_default(require("./ContainerPlugin"));
|
|
18
18
|
const _ContainerReferencePlugin = /*#__PURE__*/ _interop_require_default(require("./ContainerReferencePlugin"));
|
|
19
|
+
const _ModuleFederationPlugincheck = /*#__PURE__*/ _interop_require_default(require("webpack/schemas/plugins/container/ModuleFederationPlugin.check.js"));
|
|
20
|
+
const _ModuleFederationPlugin = /*#__PURE__*/ _interop_require_default(require("../../schemas/container/ModuleFederationPlugin"));
|
|
19
21
|
function _interop_require_default(obj) {
|
|
20
22
|
return obj && obj.__esModule ? obj : {
|
|
21
23
|
default: obj
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
const validate = (0, _createschemavalidation.default)(//eslint-disable-next-line
|
|
25
|
-
|
|
27
|
+
_ModuleFederationPlugincheck.default, ()=>_ModuleFederationPlugin.default, {
|
|
26
28
|
name: 'Module Federation Plugin',
|
|
27
29
|
baseDataPath: 'options'
|
|
28
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/ModuleFederationPlugin.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 type Compiler from 'webpack/lib/Compiler';\nimport isValidExternalsType from 'webpack/schemas/plugins/container/ExternalsType.check.js';\nimport type { ModuleFederationPluginOptions } from './ModuleFederationPluginTypes';\nimport SharePlugin from '../sharing/SharePlugin';\nimport createSchemaValidation from 'webpack/lib/util/create-schema-validation';\nimport ContainerPlugin from './ContainerPlugin';\nimport ContainerReferencePlugin from './ContainerReferencePlugin';\n\nconst validate = createSchemaValidation(\n //eslint-disable-next-line\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/container/ModuleFederationPlugin.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 type Compiler from 'webpack/lib/Compiler';\nimport isValidExternalsType from 'webpack/schemas/plugins/container/ExternalsType.check.js';\nimport type { ModuleFederationPluginOptions } from './ModuleFederationPluginTypes';\nimport SharePlugin from '../sharing/SharePlugin';\nimport createSchemaValidation from 'webpack/lib/util/create-schema-validation';\nimport ContainerPlugin from './ContainerPlugin';\nimport ContainerReferencePlugin from './ContainerReferencePlugin';\nimport checkOptions from 'webpack/schemas/plugins/container/ModuleFederationPlugin.check.js';\nimport schema from '../../schemas/container/ModuleFederationPlugin';\n\nconst validate = createSchemaValidation(\n //eslint-disable-next-line\n checkOptions,\n () => schema,\n {\n name: 'Module Federation Plugin',\n baseDataPath: 'options',\n },\n);\n\nclass ModuleFederationPlugin {\n private _options: ModuleFederationPluginOptions;\n /**\n * @param {ModuleFederationPluginOptions} options options\n */\n constructor(options: ModuleFederationPluginOptions) {\n validate(options);\n\n this._options = options;\n }\n\n /**\n * Apply the plugin\n * @param {Compiler} compiler the compiler instance\n * @returns {void}\n */\n apply(compiler: Compiler): void {\n const { _options: options } = this;\n const library = options.library || { type: 'var', name: options.name };\n const remoteType =\n options.remoteType ||\n (options.library && isValidExternalsType(options.library.type)\n ? options.library.type\n : 'script');\n if (\n library &&\n !compiler.options.output.enabledLibraryTypes?.includes(library.type)\n ) {\n compiler.options.output.enabledLibraryTypes?.push(library.type);\n }\n compiler.hooks.afterPlugins.tap('ModuleFederationPlugin', () => {\n if (\n options.exposes &&\n (Array.isArray(options.exposes)\n ? options.exposes.length > 0\n : Object.keys(options.exposes).length > 0)\n ) {\n new ContainerPlugin({\n //@ts-ignore\n name: options.name,\n library,\n filename: options.filename,\n runtime: options.runtime,\n shareScope: options.shareScope,\n exposes: options.exposes,\n }).apply(compiler);\n }\n if (\n options.remotes &&\n (Array.isArray(options.remotes)\n ? options.remotes.length > 0\n : Object.keys(options.remotes).length > 0)\n ) {\n new ContainerReferencePlugin({\n //@ts-ignore\n remoteType,\n shareScope: options.shareScope,\n remotes: options.remotes,\n }).apply(compiler);\n }\n if (options.shared) {\n new SharePlugin({\n shared: options.shared,\n shareScope: options.shareScope,\n }).apply(compiler);\n }\n });\n }\n}\n\nexport default ModuleFederationPlugin;\n"],"names":["validate","createSchemaValidation","checkOptions","schema","name","baseDataPath","ModuleFederationPlugin","apply","compiler","_options","options","library","type","remoteType","isValidExternalsType","output","enabledLibraryTypes","includes","push","hooks","afterPlugins","tap","exposes","Array","isArray","length","Object","keys","ContainerPlugin","filename","runtime","shareScope","remotes","ContainerReferencePlugin","shared","SharePlugin","constructor"],"mappings":"AAAA;;;AAGA,GAEA;;;;+BA4FA;;;eAAA;;;2EAzFiC;oEAET;+EACW;wEACP;iFACS;oFACZ;+EACN;;;;;;AAEnB,MAAMA,WAAWC,IAAAA,+BAAsB,EACrC,0BAA0B;AAC1BC,oCAAY,EACZ,IAAMC,+BAAM,EACZ;IACEC,MAAM;IACNC,cAAc;AAChB;AAGF,IAAA,AAAMC,yBAAN,MAAMA;IAWJ;;;;GAIC,GACDC,MAAMC,QAAkB,EAAQ;YAU3BA;QATH,MAAM,EAAEC,UAAUC,OAAO,EAAE,GAAG,IAAI;QAClC,MAAMC,UAAUD,QAAQC,OAAO,IAAI;YAAEC,MAAM;YAAOR,MAAMM,QAAQN,IAAI;QAAC;QACrE,MAAMS,aACJH,QAAQG,UAAU,IACjBH,CAAAA,QAAQC,OAAO,IAAIG,IAAAA,2BAAoB,EAACJ,QAAQC,OAAO,CAACC,IAAI,IACzDF,QAAQC,OAAO,CAACC,IAAI,GACpB,QAAO;QACb,IACED,WACA,GAACH,+CAAAA,SAASE,OAAO,CAACK,MAAM,CAACC,mBAAmB,qBAA3CR,6CAA6CS,QAAQ,CAACN,QAAQC,IAAI,IACnE;gBACAJ;aAAAA,gDAAAA,SAASE,OAAO,CAACK,MAAM,CAACC,mBAAmB,qBAA3CR,8CAA6CU,IAAI,CAACP,QAAQC,IAAI;QAChE;QACAJ,SAASW,KAAK,CAACC,YAAY,CAACC,GAAG,CAAC,0BAA0B;YACxD,IACEX,QAAQY,OAAO,IACdC,CAAAA,MAAMC,OAAO,CAACd,QAAQY,OAAO,IAC1BZ,QAAQY,OAAO,CAACG,MAAM,GAAG,IACzBC,OAAOC,IAAI,CAACjB,QAAQY,OAAO,EAAEG,MAAM,GAAG,CAAA,GAC1C;gBACA,IAAIG,wBAAe,CAAC;oBAClB,YAAY;oBACZxB,MAAMM,QAAQN,IAAI;oBAClBO;oBACAkB,UAAUnB,QAAQmB,QAAQ;oBAC1BC,SAASpB,QAAQoB,OAAO;oBACxBC,YAAYrB,QAAQqB,UAAU;oBAC9BT,SAASZ,QAAQY,OAAO;gBAC1B,GAAGf,KAAK,CAACC;YACX;YACA,IACEE,QAAQsB,OAAO,IACdT,CAAAA,MAAMC,OAAO,CAACd,QAAQsB,OAAO,IAC1BtB,QAAQsB,OAAO,CAACP,MAAM,GAAG,IACzBC,OAAOC,IAAI,CAACjB,QAAQsB,OAAO,EAAEP,MAAM,GAAG,CAAA,GAC1C;gBACA,IAAIQ,iCAAwB,CAAC;oBAC3B,YAAY;oBACZpB;oBACAkB,YAAYrB,QAAQqB,UAAU;oBAC9BC,SAAStB,QAAQsB,OAAO;gBAC1B,GAAGzB,KAAK,CAACC;YACX;YACA,IAAIE,QAAQwB,MAAM,EAAE;gBAClB,IAAIC,oBAAW,CAAC;oBACdD,QAAQxB,QAAQwB,MAAM;oBACtBH,YAAYrB,QAAQqB,UAAU;gBAChC,GAAGxB,KAAK,CAACC;YACX;QACF;IACF;IAjEA;;GAEC,GACD4B,YAAY1B,OAAsC,CAAE;QAClDV,SAASU;QAET,IAAI,CAACD,QAAQ,GAAGC;IAClB;AA2DF;MAEA,WAAeJ"}
|
|
@@ -23,14 +23,13 @@ let RemoteRuntimeModule = class RemoteRuntimeModule extends _RuntimeModule.defau
|
|
|
23
23
|
/**
|
|
24
24
|
* @returns {string | null} runtime code
|
|
25
25
|
*/ generate() {
|
|
26
|
-
var _this_chunk
|
|
26
|
+
var _this_chunk;
|
|
27
27
|
const { compilation, chunkGraph } = this;
|
|
28
28
|
const { runtimeTemplate, moduleGraph } = compilation;
|
|
29
29
|
const chunkToRemotesMapping = {};
|
|
30
30
|
const idToExternalAndNameMapping = {};
|
|
31
31
|
const allChunks = [
|
|
32
|
-
...Array.from(((_this_chunk = this.chunk) == null ? void 0 : _this_chunk.
|
|
33
|
-
...Array.from(((_this_chunk1 = this.chunk) == null ? void 0 : _this_chunk1.getAllInitialChunks()) || [])
|
|
32
|
+
...Array.from(((_this_chunk = this.chunk) == null ? void 0 : _this_chunk.getAllReferencedChunks()) || [])
|
|
34
33
|
];
|
|
35
34
|
for (const chunk of allChunks){
|
|
36
35
|
const modules = chunkGraph == null ? void 0 : chunkGraph.getChunkModulesIterableBySourceType(chunk, 'remote');
|
|
@@ -1 +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';\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 allChunks = [\n ...Array.from(this.chunk?.
|
|
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';\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 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 id = chunkGraph ? chunkGraph.getModuleId(module) : undefined;\n const { shareScope } = module;\n const dep = module.dependencies[0];\n const externalModule = moduleGraph.getModule(dep);\n const externalModuleId =\n chunkGraph && externalModule\n ? chunkGraph.getModuleId(externalModule)\n : undefined;\n if (id !== undefined) {\n //@ts-ignore\n remotes.push(id);\n idToExternalAndNameMapping[id] = [shareScope, name, externalModuleId];\n }\n }\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 `${\n RuntimeGlobals.ensureChunkHandlers\n }.remotes = ${runtimeTemplate.basicFunction('chunkId, promises', [\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","allChunks","Array","from","chunk","getAllReferencedChunks","modules","getChunkModulesIterableBySourceType","remotes","id","m","module","name","internalRequest","getModuleId","undefined","shareScope","dep","dependencies","externalModule","getModule","externalModuleId","push","Template","asString","JSON","stringify","RuntimeGlobals","ensureChunkHandlers","basicFunction","hasOwnProperty","indent","currentRemoteGetScope","moduleFactories","returningFunction","initializeSharing","require","constructor"],"mappings":"AAAA;;;AAGA;;;;+BAsIA;;;eAAA;;;uEArI2B;sEAGD;iEACL;;;;;;AAErB,IAAA,AAAMA,sBAAN,MAAMA,4BAA4BC,sBAAa;IAK7C;;GAEC,GACD,AAASC,WAA0B;YAMjB;QALhB,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,YAAY;eACbC,MAAMC,IAAI,CAAC,EAAA,cAAA,IAAI,CAACC,KAAK,qBAAV,YAAYC,sBAAsB,OAAM,EAAE;SACzD;QAED,KAAK,MAAMD,SAASH,UAAW;YAC7B,MAAMK,UAAUV,8BAAAA,WAAYW,mCAAmC,CAC7DH,OACA;YAEF,IAAI,CAACE,SAAS;gBACZ;YACF;YACA,aAAa;YACb,MAAME,UAAWT,qBAAqB,CAACK,MAAMK,EAAE,CAAC,GAAG,EAAE;YACrD,KAAK,MAAMC,KAAKJ,QAAS;gBACvB,MAAMK,SAAuBD;gBAC7B,MAAME,OAAOD,OAAOE,eAAe;gBACnC,MAAMJ,KAAKb,aAAaA,WAAWkB,WAAW,CAACH,UAAUI;gBACzD,MAAM,EAAEC,UAAU,EAAE,GAAGL;gBACvB,MAAMM,MAAMN,OAAOO,YAAY,CAAC,EAAE;gBAClC,MAAMC,iBAAiBrB,YAAYsB,SAAS,CAACH;gBAC7C,MAAMI,mBACJzB,c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ACvD,mBACA,UACA,WAAW,CAAC;oCACd,CAAC,mDAAmD,CAAC;iCACtD;gCACD;gCACAX,iBAAQ,CAACQ,MAAM,CAAC;oCAAC;iCAAkC;gCACnD;6BACD;4BACD;4BACAR,iBAAQ,CAACQ,MAAM,CAAC;gCAAC;6BAAkB;4BACnC;yBACD,EACD,CAAC;wBACH,CAAC,iBAAiB,EAAElC,gBAAgBqC,iBAAiB,CACnD,CAAC,0BAA0B,EAAEP,uBAAc,CAACQ,iBAAiB,CAAC,yDAAyD,CAAC,EACxH,sBACA,CAAC,CAAC;wBACJ,CAAC,oBAAoB,EAAEtC,gBAAgBqC,iBAAiB,CACtD,CAAC,oEAAoE,CAAC,EACtE,sBACA,CAAC,CAAC;wBACJ,CAAC,gBAAgB,EAAErC,gBAAgBgC,aAAa,CAAC,WAAW;4BAC1D;4BACA,CAAC,EACCF,uBAAc,CAACM,eAAe,CAC/B,OAAO,EAAEpC,gBAAgBgC,aAAa,CAAC,UAAU;gCAChD;6BACD,EAAE,CAAC;yBACL,EAAE,CAAC,CAAC;wBACL,CAAC,eAAe,EAAEF,uBAAc,CAACS,OAAO,CAAC,gCAAgC,CAAC;qBAC3E,EAAE,EAAE,CAAC;iBACP;gBACD;aACD,EAAE,CAAC;SACL;IACH;IA3HAC,aAAc;QACZ,KAAK,CAAC;IACR;AA0HF;MAEA,WAAe7C"}
|
|
@@ -65,7 +65,7 @@ let ConsumeSharedRuntimeModule = class ConsumeSharedRuntimeModule extends _Runti
|
|
|
65
65
|
/**
|
|
66
66
|
* @returns {string | null} runtime code
|
|
67
67
|
*/ generate() {
|
|
68
|
-
var _this_chunk, _this_chunk1
|
|
68
|
+
var _this_chunk, _this_chunk1;
|
|
69
69
|
const compilation = this.compilation;
|
|
70
70
|
const chunkGraph = this.chunkGraph;
|
|
71
71
|
const { runtimeTemplate, codeGenerationResults } = compilation;
|
|
@@ -86,8 +86,7 @@ let ConsumeSharedRuntimeModule = class ConsumeSharedRuntimeModule extends _Runti
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
const allChunks = [
|
|
89
|
-
...((_this_chunk = this.chunk) == null ? void 0 : _this_chunk.
|
|
90
|
-
...((_this_chunk1 = this.chunk) == null ? void 0 : _this_chunk1.getAllInitialChunks()) || []
|
|
89
|
+
...((_this_chunk = this.chunk) == null ? void 0 : _this_chunk.getAllReferencedChunks()) || []
|
|
91
90
|
];
|
|
92
91
|
for (const chunk of allChunks){
|
|
93
92
|
const modules = chunkGraph.getChunkModulesIterableBySourceType(chunk, 'consume-shared');
|
|
@@ -96,7 +95,7 @@ let ConsumeSharedRuntimeModule = class ConsumeSharedRuntimeModule extends _Runti
|
|
|
96
95
|
addModules(modules, chunk, chunkToModuleMapping[chunk.id.toString()] = []);
|
|
97
96
|
}
|
|
98
97
|
for (const chunk of [
|
|
99
|
-
...((
|
|
98
|
+
...((_this_chunk1 = this.chunk) == null ? void 0 : _this_chunk1.getAllInitialChunks()) || []
|
|
100
99
|
]){
|
|
101
100
|
const modules = chunkGraph.getChunkModulesIterableBySourceType(chunk, 'consume-shared');
|
|
102
101
|
if (!modules) continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/sharing/ConsumeSharedRuntimeModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\nimport * as RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport Template from 'webpack/lib/Template';\nimport {\n parseVersionRuntimeCode,\n versionLtRuntimeCode,\n rangeToStringRuntimeCode,\n satisfyRuntimeCode,\n} from 'webpack/lib/util/semver';\nimport RuntimeModule from 'webpack/lib/RuntimeModule';\nimport Module from 'webpack/lib/Module';\nimport ConsumeSharedModule from './ConsumeSharedModule';\nimport type ChunkGraph from 'webpack/lib/ChunkGraph';\nimport type Compilation from 'webpack/lib/Compilation';\nimport type Chunk from 'webpack/lib/Chunk';\nimport { Source } from 'webpack-sources';\n\nclass ConsumeSharedRuntimeModule extends RuntimeModule {\n private _runtimeRequirements: ReadonlySet<string>;\n\n /**\n * @param {ReadonlySet<string>} runtimeRequirements runtime requirements\n */\n constructor(runtimeRequirements: ReadonlySet<string>) {\n super('consumes', RuntimeModule.STAGE_ATTACH);\n this._runtimeRequirements = runtimeRequirements;\n }\n\n /**\n * @returns {string | null} runtime code\n */\n override generate(): string | null {\n const compilation: Compilation = this.compilation!;\n const chunkGraph: ChunkGraph = this.chunkGraph!;\n const { runtimeTemplate, codeGenerationResults } = compilation;\n const chunkToModuleMapping: Record<string, any> = {};\n const moduleIdToSourceMapping: Map<string | number, Source> = new Map();\n const initialConsumes: (string | number)[] = [];\n /**\n *\n * @param {Iterable<Module>} modules modules\n * @param {Chunk} chunk the chunk\n * @param {(string | number)[]} list list of ids\n */\n const addModules = (\n modules: Iterable<Module>,\n chunk: Chunk,\n list: (string | number)[],\n ) => {\n for (const m of modules) {\n const module: ConsumeSharedModule = m as ConsumeSharedModule;\n const id = chunkGraph.getModuleId(module);\n list.push(id);\n moduleIdToSourceMapping.set(\n id,\n codeGenerationResults.getSource(\n module,\n chunk.runtime,\n 'consume-shared',\n ),\n );\n }\n };\n const allChunks = [\n ...(this.chunk?.getAllAsyncChunks() || []),\n ...(this.chunk?.getAllInitialChunks() || []),\n ];\n for (const chunk of allChunks) {\n const modules = chunkGraph.getChunkModulesIterableBySourceType(\n chunk,\n 'consume-shared',\n );\n if (!modules) continue;\n if (!chunk.id) continue;\n\n addModules(\n modules,\n chunk,\n (chunkToModuleMapping[chunk.id.toString()] = []),\n );\n }\n for (const chunk of [...(this.chunk?.getAllInitialChunks() || [])]) {\n const modules = chunkGraph.getChunkModulesIterableBySourceType(\n chunk,\n 'consume-shared',\n );\n if (!modules) continue;\n addModules(modules, chunk, initialConsumes);\n }\n\n if (moduleIdToSourceMapping.size === 0) return null;\n\n return Template.asString([\n parseVersionRuntimeCode(runtimeTemplate),\n versionLtRuntimeCode(runtimeTemplate),\n rangeToStringRuntimeCode(runtimeTemplate),\n satisfyRuntimeCode(runtimeTemplate),\n `var ensureExistence = ${runtimeTemplate.basicFunction('scopeName, key', [\n `var scope = ${RuntimeGlobals.shareScopeMap}[scopeName];`,\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) throw new Error(\"Shared module \" + key + \" doesn't exist in shared scope \" + scopeName);`,\n 'return scope;',\n ])};`,\n `var findVersion = ${runtimeTemplate.basicFunction('scope, key', [\n 'var versions = scope[key];',\n `var key = Object.keys(versions).reduce(${runtimeTemplate.basicFunction(\n 'a, b',\n ['return !a || versionLt(a, b) ? b : a;'],\n )}, 0);`,\n 'return key && versions[key]',\n ])};`,\n `var findSingletonVersionKey = ${runtimeTemplate.basicFunction(\n 'scope, key',\n [\n 'var versions = scope[key];',\n `return Object.keys(versions).reduce(${runtimeTemplate.basicFunction(\n 'a, b',\n ['return !a || (!versions[a].loaded && versionLt(a, b)) ? b : a;'],\n )}, 0);`,\n ],\n )};`,\n `var getInvalidSingletonVersionMessage = ${runtimeTemplate.basicFunction(\n 'scope, key, version, requiredVersion',\n [\n `return \"Unsatisfied version \" + version + \" from \" + (version && scope[key][version].from) + \" of shared singleton module \" + key + \" (required \" + rangeToString(requiredVersion) + \")\"`,\n ],\n )};`,\n `var getSingleton = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var version = findSingletonVersionKey(scope, key);',\n 'return get(scope[key][version]);',\n ],\n )};`,\n `var getSingletonVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var version = findSingletonVersionKey(scope, key);',\n 'if (!satisfy(requiredVersion, version)) warn(getInvalidSingletonVersionMessage(scope, key, version, requiredVersion));',\n 'return get(scope[key][version]);',\n ],\n )};`,\n `var getStrictSingletonVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var version = findSingletonVersionKey(scope, key);',\n 'if (!satisfy(requiredVersion, version)) ' +\n 'throw new Error(getInvalidSingletonVersionMessage(scope, key, version, requiredVersion));',\n 'return get(scope[key][version]);',\n ],\n )};`,\n `var findValidVersion = ${runtimeTemplate.basicFunction(\n 'scope, key, requiredVersion',\n [\n 'var versions = scope[key];',\n `var key = Object.keys(versions).reduce(${runtimeTemplate.basicFunction(\n 'a, b',\n [\n 'if (!satisfy(requiredVersion, b)) return a;',\n 'return !a || versionLt(a, b) ? b : a;',\n ],\n )}, 0);`,\n 'return key && versions[key]',\n ],\n )};`,\n `var getInvalidVersionMessage = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var versions = scope[key];',\n 'return \"No satisfying version (\" + rangeToString(requiredVersion) + \") of shared module \" + key + \" found in shared scope \" + scopeName + \".\\\\n\" +',\n `\\t\"Available versions: \" + Object.keys(versions).map(${runtimeTemplate.basicFunction(\n 'key',\n ['return key + \" from \" + versions[key].from;'],\n )}).join(\", \");`,\n ],\n )};`,\n `var getValidVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var entry = findValidVersion(scope, key, requiredVersion);',\n 'if(entry) return get(entry);',\n 'throw new Error(getInvalidVersionMessage(scope, scopeName, key, requiredVersion));',\n ],\n )};`,\n `var warn = ${\n compilation.outputOptions.ignoreBrowserWarnings\n ? runtimeTemplate.basicFunction('', '')\n : runtimeTemplate.basicFunction('msg', [\n 'if (typeof console !== \"undefined\" && console.warn) console.warn(msg);',\n ])\n };`,\n `var warnInvalidVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'warn(getInvalidVersionMessage(scope, scopeName, key, requiredVersion));',\n ],\n )};`,\n `var get = ${runtimeTemplate.basicFunction('entry', [\n 'entry.loaded = 1;',\n 'return entry.get()',\n ])};`,\n `var init = ${runtimeTemplate.returningFunction(\n Template.asString([\n 'function(scopeName, a, b, c) {',\n Template.indent([\n `var promise = ${RuntimeGlobals.initializeSharing}(scopeName);`,\n `if (promise && promise.then) return promise.then(fn.bind(fn, scopeName, ${RuntimeGlobals.shareScopeMap}[scopeName], a, b, c));`,\n `return fn(scopeName, ${RuntimeGlobals.shareScopeMap}[scopeName], a, b, c);`,\n ]),\n '}',\n ]),\n 'fn',\n )};`,\n '',\n `var load = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key',\n [\n 'ensureExistence(scopeName, key);',\n 'return get(findVersion(scope, key));',\n ],\n )});`,\n `var loadFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, fallback',\n [\n `return scope && ${RuntimeGlobals.hasOwnProperty}(scope, key) ? get(findVersion(scope, key)) : fallback();`,\n ],\n )});`,\n `var loadVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return get(findValidVersion(scope, key, version) || warnInvalidVersion(scope, scopeName, key, version) || findVersion(scope, key));',\n ],\n )});`,\n `var loadSingleton = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key',\n [\n 'ensureExistence(scopeName, key);',\n 'return getSingleton(scope, scopeName, key);',\n ],\n )});`,\n `var loadSingletonVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return getSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadStrictVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return getValidVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadStrictSingletonVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return getStrictSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return get(findValidVersion(scope, key, version) || warnInvalidVersion(scope, scopeName, key, version) || findVersion(scope, key));',\n ],\n )});`,\n `var loadSingletonFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return getSingleton(scope, scopeName, key);',\n ],\n )});`,\n `var loadSingletonVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return getSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadStrictVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `var entry = scope && ${RuntimeGlobals.hasOwnProperty}(scope, key) && findValidVersion(scope, key, version);`,\n `return entry ? get(entry) : fallback();`,\n ],\n )});`,\n `var loadStrictSingletonVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return getStrictSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n 'var installedModules = {};',\n 'var moduleToHandlerMapping = {',\n Template.indent(\n Array.from(\n moduleIdToSourceMapping,\n ([key, source]) => `${JSON.stringify(key)}: ${source.source()}`,\n ).join(',\\n'),\n ),\n '};',\n\n initialConsumes.length > 0\n ? Template.asString([\n `var initialConsumes = ${JSON.stringify(initialConsumes)};`,\n `initialConsumes.forEach(${runtimeTemplate.basicFunction('id', [\n `${\n RuntimeGlobals.moduleFactories\n }[id] = ${runtimeTemplate.basicFunction('module', [\n '// Handle case when module is used sync',\n 'installedModules[id] = 0;',\n `delete ${RuntimeGlobals.moduleCache}[id];`,\n 'var factory = moduleToHandlerMapping[id]();',\n 'if(typeof factory !== \"function\") throw new Error(\"Shared module is not available for eager consumption: \" + id);',\n `module.exports = factory();`,\n ])}`,\n ])});`,\n ])\n : '// no consumes in initial chunks',\n this._runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)\n ? Template.asString([\n `var chunkMapping = ${JSON.stringify(\n chunkToModuleMapping,\n null,\n '\\t',\n )};`,\n `${\n RuntimeGlobals.ensureChunkHandlers\n }.consumes = ${runtimeTemplate.basicFunction('chunkId, promises', [\n `if(${RuntimeGlobals.hasOwnProperty}(chunkMapping, chunkId)) {`,\n Template.indent([\n `chunkMapping[chunkId].forEach(${runtimeTemplate.basicFunction(\n 'id',\n [\n `if(${RuntimeGlobals.hasOwnProperty}(installedModules, id)) return promises.push(installedModules[id]);`,\n `var onFactory = ${runtimeTemplate.basicFunction(\n 'factory',\n [\n 'installedModules[id] = 0;',\n `${\n RuntimeGlobals.moduleFactories\n }[id] = ${runtimeTemplate.basicFunction('module', [\n `delete ${RuntimeGlobals.moduleCache}[id];`,\n 'module.exports = factory();',\n ])}`,\n ],\n )};`,\n `var onError = ${runtimeTemplate.basicFunction('error', [\n 'delete installedModules[id];',\n `${\n RuntimeGlobals.moduleFactories\n }[id] = ${runtimeTemplate.basicFunction('module', [\n `delete ${RuntimeGlobals.moduleCache}[id];`,\n 'throw error;',\n ])}`,\n ])};`,\n 'try {',\n Template.indent([\n 'var promise = moduleToHandlerMapping[id]();',\n 'if(promise.then) {',\n Template.indent(\n \"promises.push(installedModules[id] = promise.then(onFactory)['catch'](onError));\",\n ),\n '} else onFactory(promise);',\n ]),\n '} catch(e) { onError(e); }',\n ],\n )});`,\n ]),\n '}',\n ])}`,\n ])\n : '// no chunk loading of consumes',\n ]);\n }\n}\n\nexport default ConsumeSharedRuntimeModule;\n"],"names":["ConsumeSharedRuntimeModule","RuntimeModule","generate","compilation","chunkGraph","runtimeTemplate","codeGenerationResults","chunkToModuleMapping","moduleIdToSourceMapping","Map","initialConsumes","addModules","modules","chunk","list","m","module","id","getModuleId","push","set","getSource","runtime","allChunks","getAllAsyncChunks","getAllInitialChunks","getChunkModulesIterableBySourceType","toString","size","Template","asString","parseVersionRuntimeCode","versionLtRuntimeCode","rangeToStringRuntimeCode","satisfyRuntimeCode","basicFunction","RuntimeGlobals","shareScopeMap","hasOwnProperty","outputOptions","ignoreBrowserWarnings","returningFunction","indent","initializeSharing","Array","from","key","source","JSON","stringify","join","length","moduleFactories","moduleCache","_runtimeRequirements","has","ensureChunkHandlers","constructor","runtimeRequirements","STAGE_ATTACH"],"mappings":"AAAA;;;AAGA;;;;+BA8XA;;;eAAA;;;wEA5XgC;iEACX;wBAMd;sEACmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQ1B,IAAA,AAAMA,6BAAN,MAAMA,mCAAmCC,sBAAa;IAWpD;;GAEC,GACD,AAASC,WAA0B;YAiC3B,aACA,cAgBmB;QAjDzB,MAAMC,cAA2B,IAAI,CAACA,WAAW;QACjD,MAAMC,aAAyB,IAAI,CAACA,UAAU;QAC9C,MAAM,EAAEC,eAAe,EAAEC,qBAAqB,EAAE,GAAGH;QACnD,MAAMI,uBAA4C,CAAC;QACnD,MAAMC,0BAAwD,IAAIC;QAClE,MAAMC,kBAAuC,EAAE;QAC/C;;;;;KAKC,GACD,MAAMC,aAAa,CACjBC,SACAC,OACAC;YAEA,KAAK,MAAMC,KAAKH,QAAS;gBACvB,MAAMI,SAA8BD;gBACpC,MAAME,KAAKb,WAAWc,WAAW,CAACF;gBAClCF,KAAKK,IAAI,CAACF;gBACVT,wBAAwBY,GAAG,CACzBH,IACAX,sBAAsBe,SAAS,CAC7BL,QACAH,MAAMS,OAAO,EACb;YAGN;QACF;QACA,MAAMC,YAAY;eACZ,EAAA,cAAA,IAAI,CAACV,KAAK,qBAAV,YAAYW,iBAAi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;IAtWA;;GAEC,GACDe,YAAYC,mBAAwC,CAAE;QACpD,KAAK,CAAC,YAAYzD,sBAAa,CAAC0D,YAAY;QAC5C,IAAI,CAACL,oBAAoB,GAAGI;IAC9B;AAiWF;MAEA,WAAe1D"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/enhanced/src/lib/sharing/ConsumeSharedRuntimeModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\nimport * as RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport Template from 'webpack/lib/Template';\nimport {\n parseVersionRuntimeCode,\n versionLtRuntimeCode,\n rangeToStringRuntimeCode,\n satisfyRuntimeCode,\n} from 'webpack/lib/util/semver';\nimport RuntimeModule from 'webpack/lib/RuntimeModule';\nimport Module from 'webpack/lib/Module';\nimport ConsumeSharedModule from './ConsumeSharedModule';\nimport type ChunkGraph from 'webpack/lib/ChunkGraph';\nimport type Compilation from 'webpack/lib/Compilation';\nimport type Chunk from 'webpack/lib/Chunk';\nimport { Source } from 'webpack-sources';\n\nclass ConsumeSharedRuntimeModule extends RuntimeModule {\n private _runtimeRequirements: ReadonlySet<string>;\n\n /**\n * @param {ReadonlySet<string>} runtimeRequirements runtime requirements\n */\n constructor(runtimeRequirements: ReadonlySet<string>) {\n super('consumes', RuntimeModule.STAGE_ATTACH);\n this._runtimeRequirements = runtimeRequirements;\n }\n\n /**\n * @returns {string | null} runtime code\n */\n override generate(): string | null {\n const compilation: Compilation = this.compilation!;\n const chunkGraph: ChunkGraph = this.chunkGraph!;\n const { runtimeTemplate, codeGenerationResults } = compilation;\n const chunkToModuleMapping: Record<string, any> = {};\n const moduleIdToSourceMapping: Map<string | number, Source> = new Map();\n const initialConsumes: (string | number)[] = [];\n /**\n *\n * @param {Iterable<Module>} modules modules\n * @param {Chunk} chunk the chunk\n * @param {(string | number)[]} list list of ids\n */\n const addModules = (\n modules: Iterable<Module>,\n chunk: Chunk,\n list: (string | number)[],\n ) => {\n for (const m of modules) {\n const module: ConsumeSharedModule = m as ConsumeSharedModule;\n const id = chunkGraph.getModuleId(module);\n list.push(id);\n moduleIdToSourceMapping.set(\n id,\n codeGenerationResults.getSource(\n module,\n chunk.runtime,\n 'consume-shared',\n ),\n );\n }\n };\n const allChunks = [...(this.chunk?.getAllReferencedChunks() || [])];\n for (const chunk of allChunks) {\n const modules = chunkGraph.getChunkModulesIterableBySourceType(\n chunk,\n 'consume-shared',\n );\n if (!modules) continue;\n if (!chunk.id) continue;\n\n addModules(\n modules,\n chunk,\n (chunkToModuleMapping[chunk.id.toString()] = []),\n );\n }\n for (const chunk of [...(this.chunk?.getAllInitialChunks() || [])]) {\n const modules = chunkGraph.getChunkModulesIterableBySourceType(\n chunk,\n 'consume-shared',\n );\n if (!modules) continue;\n addModules(modules, chunk, initialConsumes);\n }\n\n if (moduleIdToSourceMapping.size === 0) return null;\n\n return Template.asString([\n parseVersionRuntimeCode(runtimeTemplate),\n versionLtRuntimeCode(runtimeTemplate),\n rangeToStringRuntimeCode(runtimeTemplate),\n satisfyRuntimeCode(runtimeTemplate),\n `var ensureExistence = ${runtimeTemplate.basicFunction('scopeName, key', [\n `var scope = ${RuntimeGlobals.shareScopeMap}[scopeName];`,\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) throw new Error(\"Shared module \" + key + \" doesn't exist in shared scope \" + scopeName);`,\n 'return scope;',\n ])};`,\n `var findVersion = ${runtimeTemplate.basicFunction('scope, key', [\n 'var versions = scope[key];',\n `var key = Object.keys(versions).reduce(${runtimeTemplate.basicFunction(\n 'a, b',\n ['return !a || versionLt(a, b) ? b : a;'],\n )}, 0);`,\n 'return key && versions[key]',\n ])};`,\n `var findSingletonVersionKey = ${runtimeTemplate.basicFunction(\n 'scope, key',\n [\n 'var versions = scope[key];',\n `return Object.keys(versions).reduce(${runtimeTemplate.basicFunction(\n 'a, b',\n ['return !a || (!versions[a].loaded && versionLt(a, b)) ? b : a;'],\n )}, 0);`,\n ],\n )};`,\n `var getInvalidSingletonVersionMessage = ${runtimeTemplate.basicFunction(\n 'scope, key, version, requiredVersion',\n [\n `return \"Unsatisfied version \" + version + \" from \" + (version && scope[key][version].from) + \" of shared singleton module \" + key + \" (required \" + rangeToString(requiredVersion) + \")\"`,\n ],\n )};`,\n `var getSingleton = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var version = findSingletonVersionKey(scope, key);',\n 'return get(scope[key][version]);',\n ],\n )};`,\n `var getSingletonVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var version = findSingletonVersionKey(scope, key);',\n 'if (!satisfy(requiredVersion, version)) warn(getInvalidSingletonVersionMessage(scope, key, version, requiredVersion));',\n 'return get(scope[key][version]);',\n ],\n )};`,\n `var getStrictSingletonVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var version = findSingletonVersionKey(scope, key);',\n 'if (!satisfy(requiredVersion, version)) ' +\n 'throw new Error(getInvalidSingletonVersionMessage(scope, key, version, requiredVersion));',\n 'return get(scope[key][version]);',\n ],\n )};`,\n `var findValidVersion = ${runtimeTemplate.basicFunction(\n 'scope, key, requiredVersion',\n [\n 'var versions = scope[key];',\n `var key = Object.keys(versions).reduce(${runtimeTemplate.basicFunction(\n 'a, b',\n [\n 'if (!satisfy(requiredVersion, b)) return a;',\n 'return !a || versionLt(a, b) ? b : a;',\n ],\n )}, 0);`,\n 'return key && versions[key]',\n ],\n )};`,\n `var getInvalidVersionMessage = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var versions = scope[key];',\n 'return \"No satisfying version (\" + rangeToString(requiredVersion) + \") of shared module \" + key + \" found in shared scope \" + scopeName + \".\\\\n\" +',\n `\\t\"Available versions: \" + Object.keys(versions).map(${runtimeTemplate.basicFunction(\n 'key',\n ['return key + \" from \" + versions[key].from;'],\n )}).join(\", \");`,\n ],\n )};`,\n `var getValidVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'var entry = findValidVersion(scope, key, requiredVersion);',\n 'if(entry) return get(entry);',\n 'throw new Error(getInvalidVersionMessage(scope, scopeName, key, requiredVersion));',\n ],\n )};`,\n `var warn = ${\n compilation.outputOptions.ignoreBrowserWarnings\n ? runtimeTemplate.basicFunction('', '')\n : runtimeTemplate.basicFunction('msg', [\n 'if (typeof console !== \"undefined\" && console.warn) console.warn(msg);',\n ])\n };`,\n `var warnInvalidVersion = ${runtimeTemplate.basicFunction(\n 'scope, scopeName, key, requiredVersion',\n [\n 'warn(getInvalidVersionMessage(scope, scopeName, key, requiredVersion));',\n ],\n )};`,\n `var get = ${runtimeTemplate.basicFunction('entry', [\n 'entry.loaded = 1;',\n 'return entry.get()',\n ])};`,\n `var init = ${runtimeTemplate.returningFunction(\n Template.asString([\n 'function(scopeName, a, b, c) {',\n Template.indent([\n `var promise = ${RuntimeGlobals.initializeSharing}(scopeName);`,\n `if (promise && promise.then) return promise.then(fn.bind(fn, scopeName, ${RuntimeGlobals.shareScopeMap}[scopeName], a, b, c));`,\n `return fn(scopeName, ${RuntimeGlobals.shareScopeMap}[scopeName], a, b, c);`,\n ]),\n '}',\n ]),\n 'fn',\n )};`,\n '',\n `var load = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key',\n [\n 'ensureExistence(scopeName, key);',\n 'return get(findVersion(scope, key));',\n ],\n )});`,\n `var loadFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, fallback',\n [\n `return scope && ${RuntimeGlobals.hasOwnProperty}(scope, key) ? get(findVersion(scope, key)) : fallback();`,\n ],\n )});`,\n `var loadVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return get(findValidVersion(scope, key, version) || warnInvalidVersion(scope, scopeName, key, version) || findVersion(scope, key));',\n ],\n )});`,\n `var loadSingleton = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key',\n [\n 'ensureExistence(scopeName, key);',\n 'return getSingleton(scope, scopeName, key);',\n ],\n )});`,\n `var loadSingletonVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return getSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadStrictVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return getValidVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadStrictSingletonVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version',\n [\n 'ensureExistence(scopeName, key);',\n 'return getStrictSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return get(findValidVersion(scope, key, version) || warnInvalidVersion(scope, scopeName, key, version) || findVersion(scope, key));',\n ],\n )});`,\n `var loadSingletonFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return getSingleton(scope, scopeName, key);',\n ],\n )});`,\n `var loadSingletonVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return getSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n `var loadStrictVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `var entry = scope && ${RuntimeGlobals.hasOwnProperty}(scope, key) && findValidVersion(scope, key, version);`,\n `return entry ? get(entry) : fallback();`,\n ],\n )});`,\n `var loadStrictSingletonVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(\n 'scopeName, scope, key, version, fallback',\n [\n `if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,\n 'return getStrictSingletonVersion(scope, scopeName, key, version);',\n ],\n )});`,\n 'var installedModules = {};',\n 'var moduleToHandlerMapping = {',\n Template.indent(\n Array.from(\n moduleIdToSourceMapping,\n ([key, source]) => `${JSON.stringify(key)}: ${source.source()}`,\n ).join(',\\n'),\n ),\n '};',\n\n initialConsumes.length > 0\n ? Template.asString([\n `var initialConsumes = ${JSON.stringify(initialConsumes)};`,\n `initialConsumes.forEach(${runtimeTemplate.basicFunction('id', [\n `${\n RuntimeGlobals.moduleFactories\n }[id] = ${runtimeTemplate.basicFunction('module', [\n '// Handle case when module is used sync',\n 'installedModules[id] = 0;',\n `delete ${RuntimeGlobals.moduleCache}[id];`,\n 'var factory = moduleToHandlerMapping[id]();',\n 'if(typeof factory !== \"function\") throw new Error(\"Shared module is not available for eager consumption: \" + id);',\n `module.exports = factory();`,\n ])}`,\n ])});`,\n ])\n : '// no consumes in initial chunks',\n this._runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)\n ? Template.asString([\n `var chunkMapping = ${JSON.stringify(\n chunkToModuleMapping,\n null,\n '\\t',\n )};`,\n `${\n RuntimeGlobals.ensureChunkHandlers\n }.consumes = ${runtimeTemplate.basicFunction('chunkId, promises', [\n `if(${RuntimeGlobals.hasOwnProperty}(chunkMapping, chunkId)) {`,\n Template.indent([\n `chunkMapping[chunkId].forEach(${runtimeTemplate.basicFunction(\n 'id',\n [\n `if(${RuntimeGlobals.hasOwnProperty}(installedModules, id)) return promises.push(installedModules[id]);`,\n `var onFactory = ${runtimeTemplate.basicFunction(\n 'factory',\n [\n 'installedModules[id] = 0;',\n `${\n RuntimeGlobals.moduleFactories\n }[id] = ${runtimeTemplate.basicFunction('module', [\n `delete ${RuntimeGlobals.moduleCache}[id];`,\n 'module.exports = factory();',\n ])}`,\n ],\n )};`,\n `var onError = ${runtimeTemplate.basicFunction('error', [\n 'delete installedModules[id];',\n `${\n RuntimeGlobals.moduleFactories\n }[id] = ${runtimeTemplate.basicFunction('module', [\n `delete ${RuntimeGlobals.moduleCache}[id];`,\n 'throw error;',\n ])}`,\n ])};`,\n 'try {',\n Template.indent([\n 'var promise = moduleToHandlerMapping[id]();',\n 'if(promise.then) {',\n Template.indent(\n \"promises.push(installedModules[id] = promise.then(onFactory)['catch'](onError));\",\n ),\n '} else onFactory(promise);',\n ]),\n '} catch(e) { onError(e); }',\n ],\n )});`,\n ]),\n '}',\n ])}`,\n ])\n : '// no chunk loading of consumes',\n ]);\n }\n}\n\nexport default ConsumeSharedRuntimeModule;\n"],"names":["ConsumeSharedRuntimeModule","RuntimeModule","generate","compilation","chunkGraph","runtimeTemplate","codeGenerationResults","chunkToModuleMapping","moduleIdToSourceMapping","Map","initialConsumes","addModules","modules","chunk","list","m","module","id","getModuleId","push","set","getSource","runtime","allChunks","getAllReferencedChunks","getChunkModulesIterableBySourceType","toString","getAllInitialChunks","size","Template","asString","parseVersionRuntimeCode","versionLtRuntimeCode","rangeToStringRuntimeCode","satisfyRuntimeCode","basicFunction","RuntimeGlobals","shareScopeMap","hasOwnProperty","outputOptions","ignoreBrowserWarnings","returningFunction","indent","initializeSharing","Array","from","key","source","JSON","stringify","join","length","moduleFactories","moduleCache","_runtimeRequirements","has","ensureChunkHandlers","constructor","runtimeRequirements","STAGE_ATTACH"],"mappings":"AAAA;;;AAGA;;;;+BA2XA;;;eAAA;;;wEAzXgC;iEACX;wBAMd;sEACmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQ1B,IAAA,AAAMA,6BAAN,MAAMA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aAAa,CAAC,UAAU;oCAChD,CAAC,OAAO,EAAEC,gBAAeiB,WAAW,CAAC,KAAK,CAAC;oCAC3C;iCACD,EAAE,CAAC;6BACL,EACD,CAAC,CAAC;4BACJ,CAAC,cAAc,EAAEhD,gBAAgB8B,aAAa,CAAC,SAAS;gCACtD;gCACA,CAAC,EACCC,gBAAegB,eAAe,CAC/B,OAAO,EAAE/C,gBAAgB8B,aAAa,CAAC,UAAU;oCAChD,CAAC,OAAO,EAAEC,gBAAeiB,WAAW,CAAC,KAAK,CAAC;oCAC3C;iCACD,EAAE,CAAC;6BACL,EAAE,CAAC,CAAC;4BACL;4BACAxB,iBAAQ,CAACa,MAAM,CAAC;gCACd;gCACA;gCACAb,iBAAQ,CAACa,MAAM,CACb;gCAEF;6BACD;4BACD;yBACD,EACD,EAAE,CAAC;qBACN;oBACD;iBACD,EAAE,CAAC;aACL,IACD;SACL;IACH;IAnWA;;GAEC,GACDe,YAAYC,mBAAwC,CAAE;QACpD,KAAK,CAAC,YAAYzD,sBAAa,CAAC0D,YAAY;QAC5C,IAAI,CAACL,oBAAoB,GAAGI;IAC9B;AA8VF;MAEA,WAAe1D"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
declare function D(n: any, { instancePath: s, parentData: a, parentDataProperty: i, rootData: l, }?: {
|
|
1
|
+
declare function D(n: any, { instancePath: s, parentData, parentDataProperty, rootData: l, }?: {
|
|
3
2
|
instancePath?: string | undefined;
|
|
4
3
|
parentData: any;
|
|
5
4
|
parentDataProperty: any;
|
|
6
5
|
rootData?: any;
|
|
7
|
-
}):
|
|
8
|
-
|
|
9
|
-
export { D as default };
|
|
10
|
-
}
|
|
6
|
+
}): any;
|
|
7
|
+
export default D;
|