@atlaspack/bundler-default 2.14.5-canary.14 → 2.14.5-canary.141

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 CHANGED
@@ -1,5 +1,307 @@
1
1
  # @atlaspack/bundler-default
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#721](https://github.com/atlassian-labs/atlaspack/pull/721) [`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd) Thanks [@benjervis](https://github.com/benjervis)! - Add support for bundle merging based on `webpackChunkName` comments.
8
+
9
+ Adding a `webpackChunkName` comment to an import will allow the bundler to merge multiple imports into a single bundle.
10
+
11
+ e.g.:
12
+
13
+ ```ts
14
+ import(/* webpackChunkName: "my-chunk" */ './my-module');
15
+ import(/* webpackChunkName: "my-chunk" */ './another-module');
16
+ ```
17
+
18
+ This can be enabled with the feature flag `supportWebpackChunkName`.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
23
+ - @atlaspack/feature-flags@2.20.0
24
+ - @atlaspack/graph@3.5.10
25
+ - @atlaspack/utils@2.17.3
26
+ - @atlaspack/plugin@2.14.21
27
+
28
+ ## 3.1.2
29
+
30
+ ### Patch Changes
31
+
32
+ - [#702](https://github.com/atlassian-labs/atlaspack/pull/702) [`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa) Thanks [@alshdavid](https://github.com/alshdavid)! - Fixes to Flow types
33
+
34
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa), [`1c7865a`](https://github.com/atlassian-labs/atlaspack/commit/1c7865a64451116d94015e248302435839d347c0), [`a0b959f`](https://github.com/atlassian-labs/atlaspack/commit/a0b959fbf61fc3f820ff03c7e8988945fe40a91a)]:
35
+ - @atlaspack/plugin@2.14.20
36
+ - @atlaspack/feature-flags@2.19.2
37
+ - @atlaspack/graph@3.5.9
38
+ - @atlaspack/utils@2.17.2
39
+
40
+ ## 3.1.1
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [[`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d)]:
45
+ - @atlaspack/feature-flags@2.19.1
46
+ - @atlaspack/graph@3.5.8
47
+ - @atlaspack/utils@2.17.1
48
+ - @atlaspack/plugin@2.14.19
49
+
50
+ ## 3.1.0
51
+
52
+ ### Minor Changes
53
+
54
+ - [#640](https://github.com/atlassian-labs/atlaspack/pull/640) [`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d) Thanks [@JakeLane](https://github.com/JakeLane)! - Clean up conditional bundling feature flags
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`c4415a4`](https://github.com/atlassian-labs/atlaspack/commit/c4415a455543d984ca28452c2cb87a794d22497c), [`f0f7c71`](https://github.com/atlassian-labs/atlaspack/commit/f0f7c7168a1d3d18c6f30d2daed611275692b7c5), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
59
+ - @atlaspack/feature-flags@2.19.0
60
+ - @atlaspack/utils@2.17.0
61
+ - @atlaspack/rust@3.4.1
62
+ - @atlaspack/graph@3.5.7
63
+ - @atlaspack/plugin@2.14.18
64
+
65
+ ## 3.0.8
66
+
67
+ ### Patch Changes
68
+
69
+ - Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
70
+ - @atlaspack/rust@3.4.0
71
+ - @atlaspack/utils@2.16.1
72
+ - @atlaspack/plugin@2.14.17
73
+
74
+ ## 3.0.7
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [[`e8a60ff`](https://github.com/atlassian-labs/atlaspack/commit/e8a60ffbea41caef265786bbf73349771760081c), [`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
79
+ - @atlaspack/feature-flags@2.18.4
80
+ - @atlaspack/utils@2.16.0
81
+ - @atlaspack/graph@3.5.6
82
+ - @atlaspack/plugin@2.14.16
83
+
84
+ ## 3.0.6
85
+
86
+ ### Patch Changes
87
+
88
+ - Updated dependencies [[`5ded263`](https://github.com/atlassian-labs/atlaspack/commit/5ded263c7f11b866e8885b81c73e20dd060b25be)]:
89
+ - @atlaspack/feature-flags@2.18.3
90
+ - @atlaspack/graph@3.5.5
91
+ - @atlaspack/utils@2.15.3
92
+ - @atlaspack/plugin@2.14.15
93
+
94
+ ## 3.0.5
95
+
96
+ ### Patch Changes
97
+
98
+ - Updated dependencies [[`644b157`](https://github.com/atlassian-labs/atlaspack/commit/644b157dee72a871acc2d0facf0b87b8eea51956)]:
99
+ - @atlaspack/feature-flags@2.18.2
100
+ - @atlaspack/graph@3.5.4
101
+ - @atlaspack/utils@2.15.2
102
+ - @atlaspack/plugin@2.14.14
103
+
104
+ ## 3.0.4
105
+
106
+ ### Patch Changes
107
+
108
+ - Updated dependencies [[`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b), [`0501255`](https://github.com/atlassian-labs/atlaspack/commit/05012550da35b05ce7d356a8cc29311e7f9afdca)]:
109
+ - @atlaspack/feature-flags@2.18.1
110
+ - @atlaspack/utils@2.15.1
111
+ - @atlaspack/graph@3.5.3
112
+ - @atlaspack/plugin@2.14.13
113
+
114
+ ## 3.0.3
115
+
116
+ ### Patch Changes
117
+
118
+ - [#622](https://github.com/atlassian-labs/atlaspack/pull/622) [`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c) Thanks [@benjervis](https://github.com/benjervis)! - Change the overlap calculation system in findMergeCandidates to improve performance
119
+
120
+ - Updated dependencies [[`10fbcfb`](https://github.com/atlassian-labs/atlaspack/commit/10fbcfbfa49c7a83da5d7c40983e36e87f524a75), [`85c52d3`](https://github.com/atlassian-labs/atlaspack/commit/85c52d3f7717b3c84a118d18ab98cfbfd71dcbd2), [`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
121
+ - @atlaspack/feature-flags@2.18.0
122
+ - @atlaspack/utils@2.15.0
123
+ - @atlaspack/graph@3.5.2
124
+ - @atlaspack/plugin@2.14.12
125
+
126
+ ## 3.0.2
127
+
128
+ ### Patch Changes
129
+
130
+ - [#613](https://github.com/atlassian-labs/atlaspack/pull/613) [`4ca19d8`](https://github.com/atlassian-labs/atlaspack/commit/4ca19d8060dfcd279183e4039f2ecb43334ac44c) Thanks [@marcins](https://github.com/marcins)! - Ensure that constant modules are correctly included in MSBs even if they wouldn't otherwise be.
131
+
132
+ - Updated dependencies [[`73ea3c4`](https://github.com/atlassian-labs/atlaspack/commit/73ea3c4d85d4401fdd15abcbf988237e890e7ad3), [`b1b3693`](https://github.com/atlassian-labs/atlaspack/commit/b1b369317c66f8a431c170df2ebba4fa5b2e38ef)]:
133
+ - @atlaspack/feature-flags@2.17.0
134
+ - @atlaspack/graph@3.5.1
135
+ - @atlaspack/utils@2.14.11
136
+ - @atlaspack/plugin@2.14.11
137
+
138
+ ## 3.0.1
139
+
140
+ ### Patch Changes
141
+
142
+ - [#608](https://github.com/atlassian-labs/atlaspack/pull/608) [`471b99e`](https://github.com/atlassian-labs/atlaspack/commit/471b99e41b4d97328c88f65e90bea284372cb1b0) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Fix require of ES Module error
143
+
144
+ ## 3.0.0
145
+
146
+ ### Major Changes
147
+
148
+ - [#600](https://github.com/atlassian-labs/atlaspack/pull/600) [`1b52b99`](https://github.com/atlassian-labs/atlaspack/commit/1b52b99db4298b04c1a6eb0f97994d75a2d436f9) Thanks [@mattcompiles](https://github.com/mattcompiles)! - ### Breaking change
149
+
150
+ This new config replaces the previously released `sharedBundleMergeThreshold`.
151
+
152
+ The following options are available for each merge group.
153
+
154
+ ### Options
155
+
156
+ #### overlapThreshold
157
+
158
+ > The same as `sharedBundleMergeThreshold` from #535
159
+
160
+ Merge bundles share a percentage of source bundles
161
+
162
+ ```json
163
+ "@atlaspack/bundler-default": {
164
+ "sharedBundleMerge": [{
165
+ "overlapThreshold": 0.75
166
+ }]
167
+ }
168
+ ```
169
+
170
+ #### maxBundleSize
171
+
172
+ Merge bundles that are smaller than a configured amount of bytes.
173
+
174
+ > Keep in mind these bytes are pre-optimisation
175
+
176
+ ```json
177
+ "@atlaspack/bundler-default": {
178
+ "sharedBundleMerge": [{
179
+ "maxBundleSize": 20000
180
+ }]
181
+ }
182
+ ```
183
+
184
+ #### sourceBundles
185
+
186
+ Merge bundles that share a set of source bundles. The matching is relative to the project root, like how manual shared bundle roots work.
187
+
188
+ ```json
189
+ "@atlaspack/bundler-default": {
190
+ "sharedBundleMerge": [{
191
+ "sourceBundles": ["src/important-route", "src/important-route-2"]
192
+ }]
193
+ }
194
+ ```
195
+
196
+ #### minBundlesInGroup
197
+
198
+ Merge bundles that belong to a bundle group that's larger than a set amount. This is useful for targetting bundles that would be deleted by the `maxParallelRequests` option.
199
+
200
+ ```json
201
+ "@atlaspack/bundler-default": {
202
+ "maxParallelRequests": 30,
203
+ "sharedBundleMerge": [{
204
+ "minBundlesInGroup": 30
205
+ }]
206
+ }
207
+ ```
208
+
209
+ ## Combining options
210
+
211
+ When multiple options are provided, all must be true for a merge to be relevant.
212
+
213
+ For example, merge bundles that are smaller than 20kb and share at least 50% of the same source bundles.
214
+
215
+ ```json
216
+ "@atlaspack/bundler-default": {
217
+ "sharedBundleMerge": [{
218
+ "overlapThreshold": 0.5,
219
+ "maxBundleSize": 20000
220
+ }]
221
+ }
222
+ ```
223
+
224
+ ## Multiple merges
225
+
226
+ You can also have multiple merge configs.
227
+
228
+ ```json
229
+ "@atlaspack/bundler-default": {
230
+ "sharedBundleMerge": [
231
+ {
232
+ "overlapThreshold": 0.75,
233
+ "maxBundleSize": 20000
234
+ },
235
+ {
236
+ "minBundlesInGroup": 30
237
+ "sourceBundles": ["src/important-route", "src/important-route-2"]
238
+ }
239
+ ]
240
+ }
241
+ ```
242
+
243
+ ### Patch Changes
244
+
245
+ - Updated dependencies [[`1b52b99`](https://github.com/atlassian-labs/atlaspack/commit/1b52b99db4298b04c1a6eb0f97994d75a2d436f9)]:
246
+ - @atlaspack/graph@3.5.0
247
+
248
+ ## 2.16.3
249
+
250
+ ### Patch Changes
251
+
252
+ - Updated dependencies [[`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
253
+ - @atlaspack/rust@3.3.5
254
+ - @atlaspack/plugin@2.14.10
255
+ - @atlaspack/utils@2.14.10
256
+
257
+ ## 2.16.2
258
+
259
+ ### Patch Changes
260
+
261
+ - Updated dependencies [[`124b7ff`](https://github.com/atlassian-labs/atlaspack/commit/124b7fff44f71aac9fbad289a9a9509b3dfc9aaa), [`e052521`](https://github.com/atlassian-labs/atlaspack/commit/e0525210850ed1606146eb86991049cf567c5dec), [`15c6d70`](https://github.com/atlassian-labs/atlaspack/commit/15c6d7000bd89da876bc590aa75b17a619a41896), [`e4d966c`](https://github.com/atlassian-labs/atlaspack/commit/e4d966c3c9c4292c5013372ae65b10d19d4bacc6), [`209692f`](https://github.com/atlassian-labs/atlaspack/commit/209692ffb11eae103a0d65c5e1118a5aa1625818), [`42a775d`](https://github.com/atlassian-labs/atlaspack/commit/42a775de8eec638ad188f3271964170d8c04d84b), [`29c2f10`](https://github.com/atlassian-labs/atlaspack/commit/29c2f106de9679adfb5afa04e1910471dc65a427), [`f4da1e1`](https://github.com/atlassian-labs/atlaspack/commit/f4da1e120e73eeb5e8b8927f05e88f04d6148c7b), [`1ef91fc`](https://github.com/atlassian-labs/atlaspack/commit/1ef91fcc863fdd2831511937083dbbc1263b3d9d)]:
262
+ - @atlaspack/rust@3.3.4
263
+ - @atlaspack/feature-flags@2.16.0
264
+ - @atlaspack/utils@2.14.9
265
+ - @atlaspack/graph@3.4.7
266
+ - @atlaspack/plugin@2.14.9
267
+
268
+ ## 2.16.1
269
+
270
+ ### Patch Changes
271
+
272
+ - Updated dependencies [[`30f6017`](https://github.com/atlassian-labs/atlaspack/commit/30f60175ba4d272c5fc193973c63bc298584775b), [`1ab0a27`](https://github.com/atlassian-labs/atlaspack/commit/1ab0a275aeca40350415e2b03e7440d1dddc6228), [`b8a4ae8`](https://github.com/atlassian-labs/atlaspack/commit/b8a4ae8f83dc0a83d8b145c5f729936ce52080a3)]:
273
+ - @atlaspack/feature-flags@2.15.1
274
+ - @atlaspack/rust@3.3.3
275
+ - @atlaspack/graph@3.4.6
276
+ - @atlaspack/utils@2.14.8
277
+ - @atlaspack/plugin@2.14.8
278
+
279
+ ## 2.16.0
280
+
281
+ ### Minor Changes
282
+
283
+ - [#547](https://github.com/atlassian-labs/atlaspack/pull/547) [`a1773d2`](https://github.com/atlassian-labs/atlaspack/commit/a1773d2a62d0ef7805ac7524621dcabcc1afe929) Thanks [@benjervis](https://github.com/benjervis)! - Add a feature flag for resolving the configuration for `@atlaspack/bundler-default` from CWD, rather than exclusively from the project root.
284
+
285
+ ### Patch Changes
286
+
287
+ - Updated dependencies [[`a1773d2`](https://github.com/atlassian-labs/atlaspack/commit/a1773d2a62d0ef7805ac7524621dcabcc1afe929), [`556d6ab`](https://github.com/atlassian-labs/atlaspack/commit/556d6ab8ede759fa7f37fcd3f4da336ef1c55e8f)]:
288
+ - @atlaspack/feature-flags@2.15.0
289
+ - @atlaspack/rust@3.3.2
290
+ - @atlaspack/graph@3.4.5
291
+ - @atlaspack/utils@2.14.7
292
+ - @atlaspack/plugin@2.14.7
293
+
294
+ ## 2.15.1
295
+
296
+ ### Patch Changes
297
+
298
+ - Updated dependencies [[`e0f5337`](https://github.com/atlassian-labs/atlaspack/commit/e0f533757bd1019dbd108a04952c87da15286e09)]:
299
+ - @atlaspack/feature-flags@2.14.4
300
+ - @atlaspack/rust@3.3.1
301
+ - @atlaspack/graph@3.4.4
302
+ - @atlaspack/utils@2.14.6
303
+ - @atlaspack/plugin@2.14.6
304
+
3
305
  ## 2.15.0
4
306
 
5
307
  ### Minor Changes
@@ -0,0 +1,18 @@
1
+ import { Bundler } from '@atlaspack/plugin';
2
+ /**
3
+ *
4
+ * The Bundler works by creating an IdealGraph, which contains a BundleGraph that models bundles
5
+ * connected to other bundles by what references them, and thus models BundleGroups.
6
+ *
7
+ * First, we enter `bundle({bundleGraph, config})`. Here, "bundleGraph" is actually just the
8
+ * assetGraph turned into a type `MutableBundleGraph`, which will then be mutated in decorate,
9
+ * and turned into what we expect the bundleGraph to be as per the old (default) bundler structure
10
+ * & what the rest of Atlaspack expects a BundleGraph to be.
11
+ *
12
+ * `bundle({bundleGraph, config})` First gets a Mapping of target to entries, In most cases there is
13
+ * only one target, and one or more entries. (Targets are pertinent in monorepos or projects where you
14
+ * will have two or more distDirs, or output folders.) Then calls create IdealGraph and Decorate per target.
15
+ *
16
+ */
17
+ declare const _default: Bundler<unknown>;
18
+ export default _default;
@@ -59,6 +59,7 @@ var _default = exports.default = new (_plugin().Bundler)({
59
59
  logger
60
60
  }) {
61
61
  let targetMap = getEntryByTarget(bundleGraph); // Organize entries by target output folder/ distDir
62
+ // @ts-expect-error TS2304
62
63
  let graphs = [];
63
64
  for (let entries of targetMap.values()) {
64
65
  let singleFileEntries = new Map();
@@ -94,7 +95,11 @@ function getEntryByTarget(bundleGraph) {
94
95
  // Find entries from assetGraph per target
95
96
  let targets = new (_utils().DefaultMap)(() => new Map());
96
97
  bundleGraph.traverse({
97
- enter(node, context, actions) {
98
+ enter(
99
+ // @ts-expect-error TS2304
100
+ node, context,
101
+ // @ts-expect-error TS2304
102
+ actions) {
98
103
  if (node.type !== 'asset') {
99
104
  return node;
100
105
  }
@@ -0,0 +1,2 @@
1
+ import type { Asset, Dependency, MutableBundleGraph } from '@atlaspack/types';
2
+ export declare function addJSMonolithBundle(bundleGraph: MutableBundleGraph, entryAsset: Asset, entryDep: Dependency): void;
@@ -0,0 +1,9 @@
1
+ import type { NodeId } from '@atlaspack/graph';
2
+ import type { IdealBundleGraph } from './idealGraph';
3
+ export type MergeGroup = {
4
+ overlapThreshold?: number;
5
+ maxBundleSize?: number;
6
+ sourceBundles?: Array<NodeId>;
7
+ minBundlesInGroup?: number;
8
+ };
9
+ export declare function findMergeCandidates(bundleGraph: IdealBundleGraph, bundles: Array<NodeId>, config: Array<MergeGroup>): Array<Array<NodeId>>;
@@ -25,67 +25,137 @@ function _graph() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ function _utils() {
29
+ const data = require("@atlaspack/utils");
30
+ _utils = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ var _memoize = require("./memoize");
28
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
+ function getBundlesForBundleGroup(bundleGraph, bundleGroupId) {
38
+ let count = 0;
39
+ bundleGraph.traverse(nodeId => {
40
+ var _bundleGraph$getNode;
41
+ // @ts-expect-error TS2339
42
+ if (((_bundleGraph$getNode = bundleGraph.getNode(nodeId)) === null || _bundleGraph$getNode === void 0 ? void 0 : _bundleGraph$getNode.bundleBehavior) !== 'inline') {
43
+ count++;
44
+ }
45
+ }, bundleGroupId);
46
+ return count;
47
+ }
48
+ let getBundleOverlap = (sourceBundlesA, sourceBundlesB) => {
49
+ let allSourceBundles = (0, _utils().setUnion)(sourceBundlesA, sourceBundlesB);
50
+ let sharedSourceBundles = (0, _utils().setIntersectStatic)(sourceBundlesA, sourceBundlesB);
51
+ return sharedSourceBundles.size / allSourceBundles.size;
52
+ };
53
+
29
54
  // Returns a decimal showing the proportion source bundles are common to
30
55
  // both bundles versus the total number of source bundles.
31
- function scoreBundleMerge(bundleA, bundleB) {
32
- let sharedSourceBundles = 0;
33
- let allSourceBundles = new Set([...bundleA.sourceBundles, ...bundleB.sourceBundles]);
34
- for (let bundle of bundleB.sourceBundles) {
35
- if (bundleA.sourceBundles.has(bundle)) {
36
- sharedSourceBundles++;
56
+ function checkBundleThreshold(bundleA, bundleB, threshold) {
57
+ return getBundleOverlap(bundleA.bundle.sourceBundles, bundleB.bundle.sourceBundles) >= threshold;
58
+ }
59
+ let checkSharedSourceBundles = (0, _memoize.memoize)((bundle, importantAncestorBundles) => {
60
+ return importantAncestorBundles.every(ancestorId => bundle.sourceBundles.has(ancestorId));
61
+ });
62
+ let hasSuitableBundleGroup = (0, _memoize.memoize)((bundleGraph, bundle, minBundlesInGroup) => {
63
+ for (let sourceBundle of bundle.sourceBundles) {
64
+ let bundlesInGroup = getBundlesForBundleGroup(bundleGraph, sourceBundle);
65
+ if (bundlesInGroup >= minBundlesInGroup) {
66
+ return true;
67
+ }
68
+ }
69
+ return false;
70
+ });
71
+ function validMerge(bundleGraph, config, bundleA, bundleB) {
72
+ if (config.maxBundleSize != null) {
73
+ if (bundleA.bundle.size > config.maxBundleSize || bundleB.bundle.size > config.maxBundleSize) {
74
+ return false;
75
+ }
76
+ }
77
+ if (config.overlapThreshold != null) {
78
+ if (!checkBundleThreshold(bundleA, bundleB, config.overlapThreshold)) {
79
+ return false;
80
+ }
81
+ }
82
+ if (config.sourceBundles != null) {
83
+ if (!checkSharedSourceBundles(bundleA.bundle, config.sourceBundles) || !checkSharedSourceBundles(bundleB.bundle, config.sourceBundles)) {
84
+ return false;
85
+ }
86
+ }
87
+ if (config.minBundlesInGroup != null) {
88
+ if (!hasSuitableBundleGroup(bundleGraph, bundleA.bundle, config.minBundlesInGroup) || !hasSuitableBundleGroup(bundleGraph, bundleB.bundle, config.minBundlesInGroup)) {
89
+ return false;
37
90
  }
38
91
  }
39
- return sharedSourceBundles / allSourceBundles.size;
92
+ return true;
40
93
  }
41
94
  function getMergeClusters(graph, candidates) {
42
95
  let clusters = [];
43
- for (let candidate of candidates) {
96
+ for (let [candidate, edgeType] of candidates.entries()) {
44
97
  let cluster = [];
45
98
  graph.traverse(nodeId => {
46
99
  cluster.push((0, _nullthrows().default)(graph.getNode(nodeId)));
47
100
  // Remove node from candidates as it has already been processed
48
101
  candidates.delete(nodeId);
49
- }, candidate);
102
+ }, candidate, edgeType);
50
103
  clusters.push(cluster);
51
104
  }
52
105
  return clusters;
53
106
  }
54
- function findMergeCandidates(bundleGraph, bundles, threshold) {
107
+ function getPossibleMergeCandidates(bundleGraph, bundles) {
108
+ let mergeCandidates = bundles.map(bundleId => {
109
+ let bundle = bundleGraph.getNode(bundleId);
110
+ (0, _assert().default)(bundle && bundle !== 'root', 'Bundle should exist');
111
+ return {
112
+ id: bundleId,
113
+ bundle,
114
+ contentKey: bundleId.toString()
115
+ };
116
+ });
117
+ const uniquePairs = [];
118
+ for (let i = 0; i < mergeCandidates.length; i++) {
119
+ for (let j = i + 1; j < mergeCandidates.length; j++) {
120
+ let a = mergeCandidates[i];
121
+ let b = mergeCandidates[j];
122
+
123
+ // @ts-expect-error TS18048
124
+ if (a.bundle.internalizedAssets.equals(b.bundle.internalizedAssets)) {
125
+ uniquePairs.push([a, b]);
126
+ }
127
+ }
128
+ }
129
+ return uniquePairs;
130
+ }
131
+ function findMergeCandidates(bundleGraph, bundles, config) {
55
132
  let graph = new (_graph().ContentGraph)();
56
- let seen = new Set();
57
- let candidates = new Set();
133
+ let candidates = new Map();
134
+ let allPossibleMergeCandidates = getPossibleMergeCandidates(bundleGraph, bundles);
58
135
 
59
136
  // Build graph of clustered merge candidates
60
- for (let bundleId of bundles) {
61
- let bundle = bundleGraph.getNode(bundleId);
62
- (0, _assert().default)(bundle && bundle !== 'root');
63
- if (bundle.type !== 'js') {
64
- continue;
65
- }
66
- for (let otherBundleId of bundles) {
67
- if (bundleId === otherBundleId) {
137
+ for (let i = 0; i < config.length; i++) {
138
+ // Ensure edge type coresponds to config index
139
+ let edgeType = i + 1;
140
+ for (let group of allPossibleMergeCandidates) {
141
+ let candidateA = group[0];
142
+ let candidateB = group[1];
143
+ if (!validMerge(bundleGraph, config[i], candidateA, candidateB)) {
68
144
  continue;
69
145
  }
70
- let key = [bundleId, otherBundleId].sort().join(':');
71
- if (seen.has(key)) {
72
- continue;
73
- }
74
- seen.add(key);
75
- let otherBundle = bundleGraph.getNode(otherBundleId);
76
- (0, _assert().default)(otherBundle && otherBundle !== 'root');
77
- let score = scoreBundleMerge(bundle, otherBundle);
78
- if (score >= threshold) {
79
- let bundleNode = graph.addNodeByContentKeyIfNeeded(bundleId.toString(), bundleId);
80
- let otherBundleNode = graph.addNodeByContentKeyIfNeeded(otherBundleId.toString(), otherBundleId);
146
+ let bundleNode = graph.addNodeByContentKeyIfNeeded(candidateA.contentKey, candidateA.id);
147
+ let otherBundleNode = graph.addNodeByContentKeyIfNeeded(candidateB.contentKey, candidateB.id);
81
148
 
82
- // Add edge in both directions
83
- graph.addEdge(bundleNode, otherBundleNode);
84
- graph.addEdge(otherBundleNode, bundleNode);
85
- candidates.add(bundleNode);
86
- candidates.add(otherBundleNode);
87
- }
149
+ // Add edge in both directions
150
+ graph.addEdge(bundleNode, otherBundleNode, edgeType);
151
+ graph.addEdge(otherBundleNode, bundleNode, edgeType);
152
+ candidates.set(bundleNode, edgeType);
153
+ candidates.set(otherBundleNode, edgeType);
88
154
  }
155
+
156
+ // Remove bundles that have been allocated to a higher priority merge
157
+ allPossibleMergeCandidates = allPossibleMergeCandidates.filter(group => !graph.hasContentKey(group[0].contentKey) && !graph.hasContentKey(group[1].contentKey));
89
158
  }
159
+ (0, _memoize.clearCaches)();
90
160
  return getMergeClusters(graph, candidates);
91
161
  }
@@ -0,0 +1,27 @@
1
+ import type { Config, PluginOptions, PluginLogger } from '@atlaspack/types';
2
+ type Glob = string;
3
+ type ManualSharedBundles = Array<{
4
+ name: string;
5
+ assets: Array<Glob>;
6
+ types?: Array<string>;
7
+ root?: string;
8
+ split?: number;
9
+ }>;
10
+ export type MergeCandidates = Array<{
11
+ overlapThreshold?: number;
12
+ maxBundleSize?: number;
13
+ sourceBundles?: Array<string>;
14
+ minBundlesInGroup?: number;
15
+ }>;
16
+ export type ResolvedBundlerConfig = {
17
+ minBundles: number;
18
+ minBundleSize: number;
19
+ maxParallelRequests: number;
20
+ projectRoot: string;
21
+ disableSharedBundles: boolean;
22
+ manualSharedBundles: ManualSharedBundles;
23
+ loadConditionalBundlesInParallel?: boolean;
24
+ sharedBundleMerge?: MergeCandidates;
25
+ };
26
+ export declare function loadBundlerConfig(config: Config, options: PluginOptions, logger: PluginLogger): Promise<ResolvedBundlerConfig>;
27
+ export {};