@atlaspack/core 2.12.1-canary.3410 → 2.12.1-canary.3412

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.
@@ -62,6 +62,13 @@ function _profiler() {
62
62
  };
63
63
  return data;
64
64
  }
65
+ function _utils() {
66
+ const data = require("@atlaspack/utils");
67
+ _utils = function () {
68
+ return data;
69
+ };
70
+ return data;
71
+ }
65
72
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
66
73
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
67
74
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -81,6 +88,36 @@ function nameRuntimeBundle(bundle, siblingBundle) {
81
88
  bundle.name = name;
82
89
  bundle.displayName = name.replace(hashReference, '[hash]');
83
90
  }
91
+
92
+ /**
93
+ * The applyRuntimes function is responsible for generating all the runtimes
94
+ * (assets created during the build that don't actually exist on disk) and then
95
+ * linking them into the bundle graph.
96
+ *
97
+ * Usually, the assets returned from a runtime will go in the same bundle. It is
98
+ * possible though, for a runtime to return an asset with a `parallel` priority,
99
+ * which allows it to be moved to a separate bundle. In practice, this is
100
+ * usually used to generate application manifest files.
101
+ *
102
+ * When adding a manifest bundle (a whole new separate bundle) during a runtime,
103
+ * it needs to be added to a bundle group which will be potentially referenced
104
+ * by another bundle group. To avoid trying to reference a manifest entry which
105
+ * hasn't been created yet, we process the bundles from the bottom up, so that
106
+ * children will always be available when parents try to reference them.
107
+ *
108
+ * However, when merging those connections in to the bundle graph, the reversed
109
+ * order can create a situation where the child bundles thought they were coming
110
+ * first and so take responsibility for loading in shared bundles. When the
111
+ * parents actually load first, they're expecting bundles to be loaded which
112
+ * aren't yet, creating module not found errors.
113
+ *
114
+ * To fix that, we restore the forward topological order once all the
115
+ * connections are created.
116
+ *
117
+ * Introduction of manifest bundles: https://github.com/parcel-bundler/parcel/pull/8837
118
+ * Introduction of reverse topology: https://github.com/parcel-bundler/parcel/pull/8981
119
+ */
120
+
84
121
  async function applyRuntimes({
85
122
  bundleGraph,
86
123
  config,
@@ -93,17 +130,15 @@ async function applyRuntimes({
93
130
  configs
94
131
  }) {
95
132
  let runtimes = await config.getRuntimes();
96
- let connections = [];
97
133
 
98
- // As manifest bundles may be added during runtimes we process them in reverse topological
99
- // sort order. This allows bundles to be added to their bundle groups before they are referenced
100
- // by other bundle groups by loader runtimes
134
+ // Sort bundles into reverse topological order
101
135
  let bundles = [];
102
136
  bundleGraph.traverseBundles({
103
137
  exit(bundle) {
104
138
  bundles.push(bundle);
105
139
  }
106
140
  });
141
+ let connectionMap = new (_utils().DefaultMap)(() => []);
107
142
  for (let bundle of bundles) {
108
143
  for (let runtime of runtimes) {
109
144
  let measurement;
@@ -160,7 +195,7 @@ async function applyRuntimes({
160
195
  bundleGraph.createBundleReference(bundle, connectionBundle);
161
196
  nameRuntimeBundle(connectionBundle, bundle);
162
197
  }
163
- connections.push({
198
+ connectionMap.get(connectionBundle).push({
164
199
  bundle: connectionBundle,
165
200
  assetGroup,
166
201
  dependency,
@@ -180,8 +215,13 @@ async function applyRuntimes({
180
215
  }
181
216
  }
182
217
 
183
- // Correct connection order after generating runtimes in reverse order
184
- connections.reverse();
218
+ // Sort the bundles back into forward topological order
219
+ let connections = [];
220
+ bundleGraph.traverseBundles({
221
+ enter(bundle) {
222
+ connections.push(...connectionMap.get(bundle));
223
+ }
224
+ });
185
225
 
186
226
  // Add dev deps for runtime plugins AFTER running them, to account for lazy require().
187
227
  for (let runtime of runtimes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.12.1-canary.3410+11a9679ea",
3
+ "version": "2.12.1-canary.3412+b617f5081",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,20 +20,20 @@
20
20
  "check-ts": "tsc --noEmit index.d.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaspack/cache": "2.12.1-canary.3410+11a9679ea",
24
- "@atlaspack/diagnostic": "2.12.1-canary.3410+11a9679ea",
25
- "@atlaspack/events": "2.12.1-canary.3410+11a9679ea",
26
- "@atlaspack/feature-flags": "2.12.1-canary.3410+11a9679ea",
27
- "@atlaspack/fs": "2.12.1-canary.3410+11a9679ea",
28
- "@atlaspack/graph": "3.2.1-canary.3410+11a9679ea",
29
- "@atlaspack/logger": "2.12.1-canary.3410+11a9679ea",
30
- "@atlaspack/package-manager": "2.12.1-canary.3410+11a9679ea",
31
- "@atlaspack/plugin": "2.12.1-canary.3410+11a9679ea",
32
- "@atlaspack/profiler": "2.12.1-canary.3410+11a9679ea",
33
- "@atlaspack/rust": "2.12.1-canary.3410+11a9679ea",
34
- "@atlaspack/types": "2.12.1-canary.3410+11a9679ea",
35
- "@atlaspack/utils": "2.12.1-canary.3410+11a9679ea",
36
- "@atlaspack/workers": "2.12.1-canary.3410+11a9679ea",
23
+ "@atlaspack/cache": "2.12.1-canary.3412+b617f5081",
24
+ "@atlaspack/diagnostic": "2.12.1-canary.3412+b617f5081",
25
+ "@atlaspack/events": "2.12.1-canary.3412+b617f5081",
26
+ "@atlaspack/feature-flags": "2.12.1-canary.3412+b617f5081",
27
+ "@atlaspack/fs": "2.12.1-canary.3412+b617f5081",
28
+ "@atlaspack/graph": "3.2.1-canary.3412+b617f5081",
29
+ "@atlaspack/logger": "2.12.1-canary.3412+b617f5081",
30
+ "@atlaspack/package-manager": "2.12.1-canary.3412+b617f5081",
31
+ "@atlaspack/plugin": "2.12.1-canary.3412+b617f5081",
32
+ "@atlaspack/profiler": "2.12.1-canary.3412+b617f5081",
33
+ "@atlaspack/rust": "2.12.1-canary.3412+b617f5081",
34
+ "@atlaspack/types": "2.12.1-canary.3412+b617f5081",
35
+ "@atlaspack/utils": "2.12.1-canary.3412+b617f5081",
36
+ "@atlaspack/workers": "2.12.1-canary.3412+b617f5081",
37
37
  "@mischnic/json-sourcemap": "^0.1.0",
38
38
  "@parcel/source-map": "^2.1.1",
39
39
  "base-x": "^3.0.8",
@@ -55,5 +55,5 @@
55
55
  "browser": {
56
56
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
57
57
  },
58
- "gitHead": "11a9679ea386c5e8342aa840646e41e77cbabd92"
58
+ "gitHead": "b617f508177b7dc3c3d3b35bc95b3fbc4e517268"
59
59
  }
@@ -32,6 +32,7 @@ import createAssetGraphRequest from './requests/AssetGraphRequest';
32
32
  import {createDevDependency, runDevDepRequest} from './requests/DevDepRequest';
33
33
  import {toProjectPath, fromProjectPathRelative} from './projectPath';
34
34
  import {tracer, PluginTracer} from '@atlaspack/profiler';
35
+ import {DefaultMap} from '@atlaspack/utils';
35
36
 
36
37
  type RuntimeConnection = {|
37
38
  bundle: InternalBundle,
@@ -60,6 +61,35 @@ function nameRuntimeBundle(
60
61
  bundle.displayName = name.replace(hashReference, '[hash]');
61
62
  }
62
63
 
64
+ /**
65
+ * The applyRuntimes function is responsible for generating all the runtimes
66
+ * (assets created during the build that don't actually exist on disk) and then
67
+ * linking them into the bundle graph.
68
+ *
69
+ * Usually, the assets returned from a runtime will go in the same bundle. It is
70
+ * possible though, for a runtime to return an asset with a `parallel` priority,
71
+ * which allows it to be moved to a separate bundle. In practice, this is
72
+ * usually used to generate application manifest files.
73
+ *
74
+ * When adding a manifest bundle (a whole new separate bundle) during a runtime,
75
+ * it needs to be added to a bundle group which will be potentially referenced
76
+ * by another bundle group. To avoid trying to reference a manifest entry which
77
+ * hasn't been created yet, we process the bundles from the bottom up, so that
78
+ * children will always be available when parents try to reference them.
79
+ *
80
+ * However, when merging those connections in to the bundle graph, the reversed
81
+ * order can create a situation where the child bundles thought they were coming
82
+ * first and so take responsibility for loading in shared bundles. When the
83
+ * parents actually load first, they're expecting bundles to be loaded which
84
+ * aren't yet, creating module not found errors.
85
+ *
86
+ * To fix that, we restore the forward topological order once all the
87
+ * connections are created.
88
+ *
89
+ * Introduction of manifest bundles: https://github.com/parcel-bundler/parcel/pull/8837
90
+ * Introduction of reverse topology: https://github.com/parcel-bundler/parcel/pull/8981
91
+ */
92
+
63
93
  export default async function applyRuntimes<TResult: RequestResult>({
64
94
  bundleGraph,
65
95
  config,
@@ -82,11 +112,8 @@ export default async function applyRuntimes<TResult: RequestResult>({
82
112
  configs: Map<string, Config>,
83
113
  |}): Promise<Map<string, Asset>> {
84
114
  let runtimes = await config.getRuntimes();
85
- let connections: Array<RuntimeConnection> = [];
86
115
 
87
- // As manifest bundles may be added during runtimes we process them in reverse topological
88
- // sort order. This allows bundles to be added to their bundle groups before they are referenced
89
- // by other bundle groups by loader runtimes
116
+ // Sort bundles into reverse topological order
90
117
  let bundles = [];
91
118
  bundleGraph.traverseBundles({
92
119
  exit(bundle) {
@@ -94,6 +121,8 @@ export default async function applyRuntimes<TResult: RequestResult>({
94
121
  },
95
122
  });
96
123
 
124
+ let connectionMap = new DefaultMap(() => []);
125
+
97
126
  for (let bundle of bundles) {
98
127
  for (let runtime of runtimes) {
99
128
  let measurement;
@@ -172,7 +201,7 @@ export default async function applyRuntimes<TResult: RequestResult>({
172
201
  nameRuntimeBundle(connectionBundle, bundle);
173
202
  }
174
203
 
175
- connections.push({
204
+ connectionMap.get(connectionBundle).push({
176
205
  bundle: connectionBundle,
177
206
  assetGroup,
178
207
  dependency,
@@ -192,8 +221,14 @@ export default async function applyRuntimes<TResult: RequestResult>({
192
221
  }
193
222
  }
194
223
 
195
- // Correct connection order after generating runtimes in reverse order
196
- connections.reverse();
224
+ // Sort the bundles back into forward topological order
225
+ let connections: Array<RuntimeConnection> = [];
226
+
227
+ bundleGraph.traverseBundles({
228
+ enter(bundle) {
229
+ connections.push(...connectionMap.get(bundle));
230
+ },
231
+ });
197
232
 
198
233
  // Add dev deps for runtime plugins AFTER running them, to account for lazy require().
199
234
  for (let runtime of runtimes) {