@atlaspack/packager-js 2.14.5-canary.201 → 2.14.5-canary.203
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/dist/ESMOutputFormat.js +1 -1
- package/dist/ScopeHoistingPackager.js +43 -47
- package/lib/ESMOutputFormat.js +1 -1
- package/lib/ScopeHoistingPackager.js +41 -52
- package/lib/types/ScopeHoistingPackager.d.ts +6 -8
- package/package.json +8 -8
- package/src/ESMOutputFormat.ts +1 -1
- package/src/ScopeHoistingPackager.ts +49 -60
- package/tsconfig.tsbuildinfo +1 -1
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.203+0e967b0cf",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
20
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
21
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
22
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
23
|
-
"@atlaspack/types": "2.14.5-canary.
|
|
24
|
-
"@atlaspack/utils": "2.14.5-canary.
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.271+0e967b0cf",
|
|
20
|
+
"@atlaspack/feature-flags": "2.14.1-canary.271+0e967b0cf",
|
|
21
|
+
"@atlaspack/plugin": "2.14.5-canary.203+0e967b0cf",
|
|
22
|
+
"@atlaspack/rust": "3.2.1-canary.203+0e967b0cf",
|
|
23
|
+
"@atlaspack/types": "2.14.5-canary.203+0e967b0cf",
|
|
24
|
+
"@atlaspack/utils": "2.14.5-canary.203+0e967b0cf",
|
|
25
25
|
"@parcel/source-map": "^2.1.1",
|
|
26
26
|
"globals": "^13.2.0",
|
|
27
27
|
"nullthrows": "^1.1.1",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "0e967b0cf0fbd885588b81476ec1f25a507ffa94"
|
|
35
35
|
}
|
package/src/ESMOutputFormat.ts
CHANGED
|
@@ -83,7 +83,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
83
83
|
local,
|
|
84
84
|
exportAs,
|
|
85
85
|
} of this.packager.exportedSymbols.values()) {
|
|
86
|
-
if (this.packager.wrappedAssets.has(asset
|
|
86
|
+
if (this.packager.wrappedAssets.has(asset)) {
|
|
87
87
|
let obj = `parcelRequire("${this.packager.bundleGraph.getAssetPublicId(
|
|
88
88
|
asset,
|
|
89
89
|
)}")`;
|
|
@@ -92,7 +92,7 @@ export class ScopeHoistingPackager {
|
|
|
92
92
|
globalNames: ReadonlySet<string>;
|
|
93
93
|
// @ts-expect-error TS2564
|
|
94
94
|
assetOutputs: Map<
|
|
95
|
-
|
|
95
|
+
Asset,
|
|
96
96
|
{
|
|
97
97
|
code: string;
|
|
98
98
|
map: Buffer | null | undefined;
|
|
@@ -109,9 +109,10 @@ export class ScopeHoistingPackager {
|
|
|
109
109
|
> = new Map();
|
|
110
110
|
externals: Map<string, Map<string, string>> = new Map();
|
|
111
111
|
topLevelNames: Map<string, number> = new Map();
|
|
112
|
-
seenAssets: Set<
|
|
113
|
-
wrappedAssets: Set<
|
|
114
|
-
|
|
112
|
+
seenAssets: Set<Asset> = new Set();
|
|
113
|
+
wrappedAssets: Set<Asset> = new Set();
|
|
114
|
+
constantAssets: Set<Asset> = new Set();
|
|
115
|
+
hoistedRequires: Map<Dependency, Map<Asset, string>> = new Map();
|
|
115
116
|
seenHoistedRequires: Set<string> = new Set();
|
|
116
117
|
needsPrelude: boolean = false;
|
|
117
118
|
usedHelpers: Set<string> = new Set();
|
|
@@ -152,8 +153,7 @@ export class ScopeHoistingPackager {
|
|
|
152
153
|
contents: string;
|
|
153
154
|
map: SourceMap | null | undefined;
|
|
154
155
|
}> {
|
|
155
|
-
|
|
156
|
-
await this.loadAssets();
|
|
156
|
+
await this.loadAssets();
|
|
157
157
|
this.buildExportedSymbols();
|
|
158
158
|
|
|
159
159
|
// If building a library, the target is actually another bundler rather
|
|
@@ -196,8 +196,8 @@ export class ScopeHoistingPackager {
|
|
|
196
196
|
this.useBothScopeHoistingImprovements
|
|
197
197
|
) {
|
|
198
198
|
// Write out all constant modules used by this bundle
|
|
199
|
-
for (let asset of constantAssets) {
|
|
200
|
-
if (!this.seenAssets.has(asset
|
|
199
|
+
for (let asset of this.constantAssets) {
|
|
200
|
+
if (!this.seenAssets.has(asset)) {
|
|
201
201
|
processAsset(asset);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
@@ -205,8 +205,8 @@ export class ScopeHoistingPackager {
|
|
|
205
205
|
|
|
206
206
|
// Hoist wrapped asset to the top of the bundle to ensure that they are registered
|
|
207
207
|
// before they are used.
|
|
208
|
-
for (let asset of wrappedAssets) {
|
|
209
|
-
if (!this.seenAssets.has(asset
|
|
208
|
+
for (let asset of this.wrappedAssets) {
|
|
209
|
+
if (!this.seenAssets.has(asset)) {
|
|
210
210
|
processAsset(asset);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
@@ -214,7 +214,7 @@ export class ScopeHoistingPackager {
|
|
|
214
214
|
// Add each asset that is directly connected to the bundle. Dependencies will be handled
|
|
215
215
|
// by replacing `import` statements in the code.
|
|
216
216
|
this.bundle.traverseAssets((asset, _, actions) => {
|
|
217
|
-
if (this.seenAssets.has(asset
|
|
217
|
+
if (this.seenAssets.has(asset)) {
|
|
218
218
|
actions.skipChildren();
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
@@ -255,7 +255,7 @@ export class ScopeHoistingPackager {
|
|
|
255
255
|
|
|
256
256
|
// If any of the entry assets are wrapped, call parcelRequire so they are executed.
|
|
257
257
|
for (let entry of entries) {
|
|
258
|
-
if (this.wrappedAssets.has(entry
|
|
258
|
+
if (this.wrappedAssets.has(entry) && !this.isScriptEntry(entry)) {
|
|
259
259
|
let parcelRequire = `parcelRequire(${JSON.stringify(
|
|
260
260
|
this.bundleGraph.getAssetPublicId(entry),
|
|
261
261
|
)});\n`;
|
|
@@ -299,9 +299,7 @@ export class ScopeHoistingPackager {
|
|
|
299
299
|
lineCount++;
|
|
300
300
|
|
|
301
301
|
let mainEntry = nullthrows(this.bundle.getMainEntry());
|
|
302
|
-
let {code, map: mapBuffer} = nullthrows(
|
|
303
|
-
this.assetOutputs.get(mainEntry.id),
|
|
304
|
-
);
|
|
302
|
+
let {code, map: mapBuffer} = nullthrows(this.assetOutputs.get(mainEntry));
|
|
305
303
|
let map;
|
|
306
304
|
if (mapBuffer) {
|
|
307
305
|
map = new SourceMap(this.options.projectRoot, mapBuffer);
|
|
@@ -399,13 +397,11 @@ export class ScopeHoistingPackager {
|
|
|
399
397
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
400
398
|
}
|
|
401
399
|
|
|
402
|
-
async loadAssets()
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
let wrapped: Array<Asset> = [];
|
|
408
|
-
let constant: Array<Asset> = [];
|
|
400
|
+
async loadAssets() {
|
|
401
|
+
type QueueItem = [Asset, {code: string; map: Buffer | undefined | null}];
|
|
402
|
+
let queue = new PromiseQueue<QueueItem>({
|
|
403
|
+
maxConcurrent: 32,
|
|
404
|
+
});
|
|
409
405
|
|
|
410
406
|
this.bundle.traverseAssets((asset) => {
|
|
411
407
|
queue.add(async () => {
|
|
@@ -414,7 +410,7 @@ export class ScopeHoistingPackager {
|
|
|
414
410
|
this.bundle.env.sourceMap ? asset.getMapBuffer() : null,
|
|
415
411
|
]);
|
|
416
412
|
|
|
417
|
-
return [asset
|
|
413
|
+
return [asset, {code, map}];
|
|
418
414
|
});
|
|
419
415
|
|
|
420
416
|
if (
|
|
@@ -432,14 +428,13 @@ export class ScopeHoistingPackager {
|
|
|
432
428
|
.getIncomingDependencies(asset)
|
|
433
429
|
.some((dep) => dep.priority === 'lazy')
|
|
434
430
|
) {
|
|
435
|
-
this.wrappedAssets.add(asset
|
|
436
|
-
wrapped.push(asset);
|
|
431
|
+
this.wrappedAssets.add(asset);
|
|
437
432
|
} else if (
|
|
438
433
|
(getFeatureFlag('inlineConstOptimisationFix') ||
|
|
439
434
|
this.useBothScopeHoistingImprovements) &&
|
|
440
435
|
asset.meta.isConstantModule
|
|
441
436
|
) {
|
|
442
|
-
|
|
437
|
+
this.constantAssets.add(asset);
|
|
443
438
|
}
|
|
444
439
|
}
|
|
445
440
|
});
|
|
@@ -453,20 +448,21 @@ export class ScopeHoistingPackager {
|
|
|
453
448
|
if (!getFeatureFlag('applyScopeHoistingImprovementV2')) {
|
|
454
449
|
// Make all entry assets wrapped, to avoid any top level hoisting
|
|
455
450
|
for (let entryAsset of this.bundle.getEntryAssets()) {
|
|
456
|
-
if (!this.wrappedAssets.has(entryAsset
|
|
457
|
-
this.wrappedAssets.add(entryAsset
|
|
458
|
-
wrapped.push(entryAsset);
|
|
451
|
+
if (!this.wrappedAssets.has(entryAsset)) {
|
|
452
|
+
this.wrappedAssets.add(entryAsset);
|
|
459
453
|
}
|
|
460
454
|
}
|
|
461
455
|
}
|
|
462
456
|
|
|
463
|
-
|
|
457
|
+
// We need to make a new copy here so that we can add to the list and
|
|
458
|
+
// iterate the newly added items, without mutating the wrappedAssets set
|
|
459
|
+
let moduleGroupParents = [...this.wrappedAssets.values()];
|
|
464
460
|
|
|
465
461
|
if (getFeatureFlag('applyScopeHoistingImprovementV2')) {
|
|
466
462
|
// The main entry needs to be check to find assets that would have gone in
|
|
467
463
|
// the top level scope
|
|
468
464
|
let mainEntry = this.bundle.getMainEntry();
|
|
469
|
-
if (mainEntry && !this.wrappedAssets.has(mainEntry
|
|
465
|
+
if (mainEntry && !this.wrappedAssets.has(mainEntry)) {
|
|
470
466
|
moduleGroupParents.unshift(mainEntry);
|
|
471
467
|
}
|
|
472
468
|
}
|
|
@@ -477,7 +473,7 @@ export class ScopeHoistingPackager {
|
|
|
477
473
|
return;
|
|
478
474
|
}
|
|
479
475
|
|
|
480
|
-
if (this.wrappedAssets.has(asset
|
|
476
|
+
if (this.wrappedAssets.has(asset)) {
|
|
481
477
|
actions.skipChildren();
|
|
482
478
|
return;
|
|
483
479
|
}
|
|
@@ -486,8 +482,7 @@ export class ScopeHoistingPackager {
|
|
|
486
482
|
!asset.meta.isConstantModule &&
|
|
487
483
|
(assignedAssets.has(asset) || this.isReExported(asset))
|
|
488
484
|
) {
|
|
489
|
-
|
|
490
|
-
this.wrappedAssets.add(asset.id);
|
|
485
|
+
this.wrappedAssets.add(asset);
|
|
491
486
|
|
|
492
487
|
// This also needs to be added to the traversal so that we iterate
|
|
493
488
|
// it during this check.
|
|
@@ -501,28 +496,25 @@ export class ScopeHoistingPackager {
|
|
|
501
496
|
}, moduleGroupParentAsset);
|
|
502
497
|
}
|
|
503
498
|
} else {
|
|
504
|
-
for (let wrappedAssetRoot of
|
|
499
|
+
for (let wrappedAssetRoot of this.wrappedAssets) {
|
|
505
500
|
this.bundle.traverseAssets((asset, _, actions) => {
|
|
506
501
|
if (asset === wrappedAssetRoot) {
|
|
507
502
|
return;
|
|
508
503
|
}
|
|
509
504
|
|
|
510
|
-
if (this.wrappedAssets.has(asset
|
|
505
|
+
if (this.wrappedAssets.has(asset)) {
|
|
511
506
|
actions.skipChildren();
|
|
512
507
|
return;
|
|
513
508
|
}
|
|
514
509
|
|
|
515
510
|
if (!asset.meta.isConstantModule) {
|
|
516
|
-
this.wrappedAssets.add(asset
|
|
517
|
-
wrapped.push(asset);
|
|
511
|
+
this.wrappedAssets.add(asset);
|
|
518
512
|
}
|
|
519
513
|
}, wrappedAssetRoot);
|
|
520
514
|
}
|
|
521
515
|
}
|
|
522
516
|
|
|
523
|
-
// @ts-expect-error TS2769
|
|
524
517
|
this.assetOutputs = new Map(await queue.run());
|
|
525
|
-
return {wrapped, constant};
|
|
526
518
|
}
|
|
527
519
|
|
|
528
520
|
isReExported(asset: Asset): boolean {
|
|
@@ -555,7 +547,7 @@ export class ScopeHoistingPackager {
|
|
|
555
547
|
|
|
556
548
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
557
549
|
let entry = this.bundle.getMainEntry();
|
|
558
|
-
if (entry && !this.wrappedAssets.has(entry
|
|
550
|
+
if (entry && !this.wrappedAssets.has(entry)) {
|
|
559
551
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
560
552
|
|
|
561
553
|
for (let {
|
|
@@ -637,10 +629,10 @@ export class ScopeHoistingPackager {
|
|
|
637
629
|
}
|
|
638
630
|
|
|
639
631
|
visitAsset(asset: Asset): [string, SourceMap | null | undefined, number] {
|
|
640
|
-
invariant(!this.seenAssets.has(asset
|
|
641
|
-
this.seenAssets.add(asset
|
|
632
|
+
invariant(!this.seenAssets.has(asset), 'Already visited asset');
|
|
633
|
+
this.seenAssets.add(asset);
|
|
642
634
|
|
|
643
|
-
let {code, map} = nullthrows(this.assetOutputs.get(asset
|
|
635
|
+
let {code, map} = nullthrows(this.assetOutputs.get(asset));
|
|
644
636
|
return this.buildAsset(asset, code, map);
|
|
645
637
|
}
|
|
646
638
|
|
|
@@ -653,7 +645,7 @@ export class ScopeHoistingPackager {
|
|
|
653
645
|
code: string,
|
|
654
646
|
map?: Buffer | null,
|
|
655
647
|
): [string, SourceMap | null | undefined, number] {
|
|
656
|
-
let shouldWrap = this.wrappedAssets.has(asset
|
|
648
|
+
let shouldWrap = this.wrappedAssets.has(asset);
|
|
657
649
|
let deps = this.bundleGraph.getDependencies(asset);
|
|
658
650
|
|
|
659
651
|
let sourceMap =
|
|
@@ -680,10 +672,7 @@ export class ScopeHoistingPackager {
|
|
|
680
672
|
continue;
|
|
681
673
|
}
|
|
682
674
|
|
|
683
|
-
if (
|
|
684
|
-
this.bundle.hasAsset(resolved) &&
|
|
685
|
-
!this.seenAssets.has(resolved.id)
|
|
686
|
-
) {
|
|
675
|
+
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved)) {
|
|
687
676
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
688
677
|
depCode += code + '\n';
|
|
689
678
|
if (sourceMap && map) {
|
|
@@ -785,7 +774,7 @@ export class ScopeHoistingPackager {
|
|
|
785
774
|
|
|
786
775
|
if (
|
|
787
776
|
this.bundle.hasAsset(resolved) &&
|
|
788
|
-
!this.seenAssets.has(resolved
|
|
777
|
+
!this.seenAssets.has(resolved)
|
|
789
778
|
) {
|
|
790
779
|
// If this asset is wrapped, we need to hoist the code for the dependency
|
|
791
780
|
// outside our parcelRequire.register wrapper. This is safe because all
|
|
@@ -794,7 +783,7 @@ export class ScopeHoistingPackager {
|
|
|
794
783
|
if (this.useBothScopeHoistingImprovements) {
|
|
795
784
|
if (
|
|
796
785
|
!resolved.meta.isConstantModule &&
|
|
797
|
-
!this.wrappedAssets.has(resolved
|
|
786
|
+
!this.wrappedAssets.has(resolved)
|
|
798
787
|
) {
|
|
799
788
|
let [depCode, depMap, depLines] =
|
|
800
789
|
this.visitAsset(resolved);
|
|
@@ -1020,7 +1009,7 @@ ${code}
|
|
|
1020
1009
|
// If this asset is wrapped, we need to replace the exports namespace with `module.exports`,
|
|
1021
1010
|
// which will be provided to us by the wrapper.
|
|
1022
1011
|
if (
|
|
1023
|
-
this.wrappedAssets.has(asset
|
|
1012
|
+
this.wrappedAssets.has(asset) ||
|
|
1024
1013
|
(this.bundle.env.outputFormat === 'commonjs' &&
|
|
1025
1014
|
asset === this.bundle.getMainEntry())
|
|
1026
1015
|
) {
|
|
@@ -1210,7 +1199,7 @@ ${code}
|
|
|
1210
1199
|
}
|
|
1211
1200
|
return (
|
|
1212
1201
|
(!this.bundle.hasAsset(resolved) && !this.externalAssets.has(resolved)) ||
|
|
1213
|
-
(this.wrappedAssets.has(resolved
|
|
1202
|
+
(this.wrappedAssets.has(resolved) && resolved !== parentAsset)
|
|
1214
1203
|
);
|
|
1215
1204
|
}
|
|
1216
1205
|
|
|
@@ -1260,14 +1249,14 @@ ${code}
|
|
|
1260
1249
|
(!this.bundle.hasAsset(resolvedAsset) ||
|
|
1261
1250
|
!this.shouldSkipAsset(resolvedAsset))
|
|
1262
1251
|
) {
|
|
1263
|
-
let hoisted = this.hoistedRequires.get(dep
|
|
1252
|
+
let hoisted = this.hoistedRequires.get(dep);
|
|
1264
1253
|
if (!hoisted) {
|
|
1265
1254
|
hoisted = new Map();
|
|
1266
|
-
this.hoistedRequires.set(dep
|
|
1255
|
+
this.hoistedRequires.set(dep, hoisted);
|
|
1267
1256
|
}
|
|
1268
1257
|
|
|
1269
1258
|
hoisted.set(
|
|
1270
|
-
resolvedAsset
|
|
1259
|
+
resolvedAsset,
|
|
1271
1260
|
`var $${publicId} = parcelRequire(${JSON.stringify(publicId)});`,
|
|
1272
1261
|
);
|
|
1273
1262
|
}
|
|
@@ -1309,7 +1298,7 @@ ${code}
|
|
|
1309
1298
|
// Resolve to the namespace object if requested or this is a CJS default interop reqiure.
|
|
1310
1299
|
if (
|
|
1311
1300
|
parentAsset === resolvedAsset &&
|
|
1312
|
-
this.wrappedAssets.has(resolvedAsset
|
|
1301
|
+
this.wrappedAssets.has(resolvedAsset)
|
|
1313
1302
|
) {
|
|
1314
1303
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
1315
1304
|
return 'module.exports';
|
|
@@ -1352,7 +1341,7 @@ ${code}
|
|
|
1352
1341
|
return ['', 0];
|
|
1353
1342
|
}
|
|
1354
1343
|
|
|
1355
|
-
let hoisted = this.hoistedRequires.get(dep
|
|
1344
|
+
let hoisted = this.hoistedRequires.get(dep);
|
|
1356
1345
|
let res = '';
|
|
1357
1346
|
let lineCount = 0;
|
|
1358
1347
|
let isWrapped = this.isWrapped(resolved, parentAsset);
|
|
@@ -1364,7 +1353,7 @@ ${code}
|
|
|
1364
1353
|
if (
|
|
1365
1354
|
isWrapped &&
|
|
1366
1355
|
!dep.meta.shouldWrap &&
|
|
1367
|
-
(!hoisted || hoisted.keys().next().value !== resolved
|
|
1356
|
+
(!hoisted || hoisted.keys().next().value !== resolved) &&
|
|
1368
1357
|
!this.bundleGraph.isDependencySkipped(dep) &&
|
|
1369
1358
|
!this.shouldSkipAsset(resolved)
|
|
1370
1359
|
) {
|
|
@@ -1406,7 +1395,7 @@ ${code}
|
|
|
1406
1395
|
let prependLineCount = 0;
|
|
1407
1396
|
let append = '';
|
|
1408
1397
|
|
|
1409
|
-
let shouldWrap = this.wrappedAssets.has(asset
|
|
1398
|
+
let shouldWrap = this.wrappedAssets.has(asset);
|
|
1410
1399
|
let usedSymbols = nullthrows(this.bundleGraph.getUsedSymbols(asset));
|
|
1411
1400
|
let assetId = asset.meta.id;
|
|
1412
1401
|
invariant(typeof assetId === 'string');
|