MCPcopy
hub / github.com/FormidableLabs/webpack-dashboard / formatModules

Function formatModules

utils/format-modules.js:43–78  ·  view source on GitHub ↗
(mods)

Source from the content-addressed store, hash-verified

41}
42
43function formatModules(mods) {
44 // We _could_ use the `asset.meta.full` from inspectpack, but that is for
45 // the entire module with boilerplate included. We instead do a percentage
46 // of the files we're counting here.
47 const assetSize = mods.reduce((count, mod) => count + mod.size.full, 0);
48
49 // First, process the modules into a map to normalize file paths.
50 const modsMap = mods.reduce((memo, mod) => {
51 // File name collapses to packages for dependencies.
52 // Aggregate into object.
53 const fileName = _formatFileName(mod);
54
55 // Add in information.
56 memo[fileName] = memo[fileName] || {
57 fileName,
58 num: 0,
59 size: 0
60 };
61 memo[fileName].num += 1;
62 memo[fileName].size += mod.size.full;
63
64 return memo;
65 }, {});
66
67 return [].concat(
68 [["Name", "Size", "Percent"]],
69 Object.keys(modsMap)
70 .map(fileName => modsMap[fileName])
71 .sort((a, b) => a.size < b.size) // sort largest first
72 .map(mod => [
73 `${mod.fileName} ${mod.num > 1 ? `(${mod.num})` : ""}`,
74 filesize(mod.size),
75 _formatPercentage(mod.size, assetSize)
76 ])
77 );
78}
79
80module.exports = {
81 formatModules,

Callers 1

setSizesMethod · 0.85

Calls 2

_formatFileNameFunction · 0.85
_formatPercentageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…