Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse non-contributing directories #167

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ function makeMergedBundle(exploreResults: ExploreBundleResult[]): ExploreBundleR

type TreeNodesMap = { [source: string]: string[] };

function getNodePath(parts: string[], depthIndex: number): string {
return parts.slice(0, depthIndex + 1).join('/');
}

function getTreeNodesMap(fileDataMap: FileDataMap): TreeNodesMap {
let partsSourceTuples = Object.keys(fileDataMap).map<[string[], string]>(file => [
file.split('/'),
Expand All @@ -95,15 +99,22 @@ function getTreeNodesMap(fileDataMap: FileDataMap): TreeNodesMap {
const maxDepth = Math.max(...partsSourceTuples.map(([parts]) => parts.length));

for (let depthIndex = 0; depthIndex < maxDepth; depthIndex += 1) {
partsSourceTuples = partsSourceTuples.map(([parts, file]) => {
const rootPart = parts[depthIndex];

if (rootPart) {
const sameRootParts = partsSourceTuples.filter(
([pathParts]) => pathParts[depthIndex] === rootPart
);

if (sameRootParts.length === 1) {
partsSourceTuples = partsSourceTuples.map(([parts, file], currentNodeIndex) => {
if (parts[depthIndex]) {
const nodePath = getNodePath(parts, depthIndex);

const hasSameRootPaths = partsSourceTuples.some(([pathParts], index) => {
if (index === currentNodeIndex) {
return false;
}
if (!pathParts[depthIndex]) {
return false;
}

return getNodePath(pathParts, depthIndex) === nodePath;
});

if (!hasSameRootPaths) {
// Collapse non-contributing path parts
return [[...parts.slice(0, depthIndex), parts.slice(depthIndex).join('/')], file];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ exports['CLI should multiple bundles output result as html 1'] = `
</body>

<script>
const treeDataMap = {"0":{"name":"[combined]","data":{"name":"/ \u2022 3.62 KB \u2022 100.0%","data":{"$area":3709},"children":[{"name":"inline-map.js \u2022 2.92 KB \u2022 80.6%","data":{"$area":2991},"children":[{"name":"node_modules \u2022 480 B \u2022 12.9%","data":{"$area":480},"children":[{"name":"browser-pack \u2022 480 B \u2022 12.9%","data":{"$area":480},"children":[{"name":"_prelude.js \u2022 480 B \u2022 12.9%","data":{"$area":480}}]}]},{"name":"src \u2022 201 B \u2022 5.4%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 2.8%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 2.6%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 2.25 KB \u2022 62.2%","data":{"$area":2308}},{"name":"[unmapped] \u2022 1 B \u2022 0.0%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.0%","data":{"$area":1}}]},{"name":"foo.min.js \u2022 718 B \u2022 19.4%","data":{"$area":718},"children":[{"name":"node_modules \u2022 480 B \u2022 12.9%","data":{"$area":480},"children":[{"name":"browser-pack \u2022 480 B \u2022 12.9%","data":{"$area":480},"children":[{"name":"_prelude.js \u2022 480 B \u2022 12.9%","data":{"$area":480}}]}]},{"name":"src \u2022 201 B \u2022 5.4%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 2.8%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 2.6%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 35 B \u2022 0.9%","data":{"$area":35}},{"name":"[unmapped] \u2022 1 B \u2022 0.0%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.0%","data":{"$area":1}}]}]}},"1":{"name":"data/inline-map.js","data":{"name":"/ \u2022 2.92 KB \u2022 100.0%","data":{"$area":2991},"children":[{"name":"node_modules/browser-pack/_prelude.js \u2022 480 B \u2022 16.0%","data":{"$area":480}},{"name":"src \u2022 201 B \u2022 6.7%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 3.5%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 3.2%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 2.25 KB \u2022 77.2%","data":{"$area":2308}},{"name":"[unmapped] \u2022 1 B \u2022 0.0%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.0%","data":{"$area":1}}]}},"2":{"name":"data/foo.min.js","data":{"name":"/ \u2022 718 B \u2022 100.0%","data":{"$area":718},"children":[{"name":"node_modules/browser-pack/_prelude.js \u2022 480 B \u2022 66.9%","data":{"$area":480}},{"name":"src \u2022 201 B \u2022 28.0%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 14.5%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 13.5%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 35 B \u2022 4.9%","data":{"$area":35}},{"name":"[unmapped] \u2022 1 B \u2022 0.1%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.1%","data":{"$area":1}}]}}};
const treeDataMap = {"0":{"name":"[combined]","data":{"name":"/ \u2022 3.62 KB \u2022 100.0%","data":{"$area":3709},"children":[{"name":"inline-map.js \u2022 2.92 KB \u2022 80.6%","data":{"$area":2991},"children":[{"name":"node_modules/browser-pack/_prelude.js \u2022 480 B \u2022 12.9%","data":{"$area":480}},{"name":"src \u2022 201 B \u2022 5.4%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 2.8%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 2.6%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 2.25 KB \u2022 62.2%","data":{"$area":2308}},{"name":"[unmapped] \u2022 1 B \u2022 0.0%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.0%","data":{"$area":1}}]},{"name":"foo.min.js \u2022 718 B \u2022 19.4%","data":{"$area":718},"children":[{"name":"node_modules/browser-pack/_prelude.js \u2022 480 B \u2022 12.9%","data":{"$area":480}},{"name":"src \u2022 201 B \u2022 5.4%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 2.8%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 2.6%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 35 B \u2022 0.9%","data":{"$area":35}},{"name":"[unmapped] \u2022 1 B \u2022 0.0%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.0%","data":{"$area":1}}]}]}},"1":{"name":"data/inline-map.js","data":{"name":"/ \u2022 2.92 KB \u2022 100.0%","data":{"$area":2991},"children":[{"name":"node_modules/browser-pack/_prelude.js \u2022 480 B \u2022 16.0%","data":{"$area":480}},{"name":"src \u2022 201 B \u2022 6.7%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 3.5%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 3.2%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 2.25 KB \u2022 77.2%","data":{"$area":2308}},{"name":"[unmapped] \u2022 1 B \u2022 0.0%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.0%","data":{"$area":1}}]}},"2":{"name":"data/foo.min.js","data":{"name":"/ \u2022 718 B \u2022 100.0%","data":{"$area":718},"children":[{"name":"node_modules/browser-pack/_prelude.js \u2022 480 B \u2022 66.9%","data":{"$area":480}},{"name":"src \u2022 201 B \u2022 28.0%","data":{"$area":201},"children":[{"name":"bar.js \u2022 104 B \u2022 14.5%","data":{"$area":104}},{"name":"foo.js \u2022 97 B \u2022 13.5%","data":{"$area":97}}]},{"name":"[sourceMappingURL] \u2022 35 B \u2022 4.9%","data":{"$area":35}},{"name":"[unmapped] \u2022 1 B \u2022 0.1%","data":{"$area":1}},{"name":"[EOLs] \u2022 1 B \u2022 0.1%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& 1 deletion tests/__snapshots__/html.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ exports['html getWebTreeMapData should collapse non-contributing nodes 1'] = {
]
},
{
"name": "j/k.js \u2022 6 B \u2022 21.4%",
"name": "j/i.js \u2022 6 B \u2022 21.4%",
"data": {
"$area": 6
}
Expand Down
2 changes: 1 addition & 1 deletion tests/html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('html', () => {
'd/f.js': { size: 3 },
'd/g/h.js': { size: 4 },
'd/g/i.js': { size: 5 },
'd/j/k.js': { size: 6 },
'd/j/i.js': { size: 6 },
z: { size: 7 },
};

Expand Down