@atlaspack/bundler-default 2.12.1-dev.3502 → 2.12.1-dev.3565

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.
@@ -112,6 +112,9 @@ const CONFIG_SCHEMA = {
112
112
  },
113
113
  disableSharedBundles: {
114
114
  type: 'boolean'
115
+ },
116
+ loadConditionalBundlesInParallel: {
117
+ type: 'boolean'
115
118
  }
116
119
  },
117
120
  additionalProperties: false
@@ -172,6 +175,7 @@ async function loadBundlerConfig(config, options, logger) {
172
175
  maxParallelRequests: modeConfig.maxParallelRequests ?? defaults.maxParallelRequests,
173
176
  projectRoot: options.projectRoot,
174
177
  disableSharedBundles: modeConfig.disableSharedBundles ?? defaults.disableSharedBundles,
175
- manualSharedBundles: modeConfig.manualSharedBundles ?? defaults.manualSharedBundles
178
+ manualSharedBundles: modeConfig.manualSharedBundles ?? defaults.manualSharedBundles,
179
+ loadConditionalBundlesInParallel: modeConfig.loadConditionalBundlesInParallel
176
180
  };
177
181
  }
@@ -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
- bundleGraph.createBundleReference(legacySourceBundle, legacyTargetBundle);
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,6 +271,18 @@ function createIdealGraph(assetGraph, config, entries, logger) {
264
271
  value: bundle,
265
272
  type: 'bundle'
266
273
  }), dependencyPriorityEdges[dependency.priority]);
274
+ if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && dependency.priority === 'conditional') {
275
+ let [referencingBundleRoot, bundleGroupNodeId] = (0, _nullthrows().default)(stack[stack.length - 1]);
276
+ let referencingBundleId = (0, _nullthrows().default)(bundleRoots.get(referencingBundleRoot))[0];
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);
285
+ }
267
286
  } else if (dependency.priority === 'parallel' || childAsset.bundleBehavior === 'inline') {
268
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)
269
288
  let [referencingBundleRoot, bundleGroupNodeId] = (0, _nullthrows().default)(stack[stack.length - 1]);
@@ -419,7 +438,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
419
438
  let bundleRoot = assets[0];
420
439
  let bundle = (0, _nullthrows().default)(bundleGraph.getNode((0, _nullthrows().default)(bundles.get(bundleRoot.id))));
421
440
  if (bundle !== 'root' && bundle.bundleBehavior == null && !bundle.env.isIsolated() && bundle.env.context === root.env.context) {
422
- bundleRootGraph.addEdge(bundleRootId, (0, _nullthrows().default)(assetToBundleRootNodeId.get(bundleRoot)), dependency.priority === 'parallel' ? bundleRootEdgeTypes.parallel : bundleRootEdgeTypes.lazy);
441
+ bundleRootGraph.addEdge(bundleRootId, (0, _nullthrows().default)(assetToBundleRootNodeId.get(bundleRoot)), dependency.priority === 'parallel' || (config.loadConditionalBundlesInParallel ?? !bundle.env.shouldScopeHoist) && dependency.priority === 'conditional' ? bundleRootEdgeTypes.parallel : bundleRootEdgeTypes.lazy);
423
442
  }
424
443
  }
425
444
  if (dependency.priority !== 'sync') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/bundler-default",
3
- "version": "2.12.1-dev.3502+c2daeab5a",
3
+ "version": "2.12.1-dev.3565+b31bc6b33",
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
- "node": ">= 16.0.0",
16
- "parcel": "^2.12.1-dev.3502+c2daeab5a"
15
+ "atlaspack": "^2.12.1-dev.3565+b31bc6b33",
16
+ "node": ">= 16.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.12.1-dev.3502+c2daeab5a",
20
- "@atlaspack/feature-flags": "2.12.1-dev.3502+c2daeab5a",
21
- "@atlaspack/graph": "3.2.1-dev.3502+c2daeab5a",
22
- "@atlaspack/plugin": "2.12.1-dev.3502+c2daeab5a",
23
- "@atlaspack/rust": "2.12.1-dev.3502+c2daeab5a",
24
- "@atlaspack/utils": "2.12.1-dev.3502+c2daeab5a",
19
+ "@atlaspack/diagnostic": "2.12.1-dev.3565+b31bc6b33",
20
+ "@atlaspack/feature-flags": "2.12.1-dev.3565+b31bc6b33",
21
+ "@atlaspack/graph": "3.2.1-dev.3565+b31bc6b33",
22
+ "@atlaspack/plugin": "2.12.1-dev.3565+b31bc6b33",
23
+ "@atlaspack/rust": "2.12.1-dev.3565+b31bc6b33",
24
+ "@atlaspack/utils": "2.12.1-dev.3565+b31bc6b33",
25
25
  "nullthrows": "^1.1.1"
26
26
  },
27
- "gitHead": "c2daeab5a12461903159dec34df5671eaaa9b749"
27
+ "gitHead": "b31bc6b33de40c158b9f4d8ff177238be0de409d"
28
28
  }
@@ -27,6 +27,7 @@ type BaseBundlerConfig = {|
27
27
  maxParallelRequests?: number,
28
28
  disableSharedBundles?: boolean,
29
29
  manualSharedBundles?: ManualSharedBundles,
30
+ loadConditionalBundlesInParallel?: boolean,
30
31
  |};
31
32
 
32
33
  type BundlerConfig = {|
@@ -40,6 +41,7 @@ export type ResolvedBundlerConfig = {|
40
41
  projectRoot: string,
41
42
  disableSharedBundles: boolean,
42
43
  manualSharedBundles: ManualSharedBundles,
44
+ loadConditionalBundlesInParallel?: boolean,
43
45
  |};
44
46
 
45
47
  function resolveModeConfig(
@@ -134,6 +136,9 @@ const CONFIG_SCHEMA: SchemaEntity = {
134
136
  disableSharedBundles: {
135
137
  type: 'boolean',
136
138
  },
139
+ loadConditionalBundlesInParallel: {
140
+ type: 'boolean',
141
+ },
137
142
  },
138
143
  additionalProperties: false,
139
144
  };
@@ -226,5 +231,7 @@ export async function loadBundlerConfig(
226
231
  modeConfig.disableSharedBundles ?? defaults.disableSharedBundles,
227
232
  manualSharedBundles:
228
233
  modeConfig.manualSharedBundles ?? defaults.manualSharedBundles,
234
+ loadConditionalBundlesInParallel:
235
+ modeConfig.loadConditionalBundlesInParallel,
229
236
  };
230
237
  }
@@ -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
- bundleGraph.createBundleReference(legacySourceBundle, legacyTargetBundle);
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: Graph<Bundle | 'root'>,
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: Graph<Bundle | 'root'> = new Graph();
104
+ let bundleGraph: IdealBundleGraph = new Graph();
95
105
  let stack: Array<[BundleRoot, NodeId]> = [];
96
106
 
97
107
  let bundleRootEdgeTypes = {
@@ -362,6 +372,35 @@ export function createIdealGraph(
362
372
  ),
363
373
  dependencyPriorityEdges[dependency.priority],
364
374
  );
375
+
376
+ if (
377
+ getFeatureFlag('conditionalBundlingApi') &&
378
+ dependency.priority === 'conditional'
379
+ ) {
380
+ let [referencingBundleRoot, bundleGroupNodeId] = nullthrows(
381
+ stack[stack.length - 1],
382
+ );
383
+
384
+ let referencingBundleId = nullthrows(
385
+ bundleRoots.get(referencingBundleRoot),
386
+ )[0];
387
+
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
+ );
403
+ }
365
404
  } else if (
366
405
  dependency.priority === 'parallel' ||
367
406
  childAsset.bundleBehavior === 'inline'
@@ -582,7 +621,10 @@ export function createIdealGraph(
582
621
  bundleRootGraph.addEdge(
583
622
  bundleRootId,
584
623
  nullthrows(assetToBundleRootNodeId.get(bundleRoot)),
585
- dependency.priority === 'parallel'
624
+ dependency.priority === 'parallel' ||
625
+ ((config.loadConditionalBundlesInParallel ??
626
+ !bundle.env.shouldScopeHoist) &&
627
+ dependency.priority === 'conditional')
586
628
  ? bundleRootEdgeTypes.parallel
587
629
  : bundleRootEdgeTypes.lazy,
588
630
  );
@@ -1286,7 +1328,7 @@ export function createIdealGraph(
1286
1328
  }
1287
1329
 
1288
1330
  function removeBundle(
1289
- bundleGraph: Graph<Bundle | 'root'>,
1331
+ bundleGraph: IdealBundleGraph,
1290
1332
  bundleId: NodeId,
1291
1333
  assetReference: DefaultMap<Asset, Array<[Dependency, Bundle]>>,
1292
1334
  ) {