@atlaspack/bundler-default 2.14.0 → 2.14.1-canary.6

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