@atlaspack/bundler-default 2.14.5-canary.35 → 2.14.5-canary.351
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/CHANGELOG.md +589 -0
- package/dist/DefaultBundler.js +84 -0
- package/dist/MonolithicBundler.js +68 -0
- package/dist/bundleMerge.js +137 -0
- package/dist/bundlerConfig.js +223 -0
- package/dist/decorateLegacyGraph.js +189 -0
- package/dist/idealGraph.js +1471 -0
- package/dist/memoize.js +31 -0
- package/dist/stats.js +69 -0
- package/lib/DefaultBundler.js +6 -1
- package/lib/MonolithicBundler.js +11 -3
- package/lib/bundleMerge.js +106 -37
- package/lib/bundlerConfig.js +52 -6
- package/lib/decorateLegacyGraph.js +24 -3
- package/lib/idealGraph.js +410 -55
- package/lib/memoize.js +39 -0
- package/lib/stats.js +85 -0
- package/lib/types/DefaultBundler.d.ts +18 -0
- package/lib/types/MonolithicBundler.d.ts +2 -0
- package/lib/types/bundleMerge.d.ts +9 -0
- package/lib/types/bundlerConfig.d.ts +36 -0
- package/lib/types/decorateLegacyGraph.d.ts +3 -0
- package/lib/types/idealGraph.d.ts +40 -0
- package/lib/types/memoize.d.ts +2 -0
- package/lib/types/stats.d.ts +16 -0
- package/package.json +20 -12
- package/src/{DefaultBundler.js → DefaultBundler.ts} +21 -6
- package/src/{MonolithicBundler.js → MonolithicBundler.ts} +17 -5
- package/src/bundleMerge.ts +250 -0
- package/src/{bundlerConfig.js → bundlerConfig.ts} +106 -45
- package/src/{decorateLegacyGraph.js → decorateLegacyGraph.ts} +26 -7
- package/src/{idealGraph.js → idealGraph.ts} +729 -137
- package/src/memoize.ts +32 -0
- package/src/stats.ts +97 -0
- package/tsconfig.json +30 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/bundleMerge.js +0 -103
package/src/bundleMerge.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
|
-
import invariant from 'assert';
|
|
4
|
-
import nullthrows from 'nullthrows';
|
|
5
|
-
import type {NodeId} from '@atlaspack/graph';
|
|
6
|
-
import type {Bundle, IdealBundleGraph} from './idealGraph';
|
|
7
|
-
import {ContentGraph} from '@atlaspack/graph';
|
|
8
|
-
|
|
9
|
-
// Returns a decimal showing the proportion source bundles are common to
|
|
10
|
-
// both bundles versus the total number of source bundles.
|
|
11
|
-
function scoreBundleMerge(bundleA: Bundle, bundleB: Bundle): number {
|
|
12
|
-
let sharedSourceBundles = 0;
|
|
13
|
-
let allSourceBundles = new Set([
|
|
14
|
-
...bundleA.sourceBundles,
|
|
15
|
-
...bundleB.sourceBundles,
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
for (let bundle of bundleB.sourceBundles) {
|
|
19
|
-
if (bundleA.sourceBundles.has(bundle)) {
|
|
20
|
-
sharedSourceBundles++;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return sharedSourceBundles / allSourceBundles.size;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getMergeClusters(
|
|
28
|
-
graph: ContentGraph<NodeId>,
|
|
29
|
-
candidates: Set<NodeId>,
|
|
30
|
-
): Array<Array<NodeId>> {
|
|
31
|
-
let clusters = [];
|
|
32
|
-
|
|
33
|
-
for (let candidate of candidates) {
|
|
34
|
-
let cluster: Array<NodeId> = [];
|
|
35
|
-
|
|
36
|
-
graph.traverse((nodeId) => {
|
|
37
|
-
cluster.push(nullthrows(graph.getNode(nodeId)));
|
|
38
|
-
// Remove node from candidates as it has already been processed
|
|
39
|
-
candidates.delete(nodeId);
|
|
40
|
-
}, candidate);
|
|
41
|
-
|
|
42
|
-
clusters.push(cluster);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return clusters;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function findMergeCandidates(
|
|
49
|
-
bundleGraph: IdealBundleGraph,
|
|
50
|
-
bundles: Array<NodeId>,
|
|
51
|
-
threshold: number,
|
|
52
|
-
): Array<Array<NodeId>> {
|
|
53
|
-
let graph = new ContentGraph<NodeId>();
|
|
54
|
-
let seen = new Set<string>();
|
|
55
|
-
let candidates = new Set<NodeId>();
|
|
56
|
-
|
|
57
|
-
// Build graph of clustered merge candidates
|
|
58
|
-
for (let bundleId of bundles) {
|
|
59
|
-
let bundle = bundleGraph.getNode(bundleId);
|
|
60
|
-
invariant(bundle && bundle !== 'root');
|
|
61
|
-
if (bundle.type !== 'js') {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
for (let otherBundleId of bundles) {
|
|
66
|
-
if (bundleId === otherBundleId) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let key = [bundleId, otherBundleId].sort().join(':');
|
|
71
|
-
|
|
72
|
-
if (seen.has(key)) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
seen.add(key);
|
|
76
|
-
|
|
77
|
-
let otherBundle = bundleGraph.getNode(otherBundleId);
|
|
78
|
-
invariant(otherBundle && otherBundle !== 'root');
|
|
79
|
-
|
|
80
|
-
let score = scoreBundleMerge(bundle, otherBundle);
|
|
81
|
-
|
|
82
|
-
if (score >= threshold) {
|
|
83
|
-
let bundleNode = graph.addNodeByContentKeyIfNeeded(
|
|
84
|
-
bundleId.toString(),
|
|
85
|
-
bundleId,
|
|
86
|
-
);
|
|
87
|
-
let otherBundleNode = graph.addNodeByContentKeyIfNeeded(
|
|
88
|
-
otherBundleId.toString(),
|
|
89
|
-
otherBundleId,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
// Add edge in both directions
|
|
93
|
-
graph.addEdge(bundleNode, otherBundleNode);
|
|
94
|
-
graph.addEdge(otherBundleNode, bundleNode);
|
|
95
|
-
|
|
96
|
-
candidates.add(bundleNode);
|
|
97
|
-
candidates.add(otherBundleNode);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return getMergeClusters(graph, candidates);
|
|
103
|
-
}
|