@atlaspack/packager-js 2.14.1-dev.9 → 2.14.1-dev.91
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.
|
@@ -127,6 +127,12 @@ class ScopeHoistingPackager {
|
|
|
127
127
|
for (let b of this.bundleGraph.getReferencedBundles(this.bundle, {
|
|
128
128
|
recursive: false
|
|
129
129
|
})) {
|
|
130
|
+
// If the referenced bundle is a native node bundle then don't require it as
|
|
131
|
+
// an external as we don't want to require native node bundles from other
|
|
132
|
+
// OS architectures
|
|
133
|
+
if (process.env.ATLASPACK_SUPER_BUILD === 'true' && b.type === 'node') {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
130
136
|
this.externals.set((0, _utils().relativeBundlePath)(this.bundle, b), new Map());
|
|
131
137
|
}
|
|
132
138
|
}
|
|
@@ -229,15 +235,35 @@ class ScopeHoistingPackager {
|
|
|
229
235
|
shouldBundleQueue(bundle) {
|
|
230
236
|
let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
|
|
231
237
|
let hasHtmlReference = referencingBundles.some(b => b.type === 'html');
|
|
232
|
-
|
|
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);
|
|
233
247
|
}
|
|
234
248
|
runWhenReady(bundle, codeToRun) {
|
|
235
249
|
let deps = this.bundleGraph.getReferencedBundles(bundle).filter(b => this.shouldBundleQueue(b)).map(b => b.publicId);
|
|
236
|
-
|
|
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) {
|
|
237
263
|
// If no deps we can safely execute immediately
|
|
238
264
|
return codeToRun;
|
|
239
265
|
}
|
|
240
|
-
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(',')}])` : ''}`];
|
|
241
267
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
242
268
|
}
|
|
243
269
|
async loadAssets() {
|
|
@@ -568,6 +594,14 @@ ${code}
|
|
|
568
594
|
this.externalAssets.add(resolved);
|
|
569
595
|
continue;
|
|
570
596
|
}
|
|
597
|
+
|
|
598
|
+
// If the referencedBundle is a native node import then require it
|
|
599
|
+
// directly
|
|
600
|
+
// Only enabled for internal builds for now
|
|
601
|
+
if (process.env.ATLASPACK_SUPER_BUILD === 'true' && referencedBundle && referencedBundle.type === 'node') {
|
|
602
|
+
replacements.set((0, _nullthrows().default)(dep.symbols.get('*')).local, `require('${(0, _utils().relativeBundlePath)(this.bundle, referencedBundle)}')`);
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
571
605
|
}
|
|
572
606
|
for (let [imported, {
|
|
573
607
|
local
|
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.91+08020e0e1",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,20 +12,19 @@
|
|
|
12
12
|
"main": "lib/index.js",
|
|
13
13
|
"source": "src/index.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"atlaspack": "^2.14.1-dev.9+6d1d32abe",
|
|
16
15
|
"node": ">= 16.0.0"
|
|
17
16
|
},
|
|
18
17
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.1-dev.
|
|
20
|
-
"@atlaspack/feature-flags": "2.14.1-dev.
|
|
21
|
-
"@atlaspack/plugin": "2.14.1-dev.
|
|
22
|
-
"@atlaspack/rust": "3.0.1-dev.
|
|
23
|
-
"@atlaspack/types": "2.14.1-dev.
|
|
24
|
-
"@atlaspack/utils": "2.14.1-dev.
|
|
18
|
+
"@atlaspack/diagnostic": "2.14.1-dev.91+08020e0e1",
|
|
19
|
+
"@atlaspack/feature-flags": "2.14.1-dev.91+08020e0e1",
|
|
20
|
+
"@atlaspack/plugin": "2.14.1-dev.91+08020e0e1",
|
|
21
|
+
"@atlaspack/rust": "3.0.1-dev.91+08020e0e1",
|
|
22
|
+
"@atlaspack/types": "2.14.1-dev.91+08020e0e1",
|
|
23
|
+
"@atlaspack/utils": "2.14.1-dev.91+08020e0e1",
|
|
25
24
|
"@parcel/source-map": "^2.1.1",
|
|
26
25
|
"globals": "^13.2.0",
|
|
27
26
|
"nullthrows": "^1.1.1"
|
|
28
27
|
},
|
|
29
28
|
"type": "commonjs",
|
|
30
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "08020e0e18819f3e15e74726f9ffa697892f7bfa"
|
|
31
30
|
}
|
|
@@ -149,6 +149,13 @@ export class ScopeHoistingPackager {
|
|
|
149
149
|
for (let b of this.bundleGraph.getReferencedBundles(this.bundle, {
|
|
150
150
|
recursive: false,
|
|
151
151
|
})) {
|
|
152
|
+
// If the referenced bundle is a native node bundle then don't require it as
|
|
153
|
+
// an external as we don't want to require native node bundles from other
|
|
154
|
+
// OS architectures
|
|
155
|
+
if (process.env.ATLASPACK_SUPER_BUILD === 'true' && b.type === 'node') {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
152
159
|
this.externals.set(relativeBundlePath(this.bundle, b), new Map());
|
|
153
160
|
}
|
|
154
161
|
}
|
|
@@ -279,6 +286,19 @@ export class ScopeHoistingPackager {
|
|
|
279
286
|
let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
|
|
280
287
|
let hasHtmlReference = referencingBundles.some((b) => b.type === 'html');
|
|
281
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
|
+
|
|
282
302
|
return (
|
|
283
303
|
this.useAsyncBundleRuntime &&
|
|
284
304
|
bundle.type === 'js' &&
|
|
@@ -286,7 +306,7 @@ export class ScopeHoistingPackager {
|
|
|
286
306
|
bundle.env.outputFormat === 'esmodule' &&
|
|
287
307
|
!bundle.env.isIsolated() &&
|
|
288
308
|
bundle.bundleBehavior !== 'isolated' &&
|
|
289
|
-
hasHtmlReference
|
|
309
|
+
(hasHtmlReference || hasConditionalReference || isConditionalBundle)
|
|
290
310
|
);
|
|
291
311
|
}
|
|
292
312
|
|
|
@@ -296,7 +316,32 @@ export class ScopeHoistingPackager {
|
|
|
296
316
|
.filter((b) => this.shouldBundleQueue(b))
|
|
297
317
|
.map((b) => b.publicId);
|
|
298
318
|
|
|
299
|
-
|
|
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) {
|
|
300
345
|
// If no deps we can safely execute immediately
|
|
301
346
|
return codeToRun;
|
|
302
347
|
}
|
|
@@ -304,7 +349,13 @@ export class ScopeHoistingPackager {
|
|
|
304
349
|
let params = [
|
|
305
350
|
JSON.stringify(this.bundle.publicId),
|
|
306
351
|
fnExpr(this.bundle.env, [], [codeToRun]),
|
|
307
|
-
JSON.stringify(deps)
|
|
352
|
+
`${JSON.stringify(deps)}${
|
|
353
|
+
conditions.length > 0
|
|
354
|
+
? `.concat([${conditions
|
|
355
|
+
.map((conditions) => `...${conditions}`)
|
|
356
|
+
.join(',')}])`
|
|
357
|
+
: ''
|
|
358
|
+
}`,
|
|
308
359
|
];
|
|
309
360
|
|
|
310
361
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
@@ -765,6 +816,21 @@ ${code}
|
|
|
765
816
|
this.externalAssets.add(resolved);
|
|
766
817
|
continue;
|
|
767
818
|
}
|
|
819
|
+
|
|
820
|
+
// If the referencedBundle is a native node import then require it
|
|
821
|
+
// directly
|
|
822
|
+
// Only enabled for internal builds for now
|
|
823
|
+
if (
|
|
824
|
+
process.env.ATLASPACK_SUPER_BUILD === 'true' &&
|
|
825
|
+
referencedBundle &&
|
|
826
|
+
referencedBundle.type === 'node'
|
|
827
|
+
) {
|
|
828
|
+
replacements.set(
|
|
829
|
+
nullthrows(dep.symbols.get('*')).local,
|
|
830
|
+
`require('${relativeBundlePath(this.bundle, referencedBundle)}')`,
|
|
831
|
+
);
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
768
834
|
}
|
|
769
835
|
|
|
770
836
|
for (let [imported, {local}] of dep.symbols) {
|