@atlaspack/runtime-js 2.14.5-canary.45 → 2.14.5-canary.450

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 (35) hide show
  1. package/CHANGELOG.md +539 -0
  2. package/dist/JSRuntime.js +943 -0
  3. package/lib/JSRuntime.js +416 -41
  4. package/lib/helpers/browser/analytics/analytics.d.js +1 -0
  5. package/lib/helpers/browser/css-loader.js +4 -3
  6. package/lib/helpers/browser/html-loader.js +1 -1
  7. package/lib/helpers/browser/import-polyfill.js +1 -1
  8. package/lib/helpers/browser/js-loader.js +4 -3
  9. package/lib/helpers/browser/prefetch-loader.js +1 -1
  10. package/lib/helpers/browser/preload-loader.js +1 -1
  11. package/lib/helpers/browser/sync-js-loader.js +32 -0
  12. package/lib/helpers/browser/wasm-loader.js +1 -1
  13. package/lib/helpers/cacheLoader.js +1 -1
  14. package/lib/helpers/conditional-loader-dev.js +12 -3
  15. package/lib/helpers/conditional-loader.js +22 -2
  16. package/lib/helpers/get-worker-url.js +1 -1
  17. package/lib/helpers/node/css-loader.js +1 -1
  18. package/lib/helpers/node/html-loader.js +1 -1
  19. package/lib/helpers/node/js-loader.js +1 -1
  20. package/lib/helpers/node/wasm-loader.js +1 -1
  21. package/lib/helpers/worker/js-loader.js +1 -1
  22. package/lib/helpers/worker/wasm-loader.js +1 -1
  23. package/lib/types/JSRuntime.d.ts +9 -0
  24. package/package.json +15 -10
  25. package/src/{JSRuntime.js → JSRuntime.ts} +502 -113
  26. package/src/helpers/browser/preload-loader.js +1 -2
  27. package/src/helpers/browser/sync-js-loader.js +37 -0
  28. package/src/helpers/conditional-loader-dev.js +17 -3
  29. package/src/helpers/conditional-loader.js +24 -2
  30. package/test/analytics.test.ts +4 -1
  31. package/test/{bundle-url.test.js → bundle-url.test.ts} +1 -2
  32. package/test/esm-js-loader-retry.test.ts +4 -7
  33. package/tsconfig.json +27 -0
  34. package/tsconfig.tsbuildinfo +1 -0
  35. package/src/helpers/browser/analytics/analytics.js.flow +0 -10
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,12 +164,22 @@ 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
+ },
176
+ // Pre-computed symbols: exports Promise, no external dependencies (uses global)
177
+ symbolData: {
178
+ symbols: new Map([['default', {
179
+ local: 'module.exports',
180
+ loc: null
181
+ }]]),
182
+ dependencies: []
171
183
  }
172
184
  });
173
185
  }
@@ -175,13 +187,21 @@ var _default = exports.default = new (_plugin().Runtime)({
175
187
  // Resolve the dependency to a bundle. If inline, export the dependency id,
176
188
  // which will be replaced with the contents of that bundle later.
177
189
  let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
178
- if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
190
+ if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline' || (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inlineIsolated') {
179
191
  assets.push({
180
192
  filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
181
193
  code: `module.exports = Promise.resolve(${JSON.stringify(dependency.id)});`,
182
194
  dependency,
183
195
  env: {
184
196
  sourceType: 'module'
197
+ },
198
+ // Pre-computed symbols: exports Promise, no external dependencies
199
+ symbolData: {
200
+ symbols: new Map([['default', {
201
+ local: 'module.exports',
202
+ loc: null
203
+ }]]),
204
+ dependencies: []
185
205
  }
186
206
  });
187
207
  continue;
@@ -205,10 +225,28 @@ var _default = exports.default = new (_plugin().Runtime)({
205
225
  // replaced with a reference to this asset to implement the selection.
206
226
  const conditions = bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle);
207
227
  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}')})`;
228
+ const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
229
+
230
+ // We have fallback behaviour that can be used in development mode, so we need to handle both types of packagers
231
+ const getFallbackArgs = cond => {
232
+ const fallbackUrls = () => {
233
+ return `urls: [${[...cond.ifTrueBundles, ...cond.ifFalseBundles].map(target => {
234
+ let relativePathExpr = getRelativePathExpr(bundle, target, options);
235
+ return getAbsoluteUrlExpr(relativePathExpr, bundle, config.domainSharding);
236
+ }).join(',')}]`;
237
+ };
238
+ const fallbackBundleIds = () => {
239
+ return `i: [${[...cond.ifTrueBundles, ...cond.ifFalseBundles].map(target => `"${target.publicId}"`).join(',')}]`;
240
+ };
241
+ return `, {l: require('./helpers/browser/sync-js-loader'), ${options.mode === 'development' ? fallbackUrls() : fallbackBundleIds()}}`;
242
+ };
243
+ const shouldUseFallback = options.mode === 'development' ? (0, _featureFlags().getFeatureFlag)('condbDevFallbackDev') : (0, _featureFlags().getFeatureFlag)('condbDevFallbackProd');
244
+ const loaderPath = `./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}`;
245
+ const ifTrue = `function (){return ${requireName}('${cond.ifTrueAssetId}')}`;
246
+ const ifFalse = `function (){return ${requireName}('${cond.ifFalseAssetId}')}`;
247
+ const assetCode = `module.exports = require('${loaderPath}')('${cond.key}', ${ifTrue}, ${ifFalse}${shouldUseFallback ? getFallbackArgs(cond) : ''})`;
210
248
  assets.push({
211
- filePath: _path().default.join(__dirname, `/conditions/${cond.publicId}.js`),
249
+ filePath: _path().default.join(__dirname, `/conditions-${cond.publicId}.js`),
212
250
  code: assetCode,
213
251
  // This dependency is important, as it's the last symbol handled in scope hoisting.
214
252
  // That means that scope hoisting will use the module id for this asset to replace the symbol
@@ -216,6 +254,30 @@ var _default = exports.default = new (_plugin().Runtime)({
216
254
  dependency: cond.ifFalseDependency,
217
255
  env: {
218
256
  sourceType: 'module'
257
+ },
258
+ // Pre-computed symbols: conditional loader with potential sync-js-loader fallback
259
+ symbolData: {
260
+ symbols: new Map([['default', {
261
+ local: 'module.exports',
262
+ loc: null
263
+ }]]),
264
+ dependencies: [{
265
+ specifier: loaderPath,
266
+ symbols: new Map([['default', {
267
+ local: 'default',
268
+ loc: null,
269
+ isWeak: false
270
+ }]]),
271
+ usedSymbols: new Set(['default'])
272
+ }, ...(shouldUseFallback ? [{
273
+ specifier: './helpers/browser/sync-js-loader',
274
+ symbols: new Map([['default', {
275
+ local: 'l',
276
+ loc: null,
277
+ isWeak: false
278
+ }]]),
279
+ usedSymbols: new Set(['default'])
280
+ }] : [])]
219
281
  }
220
282
  });
221
283
  }
@@ -224,13 +286,21 @@ var _default = exports.default = new (_plugin().Runtime)({
224
286
  // Resolve the dependency to a bundle. If inline, export the dependency id,
225
287
  // which will be replaced with the contents of that bundle later.
226
288
  let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
227
- if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
289
+ if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline' || (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inlineIsolated') {
228
290
  assets.push({
229
291
  filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
230
292
  code: `module.exports = ${JSON.stringify(dependency.id)};`,
231
293
  dependency,
232
294
  env: {
233
295
  sourceType: 'module'
296
+ },
297
+ // Pre-computed symbols: simple export with no dependencies
298
+ symbolData: {
299
+ symbols: new Map([['default', {
300
+ local: 'module.exports',
301
+ loc: null
302
+ }]]),
303
+ dependencies: []
234
304
  }
235
305
  });
236
306
  continue;
@@ -248,6 +318,14 @@ var _default = exports.default = new (_plugin().Runtime)({
248
318
  dependency,
249
319
  env: {
250
320
  sourceType: 'module'
321
+ },
322
+ // Pre-computed symbols: simple export with no dependencies
323
+ symbolData: {
324
+ symbols: new Map([['default', {
325
+ local: 'module.exports',
326
+ loc: null
327
+ }]]),
328
+ dependencies: []
251
329
  }
252
330
  });
253
331
  continue;
@@ -263,7 +341,7 @@ var _default = exports.default = new (_plugin().Runtime)({
263
341
 
264
342
  // Skip URL runtimes for library builds. This is handled in packaging so that
265
343
  // the url is inlined and statically analyzable.
266
- if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated') {
344
+ if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated' && mainBundle.bundleBehavior !== 'inlineIsolated') {
267
345
  continue;
268
346
  }
269
347
 
@@ -293,11 +371,25 @@ var _default = exports.default = new (_plugin().Runtime)({
293
371
  isEntry: true,
294
372
  env: {
295
373
  sourceType: 'module'
374
+ },
375
+ // Pre-computed symbols: lazy bundle loader, requires specific loader helper
376
+ symbolData: {
377
+ symbols: new Map(),
378
+ // No exports, just side effects
379
+ dependencies: [{
380
+ specifier: loader,
381
+ symbols: new Map([['default', {
382
+ local: 'default',
383
+ loc: null,
384
+ isWeak: false
385
+ }]]),
386
+ usedSymbols: new Set(['default'])
387
+ }]
296
388
  }
297
389
  });
298
390
  }
299
391
  }
300
- if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline') && isNewContext(bundle, bundleGraph)) {
392
+ if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline' && b.bundleBehavior !== 'inlineIsolated') && isNewContext(bundle, bundleGraph)) {
301
393
  assets.push({
302
394
  filePath: __filename,
303
395
  code: getRegisterCode(bundle, bundleGraph),
@@ -305,7 +397,22 @@ var _default = exports.default = new (_plugin().Runtime)({
305
397
  env: {
306
398
  sourceType: 'module'
307
399
  },
308
- priority: getManifestBundlePriority(bundleGraph, bundle, config.splitManifestThreshold)
400
+ runtimeAssetRequiringExecutionOnLoad: true,
401
+ priority: getManifestBundlePriority(bundleGraph, bundle, config.splitManifestThreshold),
402
+ // Pre-computed symbols: requires bundle-manifest helper
403
+ symbolData: {
404
+ symbols: new Map(),
405
+ // No exports, just executes
406
+ dependencies: [{
407
+ specifier: './helpers/bundle-manifest',
408
+ symbols: new Map([['register', {
409
+ local: 'register',
410
+ loc: null,
411
+ isWeak: false
412
+ }]]),
413
+ usedSymbols: new Set(['register'])
414
+ }]
415
+ }
309
416
  });
310
417
  }
311
418
  return assets;
@@ -357,10 +464,16 @@ function getLoaderRuntime({
357
464
  return;
358
465
  }
359
466
  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
- }));
467
+ let potentialMainBundle;
468
+ if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
469
+ potentialMainBundle = externalBundles.find(bundle => bundle.getEntryAssets().some(asset => asset.id === bundleGroup.entryAssetId));
470
+ } else {
471
+ potentialMainBundle = externalBundles.find(bundle => {
472
+ var _bundle$getMainEntry;
473
+ return ((_bundle$getMainEntry = bundle.getMainEntry()) === null || _bundle$getMainEntry === void 0 ? void 0 : _bundle$getMainEntry.id) === bundleGroup.entryAssetId;
474
+ });
475
+ }
476
+ let mainBundle = (0, _nullthrows().default)(potentialMainBundle);
364
477
 
365
478
  // CommonJS is a synchronous module system, so there is no need to load bundles in parallel.
366
479
  // Importing of the other bundles will be handled by the bundle group entry.
@@ -385,6 +498,7 @@ function getLoaderRuntime({
385
498
  let needsEsmLoadPrelude = false;
386
499
  let loaderModules = [];
387
500
  function getLoaderForBundle(bundle, to, shardingConfig) {
501
+ // @ts-expect-error TS18049
388
502
  let loader = loaders[to.type];
389
503
  if (!loader) {
390
504
  return;
@@ -400,7 +514,11 @@ function getLoaderRuntime({
400
514
  if (!needsDynamicImportPolyfill) {
401
515
  return `__parcel__import__("./" + ${relativePathExpr})`;
402
516
  }
403
- loader = (0, _nullthrows().default)(loaders.IMPORT_POLYFILL, `No import() polyfill available for context '${bundle.env.context}'`);
517
+
518
+ // @ts-expect-error TS2322
519
+ loader = (0, _nullthrows().default)(
520
+ // @ts-expect-error TS18049
521
+ loaders.IMPORT_POLYFILL, `No import() polyfill available for context '${bundle.env.context}'`);
404
522
  } else if (to.type === 'js' && to.env.outputFormat === 'commonjs') {
405
523
  return `Promise.resolve(__parcel__require__("./" + ${relativePathExpr}))`;
406
524
  }
@@ -434,8 +552,16 @@ function getLoaderRuntime({
434
552
  const loaders = [];
435
553
  for (const cond of conditions) {
436
554
  // 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)));
555
+ const ifTrueLoaders = cond.ifTrueBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(
556
+ // @ts-expect-error TS2769
557
+ cond.ifTrueBundles.map(targetBundle =>
558
+ // @ts-expect-error TS2554
559
+ getLoaderForBundle(sourceBundle, targetBundle)));
560
+ const ifFalseLoaders = cond.ifFalseBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(
561
+ // @ts-expect-error TS2769
562
+ cond.ifFalseBundles.map(targetBundle =>
563
+ // @ts-expect-error TS2554
564
+ getLoaderForBundle(sourceBundle, targetBundle)));
439
565
  if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
440
566
  // Load conditional bundles with helper (and a dev mode with additional hints)
441
567
  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 +570,8 @@ function getLoaderRuntime({
444
570
  return loaders;
445
571
  }
446
572
  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
- }
573
+ let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
574
+ loaderModules.push(...getConditionalLoadersForCondition(conditionalDependencies, bundle));
462
575
  }
463
576
  for (let to of externalBundles) {
464
577
  let loaderModule = getLoaderForBundle(bundle, to, shardingConfig);
@@ -488,7 +601,7 @@ function getLoaderRuntime({
488
601
  loaderCode = `(${loaderCode})`;
489
602
  }
490
603
  if (mainBundle.type === 'js') {
491
- let parcelRequire = bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
604
+ let parcelRequire = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
492
605
  loaderCode += `.then(() => ${parcelRequire}('${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(bundleGroup.entryAssetId))}'))`;
493
606
  }
494
607
  if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
@@ -506,6 +619,22 @@ function getLoaderRuntime({
506
619
  dependency,
507
620
  env: {
508
621
  sourceType: 'module'
622
+ },
623
+ // Pre-computed symbols: ESM loader with retry, requires esm-js-loader-retry helper
624
+ symbolData: {
625
+ symbols: new Map([['default', {
626
+ local: 'module.exports',
627
+ loc: null
628
+ }]]),
629
+ dependencies: [{
630
+ specifier: './helpers/browser/esm-js-loader-retry',
631
+ symbols: new Map([['default', {
632
+ local: 'default',
633
+ loc: null,
634
+ isWeak: false
635
+ }]]),
636
+ usedSymbols: new Set(['default'])
637
+ }]
509
638
  }
510
639
  };
511
640
  }
@@ -515,12 +644,165 @@ function getLoaderRuntime({
515
644
  code.push(preludeLoad);
516
645
  }
517
646
  code.push(`module.exports = ${loaderCode};`);
647
+
648
+ // Collect all potential helper dependencies used in loader runtime
649
+ let helperDependencies = [];
650
+
651
+ // Always potential dependencies based on the code patterns
652
+ if (needsEsmLoadPrelude) {
653
+ if (shardingConfig) {
654
+ helperDependencies.push({
655
+ specifier: './helpers/browser/esm-js-loader-shards',
656
+ symbols: new Map([['default', {
657
+ local: 'default',
658
+ loc: null,
659
+ isWeak: false
660
+ }]]),
661
+ usedSymbols: new Set(['default'])
662
+ });
663
+ } else {
664
+ helperDependencies.push({
665
+ specifier: './helpers/browser/esm-js-loader',
666
+ symbols: new Map([['default', {
667
+ local: 'default',
668
+ loc: null,
669
+ isWeak: false
670
+ }]]),
671
+ usedSymbols: new Set(['default'])
672
+ });
673
+ }
674
+ }
675
+
676
+ // Bundle manifest dependency if using runtime manifest
677
+ if (shouldUseRuntimeManifest(bundle, options)) {
678
+ helperDependencies.push({
679
+ specifier: './helpers/bundle-manifest',
680
+ symbols: new Map([['resolve', {
681
+ local: 'resolve',
682
+ loc: null,
683
+ isWeak: false
684
+ }]]),
685
+ usedSymbols: new Set(['resolve'])
686
+ });
687
+ }
688
+
689
+ // Domain sharding dependency if configured
690
+ if (shardingConfig) {
691
+ helperDependencies.push({
692
+ specifier: '@atlaspack/domain-sharding',
693
+ symbols: new Map([['shardUrl', {
694
+ local: 'shardUrl',
695
+ loc: null,
696
+ isWeak: false
697
+ }]]),
698
+ usedSymbols: new Set(['shardUrl'])
699
+ });
700
+ }
701
+
702
+ // Various loader dependencies based on bundle types in externalBundles
703
+ for (let to of externalBundles) {
704
+ let loader = loaders[to.type];
705
+ if (loader && typeof loader === 'string') {
706
+ helperDependencies.push({
707
+ specifier: loader,
708
+ symbols: new Map([['default', {
709
+ local: 'default',
710
+ loc: null,
711
+ isWeak: false
712
+ }]]),
713
+ usedSymbols: new Set(['default'])
714
+ });
715
+ }
716
+ }
717
+
718
+ // Import polyfill if needed
719
+ if (needsDynamicImportPolyfill && loaders !== null && loaders !== void 0 && loaders.IMPORT_POLYFILL) {
720
+ helperDependencies.push({
721
+ specifier: loaders.IMPORT_POLYFILL,
722
+ symbols: new Map([['default', {
723
+ local: 'default',
724
+ loc: null,
725
+ isWeak: false
726
+ }]]),
727
+ usedSymbols: new Set(['default'])
728
+ });
729
+ }
730
+
731
+ // Conditional loaders if using conditional bundling
732
+ if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
733
+ const loaderPath = `./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}`;
734
+ helperDependencies.push({
735
+ specifier: loaderPath,
736
+ symbols: new Map([['default', {
737
+ local: 'default',
738
+ loc: null,
739
+ isWeak: false
740
+ }]]),
741
+ usedSymbols: new Set(['default'])
742
+ });
743
+
744
+ // Sync loader for fallback
745
+ if (options.mode === 'development') {
746
+ helperDependencies.push({
747
+ specifier: './helpers/browser/sync-js-loader',
748
+ symbols: new Map([['default', {
749
+ local: 'default',
750
+ loc: null,
751
+ isWeak: false
752
+ }]]),
753
+ usedSymbols: new Set(['default'])
754
+ });
755
+ }
756
+ }
757
+
758
+ // Preload/prefetch loaders for browser context
759
+ if (bundle.env.context === 'browser') {
760
+ helperDependencies.push({
761
+ specifier: BROWSER_PRELOAD_LOADER,
762
+ symbols: new Map([['default', {
763
+ local: 'default',
764
+ loc: null,
765
+ isWeak: false
766
+ }]]),
767
+ usedSymbols: new Set(['default'])
768
+ });
769
+ helperDependencies.push({
770
+ specifier: BROWSER_PREFETCH_LOADER,
771
+ symbols: new Map([['default', {
772
+ local: 'default',
773
+ loc: null,
774
+ isWeak: false
775
+ }]]),
776
+ usedSymbols: new Set(['default'])
777
+ });
778
+ }
779
+
780
+ // ESM loader retry if using import retry feature
781
+ if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
782
+ helperDependencies.push({
783
+ specifier: './helpers/browser/esm-js-loader-retry',
784
+ symbols: new Map([['default', {
785
+ local: 'default',
786
+ loc: null,
787
+ isWeak: false
788
+ }]]),
789
+ usedSymbols: new Set(['default'])
790
+ });
791
+ }
518
792
  return {
519
793
  filePath: __filename,
520
794
  code: code.join('\n'),
521
795
  dependency,
522
796
  env: {
523
797
  sourceType: 'module'
798
+ },
799
+ // Pre-computed symbols: loader runtime with comprehensive helper dependencies
800
+ symbolData: {
801
+ symbols: new Map([['default', {
802
+ local: 'module.exports',
803
+ loc: null
804
+ }]]),
805
+ dependencies: helperDependencies
524
806
  }
525
807
  };
526
808
  }
@@ -534,14 +816,16 @@ function getHintedBundleGroups(bundleGraph, bundle) {
534
816
  var _dependency$meta;
535
817
  let attributes = (_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.importAttributes;
536
818
  if (typeof attributes === 'object' && attributes != null && (
537
- // $FlowFixMe
819
+ // @ts-expect-error TS2339
538
820
  attributes.preload || attributes.prefetch)) {
539
821
  let resolved = bundleGraph.resolveAsyncDependency(dependency, bundle);
540
822
  if ((resolved === null || resolved === void 0 ? void 0 : resolved.type) === 'bundle_group') {
541
823
  // === true for flow
824
+ // @ts-expect-error TS2339
542
825
  if (attributes.preload === true) {
543
826
  preload.push(resolved.value);
544
827
  }
828
+ // @ts-expect-error TS2339
545
829
  if (attributes.prefetch === true) {
546
830
  prefetch.push(resolved.value);
547
831
  }
@@ -559,8 +843,11 @@ function getHintLoaders(bundleGraph, from, bundleGroups, loader, options) {
559
843
  let bundlesToPreload = bundleGraph.getBundlesInBundleGroup(bundleGroupToPreload);
560
844
  for (let bundleToPreload of bundlesToPreload) {
561
845
  let relativePathExpr = getRelativePathExpr(from, bundleToPreload, options);
846
+ // @ts-expect-error TS7053
562
847
  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')})`);
848
+ hintLoaders.push(
849
+ // @ts-expect-error TS2554
850
+ `require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(relativePathExpr, from)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify(bundleToPreload.target.env.outputFormat === 'esmodule')})`);
564
851
  }
565
852
  }
566
853
  return hintLoaders;
@@ -571,7 +858,12 @@ function isNewContext(bundle, bundleGraph) {
571
858
  return isInEntryBundleGroup || parents.length === 0 || parents.some(parent => parent.env.context !== bundle.env.context || parent.type !== 'js');
572
859
  }
573
860
  function getURLRuntime(dependency, from, to, options, shardingConfig) {
574
- let relativePathExpr = getRelativePathExpr(from, to, options);
861
+ let relativePathExpr;
862
+ if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
863
+ relativePathExpr = getRelativePathExpr(from, to, options, true);
864
+ } else {
865
+ relativePathExpr = getRelativePathExpr(from, to, options);
866
+ }
575
867
  let code;
576
868
  if (dependency.meta.webworker === true && !from.env.isLibrary) {
577
869
  code = `let workerURL = require('./helpers/get-worker-url');\n`;
@@ -589,19 +881,96 @@ function getURLRuntime(dependency, from, to, options, shardingConfig) {
589
881
  } else {
590
882
  code = `module.exports = ${getAbsoluteUrlExpr(relativePathExpr, from, shardingConfig)};`;
591
883
  }
884
+
885
+ // Collect dependencies based on the URL runtime code patterns
886
+ let urlRuntimeDependencies = [];
887
+ if (dependency.meta.webworker === true && !from.env.isLibrary) {
888
+ // Web worker runtime requires get-worker-url helper
889
+ urlRuntimeDependencies.push({
890
+ specifier: './helpers/get-worker-url',
891
+ symbols: new Map([['default', {
892
+ local: 'workerURL',
893
+ loc: null,
894
+ isWeak: false
895
+ }]]),
896
+ usedSymbols: new Set(['default'])
897
+ });
898
+ if (!(from.env.outputFormat === 'esmodule' && from.env.supports('import-meta-url'))) {
899
+ // Also requires bundle-url helper in non-ESM environments
900
+ urlRuntimeDependencies.push({
901
+ specifier: './helpers/bundle-url',
902
+ symbols: new Map([['getBundleURL', {
903
+ local: 'getBundleURL',
904
+ loc: null,
905
+ isWeak: false
906
+ }], ['getOrigin', {
907
+ local: 'getOrigin',
908
+ loc: null,
909
+ isWeak: false
910
+ }]]),
911
+ usedSymbols: new Set(['getBundleURL', 'getOrigin'])
912
+ });
913
+
914
+ // Domain sharding if configured
915
+ if (shardingConfig) {
916
+ urlRuntimeDependencies.push({
917
+ specifier: '@atlaspack/domain-sharding',
918
+ symbols: new Map([['shardUrl', {
919
+ local: 'shardUrl',
920
+ loc: null,
921
+ isWeak: false
922
+ }]]),
923
+ usedSymbols: new Set(['shardUrl'])
924
+ });
925
+ }
926
+ }
927
+ } else {
928
+ // Regular URL runtime may use bundle-url helper
929
+ if (!(from.env.outputFormat === 'esmodule' && from.env.supports('import-meta-url')) && !(from.env.outputFormat === 'commonjs')) {
930
+ urlRuntimeDependencies.push({
931
+ specifier: './helpers/bundle-url',
932
+ symbols: new Map([['getBundleURL', {
933
+ local: 'getBundleURL',
934
+ loc: null,
935
+ isWeak: false
936
+ }]]),
937
+ usedSymbols: new Set(['getBundleURL'])
938
+ });
939
+ if (shardingConfig) {
940
+ urlRuntimeDependencies.push({
941
+ specifier: '@atlaspack/domain-sharding',
942
+ symbols: new Map([['shardUrl', {
943
+ local: 'shardUrl',
944
+ loc: null,
945
+ isWeak: false
946
+ }]]),
947
+ usedSymbols: new Set(['shardUrl'])
948
+ });
949
+ }
950
+ }
951
+ }
592
952
  return {
593
953
  filePath: __filename,
594
954
  code,
595
955
  dependency,
596
956
  env: {
597
957
  sourceType: 'module'
958
+ },
959
+ // Pre-computed symbols: URL runtime with helper dependencies
960
+ symbolData: {
961
+ symbols: new Map([['default', {
962
+ local: 'module.exports',
963
+ loc: null
964
+ }]]),
965
+ dependencies: urlRuntimeDependencies
598
966
  }
599
967
  };
600
968
  }
601
969
  function getRegisterCode(entryBundle, bundleGraph) {
970
+ // @ts-expect-error TS2304
602
971
  let mappings = [];
603
972
  bundleGraph.traverseBundles((bundle, _, actions) => {
604
- if (bundle.bundleBehavior === 'inline') {
973
+ if (bundle.bundleBehavior === 'inline' || bundle.bundleBehavior === 'inlineIsolated') {
605
974
  return;
606
975
  }
607
976
 
@@ -625,13 +994,19 @@ function getRegisterCode(entryBundle, bundleGraph) {
625
994
  : `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;
626
995
  return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(JSON.stringify(mappings))}));`;
627
996
  }
628
- function getRelativePathExpr(from, to, options) {
997
+ function getRelativePathExpr(from, to, options, isURL = to.type !== 'js') {
629
998
  let relativePath = (0, _utils().relativeBundlePath)(from, to, {
630
999
  leadingDotSlash: false
631
1000
  });
632
1001
  let res = JSON.stringify(relativePath);
633
- if (options.hmrOptions) {
634
- res += ' + "?" + Date.now()';
1002
+ if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
1003
+ if (isURL && options.hmrOptions) {
1004
+ res += ' + "?" + Date.now()';
1005
+ }
1006
+ } else {
1007
+ if (options.hmrOptions) {
1008
+ res += ' + "?" + Date.now()';
1009
+ }
635
1010
  }
636
1011
  return res;
637
1012
  }
@@ -648,7 +1023,7 @@ function getAbsoluteUrlExpr(relativePathExpr, fromBundle, shardingConfig) {
648
1023
  }
649
1024
  function shouldUseRuntimeManifest(bundle, options) {
650
1025
  let env = bundle.env;
651
- return !env.isLibrary && bundle.bundleBehavior !== 'inline' && env.isBrowser() && options.mode === 'production';
1026
+ return !env.isLibrary && bundle.bundleBehavior !== 'inline' && bundle.bundleBehavior !== 'inlineIsolated' && env.isBrowser() && options.mode === 'production';
652
1027
  }
653
1028
  function getManifestBundlePriority(bundleGraph, bundle, threshold) {
654
1029
  let bundleSize = 0;
@@ -0,0 +1 @@
1
+ "use strict";