@atlaspack/bundler-default 2.14.5-canary.36 → 2.14.5-canary.360
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 +601 -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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decorateLegacyGraph = decorateLegacyGraph;
|
|
7
|
+
const graph_1 = require("@atlaspack/graph");
|
|
8
|
+
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
9
|
+
const assert_1 = __importDefault(require("assert"));
|
|
10
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
11
|
+
const idealGraph_1 = require("./idealGraph");
|
|
12
|
+
function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
13
|
+
let idealBundleToLegacyBundle = new Map();
|
|
14
|
+
let { bundleGraph: idealBundleGraph, dependencyBundleGraph, bundleGroupBundleIds, manualAssetToBundle, } = idealGraph;
|
|
15
|
+
// This line can be deleted once supportWebpackChunkName feature flag is removed.
|
|
16
|
+
let entryBundleToBundleGroup = new Map();
|
|
17
|
+
// Step Create Bundles: Create bundle groups, bundles, and shared bundles and add assets to them
|
|
18
|
+
for (let [bundleNodeId, idealBundle] of idealBundleGraph.nodes.entries()) {
|
|
19
|
+
if (!idealBundle || idealBundle === 'root')
|
|
20
|
+
continue;
|
|
21
|
+
let entryAsset = idealBundle.mainEntryAsset;
|
|
22
|
+
// This line can be deleted once supportWebpackChunkName feature flag is removed.
|
|
23
|
+
let bundleGroup;
|
|
24
|
+
let bundle;
|
|
25
|
+
if (bundleGroupBundleIds.has(bundleNodeId)) {
|
|
26
|
+
(0, assert_1.default)(idealBundle.manualSharedBundle == null, 'Processing a manualSharedBundle as a BundleGroup');
|
|
27
|
+
let dependencies = dependencyBundleGraph
|
|
28
|
+
.getNodeIdsConnectedTo(dependencyBundleGraph.getNodeIdByContentKey(String(bundleNodeId)), graph_1.ALL_EDGE_TYPES)
|
|
29
|
+
.map((nodeId) => {
|
|
30
|
+
let dependency = (0, nullthrows_1.default)(dependencyBundleGraph.getNode(nodeId));
|
|
31
|
+
(0, assert_1.default)(dependency.type === 'dependency');
|
|
32
|
+
return dependency.value;
|
|
33
|
+
});
|
|
34
|
+
(0, assert_1.default)(entryAsset != null, 'Processing a bundleGroup with no entry asset');
|
|
35
|
+
let bundleGroups = new Map();
|
|
36
|
+
for (let dependency of dependencies) {
|
|
37
|
+
bundleGroup = bundleGraph.createBundleGroup(dependency, idealBundle.target);
|
|
38
|
+
bundleGroups.set(bundleGroup.entryAssetId, bundleGroup);
|
|
39
|
+
}
|
|
40
|
+
if ((0, feature_flags_1.getFeatureFlag)('supportWebpackChunkName')) {
|
|
41
|
+
(0, assert_1.default)(bundleGroups.size > 0, 'No bundle groups created');
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
(0, assert_1.default)(bundleGroup);
|
|
45
|
+
entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
|
|
46
|
+
}
|
|
47
|
+
bundle = (0, nullthrows_1.default)(bundleGraph.createBundle({
|
|
48
|
+
entryAsset: (0, nullthrows_1.default)(entryAsset),
|
|
49
|
+
bundleRoots: Array.from(idealBundle.bundleRoots),
|
|
50
|
+
needsStableName: idealBundle.needsStableName,
|
|
51
|
+
bundleBehavior: idealBundle.bundleBehavior,
|
|
52
|
+
target: idealBundle.target,
|
|
53
|
+
manualSharedBundle: idealBundle.manualSharedBundle,
|
|
54
|
+
}));
|
|
55
|
+
if ((0, feature_flags_1.getFeatureFlag)('supportWebpackChunkName')) {
|
|
56
|
+
for (let bundleGroup of bundleGroups.values()) {
|
|
57
|
+
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
(0, assert_1.default)(bundleGroup);
|
|
62
|
+
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (idealBundle.sourceBundles.size > 0 &&
|
|
66
|
+
!idealBundle.mainEntryAsset) {
|
|
67
|
+
let uniqueKey = idealBundle.uniqueKey != null
|
|
68
|
+
? idealBundle.uniqueKey
|
|
69
|
+
: [...idealBundle.assets].map((asset) => asset.id).join(',');
|
|
70
|
+
bundle = (0, nullthrows_1.default)(bundleGraph.createBundle({
|
|
71
|
+
uniqueKey,
|
|
72
|
+
needsStableName: idealBundle.needsStableName,
|
|
73
|
+
bundleBehavior: idealBundle.bundleBehavior,
|
|
74
|
+
type: idealBundle.type,
|
|
75
|
+
target: idealBundle.target,
|
|
76
|
+
env: idealBundle.env,
|
|
77
|
+
manualSharedBundle: idealBundle.manualSharedBundle,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
else if (idealBundle.uniqueKey != null) {
|
|
81
|
+
bundle = (0, nullthrows_1.default)(bundleGraph.createBundle({
|
|
82
|
+
uniqueKey: idealBundle.uniqueKey,
|
|
83
|
+
needsStableName: idealBundle.needsStableName,
|
|
84
|
+
bundleBehavior: idealBundle.bundleBehavior,
|
|
85
|
+
type: idealBundle.type,
|
|
86
|
+
target: idealBundle.target,
|
|
87
|
+
env: idealBundle.env,
|
|
88
|
+
manualSharedBundle: idealBundle.manualSharedBundle,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
(0, assert_1.default)(entryAsset != null);
|
|
93
|
+
bundle = (0, nullthrows_1.default)(bundleGraph.createBundle({
|
|
94
|
+
entryAsset,
|
|
95
|
+
bundleRoots: Array.from(idealBundle.bundleRoots),
|
|
96
|
+
needsStableName: idealBundle.needsStableName,
|
|
97
|
+
bundleBehavior: idealBundle.bundleBehavior,
|
|
98
|
+
target: idealBundle.target,
|
|
99
|
+
manualSharedBundle: idealBundle.manualSharedBundle,
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
idealBundleToLegacyBundle.set(idealBundle, bundle);
|
|
103
|
+
for (let asset of idealBundle.assets) {
|
|
104
|
+
bundleGraph.addAssetToBundle(asset, bundle);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Step Internalization: Internalize dependencies for bundles
|
|
108
|
+
for (let idealBundle of idealBundleGraph.nodes) {
|
|
109
|
+
if (!idealBundle || idealBundle === 'root')
|
|
110
|
+
continue;
|
|
111
|
+
let bundle = (0, nullthrows_1.default)(idealBundleToLegacyBundle.get(idealBundle));
|
|
112
|
+
if (idealBundle.internalizedAssets) {
|
|
113
|
+
idealBundle.internalizedAssets.forEach((internalized) => {
|
|
114
|
+
let incomingDeps = bundleGraph.getIncomingDependencies(idealGraph.assets[internalized]);
|
|
115
|
+
for (let incomingDep of incomingDeps) {
|
|
116
|
+
if (incomingDep.priority === 'lazy' &&
|
|
117
|
+
incomingDep.specifierType !== 'url' &&
|
|
118
|
+
bundle.hasDependency(incomingDep)) {
|
|
119
|
+
bundleGraph.internalizeAsyncDependency(bundle, incomingDep);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Manual Shared Bundles
|
|
126
|
+
// NOTE: This only works under the assumption that manual shared bundles would have
|
|
127
|
+
// always already been loaded before the bundle that requires internalization.
|
|
128
|
+
for (let manualSharedAsset of manualAssetToBundle.keys()) {
|
|
129
|
+
let incomingDeps = bundleGraph.getIncomingDependencies(manualSharedAsset);
|
|
130
|
+
for (let incomingDep of incomingDeps) {
|
|
131
|
+
if (incomingDep.priority === 'lazy' &&
|
|
132
|
+
incomingDep.specifierType !== 'url') {
|
|
133
|
+
let bundles = bundleGraph.getBundlesWithDependency(incomingDep);
|
|
134
|
+
for (let bundle of bundles) {
|
|
135
|
+
bundleGraph.internalizeAsyncDependency(bundle, incomingDep);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Step Add to BundleGroups: Add bundles to their bundle groups
|
|
141
|
+
idealBundleGraph.traverse((nodeId, _, actions) => {
|
|
142
|
+
let node = idealBundleGraph.getNode(nodeId);
|
|
143
|
+
if (node === 'root') {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
actions.skipChildren();
|
|
147
|
+
let outboundNodeIds = idealBundleGraph.getNodeIdsConnectedFrom(nodeId);
|
|
148
|
+
let entryBundle = (0, nullthrows_1.default)(idealBundleGraph.getNode(nodeId));
|
|
149
|
+
(0, assert_1.default)(entryBundle !== 'root');
|
|
150
|
+
let legacyEntryBundle = (0, nullthrows_1.default)(idealBundleToLegacyBundle.get(entryBundle));
|
|
151
|
+
for (let id of outboundNodeIds) {
|
|
152
|
+
let siblingBundle = (0, nullthrows_1.default)(idealBundleGraph.getNode(id));
|
|
153
|
+
(0, assert_1.default)(siblingBundle !== 'root');
|
|
154
|
+
let legacySiblingBundle = (0, nullthrows_1.default)(idealBundleToLegacyBundle.get(siblingBundle));
|
|
155
|
+
bundleGraph.createBundleReference(legacyEntryBundle, legacySiblingBundle);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
// Step References: Add references to all bundles
|
|
159
|
+
for (let [asset, references] of idealGraph.assetReference) {
|
|
160
|
+
for (let [dependency, bundle] of references) {
|
|
161
|
+
let legacyBundle = (0, nullthrows_1.default)(idealBundleToLegacyBundle.get(bundle));
|
|
162
|
+
bundleGraph.createAssetReference(dependency, asset, legacyBundle);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// @ts-expect-error TS2488
|
|
166
|
+
for (let { type, from, to } of idealBundleGraph.getAllEdges()) {
|
|
167
|
+
let sourceBundle = (0, nullthrows_1.default)(idealBundleGraph.getNode(from));
|
|
168
|
+
if (sourceBundle === 'root') {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
// @ts-expect-error TS2367
|
|
172
|
+
(0, assert_1.default)(sourceBundle !== 'root');
|
|
173
|
+
let legacySourceBundle = (0, nullthrows_1.default)(idealBundleToLegacyBundle.get(sourceBundle));
|
|
174
|
+
let targetBundle = (0, nullthrows_1.default)(idealBundleGraph.getNode(to));
|
|
175
|
+
if (targetBundle === 'root') {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
// @ts-expect-error TS2367
|
|
179
|
+
(0, assert_1.default)(targetBundle !== 'root');
|
|
180
|
+
let legacyTargetBundle = (0, nullthrows_1.default)(idealBundleToLegacyBundle.get(targetBundle));
|
|
181
|
+
if ((0, feature_flags_1.getFeatureFlag)('conditionalBundlingApi') &&
|
|
182
|
+
type === idealGraph_1.idealBundleGraphEdges.conditional) {
|
|
183
|
+
bundleGraph.createBundleConditionalReference(legacySourceBundle, legacyTargetBundle);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
bundleGraph.createBundleReference(legacySourceBundle, legacyTargetBundle);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|