@module-federation/enhanced 0.0.7 → 0.0.8

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.
Files changed (134) hide show
  1. package/README.md +164 -6
  2. package/dist/package.json +8 -4
  3. package/dist/src/index.d.ts +12 -9
  4. package/dist/src/index.js +19 -14
  5. package/dist/src/index.js.map +1 -1
  6. package/dist/src/lib/container/AsyncBoundaryPlugin.d.ts +1 -1
  7. package/dist/src/lib/container/AsyncBoundaryPlugin.js +3 -2
  8. package/dist/src/lib/container/AsyncBoundaryPlugin.js.map +1 -1
  9. package/dist/src/lib/container/ContainerEntryDependency.d.ts +3 -1
  10. package/dist/src/lib/container/ContainerEntryDependency.js +3 -1
  11. package/dist/src/lib/container/ContainerEntryDependency.js.map +1 -1
  12. package/dist/src/lib/container/ContainerEntryModule.d.ts +4 -3
  13. package/dist/src/lib/container/ContainerEntryModule.js +32 -12
  14. package/dist/src/lib/container/ContainerEntryModule.js.map +1 -1
  15. package/dist/src/lib/container/ContainerEntryModuleFactory.js +2 -2
  16. package/dist/src/lib/container/ContainerEntryModuleFactory.js.map +1 -1
  17. package/dist/src/lib/container/ContainerPlugin.d.ts +2 -0
  18. package/dist/src/lib/container/ContainerPlugin.js +110 -10
  19. package/dist/src/lib/container/ContainerPlugin.js.map +1 -1
  20. package/dist/src/lib/container/ContainerReferencePlugin.js +5 -3
  21. package/dist/src/lib/container/ContainerReferencePlugin.js.map +1 -1
  22. package/dist/src/lib/container/FallbackModule.d.ts +1 -1
  23. package/dist/src/lib/container/FallbackModule.js +2 -2
  24. package/dist/src/lib/container/FallbackModule.js.map +1 -1
  25. package/dist/src/lib/container/HoistContainerReferencesPlugin.d.ts +3 -4
  26. package/dist/src/lib/container/HoistContainerReferencesPlugin.js +33 -50
  27. package/dist/src/lib/container/HoistContainerReferencesPlugin.js.map +1 -1
  28. package/dist/src/lib/container/ModuleFederationPlugin.d.ts +2 -2
  29. package/dist/src/lib/container/ModuleFederationPlugin.js +17 -8
  30. package/dist/src/lib/container/ModuleFederationPlugin.js.map +1 -1
  31. package/dist/src/lib/container/RemoteModule.js +2 -2
  32. package/dist/src/lib/container/RemoteModule.js.map +1 -1
  33. package/dist/src/lib/container/RemoteRuntimeModule.js +44 -46
  34. package/dist/src/lib/container/RemoteRuntimeModule.js.map +1 -1
  35. package/dist/src/lib/container/constant.d.ts +3 -0
  36. package/dist/src/lib/container/constant.js +12 -0
  37. package/dist/src/lib/container/constant.js.map +1 -0
  38. package/dist/src/lib/container/runtime/FederationRuntimeModule.d.ts +13 -0
  39. package/dist/src/lib/container/runtime/FederationRuntimeModule.js +27 -0
  40. package/dist/src/lib/container/runtime/FederationRuntimeModule.js.map +1 -0
  41. package/dist/src/lib/container/runtime/FederationRuntimePlugin.d.ts +17 -0
  42. package/dist/src/lib/container/runtime/FederationRuntimePlugin.js +190 -0
  43. package/dist/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -0
  44. package/dist/src/lib/container/runtime/getFederationGlobal.d.ts +5 -0
  45. package/dist/src/lib/container/runtime/getFederationGlobal.js +24 -0
  46. package/dist/src/lib/container/runtime/getFederationGlobal.js.map +1 -0
  47. package/dist/src/lib/container/runtime/utils.d.ts +15 -0
  48. package/dist/src/lib/container/runtime/utils.js +79 -0
  49. package/dist/src/lib/container/runtime/utils.js.map +1 -0
  50. package/dist/src/lib/sharing/ConsumeSharedModule.js +10 -5
  51. package/dist/src/lib/sharing/ConsumeSharedModule.js.map +1 -1
  52. package/dist/src/lib/sharing/ConsumeSharedPlugin.js +12 -5
  53. package/dist/src/lib/sharing/ConsumeSharedPlugin.js.map +1 -1
  54. package/dist/src/lib/sharing/ConsumeSharedRuntimeModule.js +26 -166
  55. package/dist/src/lib/sharing/ConsumeSharedRuntimeModule.js.map +1 -1
  56. package/dist/src/lib/sharing/ProvideSharedDependency.d.ts +7 -1
  57. package/dist/src/lib/sharing/ProvideSharedDependency.js +11 -2
  58. package/dist/src/lib/sharing/ProvideSharedDependency.js.map +1 -1
  59. package/dist/src/lib/sharing/ProvideSharedModule.d.ts +7 -1
  60. package/dist/src/lib/sharing/ProvideSharedModule.js +31 -8
  61. package/dist/src/lib/sharing/ProvideSharedModule.js.map +1 -1
  62. package/dist/src/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  63. package/dist/src/lib/sharing/ProvideSharedModuleFactory.js.map +1 -1
  64. package/dist/src/lib/sharing/ProvideSharedPlugin.d.ts +2 -7
  65. package/dist/src/lib/sharing/ProvideSharedPlugin.js +12 -2
  66. package/dist/src/lib/sharing/ProvideSharedPlugin.js.map +1 -1
  67. package/dist/src/lib/sharing/SharePlugin.js +3 -0
  68. package/dist/src/lib/sharing/SharePlugin.js.map +1 -1
  69. package/dist/src/lib/sharing/ShareRuntimeModule.js +24 -51
  70. package/dist/src/lib/sharing/ShareRuntimeModule.js.map +1 -1
  71. package/dist/src/lib/sharing/utils.d.ts +12 -0
  72. package/dist/src/lib/sharing/utils.js +17 -2
  73. package/dist/src/lib/sharing/utils.js.map +1 -1
  74. package/dist/src/schemas/container/ContainerPlugin.check.d.ts +7 -0
  75. package/dist/src/schemas/container/ContainerPlugin.check.js +2297 -0
  76. package/dist/src/schemas/container/ContainerPlugin.check.js.map +1 -0
  77. package/dist/src/schemas/container/ContainerPlugin.d.ts +268 -0
  78. package/dist/src/schemas/container/ContainerPlugin.js +306 -0
  79. package/dist/src/schemas/container/ContainerPlugin.js.map +1 -0
  80. package/dist/src/schemas/container/ContainerReferencePlugin.check.d.ts +7 -0
  81. package/dist/src/schemas/container/ContainerReferencePlugin.check.js +939 -0
  82. package/dist/src/schemas/container/ContainerReferencePlugin.check.js.map +1 -0
  83. package/dist/src/schemas/container/ContainerReferencePlugin.d.ts +87 -0
  84. package/dist/src/schemas/container/ContainerReferencePlugin.js +132 -0
  85. package/dist/src/schemas/container/ContainerReferencePlugin.js.map +1 -0
  86. package/dist/src/schemas/container/ModuleFederationPlugin.check.d.ts +3 -3
  87. package/dist/src/schemas/container/ModuleFederationPlugin.check.js +3653 -1341
  88. package/dist/src/schemas/container/ModuleFederationPlugin.check.js.map +1 -1
  89. package/dist/src/schemas/container/ModuleFederationPlugin.d.ts +13 -4
  90. package/dist/src/schemas/container/ModuleFederationPlugin.js +13 -4
  91. package/dist/src/schemas/container/ModuleFederationPlugin.js.map +1 -1
  92. package/dist/src/schemas/sharing/ProviderSharedPlugin.check.d.ts +7 -0
  93. package/dist/src/schemas/sharing/ProviderSharedPlugin.check.js +434 -0
  94. package/dist/src/schemas/sharing/ProviderSharedPlugin.check.js.map +1 -0
  95. package/dist/src/schemas/sharing/ProviderSharedPlugin.d.ts +104 -0
  96. package/dist/src/schemas/sharing/ProviderSharedPlugin.js +119 -0
  97. package/dist/src/schemas/sharing/ProviderSharedPlugin.js.map +1 -0
  98. package/dist/src/types/runtime.d.ts +7 -0
  99. package/dist/src/types/runtime.js +3 -0
  100. package/dist/src/types/runtime.js.map +1 -0
  101. package/dist/src/wrapper/AsyncBoundaryPlugin.d.ts +8 -0
  102. package/dist/src/wrapper/AsyncBoundaryPlugin.js +19 -0
  103. package/dist/src/wrapper/AsyncBoundaryPlugin.js.map +1 -0
  104. package/dist/src/wrapper/ConsumeSharedPlugin.d.ts +8 -0
  105. package/dist/src/wrapper/ConsumeSharedPlugin.js +19 -0
  106. package/dist/src/wrapper/ConsumeSharedPlugin.js.map +1 -0
  107. package/dist/src/wrapper/ContainerPlugin.d.ts +8 -0
  108. package/dist/src/wrapper/ContainerPlugin.js +19 -0
  109. package/dist/src/wrapper/ContainerPlugin.js.map +1 -0
  110. package/dist/src/wrapper/ContainerReferencePlugin.d.ts +8 -0
  111. package/dist/src/wrapper/ContainerReferencePlugin.js +19 -0
  112. package/dist/src/wrapper/ContainerReferencePlugin.js.map +1 -0
  113. package/dist/src/wrapper/FederationRuntimePlugin.d.ts +9 -0
  114. package/dist/src/wrapper/FederationRuntimePlugin.js +22 -0
  115. package/dist/src/wrapper/FederationRuntimePlugin.js.map +1 -0
  116. package/dist/src/wrapper/HoistContainerReferencesPlugin.d.ts +6 -0
  117. package/dist/src/wrapper/HoistContainerReferencesPlugin.js +18 -0
  118. package/dist/src/wrapper/HoistContainerReferencesPlugin.js.map +1 -0
  119. package/dist/src/wrapper/ModuleFederationPlugin.d.ts +8 -0
  120. package/dist/src/wrapper/ModuleFederationPlugin.js +24 -0
  121. package/dist/src/wrapper/ModuleFederationPlugin.js.map +1 -0
  122. package/dist/src/wrapper/ProvideSharedPlugin.d.ts +8 -0
  123. package/dist/src/wrapper/ProvideSharedPlugin.js +19 -0
  124. package/dist/src/wrapper/ProvideSharedPlugin.js.map +1 -0
  125. package/dist/src/wrapper/SharePlugin.d.ts +8 -0
  126. package/dist/src/wrapper/SharePlugin.js +19 -0
  127. package/dist/src/wrapper/SharePlugin.js.map +1 -0
  128. package/package.json +6 -3
  129. package/dist/src/runtime/ModuleInfoRuntimeModule.d.ts +0 -17
  130. package/dist/src/runtime/ModuleInfoRuntimeModule.js +0 -80
  131. package/dist/src/runtime/ModuleInfoRuntimeModule.js.map +0 -1
  132. package/dist/src/runtime/ModuleInfoRuntimePlugin.d.ts +0 -5
  133. package/dist/src/runtime/ModuleInfoRuntimePlugin.js +0 -24
  134. package/dist/src/runtime/ModuleInfoRuntimePlugin.js.map +0 -1
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
6
6
  */
7
7
  const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
8
+ const utils_1 = require("./runtime/utils");
9
+ const extractUrlAndGlobal = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/extractUrlAndGlobal'));
8
10
  const { Template, RuntimeModule, RuntimeGlobals } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
9
11
  class RemoteRuntimeModule extends RuntimeModule {
10
12
  constructor() {
@@ -18,6 +20,7 @@ class RemoteRuntimeModule extends RuntimeModule {
18
20
  const { runtimeTemplate, moduleGraph } = compilation;
19
21
  const chunkToRemotesMapping = {};
20
22
  const idToExternalAndNameMapping = {};
23
+ const idToRemoteMap = {};
21
24
  const allChunks = [
22
25
  ...Array.from(this.chunk?.getAllReferencedChunks() || []),
23
26
  ];
@@ -35,66 +38,61 @@ class RemoteRuntimeModule extends RuntimeModule {
35
38
  const id = chunkGraph ? chunkGraph.getModuleId(module) : undefined;
36
39
  const { shareScope } = module;
37
40
  const dep = module.dependencies[0];
41
+ // @ts-ignore
38
42
  const externalModule = moduleGraph.getModule(dep);
39
43
  const externalModuleId = chunkGraph && externalModule
40
- ? chunkGraph.getModuleId(externalModule)
44
+ ? // @ts-ignore
45
+ chunkGraph.getModuleId(externalModule)
41
46
  : undefined;
42
47
  if (id !== undefined) {
43
48
  //@ts-ignore
44
49
  remotes.push(id);
45
50
  idToExternalAndNameMapping[id] = [shareScope, name, externalModuleId];
51
+ const remoteModules = [];
52
+ // FallbackModule has requests
53
+ if ('requests' in externalModule && externalModule.requests) {
54
+ externalModule.dependencies.forEach((dependency) => {
55
+ const remoteModule = moduleGraph.getModule(dependency);
56
+ if (remoteModule) {
57
+ // @ts-ignore
58
+ remoteModules.push(remoteModule);
59
+ }
60
+ });
61
+ }
62
+ else {
63
+ remoteModules.push(externalModule);
64
+ }
65
+ idToRemoteMap[id] = [];
66
+ remoteModules.forEach((remoteModule) => {
67
+ let remoteName = '';
68
+ try {
69
+ const [_url, name] = extractUrlAndGlobal(remoteModule.request);
70
+ remoteName = name;
71
+ }
72
+ catch (err) {
73
+ //noop
74
+ }
75
+ const externalModuleId = chunkGraph &&
76
+ remoteModule &&
77
+ // @ts-ignore
78
+ chunkGraph.getModuleId(remoteModule);
79
+ idToRemoteMap[id].push({
80
+ externalType: remoteModule.externalType,
81
+ name: remoteModule.externalType === 'script' ? remoteName : '',
82
+ externalModuleId,
83
+ });
84
+ });
46
85
  }
47
86
  }
48
87
  }
88
+ const federationGlobal = (0, utils_1.getFederationGlobalScope)(RuntimeGlobals || {});
49
89
  return Template.asString([
50
90
  `var chunkMapping = ${JSON.stringify(chunkToRemotesMapping, null, '\t')};`,
51
91
  `var idToExternalAndNameMapping = ${JSON.stringify(idToExternalAndNameMapping, null, '\t')};`,
92
+ `var idToRemoteMap = ${JSON.stringify(idToRemoteMap, null, '\t')};`,
93
+ `${federationGlobal}.bundlerRuntimeOptions.remotes = {idToRemoteMap,chunkMapping, idToExternalAndNameMapping, webpackRequire:${RuntimeGlobals.require}};`,
52
94
  `${RuntimeGlobals.ensureChunkHandlers}.remotes = ${runtimeTemplate.basicFunction('chunkId, promises', [
53
- `if(${RuntimeGlobals.hasOwnProperty}(chunkMapping, chunkId)) {`,
54
- Template.indent([
55
- `chunkMapping[chunkId].forEach(${runtimeTemplate.basicFunction('id', [
56
- `var getScope = ${RuntimeGlobals.currentRemoteGetScope};`,
57
- 'if(!getScope) getScope = [];',
58
- 'var data = idToExternalAndNameMapping[id];',
59
- 'if(getScope.indexOf(data) >= 0) return;',
60
- 'getScope.push(data);',
61
- `if(data.p) return promises.push(data.p);`,
62
- `var onError = ${runtimeTemplate.basicFunction('error', [
63
- 'if(!error) error = new Error("Container missing");',
64
- 'if(typeof error.message === "string")',
65
- Template.indent(`error.message += '\\nwhile loading "' + data[1] + '" from ' + data[2];`),
66
- `${RuntimeGlobals.moduleFactories}[id] = ${runtimeTemplate.basicFunction('', ['throw error;'])}`,
67
- 'data.p = 0;',
68
- ])};`,
69
- `var handleFunction = ${runtimeTemplate.basicFunction('fn, arg1, arg2, d, next, first', [
70
- 'try {',
71
- Template.indent([
72
- 'var promise = fn(arg1, arg2);',
73
- 'if(promise && promise.then) {',
74
- Template.indent([
75
- `var p = promise.then(${runtimeTemplate.returningFunction('next(result, d)', 'result')}, onError);`,
76
- `if(first) promises.push(data.p = p); else return p;`,
77
- ]),
78
- '} else {',
79
- Template.indent(['return next(promise, d, first);']),
80
- '}',
81
- ]),
82
- '} catch(error) {',
83
- Template.indent(['onError(error);']),
84
- '}',
85
- ])}`,
86
- `var onExternal = ${runtimeTemplate.returningFunction(`external ? handleFunction(${RuntimeGlobals.initializeSharing}, data[0], 0, external, onInitialized, first) : onError()`, 'external, _, first')};`,
87
- `var onInitialized = ${runtimeTemplate.returningFunction(`handleFunction(external.get, data[1], getScope, 0, onFactory, first)`, '_, external, first')};`,
88
- `var onFactory = ${runtimeTemplate.basicFunction('factory', [
89
- 'data.p = 1;',
90
- `${RuntimeGlobals.moduleFactories}[id] = ${runtimeTemplate.basicFunction('module', [
91
- 'module.exports = factory();',
92
- ])}`,
93
- ])};`,
94
- `handleFunction(${RuntimeGlobals.require}, data[2], 0, 0, onExternal, 1);`,
95
- ])});`,
96
- ]),
97
- '}',
95
+ `${federationGlobal}.bundlerRuntime.remotes({idToRemoteMap,chunkMapping, idToExternalAndNameMapping, chunkId, promises, webpackRequire:${RuntimeGlobals.require}});`,
98
96
  ])}`,
99
97
  ]);
100
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RemoteRuntimeModule.js","sourceRoot":"","sources":["../../../../src/lib/container/RemoteRuntimeModule.ts"],"names":[],"mappings":";;AAAA;;;EAGE;AACF,0FAAqF;AAGrF,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,OAAO,CACzD,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAE9B,MAAM,mBAAoB,SAAQ,aAAa;IAC7C;QACE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACM,QAAQ;QACf,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QACzC,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,WAA0B,CAAC;QACpE,MAAM,qBAAqB,GAAwB,EAAE,CAAC;QACtD,MAAM,0BAA0B,GAAiC,EAAE,CAAC;QACpE,MAAM,SAAS,GAAG;YAChB,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAA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D,CAAC;QAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC;YACvB,sBAAsB,IAAI,CAAC,SAAS,CAClC,qBAAqB,EACrB,IAAI,EACJ,IAAI,CACL,GAAG;YACJ,oCAAoC,IAAI,CAAC,SAAS,CAChD,0BAA0B,EAC1B,IAAI,EACJ,IAAI,CACL,GAAG;YACJ,uBAAuB,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG;YACnE,GAAG,gBAAgB,4GAA4G,cAAc,CAAC,OAAO,IAAI;YACzJ,GACE,cAAc,CAAC,mBACjB,cAAc,eAAe,CAAC,aAAa,CAAC,mBAAmB,EAAE;gBAC/D,GAAG,gBAAgB,sHAAsH,cAAc,CAAC,OAAO,KAAK;aACrK,CAAC,EAAE;SACL,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const FEDERATION_SUPPORTED_TYPES: string[];
2
+ declare const TEMP_DIR: string;
3
+ export { FEDERATION_SUPPORTED_TYPES, TEMP_DIR };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TEMP_DIR = exports.FEDERATION_SUPPORTED_TYPES = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const FEDERATION_SUPPORTED_TYPES = ['script'];
9
+ exports.FEDERATION_SUPPORTED_TYPES = FEDERATION_SUPPORTED_TYPES;
10
+ const TEMP_DIR = path_1.default.join(`${process.cwd()}/node_modules`, `.federation`);
11
+ exports.TEMP_DIR = TEMP_DIR;
12
+ //# sourceMappingURL=constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../../src/lib/container/constant.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,MAAM,0BAA0B,GAAG,CAAC,QAAQ,CAAC,CAAC;AAGrC,gEAA0B;AAFnC,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC;AAEtC,4BAAQ"}
@@ -0,0 +1,13 @@
1
+ import { NormalizedRuntimeInitOptionsWithOutShared } from '../../../types/runtime';
2
+ declare const RuntimeModule: typeof import("webpack").RuntimeModule;
3
+ declare class FederationRuntimeModule extends RuntimeModule {
4
+ runtimeRequirements: Set<string>;
5
+ containerName: string;
6
+ initOptionsWithoutShared: NormalizedRuntimeInitOptionsWithOutShared;
7
+ constructor(runtimeRequirements: Set<string>, containerName: string, initOptionsWithoutShared: NormalizedRuntimeInitOptionsWithOutShared);
8
+ /**
9
+ * @returns {string | null} runtime code
10
+ */
11
+ generate(): string;
12
+ }
13
+ export default FederationRuntimeModule;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
7
+ // inspired by react-refresh-webpack-plugin
8
+ const getFederationGlobal_1 = __importDefault(require("./getFederationGlobal"));
9
+ const { RuntimeModule, RuntimeGlobals, Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
10
+ class FederationRuntimeModule extends RuntimeModule {
11
+ constructor(runtimeRequirements, containerName, initOptionsWithoutShared) {
12
+ super('federation runtime', RuntimeModule.STAGE_NORMAL - 1);
13
+ this.runtimeRequirements = runtimeRequirements;
14
+ this.containerName = containerName;
15
+ this.initOptionsWithoutShared = initOptionsWithoutShared;
16
+ }
17
+ /**
18
+ * @returns {string | null} runtime code
19
+ */
20
+ generate() {
21
+ return Template.asString([
22
+ (0, getFederationGlobal_1.default)(Template, RuntimeGlobals, this.initOptionsWithoutShared),
23
+ ]);
24
+ }
25
+ }
26
+ exports.default = FederationRuntimeModule;
27
+ //# sourceMappingURL=FederationRuntimeModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FederationRuntimeModule.js","sourceRoot":"","sources":["../../../../../src/lib/container/runtime/FederationRuntimeModule.ts"],"names":[],"mappings":";;;;;AAAA,0FAAqF;AACrF,2CAA2C;AAC3C,gFAAwD;AAGxD,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,OAAO,CACzD,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAE9B,MAAM,uBAAwB,SAAQ,aAAa;IAKjD,YACE,mBAAgC,EAChC,aAAqB,EACrB,wBAAmE;QAEnE,KAAK,CAAC,oBAAoB,EAAE,aAAa,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;IAC3D,CAAC;IAED;;OAEG;IACM,QAAQ;QACf,OAAO,QAAQ,CAAC,QAAQ,CAAC;YACvB,IAAA,6BAAmB,EACjB,QAAQ,EACR,cAAc,EACd,IAAI,CAAC,wBAAwB,CAC9B;SACF,CAAC,CAAC;IACL,CAAC;CACF;AACD,kBAAe,uBAAuB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Compiler } from 'webpack';
2
+ import type { ModuleFederationPluginOptions } from '../../../declarations/plugins/container/ModuleFederationPlugin';
3
+ declare class FederationRuntimePlugin {
4
+ options?: ModuleFederationPluginOptions;
5
+ entryFilePath: string;
6
+ bundlerRuntimePath: string;
7
+ constructor(options?: ModuleFederationPluginOptions);
8
+ static getTemplate(runtimePlugins: string[], bundlerRuntimePath?: string): string;
9
+ static getFilePath(containerName: string, runtimePlugins: string[], bundlerRuntimePath?: string): string;
10
+ getFilePath(): string;
11
+ ensureFile(): void;
12
+ prependEntry(compiler: Compiler): void;
13
+ injectRuntime(compiler: Compiler): void;
14
+ setRuntimeAlias(compiler: Compiler): void;
15
+ apply(compiler: Compiler): void;
16
+ }
17
+ export default FederationRuntimePlugin;
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
7
+ const FederationRuntimeModule_1 = __importDefault(require("./FederationRuntimeModule"));
8
+ const utils_1 = require("./utils");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const constant_1 = require("../constant");
12
+ const { RuntimeGlobals, Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
13
+ const { mkdirpSync } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/fs'));
14
+ const RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
15
+ const BundlerRuntimePath = require.resolve('@module-federation/webpack-bundler-runtime', {
16
+ paths: [RuntimeToolsPath],
17
+ });
18
+ const RuntimePath = require.resolve('@module-federation/runtime', {
19
+ paths: [RuntimeToolsPath],
20
+ });
21
+ const federationGlobal = (0, utils_1.getFederationGlobalScope)(RuntimeGlobals);
22
+ class FederationRuntimePlugin {
23
+ constructor(options) {
24
+ this.options = options;
25
+ this.entryFilePath = '';
26
+ this.bundlerRuntimePath = BundlerRuntimePath;
27
+ }
28
+ static getTemplate(runtimePlugins, bundlerRuntimePath) {
29
+ // internal runtime plugin
30
+ let runtimePluginTemplates = '';
31
+ const runtimePLuginNames = [];
32
+ if (Array.isArray(runtimePlugins)) {
33
+ runtimePlugins.forEach((runtimePlugin, index) => {
34
+ const runtimePluginName = `plugin_${index}`;
35
+ const runtimePluginPath = path_1.default.isAbsolute(runtimePlugin)
36
+ ? runtimePlugin
37
+ : path_1.default.join(process.cwd(), runtimePlugin);
38
+ runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\n`;
39
+ runtimePLuginNames.push(runtimePluginName);
40
+ });
41
+ }
42
+ return Template.asString([
43
+ `import federation from '${bundlerRuntimePath || BundlerRuntimePath}';`,
44
+ runtimePluginTemplates,
45
+ `${federationGlobal} = {...federation,...${federationGlobal}};`,
46
+ `if(!${federationGlobal}.instance){`,
47
+ Template.indent([
48
+ runtimePLuginNames.length
49
+ ? Template.asString([
50
+ `${federationGlobal}.initOptions.plugins = ([`,
51
+ Template.indent(runtimePLuginNames.map((item) => `${item}(),`)),
52
+ '])',
53
+ ])
54
+ : '',
55
+ `${federationGlobal}.instance = ${federationGlobal}.runtime.init(${federationGlobal}.initOptions);`,
56
+ `if(${federationGlobal}.attachShareScopeMap){`,
57
+ Template.indent([
58
+ `${federationGlobal}.attachShareScopeMap(${RuntimeGlobals.require})`,
59
+ ]),
60
+ '}',
61
+ `if(${federationGlobal}.installInitialConsumes){`,
62
+ Template.indent([`${federationGlobal}.installInitialConsumes()`]),
63
+ '}',
64
+ ]),
65
+ '}',
66
+ ]);
67
+ }
68
+ static getFilePath(containerName, runtimePlugins, bundlerRuntimePath) {
69
+ const hash = (0, utils_1.createHash)(`${containerName} ${FederationRuntimePlugin.getTemplate(runtimePlugins, bundlerRuntimePath)}`);
70
+ return path_1.default.join(constant_1.TEMP_DIR, `entry.${hash}.js`);
71
+ }
72
+ getFilePath() {
73
+ if (this.entryFilePath) {
74
+ return this.entryFilePath;
75
+ }
76
+ if (!this.options) {
77
+ return '';
78
+ }
79
+ this.entryFilePath = FederationRuntimePlugin.getFilePath(this.options.name, this.options.runtimePlugins, this.bundlerRuntimePath);
80
+ return this.entryFilePath;
81
+ }
82
+ ensureFile() {
83
+ if (!this.options) {
84
+ return;
85
+ }
86
+ const filePath = this.getFilePath();
87
+ try {
88
+ fs_1.default.readFileSync(filePath);
89
+ }
90
+ catch (err) {
91
+ mkdirpSync(fs_1.default, constant_1.TEMP_DIR);
92
+ fs_1.default.writeFileSync(filePath, FederationRuntimePlugin.getTemplate(this.options.runtimePlugins, this.bundlerRuntimePath));
93
+ }
94
+ }
95
+ prependEntry(compiler) {
96
+ this.ensureFile();
97
+ const entryFilePath = this.getFilePath();
98
+ (0, utils_1.modifyEntry)({
99
+ compiler,
100
+ prependEntry: (entry) => {
101
+ Object.keys(entry).forEach((entryName) => {
102
+ const entryItem = entry[entryName];
103
+ if (!entryItem.import) {
104
+ // TODO: maybe set this variable as constant is better https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L176
105
+ entryItem.import = ['./src'];
106
+ }
107
+ if (!entryItem.import.includes(entryFilePath)) {
108
+ entryItem.import.unshift(entryFilePath);
109
+ }
110
+ });
111
+ },
112
+ });
113
+ }
114
+ injectRuntime(compiler) {
115
+ if (!this.options || !this.options.name) {
116
+ return;
117
+ }
118
+ const name = this.options.name;
119
+ const initOptionsWithoutShared = (0, utils_1.normalizeRuntimeInitOptionsWithOutShared)(this.options);
120
+ const federationGlobal = (0, utils_1.getFederationGlobalScope)(RuntimeGlobals || {});
121
+ compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation, { normalModuleFactory }) => {
122
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(this.constructor.name, (chunk, runtimeRequirements) => {
123
+ if (runtimeRequirements.has(federationGlobal)) {
124
+ return;
125
+ }
126
+ runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);
127
+ runtimeRequirements.add(RuntimeGlobals.moduleCache);
128
+ runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
129
+ runtimeRequirements.add(federationGlobal);
130
+ compilation.addRuntimeModule(chunk, new FederationRuntimeModule_1.default(runtimeRequirements, name, initOptionsWithoutShared));
131
+ });
132
+ });
133
+ }
134
+ setRuntimeAlias(compiler) {
135
+ let runtimePath = RuntimePath;
136
+ if (this.options?.implementation) {
137
+ runtimePath = require.resolve('@module-federation/runtime', {
138
+ paths: [this.options.implementation],
139
+ });
140
+ }
141
+ compiler.options.resolve.alias = {
142
+ ...compiler.options.resolve.alias,
143
+ '@module-federation/runtime$': runtimePath,
144
+ '@module-federation/runtime-tools$': this.options?.implementation || RuntimeToolsPath,
145
+ };
146
+ }
147
+ apply(compiler) {
148
+ const useModuleFederationPlugin = compiler.options.plugins.find((p) => {
149
+ if (typeof p !== 'object' || !p) {
150
+ return false;
151
+ }
152
+ return p['name'] === 'ModuleFederationPlugin';
153
+ });
154
+ if (useModuleFederationPlugin && !this.options) {
155
+ // @ts-ignore
156
+ this.options = useModuleFederationPlugin._options;
157
+ }
158
+ const useContainerPlugin = compiler.options.plugins.find((p) => {
159
+ if (typeof p !== 'object' || !p) {
160
+ return false;
161
+ }
162
+ return p['name'] === 'ContainerPlugin';
163
+ });
164
+ if (useContainerPlugin && !this.options) {
165
+ // @ts-ignore
166
+ this.options = useContainerPlugin._options;
167
+ }
168
+ if (!useContainerPlugin && !useModuleFederationPlugin) {
169
+ this.options = {
170
+ remotes: {},
171
+ ...this.options,
172
+ };
173
+ }
174
+ if (this.options && !this.options?.name) {
175
+ // the instance may get the same one if the name is the same https://github.com/module-federation/universe/blob/main/packages/runtime/src/index.ts#L18
176
+ this.options.name =
177
+ compiler.options.output.uniqueName || `container_${Date.now()}`;
178
+ }
179
+ if (this.options?.implementation) {
180
+ this.bundlerRuntimePath = require.resolve('@module-federation/webpack-bundler-runtime', {
181
+ paths: [this.options.implementation],
182
+ });
183
+ }
184
+ this.prependEntry(compiler);
185
+ this.injectRuntime(compiler);
186
+ this.setRuntimeAlias(compiler);
187
+ }
188
+ }
189
+ exports.default = FederationRuntimePlugin;
190
+ //# sourceMappingURL=FederationRuntimePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FederationRuntimePlugin.js","sourceRoot":"","sources":["../../../../../src/lib/container/runtime/FederationRuntimePlugin.ts"],"names":[],"mappings":";;;;;AACA,0FAAqF;AACrF,wFAAgE;AAChE,mCAKiB;AACjB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AC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;CACF;AAED,kBAAe,uBAAuB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type RuntimeGlobals from 'webpack/lib/RuntimeGlobals';
2
+ import { NormalizedRuntimeInitOptionsWithOutShared } from '../../../types/runtime';
3
+ declare const Template: typeof import("webpack").Template;
4
+ declare function getFederationGlobal(template: typeof Template, runtimeGlobals: typeof RuntimeGlobals, initOptionsWithoutShared: NormalizedRuntimeInitOptionsWithOutShared): string;
5
+ export default getFederationGlobal;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
4
+ const utils_1 = require("./utils");
5
+ const { Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
6
+ function getFederationGlobal(template, runtimeGlobals, initOptionsWithoutShared) {
7
+ const federationGlobal = (0, utils_1.getFederationGlobalScope)(runtimeGlobals);
8
+ const initOptionsStrWithoutShared = JSON.stringify(initOptionsWithoutShared);
9
+ return template.asString([
10
+ `if(!${federationGlobal}){`,
11
+ template.indent([
12
+ `${federationGlobal} = {`,
13
+ template.indent([
14
+ `initOptions: ${initOptionsStrWithoutShared},`,
15
+ `initialConsumes: undefined,`,
16
+ 'bundlerRuntimeOptions: {}',
17
+ ]),
18
+ '};',
19
+ ]),
20
+ '}',
21
+ ]);
22
+ }
23
+ exports.default = getFederationGlobal;
24
+ //# sourceMappingURL=getFederationGlobal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFederationGlobal.js","sourceRoot":"","sources":["../../../../../src/lib/container/runtime/getFederationGlobal.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AACrF,mCAAmD;AAInD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAC1B,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAE9B,SAAS,mBAAmB,CAC1B,QAAyB,EACzB,cAAqC,EACrC,wBAAmE;IAEnE,MAAM,gBAAgB,GAAG,IAAA,gCAAwB,EAAC,cAAc,CAAC,CAAC;IAClE,MAAM,2BAA2B,GAAG,IAAI,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAC;IAE7E,OAAO,QAAQ,CAAC,QAAQ,CAAC;QACvB,OAAO,gBAAgB,IAAI;QAC3B,QAAQ,CAAC,MAAM,CAAC;YACd,GAAG,gBAAgB,MAAM;YACzB,QAAQ,CAAC,MAAM,CAAC;gBACd,gBAAgB,2BAA2B,GAAG;gBAC9C,6BAA6B;gBAC7B,2BAA2B;aAC5B,CAAC;YACF,IAAI;SACL,CAAC;QACF,GAAG;KACJ,CAAC,CAAC;AACL,CAAC;AAED,kBAAe,mBAAmB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type webpack from 'webpack';
2
+ import type RuntimeGlobals from 'webpack/lib/RuntimeGlobals';
3
+ import type { ModuleFederationPluginOptions } from '../../../declarations/plugins/container/ModuleFederationPlugin';
4
+ import { NormalizedRuntimeInitOptionsWithOutShared } from '../../../types/runtime';
5
+ type EntryStaticNormalized = Awaited<ReturnType<Extract<webpack.WebpackOptionsNormalized['entry'], () => any>>>;
6
+ interface ModifyEntryOptions {
7
+ compiler: webpack.Compiler;
8
+ prependEntry?: (entry: EntryStaticNormalized) => void;
9
+ staticEntry?: EntryStaticNormalized;
10
+ }
11
+ export declare function getFederationGlobalScope(runtimeGlobals: typeof RuntimeGlobals): string;
12
+ export declare function normalizeRuntimeInitOptionsWithOutShared(options: ModuleFederationPluginOptions): NormalizedRuntimeInitOptionsWithOutShared;
13
+ export declare function modifyEntry(options: ModifyEntryOptions): void;
14
+ export declare function createHash(contents: string): string;
15
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createHash = exports.modifyEntry = exports.normalizeRuntimeInitOptionsWithOutShared = exports.getFederationGlobalScope = void 0;
7
+ const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const options_1 = require("../options");
10
+ const extractUrlAndGlobal = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/extractUrlAndGlobal'));
11
+ function getFederationGlobalScope(runtimeGlobals) {
12
+ return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
13
+ }
14
+ exports.getFederationGlobalScope = getFederationGlobalScope;
15
+ function normalizeRuntimeInitOptionsWithOutShared(options) {
16
+ const parsedOptions = (0, options_1.parseOptions)(options.remotes || [], (item) => ({
17
+ external: Array.isArray(item) ? item : [item],
18
+ shareScope: options.shareScope || 'default',
19
+ }), (item) => ({
20
+ external: Array.isArray(item.external) ? item.external : [item.external],
21
+ shareScope: item.shareScope || options.shareScope || 'default',
22
+ }));
23
+ const remoteOptions = [];
24
+ parsedOptions.forEach((parsedOption) => {
25
+ const [alias, remoteInfos] = parsedOption;
26
+ const { external, shareScope } = remoteInfos;
27
+ try {
28
+ // only fit for remoteType: 'script'
29
+ const [url, globalName] = extractUrlAndGlobal(external[0]);
30
+ remoteOptions.push({
31
+ alias,
32
+ name: globalName,
33
+ entry: url,
34
+ shareScope: shareScope,
35
+ // externalType
36
+ });
37
+ }
38
+ catch (err) {
39
+ return;
40
+ }
41
+ });
42
+ const initOptionsWithoutShared = {
43
+ name: options.name,
44
+ remotes: remoteOptions,
45
+ };
46
+ return initOptionsWithoutShared;
47
+ }
48
+ exports.normalizeRuntimeInitOptionsWithOutShared = normalizeRuntimeInitOptionsWithOutShared;
49
+ function modifyEntry(options) {
50
+ const { compiler, staticEntry, prependEntry } = options;
51
+ const operator = (oriEntry, newEntry) => Object.assign(oriEntry, newEntry);
52
+ if (typeof compiler.options.entry === 'function') {
53
+ const prevEntryFn = compiler.options.entry;
54
+ compiler.options.entry = async () => {
55
+ let res = await prevEntryFn();
56
+ if (staticEntry) {
57
+ res = operator(res, staticEntry);
58
+ }
59
+ if (prependEntry) {
60
+ prependEntry(res);
61
+ }
62
+ return res;
63
+ };
64
+ }
65
+ else {
66
+ if (staticEntry) {
67
+ compiler.options.entry = operator(compiler.options.entry, staticEntry);
68
+ }
69
+ if (prependEntry) {
70
+ prependEntry(compiler.options.entry);
71
+ }
72
+ }
73
+ }
74
+ exports.modifyEntry = modifyEntry;
75
+ function createHash(contents) {
76
+ return crypto_1.default.createHash('md5').update(contents).digest('hex');
77
+ }
78
+ exports.createHash = createHash;
79
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/lib/container/runtime/utils.ts"],"names":[],"mappings":";;;;;;AAAA,0FAAqF;AACrF,oDAA4B;AAC5B,wCAA0C;AAO1C,MAAM,mBAAmB,GAAG,OAAO,CACjC,IAAA,6CAAoB,EAAC,sCAAsC,CAAC,CACJ,CAAC;AAc3D,SAAgB,wBAAwB,CACtC,cAAqC;IAErC,OAAO,GAAG,cAAc,CAAC,OAAO,IAAI,qBAAqB,aAAa,CAAC;AACzE,CAAC;AAJD,4DAIC;AAED,SAAgB,wCAAwC,CACtD,OAAsC;IAEtC,MAAM,aAAa,GAAG,IAAA,sBAAY,EAChC,OAAO,CAAC,OAAO,IAAI,EAAE,EACrB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACT,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC7C,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,SAAS;KAC5C,CAAC,EACF,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACT,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAA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3C,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE;YAClC,IAAI,GAAG,GAAG,MAAM,WAAW,EAAE,CAAC;YAC9B,IAAI,WAAW,EAAE,CAAC;gBAChB,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;YACnC,CAAC;YACD,IAAI,YAAY,EAAE,CAAC;gBACjB,YAAY,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,IAAI,WAAW,EAAE,CAAC;YAChB,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,YAAY,EAAE,CAAC;YACjB,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;AACH,CAAC;AA3BD,kCA2BC;AAED,SAAgB,UAAU,CAAC,QAAgB;IACzC,OAAO,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAFD,gCAEC"}
@@ -9,9 +9,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
11
11
  const ConsumeSharedFallbackDependency_1 = __importDefault(require("./ConsumeSharedFallbackDependency"));
12
+ const utils_1 = require("./utils");
13
+ const Constants_1 = require("../Constants");
12
14
  const { rangeToString, stringifyHoley } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/semver'));
13
15
  const { AsyncDependenciesBlock, Module, RuntimeGlobals } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
14
- const { WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/ModuleTypeConstants'));
15
16
  const { sources: webpackSources } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
16
17
  const makeSerializable = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/makeSerializable'));
17
18
  /**
@@ -33,7 +34,7 @@ class ConsumeSharedModule extends Module {
33
34
  * @param {ConsumeOptions} options consume options
34
35
  */
35
36
  constructor(context, options) {
36
- super(WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE, context);
37
+ super(Constants_1.WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE, context);
37
38
  this.options = options;
38
39
  }
39
40
  /**
@@ -41,7 +42,7 @@ class ConsumeSharedModule extends Module {
41
42
  */
42
43
  identifier() {
43
44
  const { shareKey, shareScope, importResolved, requiredVersion, strictVersion, singleton, eager, } = this.options;
44
- return `${WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE}|${shareScope}|${shareKey}|${requiredVersion && rangeToString(requiredVersion)}|${strictVersion}|${importResolved}|${singleton}|${eager}`;
45
+ return `${Constants_1.WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE}|${shareScope}|${shareKey}|${requiredVersion && rangeToString(requiredVersion)}|${strictVersion}|${importResolved}|${singleton}|${eager}`;
45
46
  }
46
47
  /**
47
48
  * @param {RequestShortener} requestShortener the request shortener
@@ -171,12 +172,16 @@ class ConsumeSharedModule extends Module {
171
172
  fn += 'Fallback';
172
173
  args.push(fallbackCode);
173
174
  }
174
- const code = runtimeTemplate.returningFunction(`${fn}(${args.join(', ')})`);
175
+ // const code = runtimeTemplate.returningFunction(`${fn}(${args.join(', ')})`);
175
176
  const sources = new Map();
176
- sources.set('consume-shared', new webpackSources.RawSource(code));
177
+ sources.set('consume-shared', new webpackSources.RawSource(fallbackCode ||
178
+ `()=>()=>{throw new Error("Can not get '${shareKey}'")}`));
179
+ const data = new Map();
180
+ data.set('consume-shared', (0, utils_1.normalizeConsumeShareOptions)(this.options));
177
181
  return {
178
182
  runtimeRequirements,
179
183
  sources,
184
+ data,
180
185
  };
181
186
  }
182
187
  /**