@atlaspack/packager-js 2.14.5-canary.76 → 2.14.5-canary.77
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/ScopeHoistingPackager.js +74 -32
- package/package.json +8 -8
- package/src/ScopeHoistingPackager.js +102 -41
|
@@ -281,36 +281,69 @@ class ScopeHoistingPackager {
|
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
});
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
284
|
+
if ((0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovement')) {
|
|
285
|
+
// Tracks which assets have been assigned to a wrap group
|
|
286
|
+
let assignedAssets = new Set();
|
|
287
|
+
for (let wrappedAsset of wrapped) {
|
|
288
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
289
|
+
if (asset === wrappedAsset) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (this.wrappedAssets.has(asset.id)) {
|
|
293
|
+
actions.skipChildren();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (assignedAssets.has(asset) || this.isReExported(asset)) {
|
|
297
|
+
wrapped.push(asset);
|
|
298
|
+
this.wrappedAssets.add(asset.id);
|
|
299
|
+
actions.skipChildren();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
assignedAssets.add(asset);
|
|
303
|
+
}, wrappedAsset);
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
for (let wrappedAssetRoot of [...wrapped]) {
|
|
307
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
308
|
+
if (asset === wrappedAssetRoot) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (this.wrappedAssets.has(asset.id)) {
|
|
312
|
+
actions.skipChildren();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// This prevents children of a wrapped asset also being wrapped - it's an "unsafe" optimisation
|
|
316
|
+
// that should only be used when you know (or think you know) what you're doing.
|
|
317
|
+
//
|
|
318
|
+
// In particular this can force an async bundle to be scope hoisted where it previously would not be
|
|
319
|
+
// due to the entry asset being wrapped.
|
|
320
|
+
if (this.forceSkipWrapAssets.length > 0 && this.forceSkipWrapAssets.some(p => p === _path().default.relative(this.options.projectRoot, asset.filePath))) {
|
|
321
|
+
this.logger.verbose({
|
|
322
|
+
message: `Force skipping wrapping of ${_path().default.relative(this.options.projectRoot, asset.filePath)}`
|
|
323
|
+
});
|
|
324
|
+
actions.skipChildren();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (!asset.meta.isConstantModule) {
|
|
328
|
+
this.wrappedAssets.add(asset.id);
|
|
329
|
+
wrapped.push(asset);
|
|
330
|
+
}
|
|
331
|
+
}, wrappedAssetRoot);
|
|
332
|
+
}
|
|
310
333
|
}
|
|
311
334
|
this.assetOutputs = new Map(await queue.run());
|
|
312
335
|
return wrapped;
|
|
313
336
|
}
|
|
337
|
+
isReExported(asset) {
|
|
338
|
+
let parentSymbols = this.bundleGraph.getIncomingDependencies(asset).map(dep => this.bundleGraph.getAssetWithDependency(dep)).flatMap(parent => {
|
|
339
|
+
if (parent == null) {
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
return this.bundleGraph.getExportedSymbols(parent, this.bundle);
|
|
343
|
+
});
|
|
344
|
+
let assetSymbols = this.bundleGraph.getExportedSymbols(asset, this.bundle);
|
|
345
|
+
return assetSymbols.some(assetSymbol => parentSymbols.some(parentSymbol => parentSymbol.symbol === assetSymbol.symbol));
|
|
346
|
+
}
|
|
314
347
|
buildExportedSymbols() {
|
|
315
348
|
if (!this.bundle.env.isLibrary || this.bundle.env.outputFormat !== 'esmodule') {
|
|
316
349
|
return;
|
|
@@ -489,13 +522,22 @@ class ScopeHoistingPackager {
|
|
|
489
522
|
// outside our parcelRequire.register wrapper. This is safe because all
|
|
490
523
|
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
491
524
|
// asset content where the import statement was.
|
|
492
|
-
if (
|
|
493
|
-
|
|
525
|
+
if ((0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovement')) {
|
|
526
|
+
if (!this.wrappedAssets.has(resolved.id)) {
|
|
527
|
+
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
528
|
+
res = depCode + '\n' + res;
|
|
529
|
+
lines += 1 + depLines;
|
|
530
|
+
map = depMap;
|
|
531
|
+
}
|
|
494
532
|
} else {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
533
|
+
if (shouldWrap) {
|
|
534
|
+
depContent.push(this.visitAsset(resolved));
|
|
535
|
+
} else {
|
|
536
|
+
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
537
|
+
res = depCode + '\n' + res;
|
|
538
|
+
lines += 1 + depLines;
|
|
539
|
+
map = depMap;
|
|
540
|
+
}
|
|
499
541
|
}
|
|
500
542
|
}
|
|
501
543
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.77+85c52d3f7",
|
|
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-canary.
|
|
19
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
20
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
21
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
22
|
-
"@atlaspack/types": "2.14.5-canary.
|
|
23
|
-
"@atlaspack/utils": "2.14.5-canary.
|
|
18
|
+
"@atlaspack/diagnostic": "2.14.1-canary.145+85c52d3f7",
|
|
19
|
+
"@atlaspack/feature-flags": "2.14.1-canary.145+85c52d3f7",
|
|
20
|
+
"@atlaspack/plugin": "2.14.5-canary.77+85c52d3f7",
|
|
21
|
+
"@atlaspack/rust": "3.2.1-canary.77+85c52d3f7",
|
|
22
|
+
"@atlaspack/types": "2.14.5-canary.77+85c52d3f7",
|
|
23
|
+
"@atlaspack/utils": "2.14.5-canary.77+85c52d3f7",
|
|
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": "85c52d3f7717b3c84a118d18ab98cfbfd71dcbd2"
|
|
30
30
|
}
|
|
@@ -363,6 +363,7 @@ export class ScopeHoistingPackager {
|
|
|
363
363
|
asset.getCode(),
|
|
364
364
|
this.bundle.env.sourceMap ? asset.getMapBuffer() : null,
|
|
365
365
|
]);
|
|
366
|
+
|
|
366
367
|
return [asset.id, {code, map}];
|
|
367
368
|
});
|
|
368
369
|
|
|
@@ -387,48 +388,97 @@ export class ScopeHoistingPackager {
|
|
|
387
388
|
}
|
|
388
389
|
});
|
|
389
390
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
391
|
+
if (getFeatureFlag('applyScopeHoistingImprovement')) {
|
|
392
|
+
// Tracks which assets have been assigned to a wrap group
|
|
393
|
+
let assignedAssets = new Set<Asset>();
|
|
395
394
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
this.
|
|
408
|
-
(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
395
|
+
for (let wrappedAsset of wrapped) {
|
|
396
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
397
|
+
if (asset === wrappedAsset) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (this.wrappedAssets.has(asset.id)) {
|
|
402
|
+
actions.skipChildren();
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (assignedAssets.has(asset) || this.isReExported(asset)) {
|
|
407
|
+
wrapped.push(asset);
|
|
408
|
+
this.wrappedAssets.add(asset.id);
|
|
409
|
+
|
|
410
|
+
actions.skipChildren();
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
assignedAssets.add(asset);
|
|
415
|
+
}, wrappedAsset);
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
for (let wrappedAssetRoot of [...wrapped]) {
|
|
419
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
420
|
+
if (asset === wrappedAssetRoot) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (this.wrappedAssets.has(asset.id)) {
|
|
425
|
+
actions.skipChildren();
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
// This prevents children of a wrapped asset also being wrapped - it's an "unsafe" optimisation
|
|
429
|
+
// that should only be used when you know (or think you know) what you're doing.
|
|
430
|
+
//
|
|
431
|
+
// In particular this can force an async bundle to be scope hoisted where it previously would not be
|
|
432
|
+
// due to the entry asset being wrapped.
|
|
433
|
+
if (
|
|
434
|
+
this.forceSkipWrapAssets.length > 0 &&
|
|
435
|
+
this.forceSkipWrapAssets.some(
|
|
436
|
+
(p) =>
|
|
437
|
+
p === path.relative(this.options.projectRoot, asset.filePath),
|
|
438
|
+
)
|
|
439
|
+
) {
|
|
440
|
+
this.logger.verbose({
|
|
441
|
+
message: `Force skipping wrapping of ${path.relative(
|
|
442
|
+
this.options.projectRoot,
|
|
443
|
+
asset.filePath,
|
|
444
|
+
)}`,
|
|
445
|
+
});
|
|
446
|
+
actions.skipChildren();
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (!asset.meta.isConstantModule) {
|
|
450
|
+
this.wrappedAssets.add(asset.id);
|
|
451
|
+
wrapped.push(asset);
|
|
452
|
+
}
|
|
453
|
+
}, wrappedAssetRoot);
|
|
454
|
+
}
|
|
426
455
|
}
|
|
427
456
|
|
|
428
457
|
this.assetOutputs = new Map(await queue.run());
|
|
458
|
+
|
|
429
459
|
return wrapped;
|
|
430
460
|
}
|
|
431
461
|
|
|
462
|
+
isReExported(asset: Asset): boolean {
|
|
463
|
+
let parentSymbols = this.bundleGraph
|
|
464
|
+
.getIncomingDependencies(asset)
|
|
465
|
+
.map((dep) => this.bundleGraph.getAssetWithDependency(dep))
|
|
466
|
+
.flatMap((parent) => {
|
|
467
|
+
if (parent == null) {
|
|
468
|
+
return [];
|
|
469
|
+
}
|
|
470
|
+
return this.bundleGraph.getExportedSymbols(parent, this.bundle);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
let assetSymbols = this.bundleGraph.getExportedSymbols(asset, this.bundle);
|
|
474
|
+
|
|
475
|
+
return assetSymbols.some((assetSymbol) =>
|
|
476
|
+
parentSymbols.some(
|
|
477
|
+
(parentSymbol) => parentSymbol.symbol === assetSymbol.symbol,
|
|
478
|
+
),
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
432
482
|
buildExportedSymbols() {
|
|
433
483
|
if (
|
|
434
484
|
!this.bundle.env.isLibrary ||
|
|
@@ -661,13 +711,24 @@ export class ScopeHoistingPackager {
|
|
|
661
711
|
// outside our parcelRequire.register wrapper. This is safe because all
|
|
662
712
|
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
663
713
|
// asset content where the import statement was.
|
|
664
|
-
if (
|
|
665
|
-
|
|
714
|
+
if (getFeatureFlag('applyScopeHoistingImprovement')) {
|
|
715
|
+
if (!this.wrappedAssets.has(resolved.id)) {
|
|
716
|
+
let [depCode, depMap, depLines] =
|
|
717
|
+
this.visitAsset(resolved);
|
|
718
|
+
res = depCode + '\n' + res;
|
|
719
|
+
lines += 1 + depLines;
|
|
720
|
+
map = depMap;
|
|
721
|
+
}
|
|
666
722
|
} else {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
723
|
+
if (shouldWrap) {
|
|
724
|
+
depContent.push(this.visitAsset(resolved));
|
|
725
|
+
} else {
|
|
726
|
+
let [depCode, depMap, depLines] =
|
|
727
|
+
this.visitAsset(resolved);
|
|
728
|
+
res = depCode + '\n' + res;
|
|
729
|
+
lines += 1 + depLines;
|
|
730
|
+
map = depMap;
|
|
731
|
+
}
|
|
671
732
|
}
|
|
672
733
|
}
|
|
673
734
|
|