@atlaspack/bundler-default 3.1.3-typescript-5b4d3ad41.0 → 3.2.0
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 +25 -0
- package/lib/DefaultBundler.js +4 -7
- package/lib/bundleMerge.js +3 -4
- package/lib/bundlerConfig.js +2 -3
- package/lib/decorateLegacyGraph.js +20 -7
- package/lib/idealGraph.js +150 -43
- package/lib/memoize.js +2 -1
- package/package.json +13 -18
- package/src/{DefaultBundler.ts → DefaultBundler.js} +7 -21
- package/src/{MonolithicBundler.ts → MonolithicBundler.js} +1 -0
- package/src/{bundleMerge.ts → bundleMerge.js} +19 -16
- package/src/{bundlerConfig.ts → bundlerConfig.js} +44 -43
- package/src/{decorateLegacyGraph.ts → decorateLegacyGraph.js} +24 -7
- package/src/{idealGraph.ts → idealGraph.js} +302 -136
- package/src/{memoize.ts → memoize.js} +6 -3
- package/LICENSE +0 -201
- package/lib/DefaultBundler.d.ts +0 -18
- package/lib/MonolithicBundler.d.ts +0 -2
- package/lib/bundleMerge.d.ts +0 -9
- package/lib/bundlerConfig.d.ts +0 -27
- package/lib/decorateLegacyGraph.d.ts +0 -3
- package/lib/idealGraph.d.ts +0 -39
- package/lib/memoize.d.ts +0 -2
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
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
|
+
|
|
3
28
|
## 3.1.2
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/lib/DefaultBundler.js
CHANGED
|
@@ -59,7 +59,6 @@ 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
|
|
63
62
|
let graphs = [];
|
|
64
63
|
for (let entries of targetMap.values()) {
|
|
65
64
|
let singleFileEntries = new Map();
|
|
@@ -76,7 +75,9 @@ var _default = exports.default = new (_plugin().Bundler)({
|
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
// Create separate bundleGraphs per distDir
|
|
79
|
-
graphs.push(
|
|
78
|
+
graphs.push(
|
|
79
|
+
// $FlowFixMe
|
|
80
|
+
(0, _idealGraph.createIdealGraph)(bundleGraph, config, idealGraphEntries, logger));
|
|
80
81
|
|
|
81
82
|
// Do this after the ideal graph so that the mutation of the bundleGraph doesn't
|
|
82
83
|
// interfere with the main bundling algorithm
|
|
@@ -95,11 +96,7 @@ function getEntryByTarget(bundleGraph) {
|
|
|
95
96
|
// Find entries from assetGraph per target
|
|
96
97
|
let targets = new (_utils().DefaultMap)(() => new Map());
|
|
97
98
|
bundleGraph.traverse({
|
|
98
|
-
enter(
|
|
99
|
-
// @ts-expect-error TS2304
|
|
100
|
-
node, context,
|
|
101
|
-
// @ts-expect-error TS2304
|
|
102
|
-
actions) {
|
|
99
|
+
enter(node, context, actions) {
|
|
103
100
|
if (node.type !== 'asset') {
|
|
104
101
|
return node;
|
|
105
102
|
}
|
package/lib/bundleMerge.js
CHANGED
|
@@ -38,7 +38,6 @@ function getBundlesForBundleGroup(bundleGraph, bundleGroupId) {
|
|
|
38
38
|
let count = 0;
|
|
39
39
|
bundleGraph.traverse(nodeId => {
|
|
40
40
|
var _bundleGraph$getNode;
|
|
41
|
-
// @ts-expect-error TS2339
|
|
42
41
|
if (((_bundleGraph$getNode = bundleGraph.getNode(nodeId)) === null || _bundleGraph$getNode === void 0 ? void 0 : _bundleGraph$getNode.bundleBehavior) !== 'inline') {
|
|
43
42
|
count++;
|
|
44
43
|
}
|
|
@@ -119,9 +118,9 @@ function getPossibleMergeCandidates(bundleGraph, bundles) {
|
|
|
119
118
|
for (let j = i + 1; j < mergeCandidates.length; j++) {
|
|
120
119
|
let a = mergeCandidates[i];
|
|
121
120
|
let b = mergeCandidates[j];
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
121
|
+
if (
|
|
122
|
+
// $FlowFixMe both bundles will always have internalizedAssets
|
|
123
|
+
a.bundle.internalizedAssets.equals(b.bundle.internalizedAssets)) {
|
|
125
124
|
uniquePairs.push([a, b]);
|
|
126
125
|
}
|
|
127
126
|
}
|
package/lib/bundlerConfig.js
CHANGED
|
@@ -39,13 +39,14 @@ function resolveModeConfig(config, mode) {
|
|
|
39
39
|
for (const key of Object.keys(config)) {
|
|
40
40
|
if (key === 'development' || key === 'production') {
|
|
41
41
|
if (key === mode) {
|
|
42
|
-
// @ts-expect-error TS2322
|
|
43
42
|
modeConfig = config[key];
|
|
44
43
|
}
|
|
45
44
|
} else {
|
|
46
45
|
generalConfig[key] = config[key];
|
|
47
46
|
}
|
|
48
47
|
}
|
|
48
|
+
|
|
49
|
+
// $FlowFixMe Not sure how to convince flow here...
|
|
49
50
|
return {
|
|
50
51
|
...generalConfig,
|
|
51
52
|
...modeConfig
|
|
@@ -171,7 +172,6 @@ async function loadBundlerConfig(config, options, logger) {
|
|
|
171
172
|
...HTTP_OPTIONS['2'],
|
|
172
173
|
projectRoot: options.projectRoot
|
|
173
174
|
};
|
|
174
|
-
// @ts-expect-error TS2322
|
|
175
175
|
return modDefault;
|
|
176
176
|
}
|
|
177
177
|
(0, _assert().default)(((_conf = conf) === null || _conf === void 0 ? void 0 : _conf.contents) != null);
|
|
@@ -212,7 +212,6 @@ async function loadBundlerConfig(config, options, logger) {
|
|
|
212
212
|
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/bundler-default')}`
|
|
213
213
|
}, '@atlaspack/bundler-default', 'Invalid config for @atlaspack/bundler-default');
|
|
214
214
|
let http = modeConfig.http ?? 2;
|
|
215
|
-
// @ts-expect-error TS7053
|
|
216
215
|
let defaults = HTTP_OPTIONS[http];
|
|
217
216
|
return {
|
|
218
217
|
minBundles: modeConfig.minBundles ?? defaults.minBundles,
|
|
@@ -42,11 +42,13 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
42
42
|
bundleGroupBundleIds,
|
|
43
43
|
manualAssetToBundle
|
|
44
44
|
} = idealGraph;
|
|
45
|
+
// This line can be deleted once supportWebpackChunkName feature flag is removed.
|
|
45
46
|
let entryBundleToBundleGroup = new Map();
|
|
46
47
|
// Step Create Bundles: Create bundle groups, bundles, and shared bundles and add assets to them
|
|
47
48
|
for (let [bundleNodeId, idealBundle] of idealBundleGraph.nodes.entries()) {
|
|
48
49
|
if (!idealBundle || idealBundle === 'root') continue;
|
|
49
50
|
let entryAsset = idealBundle.mainEntryAsset;
|
|
51
|
+
// This line can be deleted once supportWebpackChunkName feature flag is removed.
|
|
50
52
|
let bundleGroup;
|
|
51
53
|
let bundle;
|
|
52
54
|
if (bundleGroupBundleIds.has(bundleNodeId)) {
|
|
@@ -57,19 +59,33 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
57
59
|
return dependency.value;
|
|
58
60
|
});
|
|
59
61
|
(0, _assert().default)(entryAsset != null, 'Processing a bundleGroup with no entry asset');
|
|
62
|
+
let bundleGroups = new Map();
|
|
60
63
|
for (let dependency of dependencies) {
|
|
61
64
|
bundleGroup = bundleGraph.createBundleGroup(dependency, idealBundle.target);
|
|
65
|
+
bundleGroups.set(bundleGroup.entryAssetId, bundleGroup);
|
|
66
|
+
}
|
|
67
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
68
|
+
(0, _assert().default)(bundleGroups.size > 0, 'No bundle groups created');
|
|
69
|
+
} else {
|
|
70
|
+
(0, _assert().default)(bundleGroup);
|
|
71
|
+
entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
|
|
62
72
|
}
|
|
63
|
-
(0, _assert().default)(bundleGroup);
|
|
64
|
-
entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
|
|
65
73
|
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
66
74
|
entryAsset: (0, _nullthrows().default)(entryAsset),
|
|
75
|
+
bundleRoots: Array.from(idealBundle.bundleRoots),
|
|
67
76
|
needsStableName: idealBundle.needsStableName,
|
|
68
77
|
bundleBehavior: idealBundle.bundleBehavior,
|
|
69
78
|
target: idealBundle.target,
|
|
70
79
|
manualSharedBundle: idealBundle.manualSharedBundle
|
|
71
80
|
}));
|
|
72
|
-
|
|
81
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
82
|
+
for (let bundleGroup of bundleGroups.values()) {
|
|
83
|
+
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
(0, _assert().default)(bundleGroup);
|
|
87
|
+
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
|
|
88
|
+
}
|
|
73
89
|
} else if (idealBundle.sourceBundles.size > 0 && !idealBundle.mainEntryAsset) {
|
|
74
90
|
let uniqueKey = idealBundle.uniqueKey != null ? idealBundle.uniqueKey : [...idealBundle.assets].map(asset => asset.id).join(',');
|
|
75
91
|
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
@@ -95,6 +111,7 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
95
111
|
(0, _assert().default)(entryAsset != null);
|
|
96
112
|
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
97
113
|
entryAsset,
|
|
114
|
+
bundleRoots: Array.from(idealBundle.bundleRoots),
|
|
98
115
|
needsStableName: idealBundle.needsStableName,
|
|
99
116
|
bundleBehavior: idealBundle.bundleBehavior,
|
|
100
117
|
target: idealBundle.target,
|
|
@@ -162,8 +179,6 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
162
179
|
bundleGraph.createAssetReference(dependency, asset, legacyBundle);
|
|
163
180
|
}
|
|
164
181
|
}
|
|
165
|
-
|
|
166
|
-
// @ts-expect-error TS2488
|
|
167
182
|
for (let {
|
|
168
183
|
type,
|
|
169
184
|
from,
|
|
@@ -173,14 +188,12 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
173
188
|
if (sourceBundle === 'root') {
|
|
174
189
|
continue;
|
|
175
190
|
}
|
|
176
|
-
// @ts-expect-error TS2367
|
|
177
191
|
(0, _assert().default)(sourceBundle !== 'root');
|
|
178
192
|
let legacySourceBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(sourceBundle));
|
|
179
193
|
let targetBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(to));
|
|
180
194
|
if (targetBundle === 'root') {
|
|
181
195
|
continue;
|
|
182
196
|
}
|
|
183
|
-
// @ts-expect-error TS2367
|
|
184
197
|
(0, _assert().default)(targetBundle !== 'root');
|
|
185
198
|
let legacyTargetBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(targetBundle));
|
|
186
199
|
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && type === _idealGraph.idealBundleGraphEdges.conditional) {
|
package/lib/idealGraph.js
CHANGED
|
@@ -50,7 +50,6 @@ function _nullthrows() {
|
|
|
50
50
|
var _bundleMerge = require("./bundleMerge");
|
|
51
51
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
52
52
|
/* BundleRoot - An asset that is the main entry of a Bundle. */
|
|
53
|
-
|
|
54
53
|
const dependencyPriorityEdges = {
|
|
55
54
|
sync: 1,
|
|
56
55
|
parallel: 2,
|
|
@@ -66,6 +65,11 @@ const idealBundleGraphEdges = exports.idealBundleGraphEdges = Object.freeze({
|
|
|
66
65
|
// which mutates the assetGraph into the bundleGraph we would
|
|
67
66
|
// expect from default bundler
|
|
68
67
|
|
|
68
|
+
function isNonRootBundle(bundle, message) {
|
|
69
|
+
let existingBundle = (0, _nullthrows().default)(bundle, message);
|
|
70
|
+
(0, _assert().default)(existingBundle !== 'root', "Bundle cannot be 'root'");
|
|
71
|
+
return existingBundle;
|
|
72
|
+
}
|
|
69
73
|
function createIdealGraph(assetGraph, config, entries, logger) {
|
|
70
74
|
var _config$sharedBundleM;
|
|
71
75
|
// Asset to the bundle and group it's an entry of
|
|
@@ -122,7 +126,6 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
122
126
|
let parentsToConfig = new (_utils().DefaultMap)(() => []);
|
|
123
127
|
for (let c of config.manualSharedBundles) {
|
|
124
128
|
if (c.root != null) {
|
|
125
|
-
// @ts-expect-error TS2345
|
|
126
129
|
parentsToConfig.get(_path().default.join(config.projectRoot, c.root)).push(c);
|
|
127
130
|
}
|
|
128
131
|
}
|
|
@@ -159,7 +162,6 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
159
162
|
// We track all matching MSB's for constant modules as they are never duplicated
|
|
160
163
|
// and need to be assigned to all matching bundles
|
|
161
164
|
if (node.value.meta.isConstantModule === true) {
|
|
162
|
-
// @ts-expect-error TS2345
|
|
163
165
|
constantModuleToMSB.get(node.value).push(c);
|
|
164
166
|
}
|
|
165
167
|
if (assetRegexes.some(regex => regex.test(projectRelativePath))) {
|
|
@@ -200,9 +202,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
200
202
|
* adding only that asset to each bundle, not its entire subgraph.
|
|
201
203
|
*/
|
|
202
204
|
assetGraph.traverse({
|
|
203
|
-
enter(node, context,
|
|
204
|
-
// @ts-expect-error TS2304
|
|
205
|
-
actions) {
|
|
205
|
+
enter(node, context, actions) {
|
|
206
206
|
if (node.type === 'asset') {
|
|
207
207
|
if ((context === null || context === void 0 ? void 0 : context.type) === 'dependency' && context !== null && context !== void 0 && context.value.isEntry && !entries.has(node.value)) {
|
|
208
208
|
// Skip whole subtrees of other targets by skipping those entries
|
|
@@ -287,9 +287,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
287
287
|
}), dependencyBundleGraph.addNodeByContentKeyIfNeeded(String(bundleId), {
|
|
288
288
|
value: bundle,
|
|
289
289
|
type: 'bundle'
|
|
290
|
-
}),
|
|
291
|
-
// @ts-expect-error TS7053
|
|
292
|
-
dependencyPriorityEdges[dependency.priority]);
|
|
290
|
+
}), dependencyPriorityEdges[dependency.priority]);
|
|
293
291
|
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && dependency.priority === 'conditional') {
|
|
294
292
|
let [referencingBundleRoot, bundleGroupNodeId] = (0, _nullthrows().default)(stack[stack.length - 1]);
|
|
295
293
|
let referencingBundleId = (0, _nullthrows().default)(bundleRoots.get(referencingBundleRoot))[0];
|
|
@@ -349,16 +347,13 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
349
347
|
}
|
|
350
348
|
assetReference.get(childAsset).push([dependency, bundle]);
|
|
351
349
|
} else {
|
|
352
|
-
// @ts-expect-error TS2322
|
|
353
350
|
bundleId = null;
|
|
354
351
|
}
|
|
355
352
|
if (manualSharedObject && bundleId != null) {
|
|
356
353
|
// MSB Step 5: At this point we've either created or found an existing MSB bundle
|
|
357
354
|
// add the asset if it doesn't already have it and set key
|
|
358
355
|
|
|
359
|
-
(0, _assert().default)(
|
|
360
|
-
// @ts-expect-error TS2367
|
|
361
|
-
bundle !== 'root' && bundle != null && bundleId != null);
|
|
356
|
+
(0, _assert().default)(bundle !== 'root' && bundle != null && bundleId != null);
|
|
362
357
|
manualAssetToBundle.set(childAsset, bundleId);
|
|
363
358
|
if (!bundle.assets.has(childAsset)) {
|
|
364
359
|
// Add asset to bundle
|
|
@@ -379,7 +374,6 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
379
374
|
}
|
|
380
375
|
return node;
|
|
381
376
|
},
|
|
382
|
-
// @ts-expect-error TS2322
|
|
383
377
|
exit(node) {
|
|
384
378
|
var _stack;
|
|
385
379
|
if (((_stack = stack[stack.length - 1]) === null || _stack === void 0 ? void 0 : _stack[0]) === node.value) {
|
|
@@ -608,11 +602,8 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
608
602
|
}
|
|
609
603
|
function assignInlineConstants(parentAsset, bundle) {
|
|
610
604
|
for (let inlineConstant of inlineConstantDeps.get(parentAsset)) {
|
|
611
|
-
// @ts-expect-error TS2345
|
|
612
605
|
if (!bundle.assets.has(inlineConstant)) {
|
|
613
|
-
// @ts-expect-error TS2345
|
|
614
606
|
bundle.assets.add(inlineConstant);
|
|
615
|
-
// @ts-expect-error TS18046
|
|
616
607
|
bundle.size += inlineConstant.stats.size;
|
|
617
608
|
}
|
|
618
609
|
}
|
|
@@ -810,6 +801,8 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
810
801
|
}
|
|
811
802
|
}
|
|
812
803
|
let manualSharedBundleIds = new Set([...manualSharedMap.values()]);
|
|
804
|
+
let modifiedSourceBundles = new Set();
|
|
805
|
+
|
|
813
806
|
// Step split manual shared bundles for those that have the "split" property set
|
|
814
807
|
let remainderMap = new (_utils().DefaultMap)(() => []);
|
|
815
808
|
for (let id of manualSharedMap.values()) {
|
|
@@ -826,9 +819,8 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
826
819
|
if (modNum != null) {
|
|
827
820
|
for (let a of [...manualBundle.assets]) {
|
|
828
821
|
let numRep = getBigIntFromContentKey(a.id);
|
|
822
|
+
// $FlowFixMe Flow doesn't know about BigInt
|
|
829
823
|
let r = Number(numRep % BigInt(modNum));
|
|
830
|
-
|
|
831
|
-
// @ts-expect-error TS2345
|
|
832
824
|
remainderMap.get(r).push(a);
|
|
833
825
|
}
|
|
834
826
|
for (let i = 1; i < [...remainderMap.keys()].length; i++) {
|
|
@@ -850,10 +842,8 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
850
842
|
}
|
|
851
843
|
for (let sp of remainderMap.get(i)) {
|
|
852
844
|
bundle.assets.add(sp);
|
|
853
|
-
// @ts-expect-error TS2339
|
|
854
845
|
bundle.size += sp.stats.size;
|
|
855
846
|
manualBundle.assets.delete(sp);
|
|
856
|
-
// @ts-expect-error TS2339
|
|
857
847
|
manualBundle.size -= sp.stats.size;
|
|
858
848
|
}
|
|
859
849
|
}
|
|
@@ -866,21 +856,66 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
866
856
|
// match multiple MSB's
|
|
867
857
|
for (let [asset, msbs] of constantModuleToMSB.entries()) {
|
|
868
858
|
for (let manualSharedObject of msbs) {
|
|
869
|
-
// @ts-expect-error TS2339
|
|
870
859
|
let bundleId = manualSharedMap.get(manualSharedObject.name + ',js');
|
|
871
860
|
if (bundleId == null) continue;
|
|
872
861
|
let bundle = (0, _nullthrows().default)(bundleGraph.getNode(bundleId));
|
|
873
862
|
(0, _assert().default)(bundle != null && bundle !== 'root', 'We tried to use the root incorrectly');
|
|
874
|
-
|
|
875
|
-
// @ts-expect-error TS2345
|
|
876
863
|
if (!bundle.assets.has(asset)) {
|
|
877
|
-
// @ts-expect-error TS2345
|
|
878
864
|
bundle.assets.add(asset);
|
|
879
|
-
// @ts-expect-error TS18046
|
|
880
865
|
bundle.size += asset.stats.size;
|
|
881
866
|
}
|
|
882
867
|
}
|
|
883
868
|
}
|
|
869
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
870
|
+
// Merge webpack chunk name bundles
|
|
871
|
+
let chunkNameBundles = new (_utils().DefaultMap)(() => new Set());
|
|
872
|
+
for (let [nodeId, node] of dependencyBundleGraph.nodes.entries()) {
|
|
873
|
+
var _bundleNode$value$mai;
|
|
874
|
+
// meta.chunkName is set by the Rust transformer, so we just need to find
|
|
875
|
+
// bundles that have a chunkName set.
|
|
876
|
+
if (!node || node.type !== 'dependency' || node.value.meta.chunkName == null) {
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
let connectedBundles = dependencyBundleGraph.getNodeIdsConnectedFrom(nodeId, dependencyPriorityEdges[node.value.priority]);
|
|
880
|
+
if (connectedBundles.length === 0) {
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
(0, _assert().default)(connectedBundles.length === 1, 'Expected webpackChunkName dependency to be connected to no more than one bundle');
|
|
884
|
+
let bundleId = connectedBundles[0];
|
|
885
|
+
let bundleNode = dependencyBundleGraph.getNode(bundleId);
|
|
886
|
+
(0, _assert().default)(bundleNode != null && bundleNode.type === 'bundle');
|
|
887
|
+
|
|
888
|
+
// If a bundle does not have a main entry asset, it's somehow just a
|
|
889
|
+
// shared bundle, and will be merged/deleted by other means.
|
|
890
|
+
if (bundleNode.value.mainEntryAsset == null) {
|
|
891
|
+
continue;
|
|
892
|
+
}
|
|
893
|
+
let bundleNodeId = null;
|
|
894
|
+
let mainEntryAssetId = (_bundleNode$value$mai = bundleNode.value.mainEntryAsset) === null || _bundleNode$value$mai === void 0 ? void 0 : _bundleNode$value$mai.id;
|
|
895
|
+
if (mainEntryAssetId != null) {
|
|
896
|
+
bundleNodeId = bundles.get(mainEntryAssetId);
|
|
897
|
+
}
|
|
898
|
+
if (bundleNodeId == null) {
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
chunkNameBundles.get(node.value.meta.chunkName)
|
|
902
|
+
// DependencyBundleGraph uses content keys as node ids, so we can use that
|
|
903
|
+
// to get the bundle id.
|
|
904
|
+
.add(bundleNodeId);
|
|
905
|
+
}
|
|
906
|
+
for (let [chunkName, bundleIds] of chunkNameBundles.entries()) {
|
|
907
|
+
// The `[request]` placeholder is not yet supported
|
|
908
|
+
if (bundleIds.size <= 1 || typeof chunkName === 'string' && chunkName.includes('[request]')) {
|
|
909
|
+
continue; // Nothing to merge
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// Merge all bundles with the same chunk name into the first one.
|
|
913
|
+
let [firstBundleId, ...rest] = Array.from(bundleIds);
|
|
914
|
+
for (let bundleId of rest) {
|
|
915
|
+
mergeBundles(firstBundleId, bundleId);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
884
919
|
|
|
885
920
|
// Step merge shared bundles that meet the overlap threshold
|
|
886
921
|
// This step is skipped by default as the threshold defaults to 1
|
|
@@ -899,7 +934,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
899
934
|
}
|
|
900
935
|
|
|
901
936
|
// Step Remove Shared Bundles: Remove shared bundles from bundle groups that hit the parallel request limit.
|
|
902
|
-
|
|
937
|
+
|
|
903
938
|
if (config.disableSharedBundles === false) {
|
|
904
939
|
for (let bundleGroupId of bundleGraph.getNodeIdsConnectedFrom(rootNodeId)) {
|
|
905
940
|
// Find shared bundles in this bundle group.
|
|
@@ -912,7 +947,6 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
912
947
|
let numBundlesContributingToPRL = bundleIdsInGroup.reduce((count, b) => {
|
|
913
948
|
let bundle = (0, _nullthrows().default)(bundleGraph.getNode(b));
|
|
914
949
|
(0, _assert().default)(bundle !== 'root');
|
|
915
|
-
// @ts-expect-error TS2365
|
|
916
950
|
return count + (bundle.bundleBehavior !== 'inline');
|
|
917
951
|
}, 0);
|
|
918
952
|
if (numBundlesContributingToPRL > config.maxParallelRequests) {
|
|
@@ -942,9 +976,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
942
976
|
// Remove bundles until the bundle group is within the parallel request limit.
|
|
943
977
|
while (sharedBundlesInGroup.length > 0 && numBundlesContributingToPRL > config.maxParallelRequests) {
|
|
944
978
|
let bundleTuple = sharedBundlesInGroup.pop();
|
|
945
|
-
// @ts-expect-error TS18048
|
|
946
979
|
let bundleToRemove = bundleTuple.bundle;
|
|
947
|
-
// @ts-expect-error TS18048
|
|
948
980
|
let bundleIdToRemove = bundleTuple.id;
|
|
949
981
|
//TODO add integration test where bundles in bunlde group > max parallel request limit & only remove a couple shared bundles
|
|
950
982
|
// but total # bundles still exceeds limit due to non shared bundles
|
|
@@ -987,22 +1019,32 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
987
1019
|
}
|
|
988
1020
|
}
|
|
989
1021
|
}
|
|
990
|
-
function mergeBundles(
|
|
991
|
-
let bundleToKeep = (
|
|
992
|
-
let bundleToRemove = (
|
|
993
|
-
|
|
1022
|
+
function mergeBundles(bundleToKeepId, bundleToRemoveId) {
|
|
1023
|
+
let bundleToKeep = isNonRootBundle(bundleGraph.getNode(bundleToKeepId), `Bundle ${bundleToKeepId} not found`);
|
|
1024
|
+
let bundleToRemove = isNonRootBundle(bundleGraph.getNode(bundleToRemoveId), `Bundle ${bundleToRemoveId} not found`);
|
|
1025
|
+
modifiedSourceBundles.add(bundleToKeep);
|
|
994
1026
|
for (let asset of bundleToRemove.assets) {
|
|
995
1027
|
bundleToKeep.assets.add(asset);
|
|
996
1028
|
bundleToKeep.size += asset.stats.size;
|
|
997
1029
|
let newAssetReference = assetReference.get(asset).map(([dep, bundle]) => bundle === bundleToRemove ? [dep, bundleToKeep] : [dep, bundle]);
|
|
998
|
-
|
|
999
|
-
// @ts-expect-error TS2345
|
|
1000
1030
|
assetReference.set(asset, newAssetReference);
|
|
1001
1031
|
}
|
|
1002
1032
|
|
|
1003
1033
|
// Merge any internalized assets
|
|
1004
|
-
(0,
|
|
1005
|
-
|
|
1034
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
1035
|
+
if (bundleToKeep.internalizedAssets != null) {
|
|
1036
|
+
if (bundleToRemove.internalizedAssets != null) {
|
|
1037
|
+
bundleToKeep.internalizedAssets.intersect(bundleToRemove.internalizedAssets);
|
|
1038
|
+
} else {
|
|
1039
|
+
bundleToKeep.internalizedAssets.clear();
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
} else {
|
|
1043
|
+
(0, _assert().default)(bundleToKeep.internalizedAssets && bundleToRemove.internalizedAssets, 'All shared bundles should have internalized assets');
|
|
1044
|
+
bundleToKeep.internalizedAssets.union(bundleToRemove.internalizedAssets);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// Merge and clean up source bundles
|
|
1006
1048
|
for (let sourceBundleId of bundleToRemove.sourceBundles) {
|
|
1007
1049
|
if (bundleToKeep.sourceBundles.has(sourceBundleId)) {
|
|
1008
1050
|
continue;
|
|
@@ -1010,6 +1052,66 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
1010
1052
|
bundleToKeep.sourceBundles.add(sourceBundleId);
|
|
1011
1053
|
bundleGraph.addEdge(sourceBundleId, bundleToKeepId);
|
|
1012
1054
|
}
|
|
1055
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
1056
|
+
bundleToKeep.sourceBundles.delete(bundleToRemoveId);
|
|
1057
|
+
for (let bundle of bundleGraph.getNodeIdsConnectedFrom(bundleToRemoveId)) {
|
|
1058
|
+
let bundleNode = (0, _nullthrows().default)(bundleGraph.getNode(bundle));
|
|
1059
|
+
if (bundleNode === 'root') {
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// If the bundle is a source bundle, add it to the bundle to keep
|
|
1064
|
+
if (bundleNode.sourceBundles.has(bundleToRemoveId)) {
|
|
1065
|
+
bundleNode.sourceBundles.add(bundleToKeepId);
|
|
1066
|
+
bundleNode.sourceBundles.delete(bundleToRemoveId);
|
|
1067
|
+
bundleGraph.addEdge(bundleToKeepId, bundle);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// Merge bundle roots
|
|
1072
|
+
for (let bundleRoot of bundleToRemove.bundleRoots) {
|
|
1073
|
+
bundleToKeep.bundleRoots.add(bundleRoot);
|
|
1074
|
+
}
|
|
1075
|
+
if (bundleToRemove.mainEntryAsset != null) {
|
|
1076
|
+
(0, _assert().default)(bundleToKeep.mainEntryAsset != null);
|
|
1077
|
+
|
|
1078
|
+
// Merge the bundles in bundle group
|
|
1079
|
+
let bundlesInRemoveBundleGroup = getBundlesForBundleGroup(bundleToRemoveId);
|
|
1080
|
+
for (let bundleIdInGroup of bundlesInRemoveBundleGroup) {
|
|
1081
|
+
if (bundleIdInGroup === bundleToRemoveId) {
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
bundleGraph.addEdge(bundleToKeepId, bundleIdInGroup);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// Remove old bundle group
|
|
1088
|
+
bundleGroupBundleIds.delete(bundleToRemoveId);
|
|
1089
|
+
|
|
1090
|
+
// Clean up bundle roots
|
|
1091
|
+
let bundleRootToRemoveNodeId = (0, _nullthrows().default)(assetToBundleRootNodeId.get((0, _nullthrows().default)(bundleToRemove.mainEntryAsset)));
|
|
1092
|
+
let bundleRootToKeepNodeId = (0, _nullthrows().default)(assetToBundleRootNodeId.get((0, _nullthrows().default)(bundleToKeep.mainEntryAsset)));
|
|
1093
|
+
for (let nodeId of bundleRootGraph.getNodeIdsConnectedTo(bundleRootToRemoveNodeId)) {
|
|
1094
|
+
bundleRootGraph.addEdge(nodeId, bundleRootToKeepNodeId);
|
|
1095
|
+
bundleRootGraph.removeEdge(nodeId, bundleRootToRemoveNodeId);
|
|
1096
|
+
}
|
|
1097
|
+
for (let nodeId of bundleRootGraph.getNodeIdsConnectedFrom(bundleRootToRemoveNodeId)) {
|
|
1098
|
+
bundleRootGraph.addEdge(bundleRootToKeepNodeId, nodeId);
|
|
1099
|
+
bundleRootGraph.removeEdge(bundleRootToRemoveNodeId, nodeId);
|
|
1100
|
+
}
|
|
1101
|
+
bundleRoots.set((0, _nullthrows().default)(bundleToRemove.mainEntryAsset), [bundleToKeepId, bundleToKeepId]);
|
|
1102
|
+
|
|
1103
|
+
// Merge dependency bundle graph
|
|
1104
|
+
for (let dependencyNodeId of dependencyBundleGraph.getNodeIdsConnectedTo(dependencyBundleGraph.getNodeIdByContentKey(String(bundleToRemoveId)), _graph().ALL_EDGE_TYPES)) {
|
|
1105
|
+
let dependencyNode = (0, _nullthrows().default)(dependencyBundleGraph.getNode(dependencyNodeId));
|
|
1106
|
+
(0, _assert().default)(dependencyNode.type === 'dependency');
|
|
1107
|
+
|
|
1108
|
+
// Add dependency to the bundle to keep
|
|
1109
|
+
dependencyBundleGraph.addEdge(dependencyNodeId, dependencyBundleGraph.getNodeIdByContentKey(String(bundleToKeepId)), dependencyPriorityEdges[dependencyNode.value.priority]);
|
|
1110
|
+
// Remove dependency from the bundle to remove
|
|
1111
|
+
dependencyBundleGraph.removeEdge(dependencyNodeId, dependencyBundleGraph.getNodeIdByContentKey(String(bundleToRemoveId)), dependencyPriorityEdges[dependencyNode.value.priority]);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1013
1115
|
bundleGraph.removeNode(bundleToRemoveId);
|
|
1014
1116
|
}
|
|
1015
1117
|
function mergeOverlapBundles(mergeConfig) {
|
|
@@ -1044,26 +1146,29 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
1044
1146
|
})
|
|
1045
1147
|
};
|
|
1046
1148
|
}));
|
|
1149
|
+
let mergedBundles = new Set();
|
|
1047
1150
|
for (let cluster of clusters) {
|
|
1048
1151
|
let [mergeTarget, ...rest] = cluster;
|
|
1049
1152
|
for (let bundleIdToMerge of rest) {
|
|
1050
|
-
mergeBundles(
|
|
1153
|
+
mergeBundles(mergeTarget, bundleIdToMerge);
|
|
1051
1154
|
}
|
|
1155
|
+
mergedBundles.add(mergeTarget);
|
|
1156
|
+
}
|
|
1157
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
1158
|
+
return mergedBundles;
|
|
1052
1159
|
}
|
|
1053
1160
|
}
|
|
1054
1161
|
function getBigIntFromContentKey(contentKey) {
|
|
1055
1162
|
let b = Buffer.alloc(64);
|
|
1056
1163
|
b.write(contentKey);
|
|
1164
|
+
// $FlowFixMe Flow doesn't have BigInt types in this version
|
|
1057
1165
|
return b.readBigInt64BE();
|
|
1058
1166
|
}
|
|
1059
1167
|
// Fix asset order in source bundles as they are likely now incorrect after shared bundle deletion
|
|
1060
1168
|
if (modifiedSourceBundles.size > 0) {
|
|
1061
1169
|
let assetOrderMap = new Map(assets.map((a, index) => [a, index]));
|
|
1062
1170
|
for (let bundle of modifiedSourceBundles) {
|
|
1063
|
-
|
|
1064
|
-
bundle.assets = new Set(
|
|
1065
|
-
// @ts-expect-error TS18046
|
|
1066
|
-
[...bundle.assets].sort((a, b) => {
|
|
1171
|
+
bundle.assets = new Set([...bundle.assets].sort((a, b) => {
|
|
1067
1172
|
let aIndex = (0, _nullthrows().default)(assetOrderMap.get(a));
|
|
1068
1173
|
let bIndex = (0, _nullthrows().default)(assetOrderMap.get(b));
|
|
1069
1174
|
return aIndex - bIndex;
|
|
@@ -1151,6 +1256,7 @@ function createBundle(opts) {
|
|
|
1151
1256
|
bundleBehavior: opts.bundleBehavior,
|
|
1152
1257
|
env: (0, _nullthrows().default)(opts.env),
|
|
1153
1258
|
mainEntryAsset: null,
|
|
1259
|
+
bundleRoots: new Set(),
|
|
1154
1260
|
manualSharedBundle: opts.manualSharedBundle,
|
|
1155
1261
|
needsStableName: Boolean(opts.needsStableName),
|
|
1156
1262
|
size: 0,
|
|
@@ -1166,6 +1272,7 @@ function createBundle(opts) {
|
|
|
1166
1272
|
bundleBehavior: opts.bundleBehavior ?? asset.bundleBehavior,
|
|
1167
1273
|
env: opts.env ?? asset.env,
|
|
1168
1274
|
mainEntryAsset: asset,
|
|
1275
|
+
bundleRoots: new Set([asset]),
|
|
1169
1276
|
manualSharedBundle: opts.manualSharedBundle,
|
|
1170
1277
|
needsStableName: Boolean(opts.needsStableName),
|
|
1171
1278
|
size: asset.stats.size,
|
package/lib/memoize.js
CHANGED
|
@@ -13,6 +13,7 @@ function _manyKeysMap() {
|
|
|
13
13
|
return data;
|
|
14
14
|
}
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
// $FlowFixMe
|
|
16
17
|
let caches = [];
|
|
17
18
|
function clearCaches() {
|
|
18
19
|
for (let cache of caches) {
|
|
@@ -31,8 +32,8 @@ function memoize(fn) {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
// Calculate the result and cache it
|
|
34
|
-
// @ts-expect-error TS2683
|
|
35
35
|
const result = fn.apply(this, args);
|
|
36
|
+
// $FlowFixMe
|
|
36
37
|
cache.set(args, result);
|
|
37
38
|
return result;
|
|
38
39
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/bundler-default",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,24 +10,19 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "
|
|
14
|
-
"source": "
|
|
15
|
-
"types": "./lib/DefaultBundler.d.ts",
|
|
13
|
+
"main": "lib/DefaultBundler.js",
|
|
14
|
+
"source": "src/DefaultBundler.js",
|
|
16
15
|
"engines": {
|
|
17
16
|
"node": ">= 16.0.0"
|
|
18
17
|
},
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"@atlaspack/diagnostic": "2.14.
|
|
21
|
-
"@atlaspack/feature-flags": "2.
|
|
22
|
-
"@atlaspack/graph": "3.5.10
|
|
23
|
-
"@atlaspack/plugin": "2.14.21
|
|
24
|
-
"@atlaspack/rust": "3.4.
|
|
25
|
-
"@atlaspack/utils": "2.17.3
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
31
|
-
},
|
|
32
|
-
"gitHead": "5b4d3ad41ffa002b989ba77271bb3010a1f05b2a"
|
|
33
|
-
}
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1",
|
|
20
|
+
"@atlaspack/feature-flags": "2.20.0",
|
|
21
|
+
"@atlaspack/graph": "3.5.10",
|
|
22
|
+
"@atlaspack/plugin": "2.14.21",
|
|
23
|
+
"@atlaspack/rust": "3.4.1",
|
|
24
|
+
"@atlaspack/utils": "2.17.3",
|
|
25
|
+
"nullthrows": "^1.1.1",
|
|
26
|
+
"many-keys-map": "^1.0.3"
|
|
27
|
+
}
|
|
28
|
+
}
|