@atlaspack/runtime-js 2.13.2-dev.3689 → 2.14.1-canary.3710

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,26 @@
1
1
  # @atlaspack/runtime-js
2
2
 
3
+ ## 2.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#339](https://github.com/atlassian-labs/atlaspack/pull/339) [`bfe81e5`](https://github.com/atlassian-labs/atlaspack/commit/bfe81e551c4e4bb2cac7fc4745222e66962c1728) Thanks [@yamadapc](https://github.com/yamadapc)! - Update cache invalidation metrics with build type
8
+
9
+ ### Patch Changes
10
+
11
+ - [#379](https://github.com/atlassian-labs/atlaspack/pull/379) [`8bc3db9`](https://github.com/atlassian-labs/atlaspack/commit/8bc3db94cc7382b22ca8207c92af8f6389c17e2e) Thanks [@JakeLane](https://github.com/JakeLane)! - Support nested conditional imports in runtime for dynamic import edges in graph. Introduces a new feature flag `conditionalBundlingNestedRuntime`
12
+
13
+ - [#414](https://github.com/atlassian-labs/atlaspack/pull/414) [`eff9809`](https://github.com/atlassian-labs/atlaspack/commit/eff98093703b9999a511b87a19562f5aaccfcb53) Thanks [@alshdavid](https://github.com/alshdavid)! - Added type:commonjs to package.json files
14
+
15
+ - [#412](https://github.com/atlassian-labs/atlaspack/pull/412) [`be63a51`](https://github.com/atlassian-labs/atlaspack/commit/be63a515ad13dd5ec1e241843d9ef6fdae8699d5) Thanks [@yamadapc](https://github.com/yamadapc)! - Update to internal unit tests
16
+
17
+ - Updated dependencies [[`bfe81e5`](https://github.com/atlassian-labs/atlaspack/commit/bfe81e551c4e4bb2cac7fc4745222e66962c1728), [`1953d1b`](https://github.com/atlassian-labs/atlaspack/commit/1953d1bec266a39dc4bfce5f6c7959e77e63411e), [`ce4ce95`](https://github.com/atlassian-labs/atlaspack/commit/ce4ce953914e08991cf58c70c98f758690e5ee21), [`8bc3db9`](https://github.com/atlassian-labs/atlaspack/commit/8bc3db94cc7382b22ca8207c92af8f6389c17e2e), [`e962cd7`](https://github.com/atlassian-labs/atlaspack/commit/e962cd735877f7f16163e60868d70d9c10054ebe), [`4837b69`](https://github.com/atlassian-labs/atlaspack/commit/4837b6988e56ca842a24797b796160964d3696ce), [`7e21377`](https://github.com/atlassian-labs/atlaspack/commit/7e21377914e8091d484f67cb11052a1efd2227e3), [`43113f8`](https://github.com/atlassian-labs/atlaspack/commit/43113f8f00232c5a52169a3f11f846d6e4d94b0a), [`eff9809`](https://github.com/atlassian-labs/atlaspack/commit/eff98093703b9999a511b87a19562f5aaccfcb53)]:
18
+ - @atlaspack/diagnostic@2.14.0
19
+ - @atlaspack/feature-flags@2.14.0
20
+ - @atlaspack/plugin@2.14.0
21
+ - @atlaspack/utils@2.14.0
22
+ - @atlaspack/domain-sharding@2.14.0
23
+
3
24
  ## 2.13.1
4
25
 
5
26
  ### Patch Changes
package/lib/JSRuntime.js CHANGED
@@ -423,15 +423,40 @@ function getLoaderRuntime({
423
423
  }
424
424
  return code;
425
425
  }
426
- if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
427
- let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
428
- for (const cond of bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle)) {
426
+ function getConditionalLoadersForCondition(dependencies, sourceBundle) {
427
+ if (dependencies.length === 0) {
428
+ // Avoid extra work if there are no dependencies, so we don't have to traverse conditions
429
+ return [];
430
+ }
431
+
432
+ // Get all the condition objects for the conditional dependencies
433
+ const conditions = bundleGraph.getConditionsForDependencies(dependencies, sourceBundle);
434
+ const loaders = [];
435
+ for (const cond of conditions) {
429
436
  // This bundle has a conditional dependency, we need to load the bundle group
430
- const ifTrueLoaders = cond.ifTrueBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle));
431
- const ifFalseLoaders = cond.ifFalseBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle));
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)));
432
439
  if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
433
440
  // Load conditional bundles with helper (and a dev mode with additional hints)
434
- loaderModules.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return Promise.all([${ifTrueLoaders.join(',')}]);}, function (){return Promise.all([${ifFalseLoaders.join(',')}]);})`);
441
+ loaders.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return Promise.all([${ifTrueLoaders.join(',')}]);}, function (){return Promise.all([${ifFalseLoaders.join(',')}]);})`);
442
+ }
443
+ }
444
+ return loaders;
445
+ }
446
+ 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
+ }
435
460
  }
436
461
  }
437
462
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/runtime-js",
3
- "version": "2.13.2-dev.3689+7a2e6e783",
3
+ "version": "2.14.1-canary.3710+d874396ab",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,16 +12,17 @@
12
12
  "main": "lib/JSRuntime.js",
13
13
  "source": "src/JSRuntime.js",
14
14
  "engines": {
15
- "atlaspack": "^2.13.2-dev.3689+7a2e6e783",
15
+ "atlaspack": "2.14.1-canary.3710+d874396ab",
16
16
  "node": ">= 16.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.13.2-dev.3689+7a2e6e783",
20
- "@atlaspack/domain-sharding": "2.13.2-dev.3689+7a2e6e783",
21
- "@atlaspack/feature-flags": "2.13.2-dev.3689+7a2e6e783",
22
- "@atlaspack/plugin": "2.13.2-dev.3689+7a2e6e783",
23
- "@atlaspack/utils": "2.13.2-dev.3689+7a2e6e783",
19
+ "@atlaspack/diagnostic": "2.14.1-canary.3710+d874396ab",
20
+ "@atlaspack/domain-sharding": "2.14.1-canary.3710+d874396ab",
21
+ "@atlaspack/feature-flags": "2.14.1-canary.3710+d874396ab",
22
+ "@atlaspack/plugin": "2.14.1-canary.3710+d874396ab",
23
+ "@atlaspack/utils": "2.14.1-canary.3710+d874396ab",
24
24
  "nullthrows": "^1.1.1"
25
25
  },
26
- "gitHead": "7a2e6e7835fa846b27021b374097c6a4f37541ba"
26
+ "type": "commonjs",
27
+ "gitHead": "d874396ab648d0d5505d66c7eb73e1748f1eaf68"
27
28
  }
package/src/JSRuntime.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // @flow strict-local
2
-
3
2
  import type {
4
3
  BundleGraph,
5
4
  BundleGroup,
@@ -446,7 +445,7 @@ function getLoaderRuntime({
446
445
  !bundle.env.isLibrary && !bundle.env.supports('dynamic-import', true);
447
446
 
448
447
  let needsEsmLoadPrelude = false;
449
- let loaderModules = [];
448
+ let loaderModules: Array<string> = [];
450
449
 
451
450
  function getLoaderForBundle(
452
451
  bundle: NamedBundle,
@@ -514,25 +513,53 @@ function getLoaderRuntime({
514
513
  return code;
515
514
  }
516
515
 
517
- if (getFeatureFlag('conditionalBundlingApi')) {
518
- let conditionalDependencies = externalBundles.flatMap(
519
- (to) => getDependencies(to).conditionalDependencies,
516
+ function getConditionalLoadersForCondition(
517
+ dependencies: Dependency[],
518
+ sourceBundle: NamedBundle,
519
+ ): string[] {
520
+ if (dependencies.length === 0) {
521
+ // Avoid extra work if there are no dependencies, so we don't have to traverse conditions
522
+ return [];
523
+ }
524
+
525
+ // Get all the condition objects for the conditional dependencies
526
+ const conditions = bundleGraph.getConditionsForDependencies(
527
+ dependencies,
528
+ sourceBundle,
520
529
  );
521
- for (const cond of bundleGraph.getConditionsForDependencies(
522
- conditionalDependencies,
523
- bundle,
524
- )) {
530
+
531
+ const loaders = [];
532
+ for (const cond of conditions) {
525
533
  // This bundle has a conditional dependency, we need to load the bundle group
526
- const ifTrueLoaders = cond.ifTrueBundles.map((targetBundle) =>
527
- getLoaderForBundle(bundle, targetBundle),
528
- );
529
- const ifFalseLoaders = cond.ifFalseBundles.map((targetBundle) =>
530
- getLoaderForBundle(bundle, targetBundle),
531
- );
534
+ const ifTrueLoaders = cond.ifTrueBundles
535
+ .flatMap((targetBundle) =>
536
+ getConditionalLoadersForCondition(
537
+ getDependencies(targetBundle).conditionalDependencies,
538
+ targetBundle,
539
+ ),
540
+ )
541
+ .concat(
542
+ cond.ifTrueBundles.map((targetBundle) =>
543
+ getLoaderForBundle(sourceBundle, targetBundle),
544
+ ),
545
+ );
546
+
547
+ const ifFalseLoaders = cond.ifFalseBundles
548
+ .flatMap((targetBundle) =>
549
+ getConditionalLoadersForCondition(
550
+ getDependencies(targetBundle).conditionalDependencies,
551
+ targetBundle,
552
+ ),
553
+ )
554
+ .concat(
555
+ cond.ifFalseBundles.map((targetBundle) =>
556
+ getLoaderForBundle(sourceBundle, targetBundle),
557
+ ),
558
+ );
532
559
 
533
560
  if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
534
561
  // Load conditional bundles with helper (and a dev mode with additional hints)
535
- loaderModules.push(
562
+ loaders.push(
536
563
  `require('./helpers/conditional-loader${
537
564
  options.mode === 'development' ? '-dev' : ''
538
565
  }')('${
@@ -545,6 +572,51 @@ function getLoaderRuntime({
545
572
  );
546
573
  }
547
574
  }
575
+
576
+ return loaders;
577
+ }
578
+
579
+ if (getFeatureFlag('conditionalBundlingApi')) {
580
+ if (getFeatureFlag('conditionalBundlingNestedRuntime')) {
581
+ let conditionalDependencies = externalBundles.flatMap(
582
+ (to) => getDependencies(to).conditionalDependencies,
583
+ );
584
+
585
+ loaderModules.push(
586
+ ...getConditionalLoadersForCondition(conditionalDependencies, bundle),
587
+ );
588
+ } else {
589
+ let conditionalDependencies = externalBundles.flatMap(
590
+ (to) => getDependencies(to).conditionalDependencies,
591
+ );
592
+ for (const cond of bundleGraph.getConditionsForDependencies(
593
+ conditionalDependencies,
594
+ bundle,
595
+ )) {
596
+ // This bundle has a conditional dependency, we need to load the bundle group
597
+ const ifTrueLoaders = cond.ifTrueBundles.map((targetBundle) =>
598
+ getLoaderForBundle(bundle, targetBundle),
599
+ );
600
+ const ifFalseLoaders = cond.ifFalseBundles.map((targetBundle) =>
601
+ getLoaderForBundle(bundle, targetBundle),
602
+ );
603
+
604
+ if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
605
+ // Load conditional bundles with helper (and a dev mode with additional hints)
606
+ loaderModules.push(
607
+ `require('./helpers/conditional-loader${
608
+ options.mode === 'development' ? '-dev' : ''
609
+ }')('${
610
+ cond.key
611
+ }', function (){return Promise.all([${ifTrueLoaders.join(
612
+ ',',
613
+ )}]);}, function (){return Promise.all([${ifFalseLoaders.join(
614
+ ',',
615
+ )}]);})`,
616
+ );
617
+ }
618
+ }
619
+ }
548
620
  }
549
621
 
550
622
  for (let to of externalBundles) {
@@ -1,3 +1,5 @@
1
+ // @flow strict-local
2
+
1
3
  import load from '../src/helpers/browser/esm-js-loader-retry.js';
2
4
  import bundleManifest from '../src/helpers/bundle-manifest.js';
3
5
  import {mock} from 'node:test';
@@ -33,6 +35,13 @@ describe('esm-js-loader-retry', () => {
33
35
  globalThis.navigator = {onLine: true};
34
36
  globalThis.CustomEvent = globalThis.CustomEvent || class {};
35
37
  globalThis.dispatchEvent = mock.fn();
38
+
39
+ // Add mock for addEventListener
40
+ globalThis.addEventListener = mock.fn((event, callback) => {
41
+ if (event === 'online') {
42
+ callback();
43
+ }
44
+ });
36
45
  });
37
46
 
38
47
  it('should not throw', async () => {