@atlaspack/runtime-js 2.12.1-dev.3478 → 2.12.1-dev.3520

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/lib/JSRuntime.js CHANGED
@@ -192,14 +192,17 @@ var _default = exports.default = new (_plugin().Runtime)({
192
192
  // For any conditions that are used in this bundle, we want to produce a runtime asset that is used to
193
193
  // select the correct dependency that condition maps to at runtime - the conditions in the bundle will then be
194
194
  // replaced with a reference to this asset to implement the selection.
195
- const conditions = bundleGraph.getConditionsForDependencies(conditionalDependencies);
195
+ const conditions = bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle);
196
196
  for (const cond of conditions) {
197
197
  const requireName = bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
198
198
  const assetCode = `module.exports = require('../helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return ${requireName}('${cond.ifTrueAssetId}')}, function (){return ${requireName}('${cond.ifFalseAssetId}')})`;
199
199
  assets.push({
200
200
  filePath: _path().default.join(__dirname, `/conditions/${cond.publicId}.js`),
201
201
  code: assetCode,
202
- dependency: cond.ifTrueDependency,
202
+ // This dependency is important, as it's the last symbol handled in scope hoisting.
203
+ // That means that scope hoisting will use the module id for this asset to replace the symbol
204
+ // (rather than the actual conditional deps)
205
+ dependency: cond.ifFalseDependency,
203
206
  env: {
204
207
  sourceType: 'module'
205
208
  }
@@ -401,13 +404,11 @@ function getLoaderRuntime({
401
404
  }
402
405
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
403
406
  let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
404
- for (const cond of bundleGraph.getConditionsForDependencies(conditionalDependencies)) {
405
- // This bundle has a conditional dependency, we need to load it as it may not be present
406
- let ifTrueBundle = (0, _nullthrows().default)(bundleGraph.getReferencedBundle(cond.ifTrueDependency, bundle), 'ifTrueBundle was null');
407
- let ifFalseBundle = (0, _nullthrows().default)(bundleGraph.getReferencedBundle(cond.ifFalseDependency, bundle), 'ifFalseBundle was null');
407
+ for (const cond of bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle)) {
408
+ // This bundle has a conditional dependency, we need to load the bundle group
408
409
 
409
410
  // Load conditional bundles with helper (and a dev mode with additional hints)
410
- loaderModules.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return ${getLoaderForBundle(bundle, ifTrueBundle) ?? `Promise.resolve()`}}, function (){return ${getLoaderForBundle(bundle, ifFalseBundle) ?? `Promise.resolve()`}})`);
411
+ loaderModules.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return Promise.all([${cond.ifTrueBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle)).join(',')}]);}, function (){return Promise.all([${cond.ifFalseBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle)).join(',')}]);})`);
411
412
  }
412
413
  }
413
414
  for (let to of externalBundles) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/runtime-js",
3
- "version": "2.12.1-dev.3478+5fd2da535",
3
+ "version": "2.12.1-dev.3520+8a5346e28",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,14 +13,14 @@
13
13
  "source": "src/JSRuntime.js",
14
14
  "engines": {
15
15
  "node": ">= 16.0.0",
16
- "parcel": "^2.12.1-dev.3478+5fd2da535"
16
+ "parcel": "^2.12.1-dev.3520+8a5346e28"
17
17
  },
18
18
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.12.1-dev.3478+5fd2da535",
20
- "@atlaspack/feature-flags": "2.12.1-dev.3478+5fd2da535",
21
- "@atlaspack/plugin": "2.12.1-dev.3478+5fd2da535",
22
- "@atlaspack/utils": "2.12.1-dev.3478+5fd2da535",
19
+ "@atlaspack/diagnostic": "2.12.1-dev.3520+8a5346e28",
20
+ "@atlaspack/feature-flags": "2.12.1-dev.3520+8a5346e28",
21
+ "@atlaspack/plugin": "2.12.1-dev.3520+8a5346e28",
22
+ "@atlaspack/utils": "2.12.1-dev.3520+8a5346e28",
23
23
  "nullthrows": "^1.1.1"
24
24
  },
25
- "gitHead": "5fd2da535ecbe096d57e03aec15e80bb1d7601f7"
25
+ "gitHead": "8a5346e28c1bb3b9cd40f1c4e77c66dd6666f1e4"
26
26
  }
package/src/JSRuntime.js CHANGED
@@ -195,6 +195,7 @@ export default (new Runtime({
195
195
  // replaced with a reference to this asset to implement the selection.
196
196
  const conditions = bundleGraph.getConditionsForDependencies(
197
197
  conditionalDependencies,
198
+ bundle,
198
199
  );
199
200
  for (const cond of conditions) {
200
201
  const requireName = bundle.env.shouldScopeHoist
@@ -210,7 +211,10 @@ export default (new Runtime({
210
211
  assets.push({
211
212
  filePath: path.join(__dirname, `/conditions/${cond.publicId}.js`),
212
213
  code: assetCode,
213
- dependency: cond.ifTrueDependency,
214
+ // This dependency is important, as it's the last symbol handled in scope hoisting.
215
+ // That means that scope hoisting will use the module id for this asset to replace the symbol
216
+ // (rather than the actual conditional deps)
217
+ dependency: cond.ifFalseDependency,
214
218
  env: {sourceType: 'module'},
215
219
  });
216
220
  }
@@ -476,26 +480,19 @@ function getLoaderRuntime({
476
480
  );
477
481
  for (const cond of bundleGraph.getConditionsForDependencies(
478
482
  conditionalDependencies,
483
+ bundle,
479
484
  )) {
480
- // This bundle has a conditional dependency, we need to load it as it may not be present
481
- let ifTrueBundle = nullthrows(
482
- bundleGraph.getReferencedBundle(cond.ifTrueDependency, bundle),
483
- 'ifTrueBundle was null',
484
- );
485
- let ifFalseBundle = nullthrows(
486
- bundleGraph.getReferencedBundle(cond.ifFalseDependency, bundle),
487
- 'ifFalseBundle was null',
488
- );
485
+ // This bundle has a conditional dependency, we need to load the bundle group
489
486
 
490
487
  // Load conditional bundles with helper (and a dev mode with additional hints)
491
488
  loaderModules.push(
492
489
  `require('./helpers/conditional-loader${
493
490
  options.mode === 'development' ? '-dev' : ''
494
- }')('${cond.key}', function (){return ${
495
- getLoaderForBundle(bundle, ifTrueBundle) ?? `Promise.resolve()`
496
- }}, function (){return ${
497
- getLoaderForBundle(bundle, ifFalseBundle) ?? `Promise.resolve()`
498
- }})`,
491
+ }')('${cond.key}', function (){return Promise.all([${cond.ifTrueBundles
492
+ .map((targetBundle) => getLoaderForBundle(bundle, targetBundle))
493
+ .join(',')}]);}, function (){return Promise.all([${cond.ifFalseBundles
494
+ .map((targetBundle) => getLoaderForBundle(bundle, targetBundle))
495
+ .join(',')}]);})`,
499
496
  );
500
497
  }
501
498
  }