@module-federation/manifest 0.0.0-next-20240301034824 → 0.0.0-next-20240307075509

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/dist/index.cjs.js CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var chalk = require('chalk');
6
- var sdk = require('@module-federation/sdk');
7
6
  var path = require('path');
7
+ var sdk = require('@module-federation/sdk');
8
8
  var managers = require('@module-federation/managers');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -298,6 +298,33 @@ function isDev() {
298
298
  function getFileNameWithOutExt(str) {
299
299
  return str.replace(path__default["default"].extname(str), "");
300
300
  }
301
+ function getFileName(manifestOptions) {
302
+ if (!manifestOptions) {
303
+ return {
304
+ statsFileName: sdk.StatsFileName,
305
+ manifestFileName: sdk.ManifestFileName
306
+ };
307
+ }
308
+ var filePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
309
+ var fileName = typeof manifestOptions === "boolean" ? "" : manifestOptions.fileName || "";
310
+ var JSON_EXT = ".json";
311
+ var addExt = function(name) {
312
+ if (name.endsWith(JSON_EXT)) {
313
+ return name;
314
+ }
315
+ return "".concat(name).concat(JSON_EXT);
316
+ };
317
+ var insertSuffix = function(name, suffix) {
318
+ var _name_split = _sliced_to_array$2(name.split(JSON_EXT), 2), filename = _name_split[0], ext = _name_split[1];
319
+ return "".concat(filename).concat(suffix).concat(ext);
320
+ };
321
+ var manifestFileName = fileName ? addExt(fileName) : sdk.ManifestFileName;
322
+ var statsFileName = fileName ? insertSuffix(manifestFileName, "-stats") : sdk.StatsFileName;
323
+ return {
324
+ statsFileName: sdk.simpleJoinRemoteEntry(filePath, statsFileName),
325
+ manifestFileName: sdk.simpleJoinRemoteEntry(filePath, manifestFileName)
326
+ };
327
+ }
301
328
 
302
329
  function _class_call_check$3(instance, Constructor) {
303
330
  if (!(instance instanceof Constructor)) {
@@ -390,9 +417,7 @@ var ManifestManager = /*#__PURE__*/ function() {
390
417
  {
391
418
  key: "fileName",
392
419
  get: function get() {
393
- var _this__options = this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
394
- var manifestFilePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
395
- return sdk.simpleJoinRemoteEntry(manifestFilePath, sdk.ManifestFileName);
420
+ return getFileName(this._options.manifest).manifestFileName;
396
421
  }
397
422
  },
398
423
  {
@@ -1159,9 +1184,7 @@ var StatsManager = /*#__PURE__*/ function() {
1159
1184
  {
1160
1185
  key: "fileName",
1161
1186
  get: function get() {
1162
- var _this__options = this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
1163
- var statsFilePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
1164
- return sdk.simpleJoinRemoteEntry(statsFilePath, sdk.StatsFileName);
1187
+ return getFileName(this._options.manifest).statsFileName;
1165
1188
  }
1166
1189
  },
1167
1190
  {
@@ -1314,7 +1337,7 @@ var StatsManager = /*#__PURE__*/ function() {
1314
1337
  value: function _generateStats(compiler, compilation, extraOptions) {
1315
1338
  var _this = this;
1316
1339
  return _async_to_generator$1(function() {
1317
- var _this__options, name, tmp, manifestOptions, metaData, stats, remotes, liveStats, webpackStats, filteredModules, moduleHandler, _moduleHandler_collect, remotes1, exposesMap, sharedMap, err;
1340
+ var _this__options, name, tmp, manifestOptions, metaData, stats, remotes, liveStats, statsOptions, webpackStats, filteredModules, moduleHandler, _moduleHandler_collect, remotes1, exposesMap, sharedMap, err;
1318
1341
  return _ts_generator$1(this, function(_state) {
1319
1342
  switch(_state.label){
1320
1343
  case 0:
@@ -1343,7 +1366,7 @@ var StatsManager = /*#__PURE__*/ function() {
1343
1366
  ];
1344
1367
  }
1345
1368
  liveStats = compilation.getStats();
1346
- webpackStats = liveStats.toJson({
1369
+ statsOptions = {
1347
1370
  all: false,
1348
1371
  modules: true,
1349
1372
  builtAt: true,
@@ -1354,7 +1377,12 @@ var StatsManager = /*#__PURE__*/ function() {
1354
1377
  assets: false,
1355
1378
  chunks: false,
1356
1379
  reasons: true
1357
- });
1380
+ };
1381
+ if (_this._bundler === "webpack") {
1382
+ statsOptions["cached"] = true;
1383
+ statsOptions["cachedModules"] = true;
1384
+ }
1385
+ webpackStats = liveStats.toJson();
1358
1386
  filteredModules = _this._getFilteredModules(webpackStats);
1359
1387
  moduleHandler = new ModuleHandler(_this._options, filteredModules, {
1360
1388
  bundler: _this._bundler
@@ -1465,31 +1493,45 @@ var StatsManager = /*#__PURE__*/ function() {
1465
1493
  value: function generateStats(compiler, compilation, extraOptions) {
1466
1494
  var _this = this;
1467
1495
  return _async_to_generator$1(function() {
1468
- var stats, err;
1496
+ var _this__options, tmp, manifestOptions, stats, ret, err;
1469
1497
  return _ts_generator$1(this, function(_state) {
1470
1498
  switch(_state.label){
1471
1499
  case 0:
1472
1500
  _state.trys.push([
1473
1501
  0,
1474
- 2,
1502
+ 4,
1475
1503
  ,
1476
- 3
1504
+ 5
1477
1505
  ]);
1506
+ _this__options = _this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
1478
1507
  return [
1479
1508
  4,
1480
1509
  _this._generateStats(compiler, compilation)
1481
1510
  ];
1482
1511
  case 1:
1483
1512
  stats = _state.sent();
1513
+ if (!(typeof manifestOptions === "object" && manifestOptions.additionalData)) return [
1514
+ 3,
1515
+ 3
1516
+ ];
1517
+ return [
1518
+ 4,
1519
+ manifestOptions.additionalData(stats)
1520
+ ];
1521
+ case 2:
1522
+ ret = _state.sent();
1523
+ stats = ret || stats;
1524
+ _state.label = 3;
1525
+ case 3:
1484
1526
  compilation.emitAsset(_this.fileName, new compiler.webpack.sources.RawSource(JSON.stringify(stats, null, 2)));
1485
1527
  return [
1486
1528
  2,
1487
1529
  stats
1488
1530
  ];
1489
- case 2:
1531
+ case 4:
1490
1532
  err = _state.sent();
1491
1533
  throw err;
1492
- case 3:
1534
+ case 5:
1493
1535
  return [
1494
1536
  2
1495
1537
  ];
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import chalk from 'chalk';
2
- import { simpleJoinRemoteEntry, ManifestFileName, StatsFileName } from '@module-federation/sdk';
3
2
  import path from 'path';
3
+ import { StatsFileName, ManifestFileName, simpleJoinRemoteEntry } from '@module-federation/sdk';
4
4
  import { RemoteManager, SharedManager, ContainerManager, PKGJsonManager, utils } from '@module-federation/managers';
5
5
 
6
6
  var PLUGIN_IDENTIFIER = "Module Federation Manifest Plugin";
@@ -289,6 +289,33 @@ function isDev() {
289
289
  function getFileNameWithOutExt(str) {
290
290
  return str.replace(path.extname(str), "");
291
291
  }
292
+ function getFileName(manifestOptions) {
293
+ if (!manifestOptions) {
294
+ return {
295
+ statsFileName: StatsFileName,
296
+ manifestFileName: ManifestFileName
297
+ };
298
+ }
299
+ var filePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
300
+ var fileName = typeof manifestOptions === "boolean" ? "" : manifestOptions.fileName || "";
301
+ var JSON_EXT = ".json";
302
+ var addExt = function(name) {
303
+ if (name.endsWith(JSON_EXT)) {
304
+ return name;
305
+ }
306
+ return "".concat(name).concat(JSON_EXT);
307
+ };
308
+ var insertSuffix = function(name, suffix) {
309
+ var _name_split = _sliced_to_array$2(name.split(JSON_EXT), 2), filename = _name_split[0], ext = _name_split[1];
310
+ return "".concat(filename).concat(suffix).concat(ext);
311
+ };
312
+ var manifestFileName = fileName ? addExt(fileName) : ManifestFileName;
313
+ var statsFileName = fileName ? insertSuffix(manifestFileName, "-stats") : StatsFileName;
314
+ return {
315
+ statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),
316
+ manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
317
+ };
318
+ }
292
319
 
293
320
  function _class_call_check$3(instance, Constructor) {
294
321
  if (!(instance instanceof Constructor)) {
@@ -381,9 +408,7 @@ var ManifestManager = /*#__PURE__*/ function() {
381
408
  {
382
409
  key: "fileName",
383
410
  get: function get() {
384
- var _this__options = this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
385
- var manifestFilePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
386
- return simpleJoinRemoteEntry(manifestFilePath, ManifestFileName);
411
+ return getFileName(this._options.manifest).manifestFileName;
387
412
  }
388
413
  },
389
414
  {
@@ -1150,9 +1175,7 @@ var StatsManager = /*#__PURE__*/ function() {
1150
1175
  {
1151
1176
  key: "fileName",
1152
1177
  get: function get() {
1153
- var _this__options = this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
1154
- var statsFilePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
1155
- return simpleJoinRemoteEntry(statsFilePath, StatsFileName);
1178
+ return getFileName(this._options.manifest).statsFileName;
1156
1179
  }
1157
1180
  },
1158
1181
  {
@@ -1305,7 +1328,7 @@ var StatsManager = /*#__PURE__*/ function() {
1305
1328
  value: function _generateStats(compiler, compilation, extraOptions) {
1306
1329
  var _this = this;
1307
1330
  return _async_to_generator$1(function() {
1308
- var _this__options, name, tmp, manifestOptions, metaData, stats, remotes, liveStats, webpackStats, filteredModules, moduleHandler, _moduleHandler_collect, remotes1, exposesMap, sharedMap, err;
1331
+ var _this__options, name, tmp, manifestOptions, metaData, stats, remotes, liveStats, statsOptions, webpackStats, filteredModules, moduleHandler, _moduleHandler_collect, remotes1, exposesMap, sharedMap, err;
1309
1332
  return _ts_generator$1(this, function(_state) {
1310
1333
  switch(_state.label){
1311
1334
  case 0:
@@ -1334,7 +1357,7 @@ var StatsManager = /*#__PURE__*/ function() {
1334
1357
  ];
1335
1358
  }
1336
1359
  liveStats = compilation.getStats();
1337
- webpackStats = liveStats.toJson({
1360
+ statsOptions = {
1338
1361
  all: false,
1339
1362
  modules: true,
1340
1363
  builtAt: true,
@@ -1345,7 +1368,12 @@ var StatsManager = /*#__PURE__*/ function() {
1345
1368
  assets: false,
1346
1369
  chunks: false,
1347
1370
  reasons: true
1348
- });
1371
+ };
1372
+ if (_this._bundler === "webpack") {
1373
+ statsOptions["cached"] = true;
1374
+ statsOptions["cachedModules"] = true;
1375
+ }
1376
+ webpackStats = liveStats.toJson();
1349
1377
  filteredModules = _this._getFilteredModules(webpackStats);
1350
1378
  moduleHandler = new ModuleHandler(_this._options, filteredModules, {
1351
1379
  bundler: _this._bundler
@@ -1456,31 +1484,45 @@ var StatsManager = /*#__PURE__*/ function() {
1456
1484
  value: function generateStats(compiler, compilation, extraOptions) {
1457
1485
  var _this = this;
1458
1486
  return _async_to_generator$1(function() {
1459
- var stats, err;
1487
+ var _this__options, tmp, manifestOptions, stats, ret, err;
1460
1488
  return _ts_generator$1(this, function(_state) {
1461
1489
  switch(_state.label){
1462
1490
  case 0:
1463
1491
  _state.trys.push([
1464
1492
  0,
1465
- 2,
1493
+ 4,
1466
1494
  ,
1467
- 3
1495
+ 5
1468
1496
  ]);
1497
+ _this__options = _this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
1469
1498
  return [
1470
1499
  4,
1471
1500
  _this._generateStats(compiler, compilation)
1472
1501
  ];
1473
1502
  case 1:
1474
1503
  stats = _state.sent();
1504
+ if (!(typeof manifestOptions === "object" && manifestOptions.additionalData)) return [
1505
+ 3,
1506
+ 3
1507
+ ];
1508
+ return [
1509
+ 4,
1510
+ manifestOptions.additionalData(stats)
1511
+ ];
1512
+ case 2:
1513
+ ret = _state.sent();
1514
+ stats = ret || stats;
1515
+ _state.label = 3;
1516
+ case 3:
1475
1517
  compilation.emitAsset(_this.fileName, new compiler.webpack.sources.RawSource(JSON.stringify(stats, null, 2)));
1476
1518
  return [
1477
1519
  2,
1478
1520
  stats
1479
1521
  ];
1480
- case 2:
1522
+ case 4:
1481
1523
  err = _state.sent();
1482
1524
  throw err;
1483
- case 3:
1525
+ case 5:
1484
1526
  return [
1485
1527
  2
1486
1528
  ];
@@ -1,5 +1,5 @@
1
1
  import { Chunk, Compilation, StatsCompilation, StatsModule } from 'webpack';
2
- import { StatsAssets } from '@module-federation/sdk';
2
+ import { StatsAssets, moduleFederationPlugin } from '@module-federation/sdk';
3
3
  export declare function getAssetsByChunkIDs(compilation: Compilation, chunkIDMap: Record<string, Set<string | number>>): Record<string, {
4
4
  js: string[];
5
5
  css: string[];
@@ -11,3 +11,7 @@ export declare function assert(condition: any, msg: string): asserts condition;
11
11
  export declare function error(msg: string | Error | unknown): never;
12
12
  export declare function isDev(): boolean;
13
13
  export declare function getFileNameWithOutExt(str: string): string;
14
+ export declare function getFileName(manifestOptions?: moduleFederationPlugin.ModuleFederationPluginOptions['manifest']): {
15
+ statsFileName: string;
16
+ manifestFileName: string;
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/manifest",
3
- "version": "0.0.0-next-20240301034824",
3
+ "version": "0.0.0-next-20240307075509",
4
4
  "license": "MIT",
5
5
  "description": "Provide manifest/stats for webpack/rspack MF project .",
6
6
  "keywords": [
@@ -24,8 +24,8 @@
24
24
  "dependencies": {
25
25
  "find-pkg": "2.0.0",
26
26
  "chalk": "3.0.0",
27
- "@module-federation/sdk": "0.0.0-next-20240301034824",
28
- "@module-federation/managers": "0.0.0-next-20240301034824"
27
+ "@module-federation/sdk": "0.0.0-next-20240307075509",
28
+ "@module-federation/managers": "0.0.0-next-20240307075509"
29
29
  },
30
30
  "exports": {
31
31
  ".": {