@atlaspack/bundler-default 2.13.2-dev.3674 → 2.13.2-dev.3689

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.
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.addJSMonolithBundle = addJSMonolithBundle;
7
+ function _assert() {
8
+ const data = _interopRequireDefault(require("assert"));
9
+ _assert = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
7
14
  function _nullthrows() {
8
15
  const data = _interopRequireDefault(require("nullthrows"));
9
16
  _nullthrows = function () {
@@ -20,16 +27,54 @@ function addJSMonolithBundle(bundleGraph, entryAsset, entryDep) {
20
27
  entryAsset,
21
28
  target
22
29
  });
23
- bundleGraph.traverse(node => {
30
+ bundleGraph.traverse((node, _, actions) => {
24
31
  // JS assets can be added to the bundle, but the rest are ignored
25
32
  if (node.type === 'asset' && node.value.type === 'js') {
26
33
  bundleGraph.addAssetToBundle(node.value, bundle);
27
34
  return;
28
35
  }
29
- if (node.type === 'dependency' && node.value.priority === 'lazy') {
36
+ if (node.type !== 'dependency') {
37
+ return;
38
+ }
39
+ let dependency = node.value;
40
+ if (dependency.priority === 'lazy') {
30
41
  // Any async dependencies need to be internalized into the bundle, and will
31
42
  // be included by the asset check above
32
- bundleGraph.internalizeAsyncDependency(bundle, node.value);
43
+ bundleGraph.internalizeAsyncDependency(bundle, dependency);
44
+ return;
45
+ }
46
+ let assets = bundleGraph.getDependencyAssets(dependency);
47
+ (0, _assert().default)(assets.length === 1, 'Expected dependency to have exactly one asset');
48
+ let asset = assets[0];
49
+
50
+ // For assets marked as isolated, we create new bundles and let other
51
+ // plugins like optimizers include them in the primary bundle
52
+ if (asset.bundleBehavior === 'isolated') {
53
+ // Create a new bundle to hold the isolated asset
54
+ let isolatedBundle = bundleGraph.createBundle({
55
+ entryAsset: asset,
56
+ target,
57
+ bundleBehavior: 'isolated'
58
+ });
59
+ bundleGraph.addAssetToBundle(asset, isolatedBundle);
60
+
61
+ // Add the new bundle to the bundle graph, in its own bundle group
62
+ bundleGraph.createBundleReference(bundle, isolatedBundle);
63
+ bundleGraph.addBundleToBundleGroup(isolatedBundle, bundleGraph.createBundleGroup(dependency, target));
64
+
65
+ // Nothing below the isolated asset needs to go in the main bundle, so
66
+ // we can stop traversal here
67
+ actions.skipChildren();
68
+
69
+ // To be properly isolated, all of this asset's dependencies need to go
70
+ // in this new bundle
71
+ bundleGraph.traverse(subNode => {
72
+ if (subNode.type === 'asset' && subNode.value.type === 'js') {
73
+ bundleGraph.addAssetToBundle(subNode.value, isolatedBundle);
74
+ }
75
+ }, asset, {
76
+ skipUnusedDependencies: true
77
+ });
33
78
  }
34
79
  }, entryAsset, {
35
80
  skipUnusedDependencies: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/bundler-default",
3
- "version": "2.13.2-dev.3674+d7732a10a",
3
+ "version": "2.13.2-dev.3689+7a2e6e783",
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
- "atlaspack": "^2.13.2-dev.3674+d7732a10a",
15
+ "atlaspack": "^2.13.2-dev.3689+7a2e6e783",
16
16
  "node": ">= 16.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.13.2-dev.3674+d7732a10a",
20
- "@atlaspack/feature-flags": "2.13.2-dev.3674+d7732a10a",
21
- "@atlaspack/graph": "3.3.2-dev.3674+d7732a10a",
22
- "@atlaspack/plugin": "2.13.2-dev.3674+d7732a10a",
23
- "@atlaspack/rust": "2.13.2-dev.3674+d7732a10a",
24
- "@atlaspack/utils": "2.13.2-dev.3674+d7732a10a",
19
+ "@atlaspack/diagnostic": "2.13.2-dev.3689+7a2e6e783",
20
+ "@atlaspack/feature-flags": "2.13.2-dev.3689+7a2e6e783",
21
+ "@atlaspack/graph": "3.3.2-dev.3689+7a2e6e783",
22
+ "@atlaspack/plugin": "2.13.2-dev.3689+7a2e6e783",
23
+ "@atlaspack/rust": "2.13.2-dev.3689+7a2e6e783",
24
+ "@atlaspack/utils": "2.13.2-dev.3689+7a2e6e783",
25
25
  "nullthrows": "^1.1.1"
26
26
  },
27
- "gitHead": "d7732a10a9a123de06d5eedcf9800d621e740229"
27
+ "gitHead": "7a2e6e7835fa846b27021b374097c6a4f37541ba"
28
28
  }
@@ -1,5 +1,6 @@
1
1
  // @flow strict-local
2
2
  import type {Asset, Dependency, MutableBundleGraph} from '@atlaspack/types';
3
+ import invariant from 'assert';
3
4
  import nullthrows from 'nullthrows';
4
5
 
5
6
  export function addJSMonolithBundle(
@@ -16,17 +17,69 @@ export function addJSMonolithBundle(
16
17
  let bundle = bundleGraph.createBundle({entryAsset, target});
17
18
 
18
19
  bundleGraph.traverse(
19
- (node) => {
20
+ (node, _, actions) => {
20
21
  // JS assets can be added to the bundle, but the rest are ignored
21
22
  if (node.type === 'asset' && node.value.type === 'js') {
22
23
  bundleGraph.addAssetToBundle(node.value, bundle);
23
24
  return;
24
25
  }
25
26
 
26
- if (node.type === 'dependency' && node.value.priority === 'lazy') {
27
+ if (node.type !== 'dependency') {
28
+ return;
29
+ }
30
+
31
+ let dependency = node.value;
32
+
33
+ if (dependency.priority === 'lazy') {
27
34
  // Any async dependencies need to be internalized into the bundle, and will
28
35
  // be included by the asset check above
29
- bundleGraph.internalizeAsyncDependency(bundle, node.value);
36
+ bundleGraph.internalizeAsyncDependency(bundle, dependency);
37
+ return;
38
+ }
39
+
40
+ let assets = bundleGraph.getDependencyAssets(dependency);
41
+ invariant(
42
+ assets.length === 1,
43
+ 'Expected dependency to have exactly one asset',
44
+ );
45
+
46
+ let asset = assets[0];
47
+
48
+ // For assets marked as isolated, we create new bundles and let other
49
+ // plugins like optimizers include them in the primary bundle
50
+ if (asset.bundleBehavior === 'isolated') {
51
+ // Create a new bundle to hold the isolated asset
52
+ let isolatedBundle = bundleGraph.createBundle({
53
+ entryAsset: asset,
54
+ target,
55
+ bundleBehavior: 'isolated',
56
+ });
57
+
58
+ bundleGraph.addAssetToBundle(asset, isolatedBundle);
59
+
60
+ // Add the new bundle to the bundle graph, in its own bundle group
61
+ bundleGraph.createBundleReference(bundle, isolatedBundle);
62
+ bundleGraph.addBundleToBundleGroup(
63
+ isolatedBundle,
64
+ bundleGraph.createBundleGroup(dependency, target),
65
+ );
66
+
67
+ // Nothing below the isolated asset needs to go in the main bundle, so
68
+ // we can stop traversal here
69
+ actions.skipChildren();
70
+
71
+ // To be properly isolated, all of this asset's dependencies need to go
72
+ // in this new bundle
73
+ bundleGraph.traverse(
74
+ (subNode) => {
75
+ if (subNode.type === 'asset' && subNode.value.type === 'js') {
76
+ bundleGraph.addAssetToBundle(subNode.value, isolatedBundle);
77
+ return;
78
+ }
79
+ },
80
+ asset,
81
+ {skipUnusedDependencies: true},
82
+ );
30
83
  }
31
84
  },
32
85
  entryAsset,