@parcel/packager-js 2.0.0-dev.1608 → 2.0.0-dev.1652
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 +22 -6
- package/package.json +8 -8
- package/src/ScopeHoistingPackager.js +34 -10
|
@@ -26,7 +26,7 @@ function _nullthrows() {
|
|
|
26
26
|
return data;
|
|
27
27
|
}
|
|
28
28
|
function _assert() {
|
|
29
|
-
const data =
|
|
29
|
+
const data = _interopRequireWildcard(require("assert"));
|
|
30
30
|
_assert = function () {
|
|
31
31
|
return data;
|
|
32
32
|
};
|
|
@@ -214,7 +214,9 @@ class ScopeHoistingPackager {
|
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
shouldBundleQueue(bundle) {
|
|
217
|
-
|
|
217
|
+
let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
|
|
218
|
+
let hasHtmlReference = referencingBundles.some(b => b.type === 'html');
|
|
219
|
+
return this.useAsyncBundleRuntime && bundle.type === 'js' && bundle.bundleBehavior !== 'inline' && bundle.env.outputFormat === 'esmodule' && !bundle.env.isIsolated() && bundle.bundleBehavior !== 'isolated' && hasHtmlReference;
|
|
218
220
|
}
|
|
219
221
|
runWhenReady(bundle, codeToRun) {
|
|
220
222
|
let deps = this.bundleGraph.getReferencedBundles(bundle).filter(b => this.shouldBundleQueue(b)).map(b => b.publicId);
|
|
@@ -239,7 +241,8 @@ class ScopeHoistingPackager {
|
|
|
239
241
|
}];
|
|
240
242
|
});
|
|
241
243
|
if (asset.meta.shouldWrap || this.bundle.env.sourceType === 'script' || this.bundleGraph.isAssetReferenced(this.bundle, asset) || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')) {
|
|
242
|
-
if
|
|
244
|
+
// Don't wrap constant "entry" modules _except_ if they are referenced by any lazy dependency
|
|
245
|
+
if (!asset.meta.isConstantModule || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.priority === 'lazy')) {
|
|
243
246
|
this.wrappedAssets.add(asset.id);
|
|
244
247
|
wrapped.push(asset);
|
|
245
248
|
}
|
|
@@ -625,8 +628,17 @@ ${code}
|
|
|
625
628
|
if (imported === '*') {
|
|
626
629
|
replacement = renamed;
|
|
627
630
|
} else if (imported === 'default') {
|
|
628
|
-
|
|
629
|
-
|
|
631
|
+
let needsDefaultInterop = true;
|
|
632
|
+
if (referencedBundle) {
|
|
633
|
+
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
634
|
+
needsDefaultInterop = this.needsDefaultInterop(entry);
|
|
635
|
+
}
|
|
636
|
+
if (needsDefaultInterop) {
|
|
637
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
638
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
639
|
+
} else {
|
|
640
|
+
replacement = `${renamed}.default`;
|
|
641
|
+
}
|
|
630
642
|
} else {
|
|
631
643
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
632
644
|
}
|
|
@@ -688,7 +700,11 @@ ${code}
|
|
|
688
700
|
}
|
|
689
701
|
isWrapped(resolved, parentAsset) {
|
|
690
702
|
if (resolved.meta.isConstantModule) {
|
|
691
|
-
|
|
703
|
+
if (!this.bundle.hasAsset(resolved)) {
|
|
704
|
+
throw new (_assert().AssertionError)({
|
|
705
|
+
message: `Constant module ${_path().default.relative(this.options.projectRoot, resolved.filePath)} referenced from ${_path().default.relative(this.options.projectRoot, parentAsset.filePath)} not found in bundle ${this.bundle.name}`
|
|
706
|
+
});
|
|
707
|
+
}
|
|
692
708
|
return false;
|
|
693
709
|
}
|
|
694
710
|
return !this.bundle.hasAsset(resolved) && !this.externalAssets.has(resolved) || this.wrappedAssets.has(resolved.id) && resolved !== parentAsset;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.1652+8b017703f",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"source": "src/index.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 16.0.0",
|
|
20
|
-
"parcel": "^2.0.0-dev.
|
|
20
|
+
"parcel": "^2.0.0-dev.1650+8b017703f"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.0.0-dev.
|
|
24
|
-
"@parcel/plugin": "2.0.0-dev.
|
|
25
|
-
"@parcel/rust": "2.12.1-dev.
|
|
23
|
+
"@parcel/diagnostic": "2.0.0-dev.1652+8b017703f",
|
|
24
|
+
"@parcel/plugin": "2.0.0-dev.1652+8b017703f",
|
|
25
|
+
"@parcel/rust": "2.12.1-dev.3275+8b017703f",
|
|
26
26
|
"@parcel/source-map": "^2.1.1",
|
|
27
|
-
"@parcel/types": "2.0.0-dev.
|
|
28
|
-
"@parcel/utils": "2.0.0-dev.
|
|
27
|
+
"@parcel/types": "2.0.0-dev.1652+8b017703f",
|
|
28
|
+
"@parcel/utils": "2.0.0-dev.1652+8b017703f",
|
|
29
29
|
"globals": "^13.2.0",
|
|
30
30
|
"nullthrows": "^1.1.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "8b017703fdf4a90a643ce0190cdd7482060dc86b"
|
|
33
33
|
}
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from '@parcel/utils';
|
|
18
18
|
import SourceMap from '@parcel/source-map';
|
|
19
19
|
import nullthrows from 'nullthrows';
|
|
20
|
-
import invariant from 'assert';
|
|
20
|
+
import invariant, {AssertionError} from 'assert';
|
|
21
21
|
import ThrowableDiagnostic, {
|
|
22
22
|
convertSourceLocationToHighlight,
|
|
23
23
|
} from '@parcel/diagnostic';
|
|
@@ -34,7 +34,6 @@ import {
|
|
|
34
34
|
isValidIdentifier,
|
|
35
35
|
makeValidIdentifier,
|
|
36
36
|
} from './utils';
|
|
37
|
-
|
|
38
37
|
// General regex used to replace imports with the resolved code, references with resolutions,
|
|
39
38
|
// and count the number of newlines in the file for source maps.
|
|
40
39
|
const REPLACEMENT_RE =
|
|
@@ -264,6 +263,9 @@ export class ScopeHoistingPackager {
|
|
|
264
263
|
}
|
|
265
264
|
|
|
266
265
|
shouldBundleQueue(bundle: NamedBundle): boolean {
|
|
266
|
+
let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
|
|
267
|
+
let hasHtmlReference = referencingBundles.some(b => b.type === 'html');
|
|
268
|
+
|
|
267
269
|
return (
|
|
268
270
|
this.useAsyncBundleRuntime &&
|
|
269
271
|
bundle.type === 'js' &&
|
|
@@ -271,7 +273,7 @@ export class ScopeHoistingPackager {
|
|
|
271
273
|
bundle.env.outputFormat === 'esmodule' &&
|
|
272
274
|
!bundle.env.isIsolated() &&
|
|
273
275
|
bundle.bundleBehavior !== 'isolated' &&
|
|
274
|
-
|
|
276
|
+
hasHtmlReference
|
|
275
277
|
);
|
|
276
278
|
}
|
|
277
279
|
|
|
@@ -315,7 +317,13 @@ export class ScopeHoistingPackager {
|
|
|
315
317
|
.getIncomingDependencies(asset)
|
|
316
318
|
.some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')
|
|
317
319
|
) {
|
|
318
|
-
if
|
|
320
|
+
// Don't wrap constant "entry" modules _except_ if they are referenced by any lazy dependency
|
|
321
|
+
if (
|
|
322
|
+
!asset.meta.isConstantModule ||
|
|
323
|
+
this.bundleGraph
|
|
324
|
+
.getIncomingDependencies(asset)
|
|
325
|
+
.some(dep => dep.priority === 'lazy')
|
|
326
|
+
) {
|
|
319
327
|
this.wrappedAssets.add(asset.id);
|
|
320
328
|
wrapped.push(asset);
|
|
321
329
|
}
|
|
@@ -828,8 +836,17 @@ ${code}
|
|
|
828
836
|
if (imported === '*') {
|
|
829
837
|
replacement = renamed;
|
|
830
838
|
} else if (imported === 'default') {
|
|
831
|
-
|
|
832
|
-
|
|
839
|
+
let needsDefaultInterop = true;
|
|
840
|
+
if (referencedBundle) {
|
|
841
|
+
let entry = nullthrows(referencedBundle.getMainEntry());
|
|
842
|
+
needsDefaultInterop = this.needsDefaultInterop(entry);
|
|
843
|
+
}
|
|
844
|
+
if (needsDefaultInterop) {
|
|
845
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
846
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
847
|
+
} else {
|
|
848
|
+
replacement = `${renamed}.default`;
|
|
849
|
+
}
|
|
833
850
|
} else {
|
|
834
851
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
835
852
|
}
|
|
@@ -905,10 +922,17 @@ ${code}
|
|
|
905
922
|
|
|
906
923
|
isWrapped(resolved: Asset, parentAsset: Asset): boolean {
|
|
907
924
|
if (resolved.meta.isConstantModule) {
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
925
|
+
if (!this.bundle.hasAsset(resolved)) {
|
|
926
|
+
throw new AssertionError({
|
|
927
|
+
message: `Constant module ${path.relative(
|
|
928
|
+
this.options.projectRoot,
|
|
929
|
+
resolved.filePath,
|
|
930
|
+
)} referenced from ${path.relative(
|
|
931
|
+
this.options.projectRoot,
|
|
932
|
+
parentAsset.filePath,
|
|
933
|
+
)} not found in bundle ${this.bundle.name}`,
|
|
934
|
+
});
|
|
935
|
+
}
|
|
912
936
|
return false;
|
|
913
937
|
}
|
|
914
938
|
return (
|