@atlaspack/bundler-default 2.14.5-canary.16 → 2.14.5-canary.161

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,348 @@
1
1
  # @atlaspack/bundler-default
2
2
 
3
+ ## 3.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`f6b3f22`](https://github.com/atlassian-labs/atlaspack/commit/f6b3f2276c7e417580b49c4879563aab51f156b1)]:
8
+ - @atlaspack/feature-flags@2.23.0
9
+ - @atlaspack/graph@3.5.14
10
+ - @atlaspack/types-internal@2.19.1
11
+ - @atlaspack/utils@2.18.2
12
+ - @atlaspack/plugin@2.14.25
13
+
14
+ ## 3.3.1
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [[`ad26146`](https://github.com/atlassian-labs/atlaspack/commit/ad26146f13b4c1cc65d4a0f9c67060b90ef14ff3), [`f1b48e7`](https://github.com/atlassian-labs/atlaspack/commit/f1b48e7a04e005cef0f36a3e692087a9ecdb6f7a), [`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45), [`73dd7ba`](https://github.com/atlassian-labs/atlaspack/commit/73dd7baab69456ef2f6e4a0cc7dbb04f407eb148)]:
19
+ - @atlaspack/rust@3.6.0
20
+ - @atlaspack/types-internal@2.19.0
21
+ - @atlaspack/feature-flags@2.22.0
22
+ - @atlaspack/utils@2.18.1
23
+ - @atlaspack/graph@3.5.13
24
+ - @atlaspack/plugin@2.14.24
25
+
26
+ ## 3.3.0
27
+
28
+ ### Minor Changes
29
+
30
+ - [#731](https://github.com/atlassian-labs/atlaspack/pull/731) [`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2) Thanks [@marcins](https://github.com/marcins)! - Implement "inline isolated" scripts
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
35
+ - @atlaspack/feature-flags@2.21.0
36
+ - @atlaspack/utils@2.18.0
37
+ - @atlaspack/rust@3.5.0
38
+ - @atlaspack/graph@3.5.12
39
+ - @atlaspack/plugin@2.14.23
40
+
41
+ ## 3.2.1
42
+
43
+ ### Patch Changes
44
+
45
+ - [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
46
+
47
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`12bee0e`](https://github.com/atlassian-labs/atlaspack/commit/12bee0e23f0464d7f6bd3e24fbe0d19c126d587d)]:
48
+ - @atlaspack/feature-flags@2.20.1
49
+ - @atlaspack/diagnostic@2.14.2
50
+ - @atlaspack/plugin@2.14.22
51
+ - @atlaspack/graph@3.5.11
52
+ - @atlaspack/utils@2.17.4
53
+ - @atlaspack/rust@3.4.2
54
+
55
+ ## 3.2.0
56
+
57
+ ### Minor Changes
58
+
59
+ - [#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.
60
+
61
+ Adding a `webpackChunkName` comment to an import will allow the bundler to merge multiple imports into a single bundle.
62
+
63
+ e.g.:
64
+
65
+ ```ts
66
+ import(/* webpackChunkName: "my-chunk" */ './my-module');
67
+ import(/* webpackChunkName: "my-chunk" */ './another-module');
68
+ ```
69
+
70
+ This can be enabled with the feature flag `supportWebpackChunkName`.
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
75
+ - @atlaspack/feature-flags@2.20.0
76
+ - @atlaspack/graph@3.5.10
77
+ - @atlaspack/utils@2.17.3
78
+ - @atlaspack/plugin@2.14.21
79
+
80
+ ## 3.1.2
81
+
82
+ ### Patch Changes
83
+
84
+ - [#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
85
+
86
+ - 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)]:
87
+ - @atlaspack/plugin@2.14.20
88
+ - @atlaspack/feature-flags@2.19.2
89
+ - @atlaspack/graph@3.5.9
90
+ - @atlaspack/utils@2.17.2
91
+
92
+ ## 3.1.1
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies [[`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d)]:
97
+ - @atlaspack/feature-flags@2.19.1
98
+ - @atlaspack/graph@3.5.8
99
+ - @atlaspack/utils@2.17.1
100
+ - @atlaspack/plugin@2.14.19
101
+
102
+ ## 3.1.0
103
+
104
+ ### Minor Changes
105
+
106
+ - [#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
107
+
108
+ ### Patch Changes
109
+
110
+ - 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)]:
111
+ - @atlaspack/feature-flags@2.19.0
112
+ - @atlaspack/utils@2.17.0
113
+ - @atlaspack/rust@3.4.1
114
+ - @atlaspack/graph@3.5.7
115
+ - @atlaspack/plugin@2.14.18
116
+
117
+ ## 3.0.8
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
122
+ - @atlaspack/rust@3.4.0
123
+ - @atlaspack/utils@2.16.1
124
+ - @atlaspack/plugin@2.14.17
125
+
126
+ ## 3.0.7
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies [[`e8a60ff`](https://github.com/atlassian-labs/atlaspack/commit/e8a60ffbea41caef265786bbf73349771760081c), [`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
131
+ - @atlaspack/feature-flags@2.18.4
132
+ - @atlaspack/utils@2.16.0
133
+ - @atlaspack/graph@3.5.6
134
+ - @atlaspack/plugin@2.14.16
135
+
136
+ ## 3.0.6
137
+
138
+ ### Patch Changes
139
+
140
+ - Updated dependencies [[`5ded263`](https://github.com/atlassian-labs/atlaspack/commit/5ded263c7f11b866e8885b81c73e20dd060b25be)]:
141
+ - @atlaspack/feature-flags@2.18.3
142
+ - @atlaspack/graph@3.5.5
143
+ - @atlaspack/utils@2.15.3
144
+ - @atlaspack/plugin@2.14.15
145
+
146
+ ## 3.0.5
147
+
148
+ ### Patch Changes
149
+
150
+ - Updated dependencies [[`644b157`](https://github.com/atlassian-labs/atlaspack/commit/644b157dee72a871acc2d0facf0b87b8eea51956)]:
151
+ - @atlaspack/feature-flags@2.18.2
152
+ - @atlaspack/graph@3.5.4
153
+ - @atlaspack/utils@2.15.2
154
+ - @atlaspack/plugin@2.14.14
155
+
156
+ ## 3.0.4
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies [[`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b), [`0501255`](https://github.com/atlassian-labs/atlaspack/commit/05012550da35b05ce7d356a8cc29311e7f9afdca)]:
161
+ - @atlaspack/feature-flags@2.18.1
162
+ - @atlaspack/utils@2.15.1
163
+ - @atlaspack/graph@3.5.3
164
+ - @atlaspack/plugin@2.14.13
165
+
166
+ ## 3.0.3
167
+
168
+ ### Patch Changes
169
+
170
+ - [#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
171
+
172
+ - 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)]:
173
+ - @atlaspack/feature-flags@2.18.0
174
+ - @atlaspack/utils@2.15.0
175
+ - @atlaspack/graph@3.5.2
176
+ - @atlaspack/plugin@2.14.12
177
+
178
+ ## 3.0.2
179
+
180
+ ### Patch Changes
181
+
182
+ - [#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.
183
+
184
+ - Updated dependencies [[`73ea3c4`](https://github.com/atlassian-labs/atlaspack/commit/73ea3c4d85d4401fdd15abcbf988237e890e7ad3), [`b1b3693`](https://github.com/atlassian-labs/atlaspack/commit/b1b369317c66f8a431c170df2ebba4fa5b2e38ef)]:
185
+ - @atlaspack/feature-flags@2.17.0
186
+ - @atlaspack/graph@3.5.1
187
+ - @atlaspack/utils@2.14.11
188
+ - @atlaspack/plugin@2.14.11
189
+
190
+ ## 3.0.1
191
+
192
+ ### Patch Changes
193
+
194
+ - [#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
195
+
196
+ ## 3.0.0
197
+
198
+ ### Major Changes
199
+
200
+ - [#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
201
+
202
+ This new config replaces the previously released `sharedBundleMergeThreshold`.
203
+
204
+ The following options are available for each merge group.
205
+
206
+ ### Options
207
+
208
+ #### overlapThreshold
209
+
210
+ > The same as `sharedBundleMergeThreshold` from #535
211
+
212
+ Merge bundles share a percentage of source bundles
213
+
214
+ ```json
215
+ "@atlaspack/bundler-default": {
216
+ "sharedBundleMerge": [{
217
+ "overlapThreshold": 0.75
218
+ }]
219
+ }
220
+ ```
221
+
222
+ #### maxBundleSize
223
+
224
+ Merge bundles that are smaller than a configured amount of bytes.
225
+
226
+ > Keep in mind these bytes are pre-optimisation
227
+
228
+ ```json
229
+ "@atlaspack/bundler-default": {
230
+ "sharedBundleMerge": [{
231
+ "maxBundleSize": 20000
232
+ }]
233
+ }
234
+ ```
235
+
236
+ #### sourceBundles
237
+
238
+ Merge bundles that share a set of source bundles. The matching is relative to the project root, like how manual shared bundle roots work.
239
+
240
+ ```json
241
+ "@atlaspack/bundler-default": {
242
+ "sharedBundleMerge": [{
243
+ "sourceBundles": ["src/important-route", "src/important-route-2"]
244
+ }]
245
+ }
246
+ ```
247
+
248
+ #### minBundlesInGroup
249
+
250
+ 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.
251
+
252
+ ```json
253
+ "@atlaspack/bundler-default": {
254
+ "maxParallelRequests": 30,
255
+ "sharedBundleMerge": [{
256
+ "minBundlesInGroup": 30
257
+ }]
258
+ }
259
+ ```
260
+
261
+ ## Combining options
262
+
263
+ When multiple options are provided, all must be true for a merge to be relevant.
264
+
265
+ For example, merge bundles that are smaller than 20kb and share at least 50% of the same source bundles.
266
+
267
+ ```json
268
+ "@atlaspack/bundler-default": {
269
+ "sharedBundleMerge": [{
270
+ "overlapThreshold": 0.5,
271
+ "maxBundleSize": 20000
272
+ }]
273
+ }
274
+ ```
275
+
276
+ ## Multiple merges
277
+
278
+ You can also have multiple merge configs.
279
+
280
+ ```json
281
+ "@atlaspack/bundler-default": {
282
+ "sharedBundleMerge": [
283
+ {
284
+ "overlapThreshold": 0.75,
285
+ "maxBundleSize": 20000
286
+ },
287
+ {
288
+ "minBundlesInGroup": 30
289
+ "sourceBundles": ["src/important-route", "src/important-route-2"]
290
+ }
291
+ ]
292
+ }
293
+ ```
294
+
295
+ ### Patch Changes
296
+
297
+ - Updated dependencies [[`1b52b99`](https://github.com/atlassian-labs/atlaspack/commit/1b52b99db4298b04c1a6eb0f97994d75a2d436f9)]:
298
+ - @atlaspack/graph@3.5.0
299
+
300
+ ## 2.16.3
301
+
302
+ ### Patch Changes
303
+
304
+ - Updated dependencies [[`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
305
+ - @atlaspack/rust@3.3.5
306
+ - @atlaspack/plugin@2.14.10
307
+ - @atlaspack/utils@2.14.10
308
+
309
+ ## 2.16.2
310
+
311
+ ### Patch Changes
312
+
313
+ - 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)]:
314
+ - @atlaspack/rust@3.3.4
315
+ - @atlaspack/feature-flags@2.16.0
316
+ - @atlaspack/utils@2.14.9
317
+ - @atlaspack/graph@3.4.7
318
+ - @atlaspack/plugin@2.14.9
319
+
320
+ ## 2.16.1
321
+
322
+ ### Patch Changes
323
+
324
+ - 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)]:
325
+ - @atlaspack/feature-flags@2.15.1
326
+ - @atlaspack/rust@3.3.3
327
+ - @atlaspack/graph@3.4.6
328
+ - @atlaspack/utils@2.14.8
329
+ - @atlaspack/plugin@2.14.8
330
+
331
+ ## 2.16.0
332
+
333
+ ### Minor Changes
334
+
335
+ - [#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.
336
+
337
+ ### Patch Changes
338
+
339
+ - Updated dependencies [[`a1773d2`](https://github.com/atlassian-labs/atlaspack/commit/a1773d2a62d0ef7805ac7524621dcabcc1afe929), [`556d6ab`](https://github.com/atlassian-labs/atlaspack/commit/556d6ab8ede759fa7f37fcd3f4da336ef1c55e8f)]:
340
+ - @atlaspack/feature-flags@2.15.0
341
+ - @atlaspack/rust@3.3.2
342
+ - @atlaspack/graph@3.4.5
343
+ - @atlaspack/utils@2.14.7
344
+ - @atlaspack/plugin@2.14.7
345
+
3
346
  ## 2.15.1
4
347
 
5
348
  ### Patch Changes
@@ -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
  }
@@ -38,8 +38,8 @@ function addJSMonolithBundle(bundleGraph, entryAsset, entryDep) {
38
38
  }
39
39
  let assets = bundleGraph.getDependencyAssets(dependency);
40
40
  for (const asset of assets) {
41
- if (asset.bundleBehavior === 'isolated') {
42
- throw new Error('Isolated assets are not supported for single file output builds');
41
+ if (asset.bundleBehavior === 'isolated' || asset.bundleBehavior === 'inlineIsolated') {
42
+ throw new Error(`${asset.bundleBehavior === 'isolated' ? 'Isolated' : 'Inline isolated'} assets are not supported for single file output builds`);
43
43
  }
44
44
 
45
45
  // For assets marked as inline, we create new bundles and let other
@@ -25,67 +25,136 @@ 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
+ const node = bundleGraph.getNode(nodeId);
41
+ if (node && (node === 'root' || node.bundleBehavior !== 'inline' && node.bundleBehavior !== 'inlineIsolated')) {
42
+ count++;
43
+ }
44
+ }, bundleGroupId);
45
+ return count;
46
+ }
47
+ let getBundleOverlap = (sourceBundlesA, sourceBundlesB) => {
48
+ let allSourceBundles = (0, _utils().setUnion)(sourceBundlesA, sourceBundlesB);
49
+ let sharedSourceBundles = (0, _utils().setIntersectStatic)(sourceBundlesA, sourceBundlesB);
50
+ return sharedSourceBundles.size / allSourceBundles.size;
51
+ };
52
+
29
53
  // Returns a decimal showing the proportion source bundles are common to
30
54
  // 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++;
55
+ function checkBundleThreshold(bundleA, bundleB, threshold) {
56
+ return getBundleOverlap(bundleA.bundle.sourceBundles, bundleB.bundle.sourceBundles) >= threshold;
57
+ }
58
+ let checkSharedSourceBundles = (0, _memoize.memoize)((bundle, importantAncestorBundles) => {
59
+ return importantAncestorBundles.every(ancestorId => bundle.sourceBundles.has(ancestorId));
60
+ });
61
+ let hasSuitableBundleGroup = (0, _memoize.memoize)((bundleGraph, bundle, minBundlesInGroup) => {
62
+ for (let sourceBundle of bundle.sourceBundles) {
63
+ let bundlesInGroup = getBundlesForBundleGroup(bundleGraph, sourceBundle);
64
+ if (bundlesInGroup >= minBundlesInGroup) {
65
+ return true;
66
+ }
67
+ }
68
+ return false;
69
+ });
70
+ function validMerge(bundleGraph, config, bundleA, bundleB) {
71
+ if (config.maxBundleSize != null) {
72
+ if (bundleA.bundle.size > config.maxBundleSize || bundleB.bundle.size > config.maxBundleSize) {
73
+ return false;
74
+ }
75
+ }
76
+ if (config.overlapThreshold != null) {
77
+ if (!checkBundleThreshold(bundleA, bundleB, config.overlapThreshold)) {
78
+ return false;
79
+ }
80
+ }
81
+ if (config.sourceBundles != null) {
82
+ if (!checkSharedSourceBundles(bundleA.bundle, config.sourceBundles) || !checkSharedSourceBundles(bundleB.bundle, config.sourceBundles)) {
83
+ return false;
84
+ }
85
+ }
86
+ if (config.minBundlesInGroup != null) {
87
+ if (!hasSuitableBundleGroup(bundleGraph, bundleA.bundle, config.minBundlesInGroup) || !hasSuitableBundleGroup(bundleGraph, bundleB.bundle, config.minBundlesInGroup)) {
88
+ return false;
37
89
  }
38
90
  }
39
- return sharedSourceBundles / allSourceBundles.size;
91
+ return true;
40
92
  }
41
93
  function getMergeClusters(graph, candidates) {
42
94
  let clusters = [];
43
- for (let candidate of candidates) {
95
+ for (let [candidate, edgeType] of candidates.entries()) {
44
96
  let cluster = [];
45
97
  graph.traverse(nodeId => {
46
98
  cluster.push((0, _nullthrows().default)(graph.getNode(nodeId)));
47
99
  // Remove node from candidates as it has already been processed
48
100
  candidates.delete(nodeId);
49
- }, candidate);
101
+ }, candidate, edgeType);
50
102
  clusters.push(cluster);
51
103
  }
52
104
  return clusters;
53
105
  }
54
- function findMergeCandidates(bundleGraph, bundles, threshold) {
106
+ function getPossibleMergeCandidates(bundleGraph, bundles) {
107
+ let mergeCandidates = bundles.map(bundleId => {
108
+ let bundle = bundleGraph.getNode(bundleId);
109
+ (0, _assert().default)(bundle && bundle !== 'root', 'Bundle should exist');
110
+ return {
111
+ id: bundleId,
112
+ bundle,
113
+ contentKey: bundleId.toString()
114
+ };
115
+ });
116
+ const uniquePairs = [];
117
+ for (let i = 0; i < mergeCandidates.length; i++) {
118
+ for (let j = i + 1; j < mergeCandidates.length; j++) {
119
+ let a = mergeCandidates[i];
120
+ let b = mergeCandidates[j];
121
+
122
+ // @ts-expect-error TS18048
123
+ if (a.bundle.internalizedAssets.equals(b.bundle.internalizedAssets)) {
124
+ uniquePairs.push([a, b]);
125
+ }
126
+ }
127
+ }
128
+ return uniquePairs;
129
+ }
130
+ function findMergeCandidates(bundleGraph, bundles, config) {
55
131
  let graph = new (_graph().ContentGraph)();
56
- let seen = new Set();
57
- let candidates = new Set();
132
+ let candidates = new Map();
133
+ let allPossibleMergeCandidates = getPossibleMergeCandidates(bundleGraph, bundles);
58
134
 
59
135
  // 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) {
136
+ for (let i = 0; i < config.length; i++) {
137
+ // Ensure edge type coresponds to config index
138
+ let edgeType = i + 1;
139
+ for (let group of allPossibleMergeCandidates) {
140
+ let candidateA = group[0];
141
+ let candidateB = group[1];
142
+ if (!validMerge(bundleGraph, config[i], candidateA, candidateB)) {
68
143
  continue;
69
144
  }
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);
145
+ let bundleNode = graph.addNodeByContentKeyIfNeeded(candidateA.contentKey, candidateA.id);
146
+ let otherBundleNode = graph.addNodeByContentKeyIfNeeded(candidateB.contentKey, candidateB.id);
81
147
 
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
- }
148
+ // Add edge in both directions
149
+ graph.addEdge(bundleNode, otherBundleNode, edgeType);
150
+ graph.addEdge(otherBundleNode, bundleNode, edgeType);
151
+ candidates.set(bundleNode, edgeType);
152
+ candidates.set(otherBundleNode, edgeType);
88
153
  }
154
+
155
+ // Remove bundles that have been allocated to a higher priority merge
156
+ allPossibleMergeCandidates = allPossibleMergeCandidates.filter(group => !graph.hasContentKey(group[0].contentKey) && !graph.hasContentKey(group[1].contentKey));
89
157
  }
158
+ (0, _memoize.clearCaches)();
90
159
  return getMergeClusters(graph, candidates);
91
160
  }
@@ -11,6 +11,13 @@ function _diagnostic() {
11
11
  };
12
12
  return data;
13
13
  }
14
+ function _featureFlags() {
15
+ const data = require("@atlaspack/feature-flags");
16
+ _featureFlags = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
14
21
  function _utils() {
15
22
  const data = require("@atlaspack/utils");
16
23
  _utils = function () {
@@ -32,14 +39,13 @@ function resolveModeConfig(config, mode) {
32
39
  for (const key of Object.keys(config)) {
33
40
  if (key === 'development' || key === 'production') {
34
41
  if (key === mode) {
42
+ // @ts-expect-error TS2322
35
43
  modeConfig = config[key];
36
44
  }
37
45
  } else {
38
46
  generalConfig[key] = config[key];
39
47
  }
40
48
  }
41
-
42
- // $FlowFixMe Not sure how to convince flow here...
43
49
  return {
44
50
  ...generalConfig,
45
51
  ...modeConfig
@@ -54,7 +60,7 @@ const HTTP_OPTIONS = {
54
60
  minBundleSize: 30000,
55
61
  maxParallelRequests: 6,
56
62
  disableSharedBundles: false,
57
- sharedBundleMergeThreshold: 1
63
+ sharedBundleMerge: []
58
64
  },
59
65
  '2': {
60
66
  minBundles: 1,
@@ -62,7 +68,7 @@ const HTTP_OPTIONS = {
62
68
  minBundleSize: 20000,
63
69
  maxParallelRequests: 25,
64
70
  disableSharedBundles: false,
65
- sharedBundleMergeThreshold: 1
71
+ sharedBundleMerge: []
66
72
  }
67
73
  };
68
74
  const CONFIG_SCHEMA = {
@@ -103,6 +109,30 @@ const CONFIG_SCHEMA = {
103
109
  additionalProperties: false
104
110
  }
105
111
  },
112
+ sharedBundleMerge: {
113
+ type: 'array',
114
+ items: {
115
+ type: 'object',
116
+ properties: {
117
+ overlapThreshold: {
118
+ type: 'number'
119
+ },
120
+ maxBundleSize: {
121
+ type: 'number'
122
+ },
123
+ sourceBundles: {
124
+ type: 'array',
125
+ items: {
126
+ type: 'string'
127
+ }
128
+ },
129
+ minBundlesInGroup: {
130
+ type: 'number'
131
+ }
132
+ },
133
+ additionalProperties: false
134
+ }
135
+ },
106
136
  minBundles: {
107
137
  type: 'number'
108
138
  },
@@ -125,17 +155,26 @@ const CONFIG_SCHEMA = {
125
155
  additionalProperties: false
126
156
  };
127
157
  async function loadBundlerConfig(config, options, logger) {
128
- let conf = await config.getConfig([], {
129
- packageKey: '@atlaspack/bundler-default'
130
- });
158
+ var _conf;
159
+ let conf;
160
+ if ((0, _featureFlags().getFeatureFlag)('resolveBundlerConfigFromCwd')) {
161
+ conf = await config.getConfigFrom(`${process.cwd()}/index`, [], {
162
+ packageKey: '@atlaspack/bundler-default'
163
+ });
164
+ } else {
165
+ conf = await config.getConfig([], {
166
+ packageKey: '@atlaspack/bundler-default'
167
+ });
168
+ }
131
169
  if (!conf) {
132
170
  const modDefault = {
133
171
  ...HTTP_OPTIONS['2'],
134
172
  projectRoot: options.projectRoot
135
173
  };
174
+ // @ts-expect-error TS2322
136
175
  return modDefault;
137
176
  }
138
- (0, _assert().default)((conf === null || conf === void 0 ? void 0 : conf.contents) != null);
177
+ (0, _assert().default)(((_conf = conf) === null || _conf === void 0 ? void 0 : _conf.contents) != null);
139
178
  let modeConfig = resolveModeConfig(conf.contents, options.mode);
140
179
 
141
180
  // minBundles will be ignored if shared bundles are disabled
@@ -173,11 +212,12 @@ async function loadBundlerConfig(config, options, logger) {
173
212
  prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/bundler-default')}`
174
213
  }, '@atlaspack/bundler-default', 'Invalid config for @atlaspack/bundler-default');
175
214
  let http = modeConfig.http ?? 2;
215
+ // @ts-expect-error TS7053
176
216
  let defaults = HTTP_OPTIONS[http];
177
217
  return {
178
218
  minBundles: modeConfig.minBundles ?? defaults.minBundles,
179
219
  minBundleSize: modeConfig.minBundleSize ?? defaults.minBundleSize,
180
- sharedBundleMergeThreshold: modeConfig.sharedBundleMergeThreshold ?? defaults.sharedBundleMergeThreshold,
220
+ sharedBundleMerge: modeConfig.sharedBundleMerge ?? defaults.sharedBundleMerge,
181
221
  maxParallelRequests: modeConfig.maxParallelRequests ?? defaults.maxParallelRequests,
182
222
  projectRoot: options.projectRoot,
183
223
  disableSharedBundles: modeConfig.disableSharedBundles ?? defaults.disableSharedBundles,