@module-federation/manifest 0.24.1 → 2.0.1

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.
@@ -0,0 +1,512 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ /************************************************************************/
13
+ // webpack/runtime/compat_get_default_export
14
+ (() => {
15
+ // getDefaultExport function for compatibility with non-ESM modules
16
+ __webpack_require__.n = (module) => {
17
+ var getter = module && module.__esModule ?
18
+ () => (module['default']) :
19
+ () => (module);
20
+ __webpack_require__.d(getter, { a: getter });
21
+ return getter;
22
+ };
23
+
24
+ })();
25
+ // webpack/runtime/define_property_getters
26
+ (() => {
27
+ __webpack_require__.d = (exports, definition) => {
28
+ for(var key in definition) {
29
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
31
+ }
32
+ }
33
+ };
34
+ })();
35
+ // webpack/runtime/has_own_property
36
+ (() => {
37
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
38
+ })();
39
+ // webpack/runtime/make_namespace_object
40
+ (() => {
41
+ // define __esModule on exports
42
+ __webpack_require__.r = (exports) => {
43
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
44
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
45
+ }
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ };
48
+ })();
49
+ /************************************************************************/
50
+ var __webpack_exports__ = {};
51
+ // ESM COMPAT FLAG
52
+ __webpack_require__.r(__webpack_exports__);
53
+
54
+ // EXPORTS
55
+ __webpack_require__.d(__webpack_exports__, {
56
+ getExposeItem: () => (/* binding */ getExposeItem),
57
+ ModuleHandler: () => (/* binding */ ModuleHandler),
58
+ getShareItem: () => (/* binding */ getShareItem),
59
+ getExposeName: () => (/* binding */ getExposeName)
60
+ });
61
+
62
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
63
+ const sdk_namespaceObject = require("@module-federation/sdk");
64
+ ;// CONCATENATED MODULE: external "path"
65
+ const external_path_namespaceObject = require("path");
66
+ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
67
+ ;// CONCATENATED MODULE: external "@module-federation/managers"
68
+ const managers_namespaceObject = require("@module-federation/managers");
69
+ ;// CONCATENATED MODULE: external "./utils.js"
70
+ const external_utils_js_namespaceObject = require("./utils.js");
71
+ ;// CONCATENATED MODULE: ./src/ModuleHandler.ts
72
+
73
+
74
+
75
+
76
+ const isNonEmptyString = (value)=>{
77
+ return typeof value === 'string' && value.trim().length > 0;
78
+ };
79
+ const normalizeExposeValue = (exposeValue)=>{
80
+ if (!exposeValue) {
81
+ return undefined;
82
+ }
83
+ const toImportArray = (value)=>{
84
+ if (isNonEmptyString(value)) {
85
+ return [
86
+ value
87
+ ];
88
+ }
89
+ if (Array.isArray(value)) {
90
+ const normalized = value.filter(isNonEmptyString);
91
+ return normalized.length ? normalized : undefined;
92
+ }
93
+ return undefined;
94
+ };
95
+ if (typeof exposeValue === 'object') {
96
+ if ('import' in exposeValue) {
97
+ const { import: rawImport, name } = exposeValue;
98
+ const normalizedImport = toImportArray(rawImport);
99
+ if (!(normalizedImport === null || normalizedImport === void 0 ? void 0 : normalizedImport.length)) {
100
+ return undefined;
101
+ }
102
+ return {
103
+ import: normalizedImport,
104
+ ...isNonEmptyString(name) ? {
105
+ name
106
+ } : {}
107
+ };
108
+ }
109
+ return undefined;
110
+ }
111
+ const normalizedImport = toImportArray(exposeValue);
112
+ if (!(normalizedImport === null || normalizedImport === void 0 ? void 0 : normalizedImport.length)) {
113
+ return undefined;
114
+ }
115
+ return {
116
+ import: normalizedImport
117
+ };
118
+ };
119
+ const parseContainerExposeEntries = (identifier)=>{
120
+ const startIndex = identifier.indexOf('[');
121
+ if (startIndex < 0) {
122
+ return undefined;
123
+ }
124
+ let depth = 0;
125
+ let inString = false;
126
+ let isEscaped = false;
127
+ for(let cursor = startIndex; cursor < identifier.length; cursor++){
128
+ const char = identifier[cursor];
129
+ if (isEscaped) {
130
+ isEscaped = false;
131
+ continue;
132
+ }
133
+ if (char === '\\') {
134
+ isEscaped = true;
135
+ continue;
136
+ }
137
+ if (char === '"') {
138
+ inString = !inString;
139
+ continue;
140
+ }
141
+ if (inString) {
142
+ continue;
143
+ }
144
+ if (char === '[') {
145
+ depth++;
146
+ } else if (char === ']') {
147
+ depth--;
148
+ if (depth === 0) {
149
+ const serialized = identifier.slice(startIndex, cursor + 1);
150
+ try {
151
+ return JSON.parse(serialized);
152
+ } catch {
153
+ return undefined;
154
+ }
155
+ }
156
+ }
157
+ }
158
+ return undefined;
159
+ };
160
+ const getExposeName = (exposeKey)=>{
161
+ return exposeKey.replace('./', '');
162
+ };
163
+ function getExposeItem({ exposeKey, name, file }) {
164
+ const exposeModuleName = getExposeName(exposeKey);
165
+ return {
166
+ path: exposeKey,
167
+ id: (0,sdk_namespaceObject.composeKeyWithSeparator)(name, exposeModuleName),
168
+ name: exposeModuleName,
169
+ // @ts-ignore to deduplicate
170
+ requires: [],
171
+ file: external_path_default().relative(process.cwd(), file.import[0]),
172
+ assets: {
173
+ js: {
174
+ async: [],
175
+ sync: []
176
+ },
177
+ css: {
178
+ async: [],
179
+ sync: []
180
+ }
181
+ }
182
+ };
183
+ }
184
+ const getShareItem = ({ pkgName, normalizedShareOptions, pkgVersion, hostName })=>{
185
+ return {
186
+ ...normalizedShareOptions,
187
+ id: `${hostName}:${pkgName}`,
188
+ requiredVersion: (normalizedShareOptions === null || normalizedShareOptions === void 0 ? void 0 : normalizedShareOptions.requiredVersion) || `^${pkgVersion}`,
189
+ name: pkgName,
190
+ version: pkgVersion,
191
+ assets: {
192
+ js: {
193
+ async: [],
194
+ sync: []
195
+ },
196
+ css: {
197
+ async: [],
198
+ sync: []
199
+ }
200
+ },
201
+ // @ts-ignore to deduplicate
202
+ usedIn: new Set(),
203
+ usedExports: [],
204
+ fallback: ''
205
+ };
206
+ };
207
+ class ModuleHandler {
208
+ get isRspack() {
209
+ return this._bundler === 'rspack';
210
+ }
211
+ _handleSharedModule(mod, sharedMap, exposesMap) {
212
+ const { identifier, moduleType } = mod;
213
+ if (!identifier) {
214
+ return;
215
+ }
216
+ const sharedManagerNormalizedOptions = this._sharedManager.normalizedOptions;
217
+ const initShared = (pkgName, pkgVersion)=>{
218
+ if (sharedMap[pkgName]) {
219
+ return;
220
+ }
221
+ sharedMap[pkgName] = getShareItem({
222
+ pkgName,
223
+ pkgVersion,
224
+ normalizedShareOptions: sharedManagerNormalizedOptions[pkgName],
225
+ hostName: this._options.name
226
+ });
227
+ };
228
+ const collectRelationshipMap = (mod, pkgName)=>{
229
+ const { issuerName, reasons } = mod;
230
+ if (issuerName) {
231
+ if (exposesMap[(0,external_utils_js_namespaceObject.getFileNameWithOutExt)(issuerName)]) {
232
+ const expose = exposesMap[(0,external_utils_js_namespaceObject.getFileNameWithOutExt)(issuerName)];
233
+ // @ts-ignore use Set to deduplicate
234
+ expose.requires.push(pkgName);
235
+ // @ts-ignore use Set to deduplicate
236
+ sharedMap[pkgName].usedIn.add(expose.path);
237
+ }
238
+ }
239
+ if (reasons) {
240
+ reasons.forEach(({ resolvedModule, moduleName })=>{
241
+ let exposeModName = this.isRspack ? moduleName : resolvedModule;
242
+ // filters out entrypoints
243
+ if (exposeModName) {
244
+ if (exposesMap[(0,external_utils_js_namespaceObject.getFileNameWithOutExt)(exposeModName)]) {
245
+ const expose = exposesMap[(0,external_utils_js_namespaceObject.getFileNameWithOutExt)(exposeModName)];
246
+ // @ts-ignore to deduplicate
247
+ expose.requires.push(pkgName);
248
+ // @ts-ignore to deduplicate
249
+ sharedMap[pkgName].usedIn.add(expose.path);
250
+ }
251
+ }
252
+ });
253
+ }
254
+ };
255
+ const parseResolvedIdentifier = (nameAndVersion)=>{
256
+ let name = '';
257
+ let version = '';
258
+ if (nameAndVersion.startsWith('@')) {
259
+ const splitInfo = nameAndVersion.split('@');
260
+ splitInfo[0] = '@';
261
+ name = splitInfo[0] + splitInfo[1];
262
+ version = splitInfo[2];
263
+ } else if (nameAndVersion.includes('@')) {
264
+ [name, version] = nameAndVersion.split('@');
265
+ version = version.replace(/[\^~>|>=]/g, '');
266
+ }
267
+ return {
268
+ name,
269
+ version
270
+ };
271
+ };
272
+ if (moduleType === 'provide-module') {
273
+ // identifier(rspack) = provide shared module (default) react@18.2.0 = /temp/node_modules/.pnpm/react@18.2.0/node_modules/react/index.js
274
+ // identifier(webpack) = provide module (default) react@18.2.0 = /temp/node_modules/.pnpm/react@18.2.0/node_modules/react/index.js
275
+ const data = identifier.split(' ');
276
+ const nameAndVersion = this.isRspack ? data[4] : data[3];
277
+ const { name, version } = parseResolvedIdentifier(nameAndVersion);
278
+ if (name && version) {
279
+ initShared(name, version);
280
+ collectRelationshipMap(mod, name);
281
+ }
282
+ }
283
+ if (moduleType === 'consume-shared-module') {
284
+ // identifier(rspack) = consume shared module (default) lodash/get@^4.17.21 (strict) (fallback: /temp/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/get.js)
285
+ // identifier(webpack) = consume-shared-module|default|react-dom|!=1.8...2...0|false|/temp/node_modules/.pnpm/react-dom@18.2.0_react@18.2.0/node_modules/react-dom/index.js|true|false
286
+ const SEPARATOR = this.isRspack ? ' ' : '|';
287
+ const data = identifier.split(SEPARATOR);
288
+ let pkgName = '';
289
+ let pkgVersion = '';
290
+ if (this.isRspack) {
291
+ const nameAndVersion = data[4];
292
+ const res = parseResolvedIdentifier(nameAndVersion);
293
+ pkgName = res.name;
294
+ pkgVersion = res.version;
295
+ } else {
296
+ pkgName = data[2];
297
+ const pkgVersionRange = data[3];
298
+ pkgVersion = '';
299
+ if (pkgVersionRange.startsWith('=')) {
300
+ pkgVersion = data[3].replace('=', '');
301
+ } else {
302
+ if (sharedManagerNormalizedOptions[pkgName]) {
303
+ pkgVersion = sharedManagerNormalizedOptions[pkgName].version;
304
+ } else {
305
+ const fullPkgName = pkgName.split('/').slice(0, -1).join('/');
306
+ // pkgName: react-dom/
307
+ if (sharedManagerNormalizedOptions[`${fullPkgName}/`]) {
308
+ if (sharedManagerNormalizedOptions[fullPkgName]) {
309
+ pkgVersion = sharedManagerNormalizedOptions[fullPkgName].version;
310
+ } else {
311
+ pkgVersion = sharedManagerNormalizedOptions[`${fullPkgName}/`].version;
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
317
+ if (pkgName && pkgVersion) {
318
+ initShared(pkgName, pkgVersion);
319
+ collectRelationshipMap(mod, pkgName);
320
+ }
321
+ }
322
+ }
323
+ _handleRemoteModule(mod, remotes, remotesConsumerMap) {
324
+ const { identifier, reasons, nameForCondition } = mod;
325
+ if (!identifier) {
326
+ return;
327
+ }
328
+ const remoteManagerNormalizedOptions = this._remoteManager.normalizedOptions;
329
+ // identifier = remote (default) webpack/container/reference/app2 ./Button
330
+ const data = identifier.split(' ');
331
+ if (data.length === 4) {
332
+ const moduleName = data[3].replace('./', '');
333
+ const remoteAlias = data[2].replace('webpack/container/reference/', '');
334
+ const normalizedRemote = remoteManagerNormalizedOptions[remoteAlias];
335
+ const basicRemote = {
336
+ alias: normalizedRemote.alias,
337
+ consumingFederationContainerName: this._options.name || '',
338
+ federationContainerName: remoteManagerNormalizedOptions[remoteAlias].name,
339
+ moduleName,
340
+ // @ts-ignore to deduplicate
341
+ usedIn: new Set()
342
+ };
343
+ if (!nameForCondition) {
344
+ return;
345
+ }
346
+ let remote;
347
+ if ('version' in normalizedRemote) {
348
+ remote = {
349
+ ...basicRemote,
350
+ version: normalizedRemote.version
351
+ };
352
+ } else {
353
+ remote = {
354
+ ...basicRemote,
355
+ entry: normalizedRemote.entry
356
+ };
357
+ }
358
+ remotes.push(remote);
359
+ remotesConsumerMap[nameForCondition] = remote;
360
+ }
361
+ if (reasons) {
362
+ reasons.forEach(({ userRequest, resolvedModule, moduleName })=>{
363
+ let exposeModName = this.isRspack ? moduleName : resolvedModule;
364
+ if (userRequest && exposeModName && remotesConsumerMap[userRequest]) {
365
+ // @ts-ignore to deduplicate
366
+ remotesConsumerMap[userRequest].usedIn.add(exposeModName.replace('./', ''));
367
+ }
368
+ });
369
+ }
370
+ }
371
+ _handleContainerModule(mod, exposesMap) {
372
+ const { identifier } = mod;
373
+ if (!identifier) {
374
+ return;
375
+ }
376
+ // identifier: container entry (default) [[".",{"import":["./src/routes/page.tsx"],"name":"__federation_expose_default_export"}]]'
377
+ const entries = parseContainerExposeEntries(identifier) ?? this._getContainerExposeEntriesFromOptions();
378
+ if (!entries) {
379
+ return;
380
+ }
381
+ entries.forEach(([prefixedName, file])=>{
382
+ // TODO: support multiple import
383
+ exposesMap[(0,external_utils_js_namespaceObject.getFileNameWithOutExt)(file.import[0])] = getExposeItem({
384
+ exposeKey: prefixedName,
385
+ name: this._options.name,
386
+ file
387
+ });
388
+ });
389
+ }
390
+ _getContainerExposeEntriesFromOptions() {
391
+ const exposes = this._containerManager.containerPluginExposesOptions;
392
+ const normalizedEntries = Object.entries(exposes).reduce((acc, [exposeKey, exposeOptions])=>{
393
+ const normalizedExpose = normalizeExposeValue(exposeOptions);
394
+ if (!(normalizedExpose === null || normalizedExpose === void 0 ? void 0 : normalizedExpose.import.length)) {
395
+ return acc;
396
+ }
397
+ acc.push([
398
+ exposeKey,
399
+ normalizedExpose
400
+ ]);
401
+ return acc;
402
+ }, []);
403
+ if (normalizedEntries.length) {
404
+ return normalizedEntries;
405
+ }
406
+ const rawExposes = this._options.exposes;
407
+ if (!rawExposes || Array.isArray(rawExposes)) {
408
+ return undefined;
409
+ }
410
+ const normalizedFromOptions = Object.entries(rawExposes).reduce((acc, [exposeKey, exposeOptions])=>{
411
+ const normalizedExpose = normalizeExposeValue(exposeOptions);
412
+ if (!(normalizedExpose === null || normalizedExpose === void 0 ? void 0 : normalizedExpose.import.length)) {
413
+ return acc;
414
+ }
415
+ acc.push([
416
+ exposeKey,
417
+ normalizedExpose
418
+ ]);
419
+ return acc;
420
+ }, []);
421
+ return normalizedFromOptions.length ? normalizedFromOptions : undefined;
422
+ }
423
+ _initializeExposesFromOptions(exposesMap) {
424
+ if (!this._options.name || !this._containerManager.enable) {
425
+ return;
426
+ }
427
+ const exposes = this._containerManager.containerPluginExposesOptions;
428
+ Object.entries(exposes).forEach(([exposeKey, exposeOptions])=>{
429
+ var _exposeOptions_import;
430
+ if (!((_exposeOptions_import = exposeOptions.import) === null || _exposeOptions_import === void 0 ? void 0 : _exposeOptions_import.length)) {
431
+ return;
432
+ }
433
+ const [exposeImport] = exposeOptions.import;
434
+ if (!exposeImport) {
435
+ return;
436
+ }
437
+ const exposeMapKey = (0,external_utils_js_namespaceObject.getFileNameWithOutExt)(exposeImport);
438
+ if (!exposesMap[exposeMapKey]) {
439
+ exposesMap[exposeMapKey] = getExposeItem({
440
+ exposeKey,
441
+ name: this._options.name,
442
+ file: exposeOptions
443
+ });
444
+ }
445
+ });
446
+ }
447
+ collect() {
448
+ const remotes = [];
449
+ const remotesConsumerMap = {};
450
+ const exposesMap = {};
451
+ const sharedMap = {};
452
+ this._initializeExposesFromOptions(exposesMap);
453
+ const isSharedModule = (moduleType)=>{
454
+ return Boolean(moduleType && [
455
+ 'provide-module',
456
+ 'consume-shared-module'
457
+ ].includes(moduleType));
458
+ };
459
+ const isContainerModule = (identifier)=>{
460
+ return identifier.startsWith('container entry');
461
+ };
462
+ const isRemoteModule = (identifier)=>{
463
+ return identifier.startsWith('remote ');
464
+ };
465
+ // handle remote/expose
466
+ this._modules.forEach((mod)=>{
467
+ const { identifier, reasons, nameForCondition, moduleType } = mod;
468
+ if (!identifier) {
469
+ return;
470
+ }
471
+ if (isSharedModule(moduleType)) {
472
+ this._handleSharedModule(mod, sharedMap, exposesMap);
473
+ }
474
+ if (isRemoteModule(identifier)) {
475
+ this._handleRemoteModule(mod, remotes, remotesConsumerMap);
476
+ } else if (isContainerModule(identifier)) {
477
+ this._handleContainerModule(mod, exposesMap);
478
+ }
479
+ });
480
+ return {
481
+ remotes,
482
+ exposesMap,
483
+ sharedMap
484
+ };
485
+ }
486
+ constructor(options, modules, { bundler }){
487
+ this._bundler = 'webpack';
488
+ this._remoteManager = new managers_namespaceObject.RemoteManager();
489
+ this._sharedManager = new managers_namespaceObject.SharedManager();
490
+ this._options = options;
491
+ this._modules = modules;
492
+ this._bundler = bundler;
493
+ this._containerManager = new managers_namespaceObject.ContainerManager();
494
+ this._containerManager.init(options);
495
+ this._remoteManager = new managers_namespaceObject.RemoteManager();
496
+ this._remoteManager.init(options);
497
+ this._sharedManager = new managers_namespaceObject.SharedManager();
498
+ this._sharedManager.init(options);
499
+ }
500
+ }
501
+
502
+
503
+ exports.ModuleHandler = __webpack_exports__.ModuleHandler;
504
+ exports.getExposeItem = __webpack_exports__.getExposeItem;
505
+ exports.getExposeName = __webpack_exports__.getExposeName;
506
+ exports.getShareItem = __webpack_exports__.getShareItem;
507
+ for(var __webpack_i__ in __webpack_exports__) {
508
+ if(["ModuleHandler","getExposeItem","getExposeName","getShareItem"].indexOf(__webpack_i__) === -1) {
509
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
510
+ }
511
+ }
512
+ Object.defineProperty(exports, '__esModule', { value: true });