@atlaspack/packager-js 2.14.1-dev.15 → 2.14.1-dev.26
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.
|
@@ -229,15 +229,35 @@ class ScopeHoistingPackager {
|
|
|
229
229
|
shouldBundleQueue(bundle) {
|
|
230
230
|
let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
|
|
231
231
|
let hasHtmlReference = referencingBundles.some(b => b.type === 'html');
|
|
232
|
-
|
|
232
|
+
let hasConditionalReference = false;
|
|
233
|
+
let isConditionalBundle = false;
|
|
234
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && (0, _featureFlags().getFeatureFlag)('conditionalBundlingAsyncRuntime')) {
|
|
235
|
+
// If the bundle has a conditional bundle reference (has an importCond)
|
|
236
|
+
hasConditionalReference = this.bundleGraph.getReferencedConditionalBundles(bundle).length > 0;
|
|
237
|
+
// If the bundle is a conditional bundle
|
|
238
|
+
isConditionalBundle = this.hasConditionalDependency();
|
|
239
|
+
}
|
|
240
|
+
return this.useAsyncBundleRuntime && bundle.type === 'js' && bundle.bundleBehavior !== 'inline' && bundle.env.outputFormat === 'esmodule' && !bundle.env.isIsolated() && bundle.bundleBehavior !== 'isolated' && (hasHtmlReference || hasConditionalReference || isConditionalBundle);
|
|
233
241
|
}
|
|
234
242
|
runWhenReady(bundle, codeToRun) {
|
|
235
243
|
let deps = this.bundleGraph.getReferencedBundles(bundle).filter(b => this.shouldBundleQueue(b)).map(b => b.publicId);
|
|
236
|
-
|
|
244
|
+
const conditions = [];
|
|
245
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && (0, _featureFlags().getFeatureFlag)('conditionalBundlingAsyncRuntime')) {
|
|
246
|
+
const conditionSet = this.bundleGraph.getConditionalBundleMapping().get(bundle.id);
|
|
247
|
+
for (const [key, {
|
|
248
|
+
ifTrueBundles,
|
|
249
|
+
ifFalseBundles
|
|
250
|
+
}] of (conditionSet === null || conditionSet === void 0 ? void 0 : conditionSet.entries()) ?? []) {
|
|
251
|
+
const ifTrueBundleIds = ifTrueBundles.map(b => `"${b.publicId}"`).join(',');
|
|
252
|
+
const ifFalseBundleIds = ifFalseBundles.map(b => `"${b.publicId}"`).join(',');
|
|
253
|
+
conditions.push(`(globalThis.__MCOND && globalThis.__MCOND('${key}') ? [${ifTrueBundleIds}] : [${ifFalseBundleIds}])`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (deps.length === 0 && conditions.length === 0) {
|
|
237
257
|
// If no deps we can safely execute immediately
|
|
238
258
|
return codeToRun;
|
|
239
259
|
}
|
|
240
|
-
let params = [JSON.stringify(this.bundle.publicId), (0, _helpers.fnExpr)(this.bundle.env, [], [codeToRun]), JSON.stringify(deps)];
|
|
260
|
+
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(',')}])` : ''}`];
|
|
241
261
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
242
262
|
}
|
|
243
263
|
async loadAssets() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.14.1-dev.
|
|
3
|
+
"version": "2.14.1-dev.26+01507b628",
|
|
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.
|
|
19
|
-
"@atlaspack/feature-flags": "2.14.1-dev.
|
|
20
|
-
"@atlaspack/plugin": "2.14.1-dev.
|
|
21
|
-
"@atlaspack/rust": "3.0.1-dev.
|
|
22
|
-
"@atlaspack/types": "2.14.1-dev.
|
|
23
|
-
"@atlaspack/utils": "2.14.1-dev.
|
|
18
|
+
"@atlaspack/diagnostic": "2.14.1-dev.26+01507b628",
|
|
19
|
+
"@atlaspack/feature-flags": "2.14.1-dev.26+01507b628",
|
|
20
|
+
"@atlaspack/plugin": "2.14.1-dev.26+01507b628",
|
|
21
|
+
"@atlaspack/rust": "3.0.1-dev.26+01507b628",
|
|
22
|
+
"@atlaspack/types": "2.14.1-dev.26+01507b628",
|
|
23
|
+
"@atlaspack/utils": "2.14.1-dev.26+01507b628",
|
|
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": "
|
|
29
|
+
"gitHead": "01507b628930d24dac9c29f19e2866dee381b09e"
|
|
30
30
|
}
|
|
@@ -279,6 +279,19 @@ export class ScopeHoistingPackager {
|
|
|
279
279
|
let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
|
|
280
280
|
let hasHtmlReference = referencingBundles.some((b) => b.type === 'html');
|
|
281
281
|
|
|
282
|
+
let hasConditionalReference = false;
|
|
283
|
+
let isConditionalBundle = false;
|
|
284
|
+
if (
|
|
285
|
+
getFeatureFlag('conditionalBundlingApi') &&
|
|
286
|
+
getFeatureFlag('conditionalBundlingAsyncRuntime')
|
|
287
|
+
) {
|
|
288
|
+
// If the bundle has a conditional bundle reference (has an importCond)
|
|
289
|
+
hasConditionalReference =
|
|
290
|
+
this.bundleGraph.getReferencedConditionalBundles(bundle).length > 0;
|
|
291
|
+
// If the bundle is a conditional bundle
|
|
292
|
+
isConditionalBundle = this.hasConditionalDependency();
|
|
293
|
+
}
|
|
294
|
+
|
|
282
295
|
return (
|
|
283
296
|
this.useAsyncBundleRuntime &&
|
|
284
297
|
bundle.type === 'js' &&
|
|
@@ -286,7 +299,7 @@ export class ScopeHoistingPackager {
|
|
|
286
299
|
bundle.env.outputFormat === 'esmodule' &&
|
|
287
300
|
!bundle.env.isIsolated() &&
|
|
288
301
|
bundle.bundleBehavior !== 'isolated' &&
|
|
289
|
-
hasHtmlReference
|
|
302
|
+
(hasHtmlReference || hasConditionalReference || isConditionalBundle)
|
|
290
303
|
);
|
|
291
304
|
}
|
|
292
305
|
|
|
@@ -296,7 +309,32 @@ export class ScopeHoistingPackager {
|
|
|
296
309
|
.filter((b) => this.shouldBundleQueue(b))
|
|
297
310
|
.map((b) => b.publicId);
|
|
298
311
|
|
|
299
|
-
|
|
312
|
+
const conditions = [];
|
|
313
|
+
if (
|
|
314
|
+
getFeatureFlag('conditionalBundlingApi') &&
|
|
315
|
+
getFeatureFlag('conditionalBundlingAsyncRuntime')
|
|
316
|
+
) {
|
|
317
|
+
const conditionSet = this.bundleGraph
|
|
318
|
+
.getConditionalBundleMapping()
|
|
319
|
+
.get(bundle.id);
|
|
320
|
+
|
|
321
|
+
for (const [
|
|
322
|
+
key,
|
|
323
|
+
{ifTrueBundles, ifFalseBundles},
|
|
324
|
+
] of conditionSet?.entries() ?? []) {
|
|
325
|
+
const ifTrueBundleIds = ifTrueBundles
|
|
326
|
+
.map((b) => `"${b.publicId}"`)
|
|
327
|
+
.join(',');
|
|
328
|
+
const ifFalseBundleIds = ifFalseBundles
|
|
329
|
+
.map((b) => `"${b.publicId}"`)
|
|
330
|
+
.join(',');
|
|
331
|
+
conditions.push(
|
|
332
|
+
`(globalThis.__MCOND && globalThis.__MCOND('${key}') ? [${ifTrueBundleIds}] : [${ifFalseBundleIds}])`,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (deps.length === 0 && conditions.length === 0) {
|
|
300
338
|
// If no deps we can safely execute immediately
|
|
301
339
|
return codeToRun;
|
|
302
340
|
}
|
|
@@ -304,7 +342,13 @@ export class ScopeHoistingPackager {
|
|
|
304
342
|
let params = [
|
|
305
343
|
JSON.stringify(this.bundle.publicId),
|
|
306
344
|
fnExpr(this.bundle.env, [], [codeToRun]),
|
|
307
|
-
JSON.stringify(deps)
|
|
345
|
+
`${JSON.stringify(deps)}${
|
|
346
|
+
conditions.length > 0
|
|
347
|
+
? `.concat([${conditions
|
|
348
|
+
.map((conditions) => `...${conditions}`)
|
|
349
|
+
.join(',')}])`
|
|
350
|
+
: ''
|
|
351
|
+
}`,
|
|
308
352
|
];
|
|
309
353
|
|
|
310
354
|
return `$parcel$global.rwr(${params.join(', ')});`;
|