@parcel/packager-js 2.7.0 → 2.8.0
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/DevPackager.js +8 -10
- package/lib/ScopeHoistingPackager.js +45 -40
- package/package.json +8 -8
- package/src/DevPackager.js +8 -10
- package/src/ScopeHoistingPackager.js +59 -52
package/lib/DevPackager.js
CHANGED
|
@@ -74,16 +74,14 @@ class DevPackager {
|
|
|
74
74
|
let queue = new (_utils().PromiseQueue)({
|
|
75
75
|
maxConcurrent: 32
|
|
76
76
|
});
|
|
77
|
-
this.bundle.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
}
|
|
77
|
+
this.bundle.traverseAssets(asset => {
|
|
78
|
+
queue.add(async () => {
|
|
79
|
+
let [code, mapBuffer] = await Promise.all([asset.getCode(), this.bundle.env.sourceMap && asset.getMapBuffer()]);
|
|
80
|
+
return {
|
|
81
|
+
code,
|
|
82
|
+
mapBuffer
|
|
83
|
+
};
|
|
84
|
+
});
|
|
87
85
|
});
|
|
88
86
|
let results = await queue.run();
|
|
89
87
|
let assets = '';
|
|
@@ -468,55 +468,60 @@ class ScopeHoistingPackager {
|
|
|
468
468
|
|
|
469
469
|
|
|
470
470
|
if (d != null) {
|
|
471
|
-
let
|
|
471
|
+
let deps = depMap.get(d);
|
|
472
472
|
|
|
473
|
-
if (!
|
|
473
|
+
if (!deps) {
|
|
474
474
|
return m;
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
let
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
477
|
+
let replacement = ''; // A single `${id}:${specifier}:esm` might have been resolved to multiple assets due to
|
|
478
|
+
// reexports.
|
|
479
|
+
|
|
480
|
+
for (let dep of deps) {
|
|
481
|
+
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
482
|
+
let skipped = this.bundleGraph.isDependencySkipped(dep);
|
|
483
|
+
|
|
484
|
+
if (resolved && !skipped) {
|
|
485
|
+
// Hoist variable declarations for the referenced parcelRequire dependencies
|
|
486
|
+
// after the dependency is declared. This handles the case where the resulting asset
|
|
487
|
+
// is wrapped, but the dependency in this asset is not marked as wrapped. This means
|
|
488
|
+
// that it was imported/required at the top-level, so its side effects should run immediately.
|
|
489
|
+
let [res, lines] = this.getHoistedParcelRequires(asset, dep, resolved);
|
|
490
|
+
let map;
|
|
491
|
+
|
|
492
|
+
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved.id)) {
|
|
493
|
+
// If this asset is wrapped, we need to hoist the code for the dependency
|
|
494
|
+
// outside our parcelRequire.register wrapper. This is safe because all
|
|
495
|
+
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
496
|
+
// asset content where the import statement was.
|
|
497
|
+
if (shouldWrap) {
|
|
498
|
+
depContent.push(this.visitAsset(resolved));
|
|
499
|
+
} else {
|
|
500
|
+
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
501
|
+
res = depCode + '\n' + res;
|
|
502
|
+
lines += 1 + depLines;
|
|
503
|
+
map = depMap;
|
|
504
|
+
}
|
|
505
|
+
} // Push this asset's source mappings down by the number of lines in the dependency
|
|
506
|
+
// plus the number of hoisted parcelRequires. Then insert the source map for the dependency.
|
|
503
507
|
|
|
504
508
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
+
if (sourceMap) {
|
|
510
|
+
if (lines > 0) {
|
|
511
|
+
sourceMap.offsetLines(lineCount + 1, lines);
|
|
512
|
+
}
|
|
509
513
|
|
|
510
|
-
|
|
511
|
-
|
|
514
|
+
if (map) {
|
|
515
|
+
sourceMap.addSourceMap(map, lineCount);
|
|
516
|
+
}
|
|
512
517
|
}
|
|
513
|
-
}
|
|
514
518
|
|
|
515
|
-
|
|
516
|
-
|
|
519
|
+
replacement += res;
|
|
520
|
+
lineCount += lines;
|
|
521
|
+
}
|
|
517
522
|
}
|
|
518
523
|
|
|
519
|
-
return
|
|
524
|
+
return replacement;
|
|
520
525
|
} // If it wasn't a dependency, then it was an inline replacement (e.g. $id$import$foo -> $id$export$foo).
|
|
521
526
|
|
|
522
527
|
|
|
@@ -571,12 +576,12 @@ ${code}
|
|
|
571
576
|
(0, _assert().default)(typeof assetId === 'string'); // Build two maps: one of import specifiers, and one of imported symbols to replace.
|
|
572
577
|
// These will be used to build a regex below.
|
|
573
578
|
|
|
574
|
-
let depMap = new
|
|
579
|
+
let depMap = new (_utils().DefaultMap)(() => []);
|
|
575
580
|
let replacements = new Map();
|
|
576
581
|
|
|
577
582
|
for (let dep of deps) {
|
|
578
583
|
let specifierType = dep.specifierType === 'esm' ? `:${dep.specifierType}` : '';
|
|
579
|
-
depMap.
|
|
584
|
+
depMap.get(`${assetId}:${(0, _utils2.getSpecifier)(dep)}${!dep.meta.placeholder ? specifierType : ''}`).push(dep);
|
|
580
585
|
let asyncResolution = this.bundleGraph.resolveAsyncDependency(dep, this.bundle);
|
|
581
586
|
let resolved = (asyncResolution === null || asyncResolution === void 0 ? void 0 : asyncResolution.type) === 'asset' ? // Prefer the underlying asset over a runtime to load it. It will
|
|
582
587
|
// be wrapped in Promise.resolve() later.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/index.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.
|
|
20
|
+
"parcel": "^2.8.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.
|
|
24
|
-
"@parcel/hash": "2.
|
|
25
|
-
"@parcel/plugin": "2.
|
|
26
|
-
"@parcel/source-map": "^2.
|
|
27
|
-
"@parcel/utils": "2.
|
|
23
|
+
"@parcel/diagnostic": "2.8.0",
|
|
24
|
+
"@parcel/hash": "2.8.0",
|
|
25
|
+
"@parcel/plugin": "2.8.0",
|
|
26
|
+
"@parcel/source-map": "^2.1.1",
|
|
27
|
+
"@parcel/utils": "2.8.0",
|
|
28
28
|
"globals": "^13.2.0",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "c3bbe0a6160186f496ca2f9e9bead9376c0522f1"
|
|
32
32
|
}
|
package/src/DevPackager.js
CHANGED
|
@@ -39,16 +39,14 @@ export class DevPackager {
|
|
|
39
39
|
async package(): Promise<{|contents: string, map: ?SourceMap|}> {
|
|
40
40
|
// Load assets
|
|
41
41
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
42
|
-
this.bundle.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
}
|
|
42
|
+
this.bundle.traverseAssets(asset => {
|
|
43
|
+
queue.add(async () => {
|
|
44
|
+
let [code, mapBuffer] = await Promise.all([
|
|
45
|
+
asset.getCode(),
|
|
46
|
+
this.bundle.env.sourceMap && asset.getMapBuffer(),
|
|
47
|
+
]);
|
|
48
|
+
return {code, mapBuffer};
|
|
49
|
+
});
|
|
52
50
|
});
|
|
53
51
|
|
|
54
52
|
let results = await queue.run();
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
} from '@parcel/types';
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
+
DefaultMap,
|
|
12
13
|
PromiseQueue,
|
|
13
14
|
relativeBundlePath,
|
|
14
15
|
countLines,
|
|
@@ -472,59 +473,64 @@ export class ScopeHoistingPackager {
|
|
|
472
473
|
|
|
473
474
|
// If we matched an import, replace with the source code for the dependency.
|
|
474
475
|
if (d != null) {
|
|
475
|
-
let
|
|
476
|
-
if (!
|
|
476
|
+
let deps = depMap.get(d);
|
|
477
|
+
if (!deps) {
|
|
477
478
|
return m;
|
|
478
479
|
}
|
|
479
480
|
|
|
480
|
-
let
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
481
|
+
let replacement = '';
|
|
482
|
+
|
|
483
|
+
// A single `${id}:${specifier}:esm` might have been resolved to multiple assets due to
|
|
484
|
+
// reexports.
|
|
485
|
+
for (let dep of deps) {
|
|
486
|
+
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
487
|
+
let skipped = this.bundleGraph.isDependencySkipped(dep);
|
|
488
|
+
if (resolved && !skipped) {
|
|
489
|
+
// Hoist variable declarations for the referenced parcelRequire dependencies
|
|
490
|
+
// after the dependency is declared. This handles the case where the resulting asset
|
|
491
|
+
// is wrapped, but the dependency in this asset is not marked as wrapped. This means
|
|
492
|
+
// that it was imported/required at the top-level, so its side effects should run immediately.
|
|
493
|
+
let [res, lines] = this.getHoistedParcelRequires(
|
|
494
|
+
asset,
|
|
495
|
+
dep,
|
|
496
|
+
resolved,
|
|
497
|
+
);
|
|
498
|
+
let map;
|
|
499
|
+
if (
|
|
500
|
+
this.bundle.hasAsset(resolved) &&
|
|
501
|
+
!this.seenAssets.has(resolved.id)
|
|
502
|
+
) {
|
|
503
|
+
// If this asset is wrapped, we need to hoist the code for the dependency
|
|
504
|
+
// outside our parcelRequire.register wrapper. This is safe because all
|
|
505
|
+
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
506
|
+
// asset content where the import statement was.
|
|
507
|
+
if (shouldWrap) {
|
|
508
|
+
depContent.push(this.visitAsset(resolved));
|
|
509
|
+
} else {
|
|
510
|
+
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
511
|
+
res = depCode + '\n' + res;
|
|
512
|
+
lines += 1 + depLines;
|
|
513
|
+
map = depMap;
|
|
514
|
+
}
|
|
508
515
|
}
|
|
509
|
-
}
|
|
510
516
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
+
// Push this asset's source mappings down by the number of lines in the dependency
|
|
518
|
+
// plus the number of hoisted parcelRequires. Then insert the source map for the dependency.
|
|
519
|
+
if (sourceMap) {
|
|
520
|
+
if (lines > 0) {
|
|
521
|
+
sourceMap.offsetLines(lineCount + 1, lines);
|
|
522
|
+
}
|
|
517
523
|
|
|
518
|
-
|
|
519
|
-
|
|
524
|
+
if (map) {
|
|
525
|
+
sourceMap.addSourceMap(map, lineCount);
|
|
526
|
+
}
|
|
520
527
|
}
|
|
521
|
-
}
|
|
522
528
|
|
|
523
|
-
|
|
524
|
-
|
|
529
|
+
replacement += res;
|
|
530
|
+
lineCount += lines;
|
|
531
|
+
}
|
|
525
532
|
}
|
|
526
|
-
|
|
527
|
-
return '';
|
|
533
|
+
return replacement;
|
|
528
534
|
}
|
|
529
535
|
|
|
530
536
|
// If it wasn't a dependency, then it was an inline replacement (e.g. $id$import$foo -> $id$export$foo).
|
|
@@ -580,23 +586,24 @@ ${code}
|
|
|
580
586
|
buildReplacements(
|
|
581
587
|
asset: Asset,
|
|
582
588
|
deps: Array<Dependency>,
|
|
583
|
-
): [Map<string, Dependency
|
|
589
|
+
): [Map<string, Array<Dependency>>, Map<string, string>] {
|
|
584
590
|
let assetId = asset.meta.id;
|
|
585
591
|
invariant(typeof assetId === 'string');
|
|
586
592
|
|
|
587
593
|
// Build two maps: one of import specifiers, and one of imported symbols to replace.
|
|
588
594
|
// These will be used to build a regex below.
|
|
589
|
-
let depMap = new
|
|
595
|
+
let depMap = new DefaultMap<string, Array<Dependency>>(() => []);
|
|
590
596
|
let replacements = new Map();
|
|
591
597
|
for (let dep of deps) {
|
|
592
598
|
let specifierType =
|
|
593
599
|
dep.specifierType === 'esm' ? `:${dep.specifierType}` : '';
|
|
594
|
-
depMap
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
+
depMap
|
|
601
|
+
.get(
|
|
602
|
+
`${assetId}:${getSpecifier(dep)}${
|
|
603
|
+
!dep.meta.placeholder ? specifierType : ''
|
|
604
|
+
}`,
|
|
605
|
+
)
|
|
606
|
+
.push(dep);
|
|
600
607
|
|
|
601
608
|
let asyncResolution = this.bundleGraph.resolveAsyncDependency(
|
|
602
609
|
dep,
|