@atlaspack/runtime-js 2.19.9-dev-swc44-2ebba71e5.0 → 2.20.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @atlaspack/runtime-js
2
2
 
3
+ ## 2.20.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#925](https://github.com/atlassian-labs/atlaspack/pull/925) [`00fa643`](https://github.com/atlassian-labs/atlaspack/commit/00fa6433202bfd3311479f6314c9ec878a789f2c) Thanks [@benjervis](https://github.com/benjervis)! - Save propagating symbols for runtimes by requiring symbol and dependency data be returned at the time the assets are injected.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`00fa643`](https://github.com/atlassian-labs/atlaspack/commit/00fa6433202bfd3311479f6314c9ec878a789f2c)]:
12
+ - @atlaspack/types-internal@2.22.0
13
+ - @atlaspack/plugin@2.14.43
14
+ - @atlaspack/utils@3.2.4
15
+
16
+ ## 2.19.9
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [[`cbb66a5`](https://github.com/atlassian-labs/atlaspack/commit/cbb66a554f7ad679fd4dfc9e2bf2d5abb859f846)]:
21
+ - @atlaspack/feature-flags@2.27.3
22
+ - @atlaspack/utils@3.2.3
23
+ - @atlaspack/types-internal@2.21.3
24
+ - @atlaspack/plugin@2.14.42
25
+
3
26
  ## 2.19.8
4
27
 
5
28
  ### Patch Changes
package/dist/JSRuntime.js CHANGED
@@ -123,6 +123,13 @@ exports.default = new plugin_1.Runtime({
123
123
  code: `module.exports = Promise.resolve(${requireName}(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
124
124
  dependency,
125
125
  env: { sourceType: 'module' },
126
+ // Pre-computed symbols: exports Promise, no external dependencies (uses global)
127
+ symbolData: {
128
+ symbols: new Map([
129
+ ['default', { local: 'module.exports', loc: null }],
130
+ ]),
131
+ dependencies: [],
132
+ },
126
133
  });
127
134
  }
128
135
  }
@@ -137,6 +144,13 @@ exports.default = new plugin_1.Runtime({
137
144
  code: `module.exports = Promise.resolve(${JSON.stringify(dependency.id)});`,
138
145
  dependency,
139
146
  env: { sourceType: 'module' },
147
+ // Pre-computed symbols: exports Promise, no external dependencies
148
+ symbolData: {
149
+ symbols: new Map([
150
+ ['default', { local: 'module.exports', loc: null }],
151
+ ]),
152
+ dependencies: [],
153
+ },
140
154
  });
141
155
  continue;
142
156
  }
@@ -196,6 +210,32 @@ exports.default = new plugin_1.Runtime({
196
210
  // (rather than the actual conditional deps)
197
211
  dependency: cond.ifFalseDependency,
198
212
  env: { sourceType: 'module' },
213
+ // Pre-computed symbols: conditional loader with potential sync-js-loader fallback
214
+ symbolData: {
215
+ symbols: new Map([
216
+ ['default', { local: 'module.exports', loc: null }],
217
+ ]),
218
+ dependencies: [
219
+ {
220
+ specifier: loaderPath,
221
+ symbols: new Map([
222
+ ['default', { local: 'default', loc: null, isWeak: false }],
223
+ ]),
224
+ usedSymbols: new Set(['default']),
225
+ },
226
+ ...(shouldUseFallback
227
+ ? [
228
+ {
229
+ specifier: './helpers/browser/sync-js-loader',
230
+ symbols: new Map([
231
+ ['default', { local: 'l', loc: null, isWeak: false }],
232
+ ]),
233
+ usedSymbols: new Set(['default']),
234
+ },
235
+ ]
236
+ : []),
237
+ ],
238
+ },
199
239
  });
200
240
  }
201
241
  }
@@ -210,6 +250,13 @@ exports.default = new plugin_1.Runtime({
210
250
  code: `module.exports = ${JSON.stringify(dependency.id)};`,
211
251
  dependency,
212
252
  env: { sourceType: 'module' },
253
+ // Pre-computed symbols: simple export with no dependencies
254
+ symbolData: {
255
+ symbols: new Map([
256
+ ['default', { local: 'module.exports', loc: null }],
257
+ ]),
258
+ dependencies: [],
259
+ },
213
260
  });
214
261
  continue;
215
262
  }
@@ -224,6 +271,13 @@ exports.default = new plugin_1.Runtime({
224
271
  code: `module.exports = ${JSON.stringify(dependency.specifier)}`,
225
272
  dependency,
226
273
  env: { sourceType: 'module' },
274
+ // Pre-computed symbols: simple export with no dependencies
275
+ symbolData: {
276
+ symbols: new Map([
277
+ ['default', { local: 'module.exports', loc: null }],
278
+ ]),
279
+ dependencies: [],
280
+ },
227
281
  });
228
282
  continue;
229
283
  }
@@ -266,6 +320,19 @@ exports.default = new plugin_1.Runtime({
266
320
  code: loaderCode,
267
321
  isEntry: true,
268
322
  env: { sourceType: 'module' },
323
+ // Pre-computed symbols: lazy bundle loader, requires specific loader helper
324
+ symbolData: {
325
+ symbols: new Map(), // No exports, just side effects
326
+ dependencies: [
327
+ {
328
+ specifier: loader,
329
+ symbols: new Map([
330
+ ['default', { local: 'default', loc: null, isWeak: false }],
331
+ ]),
332
+ usedSymbols: new Set(['default']),
333
+ },
334
+ ],
335
+ },
269
336
  });
270
337
  }
271
338
  }
@@ -282,6 +349,19 @@ exports.default = new plugin_1.Runtime({
282
349
  env: { sourceType: 'module' },
283
350
  runtimeAssetRequiringExecutionOnLoad: true,
284
351
  priority: getManifestBundlePriority(bundleGraph, bundle, config.splitManifestThreshold),
352
+ // Pre-computed symbols: requires bundle-manifest helper
353
+ symbolData: {
354
+ symbols: new Map(), // No exports, just executes
355
+ dependencies: [
356
+ {
357
+ specifier: './helpers/bundle-manifest',
358
+ symbols: new Map([
359
+ ['register', { local: 'register', loc: null, isWeak: false }],
360
+ ]),
361
+ usedSymbols: new Set(['register']),
362
+ },
363
+ ],
364
+ },
285
365
  });
286
366
  }
287
367
  return assets;
@@ -489,6 +569,19 @@ function getLoaderRuntime({ bundle, dependency, bundleGroup, bundleGraph, option
489
569
  code: loaderCode,
490
570
  dependency,
491
571
  env: { sourceType: 'module' },
572
+ // Pre-computed symbols: ESM loader with retry, requires esm-js-loader-retry helper
573
+ symbolData: {
574
+ symbols: new Map([['default', { local: 'module.exports', loc: null }]]),
575
+ dependencies: [
576
+ {
577
+ specifier: './helpers/browser/esm-js-loader-retry',
578
+ symbols: new Map([
579
+ ['default', { local: 'default', loc: null, isWeak: false }],
580
+ ]),
581
+ usedSymbols: new Set(['default']),
582
+ },
583
+ ],
584
+ },
492
585
  };
493
586
  }
494
587
  let code = [];
@@ -499,11 +592,130 @@ function getLoaderRuntime({ bundle, dependency, bundleGroup, bundleGraph, option
499
592
  code.push(preludeLoad);
500
593
  }
501
594
  code.push(`module.exports = ${loaderCode};`);
595
+ // Collect all potential helper dependencies used in loader runtime
596
+ let helperDependencies = [];
597
+ // Always potential dependencies based on the code patterns
598
+ if (needsEsmLoadPrelude) {
599
+ if (shardingConfig) {
600
+ helperDependencies.push({
601
+ specifier: './helpers/browser/esm-js-loader-shards',
602
+ symbols: new Map([
603
+ ['default', { local: 'default', loc: null, isWeak: false }],
604
+ ]),
605
+ usedSymbols: new Set(['default']),
606
+ });
607
+ }
608
+ else {
609
+ helperDependencies.push({
610
+ specifier: './helpers/browser/esm-js-loader',
611
+ symbols: new Map([
612
+ ['default', { local: 'default', loc: null, isWeak: false }],
613
+ ]),
614
+ usedSymbols: new Set(['default']),
615
+ });
616
+ }
617
+ }
618
+ // Bundle manifest dependency if using runtime manifest
619
+ if (shouldUseRuntimeManifest(bundle, options)) {
620
+ helperDependencies.push({
621
+ specifier: './helpers/bundle-manifest',
622
+ symbols: new Map([
623
+ ['resolve', { local: 'resolve', loc: null, isWeak: false }],
624
+ ]),
625
+ usedSymbols: new Set(['resolve']),
626
+ });
627
+ }
628
+ // Domain sharding dependency if configured
629
+ if (shardingConfig) {
630
+ helperDependencies.push({
631
+ specifier: '@atlaspack/domain-sharding',
632
+ symbols: new Map([
633
+ ['shardUrl', { local: 'shardUrl', loc: null, isWeak: false }],
634
+ ]),
635
+ usedSymbols: new Set(['shardUrl']),
636
+ });
637
+ }
638
+ // Various loader dependencies based on bundle types in externalBundles
639
+ for (let to of externalBundles) {
640
+ let loader = loaders[to.type];
641
+ if (loader && typeof loader === 'string') {
642
+ helperDependencies.push({
643
+ specifier: loader,
644
+ symbols: new Map([
645
+ ['default', { local: 'default', loc: null, isWeak: false }],
646
+ ]),
647
+ usedSymbols: new Set(['default']),
648
+ });
649
+ }
650
+ }
651
+ // Import polyfill if needed
652
+ if (needsDynamicImportPolyfill && loaders?.IMPORT_POLYFILL) {
653
+ helperDependencies.push({
654
+ specifier: loaders.IMPORT_POLYFILL,
655
+ symbols: new Map([
656
+ ['default', { local: 'default', loc: null, isWeak: false }],
657
+ ]),
658
+ usedSymbols: new Set(['default']),
659
+ });
660
+ }
661
+ // Conditional loaders if using conditional bundling
662
+ if ((0, feature_flags_1.getFeatureFlag)('conditionalBundlingApi')) {
663
+ const loaderPath = `./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}`;
664
+ helperDependencies.push({
665
+ specifier: loaderPath,
666
+ symbols: new Map([
667
+ ['default', { local: 'default', loc: null, isWeak: false }],
668
+ ]),
669
+ usedSymbols: new Set(['default']),
670
+ });
671
+ // Sync loader for fallback
672
+ if (options.mode === 'development') {
673
+ helperDependencies.push({
674
+ specifier: './helpers/browser/sync-js-loader',
675
+ symbols: new Map([
676
+ ['default', { local: 'default', loc: null, isWeak: false }],
677
+ ]),
678
+ usedSymbols: new Set(['default']),
679
+ });
680
+ }
681
+ }
682
+ // Preload/prefetch loaders for browser context
683
+ if (bundle.env.context === 'browser') {
684
+ helperDependencies.push({
685
+ specifier: BROWSER_PRELOAD_LOADER,
686
+ symbols: new Map([
687
+ ['default', { local: 'default', loc: null, isWeak: false }],
688
+ ]),
689
+ usedSymbols: new Set(['default']),
690
+ });
691
+ helperDependencies.push({
692
+ specifier: BROWSER_PREFETCH_LOADER,
693
+ symbols: new Map([
694
+ ['default', { local: 'default', loc: null, isWeak: false }],
695
+ ]),
696
+ usedSymbols: new Set(['default']),
697
+ });
698
+ }
699
+ // ESM loader retry if using import retry feature
700
+ if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
701
+ helperDependencies.push({
702
+ specifier: './helpers/browser/esm-js-loader-retry',
703
+ symbols: new Map([
704
+ ['default', { local: 'default', loc: null, isWeak: false }],
705
+ ]),
706
+ usedSymbols: new Set(['default']),
707
+ });
708
+ }
502
709
  return {
503
710
  filePath: __filename,
504
711
  code: code.join('\n'),
505
712
  dependency,
506
713
  env: { sourceType: 'module' },
714
+ // Pre-computed symbols: loader runtime with comprehensive helper dependencies
715
+ symbolData: {
716
+ symbols: new Map([['default', { local: 'module.exports', loc: null }]]),
717
+ dependencies: helperDependencies,
718
+ },
507
719
  };
508
720
  }
509
721
  function getHintedBundleGroups(bundleGraph, bundle) {
@@ -584,11 +796,73 @@ function getURLRuntime(dependency, from, to, options, shardingConfig) {
584
796
  else {
585
797
  code = `module.exports = ${getAbsoluteUrlExpr(relativePathExpr, from, shardingConfig)};`;
586
798
  }
799
+ // Collect dependencies based on the URL runtime code patterns
800
+ let urlRuntimeDependencies = [];
801
+ if (dependency.meta.webworker === true && !from.env.isLibrary) {
802
+ // Web worker runtime requires get-worker-url helper
803
+ urlRuntimeDependencies.push({
804
+ specifier: './helpers/get-worker-url',
805
+ symbols: new Map([
806
+ ['default', { local: 'workerURL', loc: null, isWeak: false }],
807
+ ]),
808
+ usedSymbols: new Set(['default']),
809
+ });
810
+ if (!(from.env.outputFormat === 'esmodule' &&
811
+ from.env.supports('import-meta-url'))) {
812
+ // Also requires bundle-url helper in non-ESM environments
813
+ urlRuntimeDependencies.push({
814
+ specifier: './helpers/bundle-url',
815
+ symbols: new Map([
816
+ ['getBundleURL', { local: 'getBundleURL', loc: null, isWeak: false }],
817
+ ['getOrigin', { local: 'getOrigin', loc: null, isWeak: false }],
818
+ ]),
819
+ usedSymbols: new Set(['getBundleURL', 'getOrigin']),
820
+ });
821
+ // Domain sharding if configured
822
+ if (shardingConfig) {
823
+ urlRuntimeDependencies.push({
824
+ specifier: '@atlaspack/domain-sharding',
825
+ symbols: new Map([
826
+ ['shardUrl', { local: 'shardUrl', loc: null, isWeak: false }],
827
+ ]),
828
+ usedSymbols: new Set(['shardUrl']),
829
+ });
830
+ }
831
+ }
832
+ }
833
+ else {
834
+ // Regular URL runtime may use bundle-url helper
835
+ if (!(from.env.outputFormat === 'esmodule' &&
836
+ from.env.supports('import-meta-url')) &&
837
+ !(from.env.outputFormat === 'commonjs')) {
838
+ urlRuntimeDependencies.push({
839
+ specifier: './helpers/bundle-url',
840
+ symbols: new Map([
841
+ ['getBundleURL', { local: 'getBundleURL', loc: null, isWeak: false }],
842
+ ]),
843
+ usedSymbols: new Set(['getBundleURL']),
844
+ });
845
+ if (shardingConfig) {
846
+ urlRuntimeDependencies.push({
847
+ specifier: '@atlaspack/domain-sharding',
848
+ symbols: new Map([
849
+ ['shardUrl', { local: 'shardUrl', loc: null, isWeak: false }],
850
+ ]),
851
+ usedSymbols: new Set(['shardUrl']),
852
+ });
853
+ }
854
+ }
855
+ }
587
856
  return {
588
857
  filePath: __filename,
589
858
  code,
590
859
  dependency,
591
860
  env: { sourceType: 'module' },
861
+ // Pre-computed symbols: URL runtime with helper dependencies
862
+ symbolData: {
863
+ symbols: new Map([['default', { local: 'module.exports', loc: null }]]),
864
+ dependencies: urlRuntimeDependencies,
865
+ },
592
866
  };
593
867
  }
594
868
  function getRegisterCode(entryBundle, bundleGraph) {