@atlaspack/bundler-default 2.12.1-dev.3520 → 2.12.1-dev.3566
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/lib/bundlerConfig.js +3 -0
- package/lib/decorateLegacyGraph.js +14 -1
- package/lib/idealGraph.js +19 -7
- package/package.json +10 -10
- package/src/bundlerConfig.js +3 -0
- package/src/decorateLegacyGraph.js +14 -2
- package/src/idealGraph.js +36 -15
package/lib/bundlerConfig.js
CHANGED
|
@@ -11,6 +11,13 @@ function _graph() {
|
|
|
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 _assert() {
|
|
15
22
|
const data = _interopRequireDefault(require("assert"));
|
|
16
23
|
_assert = function () {
|
|
@@ -25,6 +32,7 @@ function _nullthrows() {
|
|
|
25
32
|
};
|
|
26
33
|
return data;
|
|
27
34
|
}
|
|
35
|
+
var _idealGraph = require("./idealGraph");
|
|
28
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
37
|
function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
30
38
|
let idealBundleToLegacyBundle = new Map();
|
|
@@ -155,6 +163,7 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
for (let {
|
|
166
|
+
type,
|
|
158
167
|
from,
|
|
159
168
|
to
|
|
160
169
|
} of idealBundleGraph.getAllEdges()) {
|
|
@@ -170,6 +179,10 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
170
179
|
}
|
|
171
180
|
(0, _assert().default)(targetBundle !== 'root');
|
|
172
181
|
let legacyTargetBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(targetBundle));
|
|
173
|
-
|
|
182
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && type === _idealGraph.idealBundleGraphEdges.conditional) {
|
|
183
|
+
bundleGraph.createBundleConditionalReference(legacySourceBundle, legacyTargetBundle);
|
|
184
|
+
} else {
|
|
185
|
+
bundleGraph.createBundleReference(legacySourceBundle, legacyTargetBundle);
|
|
186
|
+
}
|
|
174
187
|
}
|
|
175
188
|
}
|
package/lib/idealGraph.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createIdealGraph = createIdealGraph;
|
|
7
|
+
exports.idealBundleGraphEdges = void 0;
|
|
7
8
|
function _path() {
|
|
8
9
|
const data = _interopRequireDefault(require("path"));
|
|
9
10
|
_path = function () {
|
|
@@ -48,15 +49,21 @@ function _nullthrows() {
|
|
|
48
49
|
}
|
|
49
50
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
50
51
|
/* BundleRoot - An asset that is the main entry of a Bundle. */
|
|
51
|
-
// IdealGraph is the structure we will pass to decorate,
|
|
52
|
-
// which mutates the assetGraph into the bundleGraph we would
|
|
53
|
-
// expect from default bundler
|
|
54
52
|
const dependencyPriorityEdges = {
|
|
55
53
|
sync: 1,
|
|
56
54
|
parallel: 2,
|
|
57
55
|
lazy: 3,
|
|
58
56
|
conditional: 4
|
|
59
57
|
};
|
|
58
|
+
const idealBundleGraphEdges = exports.idealBundleGraphEdges = Object.freeze({
|
|
59
|
+
default: 1,
|
|
60
|
+
conditional: 2
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// IdealGraph is the structure we will pass to decorate,
|
|
64
|
+
// which mutates the assetGraph into the bundleGraph we would
|
|
65
|
+
// expect from default bundler
|
|
66
|
+
|
|
60
67
|
function createIdealGraph(assetGraph, config, entries, logger) {
|
|
61
68
|
// Asset to the bundle and group it's an entry of
|
|
62
69
|
let bundleRoots = new Map();
|
|
@@ -264,12 +271,17 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
264
271
|
value: bundle,
|
|
265
272
|
type: 'bundle'
|
|
266
273
|
}), dependencyPriorityEdges[dependency.priority]);
|
|
267
|
-
if ((
|
|
268
|
-
// When configured (or serving code in development), serve conditional bundles in parallel so we don't get module not found errors
|
|
274
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && dependency.priority === 'conditional') {
|
|
269
275
|
let [referencingBundleRoot, bundleGroupNodeId] = (0, _nullthrows().default)(stack[stack.length - 1]);
|
|
270
276
|
let referencingBundleId = (0, _nullthrows().default)(bundleRoots.get(referencingBundleRoot))[0];
|
|
271
|
-
|
|
272
|
-
|
|
277
|
+
if (config.loadConditionalBundlesInParallel ?? !bundle.env.shouldScopeHoist) {
|
|
278
|
+
// When configured (or serving code in development), serve conditional bundles in parallel so we don't get module not found errors
|
|
279
|
+
bundleRoots.set(childAsset, [bundleId, bundleGroupNodeId]);
|
|
280
|
+
bundleGraph.addEdge(referencingBundleId, bundleId);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Add conditional edge to track which bundles request each other
|
|
284
|
+
bundleGraph.addEdge(referencingBundleId, bundleId, idealBundleGraphEdges.conditional);
|
|
273
285
|
}
|
|
274
286
|
} else if (dependency.priority === 'parallel' || childAsset.bundleBehavior === 'inline') {
|
|
275
287
|
// The referencing bundleRoot is the root of a Bundle that first brings in another bundle (essentially the FIRST parent of a bundle, this may or may not be a bundleGroup)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/bundler-default",
|
|
3
|
-
"version": "2.12.1-dev.
|
|
3
|
+
"version": "2.12.1-dev.3566+facdfb05f",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
"main": "lib/DefaultBundler.js",
|
|
13
13
|
"source": "src/DefaultBundler.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"atlaspack": "^2.12.1-dev.3566+facdfb05f",
|
|
16
|
+
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.12.1-dev.
|
|
20
|
-
"@atlaspack/feature-flags": "2.12.1-dev.
|
|
21
|
-
"@atlaspack/graph": "3.2.1-dev.
|
|
22
|
-
"@atlaspack/plugin": "2.12.1-dev.
|
|
23
|
-
"@atlaspack/rust": "2.12.1-dev.
|
|
24
|
-
"@atlaspack/utils": "2.12.1-dev.
|
|
19
|
+
"@atlaspack/diagnostic": "2.12.1-dev.3566+facdfb05f",
|
|
20
|
+
"@atlaspack/feature-flags": "2.12.1-dev.3566+facdfb05f",
|
|
21
|
+
"@atlaspack/graph": "3.2.1-dev.3566+facdfb05f",
|
|
22
|
+
"@atlaspack/plugin": "2.12.1-dev.3566+facdfb05f",
|
|
23
|
+
"@atlaspack/rust": "2.12.1-dev.3566+facdfb05f",
|
|
24
|
+
"@atlaspack/utils": "2.12.1-dev.3566+facdfb05f",
|
|
25
25
|
"nullthrows": "^1.1.1"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "facdfb05f693e50037a82a4afa101adf093fd8c9"
|
|
28
28
|
}
|
package/src/bundlerConfig.js
CHANGED
|
@@ -6,10 +6,12 @@ import type {
|
|
|
6
6
|
BundleGroup,
|
|
7
7
|
MutableBundleGraph,
|
|
8
8
|
} from '@atlaspack/types';
|
|
9
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
9
10
|
import invariant from 'assert';
|
|
10
11
|
import nullthrows from 'nullthrows';
|
|
11
12
|
|
|
12
13
|
import type {Bundle, IdealGraph} from './idealGraph';
|
|
14
|
+
import {idealBundleGraphEdges} from './idealGraph';
|
|
13
15
|
|
|
14
16
|
export function decorateLegacyGraph(
|
|
15
17
|
idealGraph: IdealGraph,
|
|
@@ -193,7 +195,7 @@ export function decorateLegacyGraph(
|
|
|
193
195
|
}
|
|
194
196
|
}
|
|
195
197
|
|
|
196
|
-
for (let {from, to} of idealBundleGraph.getAllEdges()) {
|
|
198
|
+
for (let {type, from, to} of idealBundleGraph.getAllEdges()) {
|
|
197
199
|
let sourceBundle = nullthrows(idealBundleGraph.getNode(from));
|
|
198
200
|
if (sourceBundle === 'root') {
|
|
199
201
|
continue;
|
|
@@ -212,6 +214,16 @@ export function decorateLegacyGraph(
|
|
|
212
214
|
let legacyTargetBundle = nullthrows(
|
|
213
215
|
idealBundleToLegacyBundle.get(targetBundle),
|
|
214
216
|
);
|
|
215
|
-
|
|
217
|
+
if (
|
|
218
|
+
getFeatureFlag('conditionalBundlingApi') &&
|
|
219
|
+
type === idealBundleGraphEdges.conditional
|
|
220
|
+
) {
|
|
221
|
+
bundleGraph.createBundleConditionalReference(
|
|
222
|
+
legacySourceBundle,
|
|
223
|
+
legacyTargetBundle,
|
|
224
|
+
);
|
|
225
|
+
} else {
|
|
226
|
+
bundleGraph.createBundleReference(legacySourceBundle, legacyTargetBundle);
|
|
227
|
+
}
|
|
216
228
|
}
|
|
217
229
|
}
|
package/src/idealGraph.js
CHANGED
|
@@ -55,25 +55,35 @@ export type DependencyBundleGraph = ContentGraph<
|
|
|
55
55
|
number,
|
|
56
56
|
>;
|
|
57
57
|
|
|
58
|
+
const dependencyPriorityEdges = {
|
|
59
|
+
sync: 1,
|
|
60
|
+
parallel: 2,
|
|
61
|
+
lazy: 3,
|
|
62
|
+
conditional: 4,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const idealBundleGraphEdges = Object.freeze({
|
|
66
|
+
default: 1,
|
|
67
|
+
conditional: 2,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
type IdealBundleGraph = Graph<
|
|
71
|
+
Bundle | 'root',
|
|
72
|
+
$Values<typeof idealBundleGraphEdges>,
|
|
73
|
+
>;
|
|
74
|
+
|
|
58
75
|
// IdealGraph is the structure we will pass to decorate,
|
|
59
76
|
// which mutates the assetGraph into the bundleGraph we would
|
|
60
77
|
// expect from default bundler
|
|
61
78
|
export type IdealGraph = {|
|
|
62
79
|
assetReference: DefaultMap<Asset, Array<[Dependency, Bundle]>>,
|
|
63
80
|
assets: Array<Asset>,
|
|
64
|
-
bundleGraph:
|
|
81
|
+
bundleGraph: IdealBundleGraph,
|
|
65
82
|
bundleGroupBundleIds: Set<NodeId>,
|
|
66
83
|
dependencyBundleGraph: DependencyBundleGraph,
|
|
67
84
|
manualAssetToBundle: Map<Asset, NodeId>,
|
|
68
85
|
|};
|
|
69
86
|
|
|
70
|
-
const dependencyPriorityEdges = {
|
|
71
|
-
sync: 1,
|
|
72
|
-
parallel: 2,
|
|
73
|
-
lazy: 3,
|
|
74
|
-
conditional: 4,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
87
|
export function createIdealGraph(
|
|
78
88
|
assetGraph: MutableBundleGraph,
|
|
79
89
|
config: ResolvedBundlerConfig,
|
|
@@ -91,7 +101,7 @@ export function createIdealGraph(
|
|
|
91
101
|
|
|
92
102
|
// A Graph of Bundles and a root node (dummy string), which models only Bundles, and connections to their
|
|
93
103
|
// referencing Bundle. There are no actual BundleGroup nodes, just bundles that take on that role.
|
|
94
|
-
let bundleGraph:
|
|
104
|
+
let bundleGraph: IdealBundleGraph = new Graph();
|
|
95
105
|
let stack: Array<[BundleRoot, NodeId]> = [];
|
|
96
106
|
|
|
97
107
|
let bundleRootEdgeTypes = {
|
|
@@ -364,11 +374,9 @@ export function createIdealGraph(
|
|
|
364
374
|
);
|
|
365
375
|
|
|
366
376
|
if (
|
|
367
|
-
(
|
|
368
|
-
!bundle.env.shouldScopeHoist) &&
|
|
377
|
+
getFeatureFlag('conditionalBundlingApi') &&
|
|
369
378
|
dependency.priority === 'conditional'
|
|
370
379
|
) {
|
|
371
|
-
// When configured (or serving code in development), serve conditional bundles in parallel so we don't get module not found errors
|
|
372
380
|
let [referencingBundleRoot, bundleGroupNodeId] = nullthrows(
|
|
373
381
|
stack[stack.length - 1],
|
|
374
382
|
);
|
|
@@ -377,8 +385,21 @@ export function createIdealGraph(
|
|
|
377
385
|
bundleRoots.get(referencingBundleRoot),
|
|
378
386
|
)[0];
|
|
379
387
|
|
|
380
|
-
|
|
381
|
-
|
|
388
|
+
if (
|
|
389
|
+
config.loadConditionalBundlesInParallel ??
|
|
390
|
+
!bundle.env.shouldScopeHoist
|
|
391
|
+
) {
|
|
392
|
+
// When configured (or serving code in development), serve conditional bundles in parallel so we don't get module not found errors
|
|
393
|
+
bundleRoots.set(childAsset, [bundleId, bundleGroupNodeId]);
|
|
394
|
+
bundleGraph.addEdge(referencingBundleId, bundleId);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Add conditional edge to track which bundles request each other
|
|
398
|
+
bundleGraph.addEdge(
|
|
399
|
+
referencingBundleId,
|
|
400
|
+
bundleId,
|
|
401
|
+
idealBundleGraphEdges.conditional,
|
|
402
|
+
);
|
|
382
403
|
}
|
|
383
404
|
} else if (
|
|
384
405
|
dependency.priority === 'parallel' ||
|
|
@@ -1307,7 +1328,7 @@ export function createIdealGraph(
|
|
|
1307
1328
|
}
|
|
1308
1329
|
|
|
1309
1330
|
function removeBundle(
|
|
1310
|
-
bundleGraph:
|
|
1331
|
+
bundleGraph: IdealBundleGraph,
|
|
1311
1332
|
bundleId: NodeId,
|
|
1312
1333
|
assetReference: DefaultMap<Asset, Array<[Dependency, Bundle]>>,
|
|
1313
1334
|
) {
|