@atlaspack/runtime-js 2.14.5-canary.16 → 2.14.5-canary.161

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +206 -0
  2. package/lib/JSRuntime.js +79 -40
  3. package/lib/helpers/browser/analytics/analytics.d.js +1 -0
  4. package/lib/helpers/browser/css-loader.js +4 -3
  5. package/lib/helpers/browser/html-loader.js +1 -1
  6. package/lib/helpers/browser/import-polyfill.js +1 -1
  7. package/lib/helpers/browser/js-loader.js +4 -3
  8. package/lib/helpers/browser/prefetch-loader.js +1 -1
  9. package/lib/helpers/browser/preload-loader.js +1 -1
  10. package/lib/helpers/browser/sync-js-loader.js +33 -0
  11. package/lib/helpers/browser/wasm-loader.js +1 -1
  12. package/lib/helpers/cacheLoader.js +1 -1
  13. package/lib/helpers/conditional-loader-dev.js +10 -3
  14. package/lib/helpers/conditional-loader.js +15 -2
  15. package/lib/helpers/get-worker-url.js +1 -1
  16. package/lib/helpers/node/css-loader.js +1 -1
  17. package/lib/helpers/node/html-loader.js +1 -1
  18. package/lib/helpers/node/js-loader.js +1 -1
  19. package/lib/helpers/node/wasm-loader.js +1 -1
  20. package/lib/helpers/worker/js-loader.js +1 -1
  21. package/lib/helpers/worker/wasm-loader.js +1 -1
  22. package/lib/types/JSRuntime.d.ts +9 -0
  23. package/package.json +15 -9
  24. package/src/{JSRuntime.js → JSRuntime.ts} +183 -113
  25. package/src/helpers/browser/preload-loader.js +1 -2
  26. package/src/helpers/browser/sync-js-loader.js +39 -0
  27. package/src/helpers/conditional-loader-dev.js +11 -3
  28. package/src/helpers/conditional-loader.js +18 -2
  29. package/test/analytics.test.ts +4 -1
  30. package/test/{bundle-url.test.js → bundle-url.test.ts} +1 -2
  31. package/test/esm-js-loader-retry.test.ts +4 -7
  32. package/tsconfig.json +4 -0
  33. package/src/helpers/browser/analytics/analytics.js.flow +0 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,211 @@
1
1
  # @atlaspack/runtime-js
2
2
 
3
+ ## 2.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`f6b3f22`](https://github.com/atlassian-labs/atlaspack/commit/f6b3f2276c7e417580b49c4879563aab51f156b1)]:
8
+ - @atlaspack/feature-flags@2.23.0
9
+ - @atlaspack/utils@2.18.2
10
+ - @atlaspack/plugin@2.14.25
11
+
12
+ ## 2.18.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#732](https://github.com/atlassian-labs/atlaspack/pull/732) [`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45) Thanks [@vykimnguyen](https://github.com/vykimnguyen)! - add tesseract context
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [[`73dd7ba`](https://github.com/atlassian-labs/atlaspack/commit/73dd7baab69456ef2f6e4a0cc7dbb04f407eb148)]:
21
+ - @atlaspack/feature-flags@2.22.0
22
+ - @atlaspack/utils@2.18.1
23
+ - @atlaspack/plugin@2.14.24
24
+
25
+ ## 2.17.0
26
+
27
+ ### Minor Changes
28
+
29
+ - [#731](https://github.com/atlassian-labs/atlaspack/pull/731) [`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2) Thanks [@marcins](https://github.com/marcins)! - Implement "inline isolated" scripts
30
+
31
+ ### Patch Changes
32
+
33
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
34
+ - @atlaspack/feature-flags@2.21.0
35
+ - @atlaspack/utils@2.18.0
36
+ - @atlaspack/plugin@2.14.23
37
+
38
+ ## 2.16.1
39
+
40
+ ### Patch Changes
41
+
42
+ - [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
43
+
44
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`12bee0e`](https://github.com/atlassian-labs/atlaspack/commit/12bee0e23f0464d7f6bd3e24fbe0d19c126d587d)]:
45
+ - @atlaspack/domain-sharding@2.14.2
46
+ - @atlaspack/feature-flags@2.20.1
47
+ - @atlaspack/diagnostic@2.14.2
48
+ - @atlaspack/plugin@2.14.22
49
+ - @atlaspack/utils@2.17.4
50
+
51
+ ## 2.16.0
52
+
53
+ ### Minor Changes
54
+
55
+ - [#721](https://github.com/atlassian-labs/atlaspack/pull/721) [`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd) Thanks [@benjervis](https://github.com/benjervis)! - Add support for bundle merging based on `webpackChunkName` comments.
56
+
57
+ Adding a `webpackChunkName` comment to an import will allow the bundler to merge multiple imports into a single bundle.
58
+
59
+ e.g.:
60
+
61
+ ```ts
62
+ import(/* webpackChunkName: "my-chunk" */ './my-module');
63
+ import(/* webpackChunkName: "my-chunk" */ './another-module');
64
+ ```
65
+
66
+ This can be enabled with the feature flag `supportWebpackChunkName`.
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
71
+ - @atlaspack/feature-flags@2.20.0
72
+ - @atlaspack/utils@2.17.3
73
+ - @atlaspack/plugin@2.14.21
74
+
75
+ ## 2.15.2
76
+
77
+ ### Patch Changes
78
+
79
+ - [#702](https://github.com/atlassian-labs/atlaspack/pull/702) [`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa) Thanks [@alshdavid](https://github.com/alshdavid)! - Fixes to Flow types
80
+
81
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa), [`1c7865a`](https://github.com/atlassian-labs/atlaspack/commit/1c7865a64451116d94015e248302435839d347c0), [`a0b959f`](https://github.com/atlassian-labs/atlaspack/commit/a0b959fbf61fc3f820ff03c7e8988945fe40a91a)]:
82
+ - @atlaspack/plugin@2.14.20
83
+ - @atlaspack/feature-flags@2.19.2
84
+ - @atlaspack/utils@2.17.2
85
+
86
+ ## 2.15.1
87
+
88
+ ### Patch Changes
89
+
90
+ - [#692](https://github.com/atlassian-labs/atlaspack/pull/692) [`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d) Thanks [@JakeLane](https://github.com/JakeLane)! - Add fallback behaviour when conditional bundle is missing
91
+
92
+ - Updated dependencies [[`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d)]:
93
+ - @atlaspack/feature-flags@2.19.1
94
+ - @atlaspack/utils@2.17.1
95
+ - @atlaspack/plugin@2.14.19
96
+
97
+ ## 2.15.0
98
+
99
+ ### Minor Changes
100
+
101
+ - [#640](https://github.com/atlassian-labs/atlaspack/pull/640) [`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d) Thanks [@JakeLane](https://github.com/JakeLane)! - Clean up conditional bundling feature flags
102
+
103
+ ### Patch Changes
104
+
105
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`c4415a4`](https://github.com/atlassian-labs/atlaspack/commit/c4415a455543d984ca28452c2cb87a794d22497c), [`f0f7c71`](https://github.com/atlassian-labs/atlaspack/commit/f0f7c7168a1d3d18c6f30d2daed611275692b7c5), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
106
+ - @atlaspack/feature-flags@2.19.0
107
+ - @atlaspack/utils@2.17.0
108
+ - @atlaspack/plugin@2.14.18
109
+
110
+ ## 2.14.17
111
+
112
+ ### Patch Changes
113
+
114
+ - Updated dependencies []:
115
+ - @atlaspack/utils@2.16.1
116
+ - @atlaspack/plugin@2.14.17
117
+
118
+ ## 2.14.16
119
+
120
+ ### Patch Changes
121
+
122
+ - Updated dependencies [[`e8a60ff`](https://github.com/atlassian-labs/atlaspack/commit/e8a60ffbea41caef265786bbf73349771760081c), [`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
123
+ - @atlaspack/feature-flags@2.18.4
124
+ - @atlaspack/utils@2.16.0
125
+ - @atlaspack/plugin@2.14.16
126
+
127
+ ## 2.14.15
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [[`5ded263`](https://github.com/atlassian-labs/atlaspack/commit/5ded263c7f11b866e8885b81c73e20dd060b25be)]:
132
+ - @atlaspack/feature-flags@2.18.3
133
+ - @atlaspack/utils@2.15.3
134
+ - @atlaspack/plugin@2.14.15
135
+
136
+ ## 2.14.14
137
+
138
+ ### Patch Changes
139
+
140
+ - Updated dependencies [[`644b157`](https://github.com/atlassian-labs/atlaspack/commit/644b157dee72a871acc2d0facf0b87b8eea51956)]:
141
+ - @atlaspack/feature-flags@2.18.2
142
+ - @atlaspack/utils@2.15.2
143
+ - @atlaspack/plugin@2.14.14
144
+
145
+ ## 2.14.13
146
+
147
+ ### Patch Changes
148
+
149
+ - [#633](https://github.com/atlassian-labs/atlaspack/pull/633) [`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b) Thanks [@sbhuiyan-atlassian](https://github.com/sbhuiyan-atlassian)! - Ported various HMR changes from Parcel
150
+
151
+ - Updated dependencies [[`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b), [`0501255`](https://github.com/atlassian-labs/atlaspack/commit/05012550da35b05ce7d356a8cc29311e7f9afdca)]:
152
+ - @atlaspack/feature-flags@2.18.1
153
+ - @atlaspack/utils@2.15.1
154
+ - @atlaspack/plugin@2.14.13
155
+
156
+ ## 2.14.12
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies [[`10fbcfb`](https://github.com/atlassian-labs/atlaspack/commit/10fbcfbfa49c7a83da5d7c40983e36e87f524a75), [`85c52d3`](https://github.com/atlassian-labs/atlaspack/commit/85c52d3f7717b3c84a118d18ab98cfbfd71dcbd2), [`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
161
+ - @atlaspack/feature-flags@2.18.0
162
+ - @atlaspack/utils@2.15.0
163
+ - @atlaspack/plugin@2.14.12
164
+
165
+ ## 2.14.11
166
+
167
+ ### Patch Changes
168
+
169
+ - Updated dependencies [[`73ea3c4`](https://github.com/atlassian-labs/atlaspack/commit/73ea3c4d85d4401fdd15abcbf988237e890e7ad3), [`b1b3693`](https://github.com/atlassian-labs/atlaspack/commit/b1b369317c66f8a431c170df2ebba4fa5b2e38ef)]:
170
+ - @atlaspack/feature-flags@2.17.0
171
+ - @atlaspack/utils@2.14.11
172
+ - @atlaspack/plugin@2.14.11
173
+
174
+ ## 2.14.10
175
+
176
+ ### Patch Changes
177
+
178
+ - Updated dependencies []:
179
+ - @atlaspack/plugin@2.14.10
180
+ - @atlaspack/utils@2.14.10
181
+
182
+ ## 2.14.9
183
+
184
+ ### Patch Changes
185
+
186
+ - Updated dependencies [[`209692f`](https://github.com/atlassian-labs/atlaspack/commit/209692ffb11eae103a0d65c5e1118a5aa1625818), [`f4da1e1`](https://github.com/atlassian-labs/atlaspack/commit/f4da1e120e73eeb5e8b8927f05e88f04d6148c7b)]:
187
+ - @atlaspack/feature-flags@2.16.0
188
+ - @atlaspack/utils@2.14.9
189
+ - @atlaspack/plugin@2.14.9
190
+
191
+ ## 2.14.8
192
+
193
+ ### Patch Changes
194
+
195
+ - Updated dependencies [[`30f6017`](https://github.com/atlassian-labs/atlaspack/commit/30f60175ba4d272c5fc193973c63bc298584775b)]:
196
+ - @atlaspack/feature-flags@2.15.1
197
+ - @atlaspack/utils@2.14.8
198
+ - @atlaspack/plugin@2.14.8
199
+
200
+ ## 2.14.7
201
+
202
+ ### Patch Changes
203
+
204
+ - Updated dependencies [[`a1773d2`](https://github.com/atlassian-labs/atlaspack/commit/a1773d2a62d0ef7805ac7524621dcabcc1afe929)]:
205
+ - @atlaspack/feature-flags@2.15.0
206
+ - @atlaspack/utils@2.14.7
207
+ - @atlaspack/plugin@2.14.7
208
+
3
209
  ## 2.14.6
4
210
 
5
211
  ### Patch Changes
package/lib/JSRuntime.js CHANGED
@@ -76,8 +76,10 @@ const LOADERS = {
76
76
  }
77
77
  };
78
78
  function getLoaders(ctx) {
79
- if (ctx.isWorker()) return LOADERS.worker;
79
+ // @ts-expect-error TS2322
80
+ if (ctx.isWorker() || ctx.isTesseract()) return LOADERS.worker;
80
81
  if (ctx.isBrowser()) return LOADERS.browser;
82
+ // @ts-expect-error TS2322
81
83
  if (ctx.isNode()) return LOADERS.node;
82
84
  return null;
83
85
  }
@@ -162,9 +164,11 @@ var _default = exports.default = new (_plugin().Runtime)({
162
164
  // If this bundle already has the asset this dependency references,
163
165
  // return a simple runtime of `Promise.resolve(internalRequire(assetId))`.
164
166
  // The linker handles this for scope-hoisting.
167
+
168
+ const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') ? 'parcelRequire' : 'module.bundle.root';
165
169
  assets.push({
166
170
  filePath: __filename,
167
- code: `module.exports = Promise.resolve(module.bundle.root(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
171
+ code: `module.exports = Promise.resolve(${requireName}(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
168
172
  dependency,
169
173
  env: {
170
174
  sourceType: 'module'
@@ -175,7 +179,7 @@ var _default = exports.default = new (_plugin().Runtime)({
175
179
  // Resolve the dependency to a bundle. If inline, export the dependency id,
176
180
  // which will be replaced with the contents of that bundle later.
177
181
  let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
178
- if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
182
+ if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline' || (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inlineIsolated') {
179
183
  assets.push({
180
184
  filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
181
185
  code: `module.exports = Promise.resolve(${JSON.stringify(dependency.id)});`,
@@ -205,10 +209,22 @@ var _default = exports.default = new (_plugin().Runtime)({
205
209
  // replaced with a reference to this asset to implement the selection.
206
210
  const conditions = bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle);
207
211
  for (const cond of conditions) {
208
- const requireName = bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
209
- const assetCode = `module.exports = require('../helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return ${requireName}('${cond.ifTrueAssetId}')}, function (){return ${requireName}('${cond.ifFalseAssetId}')})`;
212
+ const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
213
+
214
+ // @ts-expect-error TS7006
215
+ const fallbackUrls = cond => {
216
+ return `[${[...cond.ifTrueBundles, ...cond.ifFalseBundles].map(target => {
217
+ let relativePathExpr = getRelativePathExpr(bundle, target, options);
218
+ return getAbsoluteUrlExpr(relativePathExpr, bundle, config.domainSharding);
219
+ }).join(',')}]`;
220
+ };
221
+ const shouldUseFallback = options.mode === 'development' ? (0, _featureFlags().getFeatureFlag)('condbDevFallbackDev') : (0, _featureFlags().getFeatureFlag)('condbDevFallbackProd');
222
+ const loaderPath = `./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}`;
223
+ const ifTrue = `function (){return ${requireName}('${cond.ifTrueAssetId}')}`;
224
+ const ifFalse = `function (){return ${requireName}('${cond.ifFalseAssetId}')}`;
225
+ const assetCode = `module.exports = require('${loaderPath}')('${cond.key}', ${ifTrue}, ${ifFalse}${shouldUseFallback ? `, {loader: require('./helpers/browser/sync-js-loader'), urls: ${fallbackUrls(cond)}}` : ''})`;
210
226
  assets.push({
211
- filePath: _path().default.join(__dirname, `/conditions/${cond.publicId}.js`),
227
+ filePath: _path().default.join(__dirname, `/conditions-${cond.publicId}.js`),
212
228
  code: assetCode,
213
229
  // This dependency is important, as it's the last symbol handled in scope hoisting.
214
230
  // That means that scope hoisting will use the module id for this asset to replace the symbol
@@ -224,7 +240,7 @@ var _default = exports.default = new (_plugin().Runtime)({
224
240
  // Resolve the dependency to a bundle. If inline, export the dependency id,
225
241
  // which will be replaced with the contents of that bundle later.
226
242
  let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
227
- if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
243
+ if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline' || (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inlineIsolated') {
228
244
  assets.push({
229
245
  filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
230
246
  code: `module.exports = ${JSON.stringify(dependency.id)};`,
@@ -263,7 +279,7 @@ var _default = exports.default = new (_plugin().Runtime)({
263
279
 
264
280
  // Skip URL runtimes for library builds. This is handled in packaging so that
265
281
  // the url is inlined and statically analyzable.
266
- if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated') {
282
+ if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated' && mainBundle.bundleBehavior !== 'inlineIsolated') {
267
283
  continue;
268
284
  }
269
285
 
@@ -297,7 +313,7 @@ var _default = exports.default = new (_plugin().Runtime)({
297
313
  });
298
314
  }
299
315
  }
300
- if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline') && isNewContext(bundle, bundleGraph)) {
316
+ if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline' && b.bundleBehavior !== 'inlineIsolated') && isNewContext(bundle, bundleGraph)) {
301
317
  assets.push({
302
318
  filePath: __filename,
303
319
  code: getRegisterCode(bundle, bundleGraph),
@@ -357,10 +373,16 @@ function getLoaderRuntime({
357
373
  return;
358
374
  }
359
375
  let externalBundles = bundleGraph.getBundlesInBundleGroup(bundleGroup);
360
- let mainBundle = (0, _nullthrows().default)(externalBundles.find(bundle => {
361
- var _bundle$getMainEntry;
362
- return ((_bundle$getMainEntry = bundle.getMainEntry()) === null || _bundle$getMainEntry === void 0 ? void 0 : _bundle$getMainEntry.id) === bundleGroup.entryAssetId;
363
- }));
376
+ let potentialMainBundle;
377
+ if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
378
+ potentialMainBundle = externalBundles.find(bundle => bundle.getEntryAssets().some(asset => asset.id === bundleGroup.entryAssetId));
379
+ } else {
380
+ potentialMainBundle = externalBundles.find(bundle => {
381
+ var _bundle$getMainEntry;
382
+ return ((_bundle$getMainEntry = bundle.getMainEntry()) === null || _bundle$getMainEntry === void 0 ? void 0 : _bundle$getMainEntry.id) === bundleGroup.entryAssetId;
383
+ });
384
+ }
385
+ let mainBundle = (0, _nullthrows().default)(potentialMainBundle);
364
386
 
365
387
  // CommonJS is a synchronous module system, so there is no need to load bundles in parallel.
366
388
  // Importing of the other bundles will be handled by the bundle group entry.
@@ -385,6 +407,7 @@ function getLoaderRuntime({
385
407
  let needsEsmLoadPrelude = false;
386
408
  let loaderModules = [];
387
409
  function getLoaderForBundle(bundle, to, shardingConfig) {
410
+ // @ts-expect-error TS18049
388
411
  let loader = loaders[to.type];
389
412
  if (!loader) {
390
413
  return;
@@ -400,7 +423,11 @@ function getLoaderRuntime({
400
423
  if (!needsDynamicImportPolyfill) {
401
424
  return `__parcel__import__("./" + ${relativePathExpr})`;
402
425
  }
403
- loader = (0, _nullthrows().default)(loaders.IMPORT_POLYFILL, `No import() polyfill available for context '${bundle.env.context}'`);
426
+
427
+ // @ts-expect-error TS2322
428
+ loader = (0, _nullthrows().default)(
429
+ // @ts-expect-error TS18049
430
+ loaders.IMPORT_POLYFILL, `No import() polyfill available for context '${bundle.env.context}'`);
404
431
  } else if (to.type === 'js' && to.env.outputFormat === 'commonjs') {
405
432
  return `Promise.resolve(__parcel__require__("./" + ${relativePathExpr}))`;
406
433
  }
@@ -434,8 +461,16 @@ function getLoaderRuntime({
434
461
  const loaders = [];
435
462
  for (const cond of conditions) {
436
463
  // This bundle has a conditional dependency, we need to load the bundle group
437
- const ifTrueLoaders = cond.ifTrueBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(cond.ifTrueBundles.map(targetBundle => getLoaderForBundle(sourceBundle, targetBundle)));
438
- const ifFalseLoaders = cond.ifFalseBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(cond.ifFalseBundles.map(targetBundle => getLoaderForBundle(sourceBundle, targetBundle)));
464
+ const ifTrueLoaders = cond.ifTrueBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(
465
+ // @ts-expect-error TS2769
466
+ cond.ifTrueBundles.map(targetBundle =>
467
+ // @ts-expect-error TS2554
468
+ getLoaderForBundle(sourceBundle, targetBundle)));
469
+ const ifFalseLoaders = cond.ifFalseBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(
470
+ // @ts-expect-error TS2769
471
+ cond.ifFalseBundles.map(targetBundle =>
472
+ // @ts-expect-error TS2554
473
+ getLoaderForBundle(sourceBundle, targetBundle)));
439
474
  if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
440
475
  // Load conditional bundles with helper (and a dev mode with additional hints)
441
476
  loaders.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return Promise.all([${ifTrueLoaders.join(',')}]);}, function (){return Promise.all([${ifFalseLoaders.join(',')}]);})`);
@@ -444,21 +479,8 @@ function getLoaderRuntime({
444
479
  return loaders;
445
480
  }
446
481
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
447
- if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingNestedRuntime')) {
448
- let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
449
- loaderModules.push(...getConditionalLoadersForCondition(conditionalDependencies, bundle));
450
- } else {
451
- let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
452
- for (const cond of bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle)) {
453
- // This bundle has a conditional dependency, we need to load the bundle group
454
- const ifTrueLoaders = cond.ifTrueBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle));
455
- const ifFalseLoaders = cond.ifFalseBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle));
456
- if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
457
- // Load conditional bundles with helper (and a dev mode with additional hints)
458
- loaderModules.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return Promise.all([${ifTrueLoaders.join(',')}]);}, function (){return Promise.all([${ifFalseLoaders.join(',')}]);})`);
459
- }
460
- }
461
- }
482
+ let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
483
+ loaderModules.push(...getConditionalLoadersForCondition(conditionalDependencies, bundle));
462
484
  }
463
485
  for (let to of externalBundles) {
464
486
  let loaderModule = getLoaderForBundle(bundle, to, shardingConfig);
@@ -488,7 +510,7 @@ function getLoaderRuntime({
488
510
  loaderCode = `(${loaderCode})`;
489
511
  }
490
512
  if (mainBundle.type === 'js') {
491
- let parcelRequire = bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
513
+ let parcelRequire = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
492
514
  loaderCode += `.then(() => ${parcelRequire}('${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(bundleGroup.entryAssetId))}'))`;
493
515
  }
494
516
  if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
@@ -534,14 +556,16 @@ function getHintedBundleGroups(bundleGraph, bundle) {
534
556
  var _dependency$meta;
535
557
  let attributes = (_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.importAttributes;
536
558
  if (typeof attributes === 'object' && attributes != null && (
537
- // $FlowFixMe
559
+ // @ts-expect-error TS2339
538
560
  attributes.preload || attributes.prefetch)) {
539
561
  let resolved = bundleGraph.resolveAsyncDependency(dependency, bundle);
540
562
  if ((resolved === null || resolved === void 0 ? void 0 : resolved.type) === 'bundle_group') {
541
563
  // === true for flow
564
+ // @ts-expect-error TS2339
542
565
  if (attributes.preload === true) {
543
566
  preload.push(resolved.value);
544
567
  }
568
+ // @ts-expect-error TS2339
545
569
  if (attributes.prefetch === true) {
546
570
  prefetch.push(resolved.value);
547
571
  }
@@ -559,8 +583,11 @@ function getHintLoaders(bundleGraph, from, bundleGroups, loader, options) {
559
583
  let bundlesToPreload = bundleGraph.getBundlesInBundleGroup(bundleGroupToPreload);
560
584
  for (let bundleToPreload of bundlesToPreload) {
561
585
  let relativePathExpr = getRelativePathExpr(from, bundleToPreload, options);
586
+ // @ts-expect-error TS7053
562
587
  let priority = TYPE_TO_RESOURCE_PRIORITY[bundleToPreload.type];
563
- hintLoaders.push(`require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(relativePathExpr, from)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify(bundleToPreload.target.env.outputFormat === 'esmodule')})`);
588
+ hintLoaders.push(
589
+ // @ts-expect-error TS2554
590
+ `require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(relativePathExpr, from)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify(bundleToPreload.target.env.outputFormat === 'esmodule')})`);
564
591
  }
565
592
  }
566
593
  return hintLoaders;
@@ -571,7 +598,12 @@ function isNewContext(bundle, bundleGraph) {
571
598
  return isInEntryBundleGroup || parents.length === 0 || parents.some(parent => parent.env.context !== bundle.env.context || parent.type !== 'js');
572
599
  }
573
600
  function getURLRuntime(dependency, from, to, options, shardingConfig) {
574
- let relativePathExpr = getRelativePathExpr(from, to, options);
601
+ let relativePathExpr;
602
+ if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
603
+ relativePathExpr = getRelativePathExpr(from, to, options, true);
604
+ } else {
605
+ relativePathExpr = getRelativePathExpr(from, to, options);
606
+ }
575
607
  let code;
576
608
  if (dependency.meta.webworker === true && !from.env.isLibrary) {
577
609
  code = `let workerURL = require('./helpers/get-worker-url');\n`;
@@ -599,9 +631,10 @@ function getURLRuntime(dependency, from, to, options, shardingConfig) {
599
631
  };
600
632
  }
601
633
  function getRegisterCode(entryBundle, bundleGraph) {
634
+ // @ts-expect-error TS2304
602
635
  let mappings = [];
603
636
  bundleGraph.traverseBundles((bundle, _, actions) => {
604
- if (bundle.bundleBehavior === 'inline') {
637
+ if (bundle.bundleBehavior === 'inline' || bundle.bundleBehavior === 'inlineIsolated') {
605
638
  return;
606
639
  }
607
640
 
@@ -625,13 +658,19 @@ function getRegisterCode(entryBundle, bundleGraph) {
625
658
  : `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;
626
659
  return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(JSON.stringify(mappings))}));`;
627
660
  }
628
- function getRelativePathExpr(from, to, options) {
661
+ function getRelativePathExpr(from, to, options, isURL = to.type !== 'js') {
629
662
  let relativePath = (0, _utils().relativeBundlePath)(from, to, {
630
663
  leadingDotSlash: false
631
664
  });
632
665
  let res = JSON.stringify(relativePath);
633
- if (options.hmrOptions) {
634
- res += ' + "?" + Date.now()';
666
+ if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
667
+ if (isURL && options.hmrOptions) {
668
+ res += ' + "?" + Date.now()';
669
+ }
670
+ } else {
671
+ if (options.hmrOptions) {
672
+ res += ' + "?" + Date.now()';
673
+ }
635
674
  }
636
675
  return res;
637
676
  }
@@ -648,7 +687,7 @@ function getAbsoluteUrlExpr(relativePathExpr, fromBundle, shardingConfig) {
648
687
  }
649
688
  function shouldUseRuntimeManifest(bundle, options) {
650
689
  let env = bundle.env;
651
- return !env.isLibrary && bundle.bundleBehavior !== 'inline' && env.isBrowser() && options.mode === 'production';
690
+ return !env.isLibrary && bundle.bundleBehavior !== 'inline' && bundle.bundleBehavior !== 'inlineIsolated' && env.isBrowser() && options.mode === 'production';
652
691
  }
653
692
  function getManifestBundlePriority(bundleGraph, bundle, threshold) {
654
693
  let bundleSize = 0;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
4
+ module.exports = cacheLoader(function loadCSSBundle(bundle) {
5
5
  return new Promise(function (resolve, reject) {
6
6
  // Don't insert the same link element twice (e.g. if it was already in the HTML)
7
7
  let existingLinks = document.getElementsByTagName('link');
8
- if ([].concat(existingLinks).some(function (link) {
8
+ let isCurrentBundle = function (link) {
9
9
  return link.href === bundle && link.rel.indexOf('stylesheet') > -1;
10
- })) {
10
+ };
11
+ if ([].concat(existingLinks).some(isCurrentBundle)) {
11
12
  resolve();
12
13
  return;
13
14
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
4
+ module.exports = cacheLoader(function loadHTMLBundle(bundle) {
5
5
  return fetch(bundle).then(function (res) {
6
6
  return res.text();
7
7
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
4
+ module.exports = cacheLoader(function importModule(bundle) {
5
5
  return new Promise((resolve, reject) => {
6
6
  // Add a global function to handle when the script loads.
7
7
  let globalName = `i${('' + Math.random()).slice(2)}`;
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
4
+ module.exports = cacheLoader(function loadJSBundle(bundle) {
5
5
  return new Promise(function (resolve, reject) {
6
6
  // Don't insert the same script twice (e.g. if it was already in the HTML)
7
7
  let existingScripts = document.getElementsByTagName('script');
8
- if ([].concat(existingScripts).some(function (script) {
8
+ let isCurrentBundle = function (script) {
9
9
  return script.src === bundle;
10
- })) {
10
+ };
11
+ if ([].concat(existingScripts).some(isCurrentBundle)) {
11
12
  resolve();
12
13
  return;
13
14
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle, priority) {
4
+ module.exports = cacheLoader(function prefetchJSBundle(bundle, priority) {
5
5
  var link = document.createElement('link');
6
6
  link.rel = 'prefetch';
7
7
  link.href = bundle;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle, priority, isModule) {
4
+ module.exports = cacheLoader(function preloadJSBundle(bundle, priority, isModule) {
5
5
  var link = document.createElement('link');
6
6
  link.charset = 'utf-8';
7
7
  link.rel = isModule ? 'modulepreload' : 'preload';
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ const cacheLoader = require('../cacheLoader');
4
+ module.exports = function loadJSBundle(bundle) {
5
+ // Don't insert the same script twice (e.g. if it was already in the HTML)
6
+ let existingScripts = document.getElementsByTagName('script');
7
+ let isCurrentBundle = function (script) {
8
+ return script.src === bundle;
9
+ };
10
+ if ([].concat(existingScripts).some(isCurrentBundle)) {
11
+ return;
12
+ }
13
+
14
+ // Request using XHR because it's synchronous and we can't use promises here
15
+ // This has extremely poor performance because we're idle during this fetch, so we only use this so that the app won't crash
16
+ const xhr = new XMLHttpRequest();
17
+ xhr.open('GET', bundle, false);
18
+ try {
19
+ xhr.send();
20
+ if (xhr.status === 200) {
21
+ const script = document.createElement('script');
22
+ script.type = 'text/javascript';
23
+ script.text = xhr.responseText;
24
+
25
+ // Execute the script synchronously
26
+ document.head.appendChild(script);
27
+ } else {
28
+ throw new TypeError(`Failed to fetch dynamically imported module: ${bundle}. Status: ${xhr.status}`);
29
+ }
30
+ } catch (e) {
31
+ throw new TypeError(`Failed to fetch dynamically imported module: ${bundle}. Error: ${e.message}`);
32
+ }
33
+ };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
4
+ module.exports = cacheLoader(function loadWASMBundle(bundle) {
5
5
  return fetch(bundle).then(function (res) {
6
6
  if (WebAssembly.instantiateStreaming) {
7
7
  return WebAssembly.instantiateStreaming(res);
@@ -13,7 +13,7 @@ function getCache(type) {
13
13
  return cachedBundles;
14
14
  }
15
15
  }
16
- module.exports = function (loader, type) {
16
+ module.exports = function cacheLoader(loader, type) {
17
17
  return function (bundle) {
18
18
  let cache = getCache(type);
19
19
  if (cache[bundle]) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- module.exports = function (cond, ifTrue, ifFalse) {
3
+ module.exports = function loadCond(cond, ifTrue, ifFalse, fallback) {
4
4
  if (typeof globalThis.__MCOND !== 'function') {
5
5
  throw new TypeError('"globalThis.__MCOND" was not set to an object. Ensure the function is set to return the key condition for conditional bundles to load with.');
6
6
  }
@@ -10,7 +10,14 @@ module.exports = function (cond, ifTrue, ifFalse) {
10
10
  try {
11
11
  return globalThis.__MCOND(cond) ? ifTrue() : ifFalse();
12
12
  } catch (err) {
13
- console.error('Conditional dependency was missing. Ensure the server sends the correct scripts to the client ("conditional-manifest.json").');
14
- throw err;
13
+ console.error('Conditional dependency was not registered when executing. Ensure the server sends the correct scripts to the client. Falling back to synchronous bundle loading.');
14
+ if (fallback) {
15
+ for (const url of fallback.urls) {
16
+ fallback.loader(url);
17
+ }
18
+ return globalThis.__MCOND(cond) ? ifTrue() : ifFalse();
19
+ } else {
20
+ throw new Error('No fallback urls specified, cannot fallback safely');
21
+ }
15
22
  }
16
23
  };