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

Function _formatFileName

utils/format-modules.js:15–35  ·  view source on GitHub ↗
(mod)

Source from the content-addressed store, hash-verified

13// - existing source file name
14// - the path leading up to **just** the package (not including subpath).
15function _formatFileName(mod) {
16 const { fileName, baseName } = mod;
17
18 // Source file.
19 if (!baseName) {
20 return `{green-fg}.${sep}${relative(process.cwd(), resolve(fileName))}{/}`;
21 }
22
23 // Package
24 let parts = fileName.split(sep);
25 // Remove starting path.
26 const firstNmIdx = parts.indexOf("node_modules");
27 parts = parts.slice(firstNmIdx);
28
29 // Remove trailing path after package.
30 const lastNmIdx = parts.lastIndexOf("node_modules");
31 const isScoped = (parts[lastNmIdx + 1] || "").startsWith("@");
32 parts = parts.slice(0, lastNmIdx + (isScoped ? 3 : 2)); // eslint-disable-line no-magic-numbers
33
34 return parts.map(part => (part === "node_modules" ? "~" : `{yellow-fg}${part}{/}`)).join(sep);
35}
36
37function _formatPercentage(modSize, assetSize) {
38 const percentage = ((modSize / assetSize) * PERCENT_MULTIPLIER).toPrecision(PERCENT_PRECISION);

Callers 2

formatModulesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…