@parcel/packager-js 2.0.0-dev.1605 → 2.0.0-dev.1632

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.
@@ -214,7 +214,9 @@ class ScopeHoistingPackager {
214
214
  };
215
215
  }
216
216
  shouldBundleQueue(bundle) {
217
- return this.useAsyncBundleRuntime && bundle.type === 'js' && bundle.bundleBehavior !== 'inline' && bundle.env.outputFormat === 'esmodule' && !bundle.env.isIsolated() && bundle.bundleBehavior !== 'isolated' && !this.bundleGraph.hasParentBundleOfType(bundle, 'js');
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 (!asset.meta.isConstantModule) {
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
- replacement = `($parcel$interopDefault(${renamed}))`;
629
- this.usedHelpers.add('$parcel$interopDefault');
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/packager-js",
3
- "version": "2.0.0-dev.1605+2125d8fe4",
3
+ "version": "2.0.0-dev.1632+339350eb3",
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.1603+2125d8fe4"
20
+ "parcel": "^2.0.0-dev.1630+339350eb3"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.0.0-dev.1605+2125d8fe4",
24
- "@parcel/plugin": "2.0.0-dev.1605+2125d8fe4",
25
- "@parcel/rust": "2.12.1-dev.3228+2125d8fe4",
23
+ "@parcel/diagnostic": "2.0.0-dev.1632+339350eb3",
24
+ "@parcel/plugin": "2.0.0-dev.1632+339350eb3",
25
+ "@parcel/rust": "2.12.1-dev.3260+339350eb3",
26
26
  "@parcel/source-map": "^2.1.1",
27
- "@parcel/types": "2.0.0-dev.1605+2125d8fe4",
28
- "@parcel/utils": "2.0.0-dev.1605+2125d8fe4",
27
+ "@parcel/types": "2.0.0-dev.1632+339350eb3",
28
+ "@parcel/utils": "2.0.0-dev.1632+339350eb3",
29
29
  "globals": "^13.2.0",
30
30
  "nullthrows": "^1.1.1"
31
31
  },
32
- "gitHead": "2125d8fe4b8352c01d5ae1d98a32572352d8ab14"
32
+ "gitHead": "339350eb31fd33849cb1efe5fd7ad2cb096319f0"
33
33
  }
@@ -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
- !this.bundleGraph.hasParentBundleOfType(bundle, 'js')
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 (!asset.meta.isConstantModule) {
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
- replacement = `($parcel$interopDefault(${renamed}))`;
832
- this.usedHelpers.add('$parcel$interopDefault');
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
  }