@atlaspack/packager-js 2.14.1-dev.53 → 2.14.1-dev.82

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.
@@ -235,15 +235,35 @@ class ScopeHoistingPackager {
235
235
  shouldBundleQueue(bundle) {
236
236
  let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
237
237
  let hasHtmlReference = referencingBundles.some(b => b.type === 'html');
238
- return this.useAsyncBundleRuntime && bundle.type === 'js' && bundle.bundleBehavior !== 'inline' && bundle.env.outputFormat === 'esmodule' && !bundle.env.isIsolated() && bundle.bundleBehavior !== 'isolated' && hasHtmlReference;
238
+ let hasConditionalReference = false;
239
+ let isConditionalBundle = false;
240
+ if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && (0, _featureFlags().getFeatureFlag)('conditionalBundlingAsyncRuntime')) {
241
+ // If the bundle has a conditional bundle reference (has an importCond)
242
+ hasConditionalReference = this.bundleGraph.getReferencedConditionalBundles(bundle).length > 0;
243
+ // If the bundle is a conditional bundle
244
+ isConditionalBundle = this.hasConditionalDependency();
245
+ }
246
+ return this.useAsyncBundleRuntime && bundle.type === 'js' && bundle.bundleBehavior !== 'inline' && bundle.env.outputFormat === 'esmodule' && !bundle.env.isIsolated() && bundle.bundleBehavior !== 'isolated' && (hasHtmlReference || hasConditionalReference || isConditionalBundle);
239
247
  }
240
248
  runWhenReady(bundle, codeToRun) {
241
249
  let deps = this.bundleGraph.getReferencedBundles(bundle).filter(b => this.shouldBundleQueue(b)).map(b => b.publicId);
242
- if (deps.length === 0) {
250
+ const conditions = [];
251
+ if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && (0, _featureFlags().getFeatureFlag)('conditionalBundlingAsyncRuntime')) {
252
+ const conditionSet = this.bundleGraph.getConditionalBundleMapping().get(bundle.id);
253
+ for (const [key, {
254
+ ifTrueBundles,
255
+ ifFalseBundles
256
+ }] of (conditionSet === null || conditionSet === void 0 ? void 0 : conditionSet.entries()) ?? []) {
257
+ const ifTrueBundleIds = ifTrueBundles.map(b => `"${b.publicId}"`).join(',');
258
+ const ifFalseBundleIds = ifFalseBundles.map(b => `"${b.publicId}"`).join(',');
259
+ conditions.push(`(globalThis.__MCOND && globalThis.__MCOND('${key}') ? [${ifTrueBundleIds}] : [${ifFalseBundleIds}])`);
260
+ }
261
+ }
262
+ if (deps.length === 0 && conditions.length === 0) {
243
263
  // If no deps we can safely execute immediately
244
264
  return codeToRun;
245
265
  }
246
- let params = [JSON.stringify(this.bundle.publicId), (0, _helpers.fnExpr)(this.bundle.env, [], [codeToRun]), JSON.stringify(deps)];
266
+ let params = [JSON.stringify(this.bundle.publicId), (0, _helpers.fnExpr)(this.bundle.env, [], [codeToRun]), `${JSON.stringify(deps)}${conditions.length > 0 ? `.concat([${conditions.map(conditions => `...${conditions}`).join(',')}])` : ''}`];
247
267
  return `$parcel$global.rwr(${params.join(', ')});`;
248
268
  }
249
269
  async loadAssets() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/packager-js",
3
- "version": "2.14.1-dev.53+75290c6cb",
3
+ "version": "2.14.1-dev.82+5e3ca3e0c",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,16 +15,16 @@
15
15
  "node": ">= 16.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "@atlaspack/diagnostic": "2.14.1-dev.53+75290c6cb",
19
- "@atlaspack/feature-flags": "2.14.1-dev.53+75290c6cb",
20
- "@atlaspack/plugin": "2.14.1-dev.53+75290c6cb",
21
- "@atlaspack/rust": "3.0.1-dev.53+75290c6cb",
22
- "@atlaspack/types": "2.14.1-dev.53+75290c6cb",
23
- "@atlaspack/utils": "2.14.1-dev.53+75290c6cb",
18
+ "@atlaspack/diagnostic": "2.14.1-dev.82+5e3ca3e0c",
19
+ "@atlaspack/feature-flags": "2.14.1-dev.82+5e3ca3e0c",
20
+ "@atlaspack/plugin": "2.14.1-dev.82+5e3ca3e0c",
21
+ "@atlaspack/rust": "3.0.1-dev.82+5e3ca3e0c",
22
+ "@atlaspack/types": "2.14.1-dev.82+5e3ca3e0c",
23
+ "@atlaspack/utils": "2.14.1-dev.82+5e3ca3e0c",
24
24
  "@parcel/source-map": "^2.1.1",
25
25
  "globals": "^13.2.0",
26
26
  "nullthrows": "^1.1.1"
27
27
  },
28
28
  "type": "commonjs",
29
- "gitHead": "75290c6cb03e7253ab1f9bfc6859d518a7d313cc"
29
+ "gitHead": "5e3ca3e0cbbd49f4e67ac8d9b8aeebba1c3e76ef"
30
30
  }
@@ -286,6 +286,19 @@ export class ScopeHoistingPackager {
286
286
  let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
287
287
  let hasHtmlReference = referencingBundles.some((b) => b.type === 'html');
288
288
 
289
+ let hasConditionalReference = false;
290
+ let isConditionalBundle = false;
291
+ if (
292
+ getFeatureFlag('conditionalBundlingApi') &&
293
+ getFeatureFlag('conditionalBundlingAsyncRuntime')
294
+ ) {
295
+ // If the bundle has a conditional bundle reference (has an importCond)
296
+ hasConditionalReference =
297
+ this.bundleGraph.getReferencedConditionalBundles(bundle).length > 0;
298
+ // If the bundle is a conditional bundle
299
+ isConditionalBundle = this.hasConditionalDependency();
300
+ }
301
+
289
302
  return (
290
303
  this.useAsyncBundleRuntime &&
291
304
  bundle.type === 'js' &&
@@ -293,7 +306,7 @@ export class ScopeHoistingPackager {
293
306
  bundle.env.outputFormat === 'esmodule' &&
294
307
  !bundle.env.isIsolated() &&
295
308
  bundle.bundleBehavior !== 'isolated' &&
296
- hasHtmlReference
309
+ (hasHtmlReference || hasConditionalReference || isConditionalBundle)
297
310
  );
298
311
  }
299
312
 
@@ -303,7 +316,32 @@ export class ScopeHoistingPackager {
303
316
  .filter((b) => this.shouldBundleQueue(b))
304
317
  .map((b) => b.publicId);
305
318
 
306
- if (deps.length === 0) {
319
+ const conditions = [];
320
+ if (
321
+ getFeatureFlag('conditionalBundlingApi') &&
322
+ getFeatureFlag('conditionalBundlingAsyncRuntime')
323
+ ) {
324
+ const conditionSet = this.bundleGraph
325
+ .getConditionalBundleMapping()
326
+ .get(bundle.id);
327
+
328
+ for (const [
329
+ key,
330
+ {ifTrueBundles, ifFalseBundles},
331
+ ] of conditionSet?.entries() ?? []) {
332
+ const ifTrueBundleIds = ifTrueBundles
333
+ .map((b) => `"${b.publicId}"`)
334
+ .join(',');
335
+ const ifFalseBundleIds = ifFalseBundles
336
+ .map((b) => `"${b.publicId}"`)
337
+ .join(',');
338
+ conditions.push(
339
+ `(globalThis.__MCOND && globalThis.__MCOND('${key}') ? [${ifTrueBundleIds}] : [${ifFalseBundleIds}])`,
340
+ );
341
+ }
342
+ }
343
+
344
+ if (deps.length === 0 && conditions.length === 0) {
307
345
  // If no deps we can safely execute immediately
308
346
  return codeToRun;
309
347
  }
@@ -311,7 +349,13 @@ export class ScopeHoistingPackager {
311
349
  let params = [
312
350
  JSON.stringify(this.bundle.publicId),
313
351
  fnExpr(this.bundle.env, [], [codeToRun]),
314
- JSON.stringify(deps),
352
+ `${JSON.stringify(deps)}${
353
+ conditions.length > 0
354
+ ? `.concat([${conditions
355
+ .map((conditions) => `...${conditions}`)
356
+ .join(',')}])`
357
+ : ''
358
+ }`,
315
359
  ];
316
360
 
317
361
  return `$parcel$global.rwr(${params.join(', ')});`;