@jsenv/node-esm-resolution 1.1.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/node-esm-resolution",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,5 +22,6 @@
22
22
  "/dist/",
23
23
  "/src/",
24
24
  "/main.js"
25
- ]
25
+ ],
26
+ "sideEffects": false
26
27
  }
@@ -154,6 +154,7 @@ const applyBrowserFieldResolution = (specifier, resolutionContext) => {
154
154
  if (url) {
155
155
  return {
156
156
  type: "field:browser",
157
+ isMain: true,
157
158
  packageDirectoryUrl,
158
159
  packageJson,
159
160
  url,
@@ -197,7 +198,7 @@ const applyPackageImportsResolution = (
197
198
  };
198
199
 
199
200
  const applyPackageResolve = (packageSpecifier, resolutionContext) => {
200
- const { parentUrl, conditions, readPackageJson, preservesSymlink } =
201
+ const { parentUrl, conditions, readPackageJson, preservesSymlink, isImport } =
201
202
  resolutionContext;
202
203
  if (packageSpecifier === "") {
203
204
  throw new Error("invalid module specifier");
@@ -223,7 +224,7 @@ const applyPackageResolve = (packageSpecifier, resolutionContext) => {
223
224
  resolutionContext,
224
225
  );
225
226
  }
226
- if (packageSubpath.endsWith("/")) {
227
+ if (isImport && packageSubpath.endsWith("/")) {
227
228
  throw new Error("invalid module specifier");
228
229
  }
229
230
  const questionCharIndex = packageName.indexOf("?");
@@ -404,6 +405,7 @@ const applyPackageTargetResolution = (target, resolutionContext) => {
404
405
  }
405
406
  return {
406
407
  type: isImport ? "field:imports" : "field:exports",
408
+ isMain: subpath === "" || subpath === ".",
407
409
  packageDirectoryUrl,
408
410
  packageJson,
409
411
  url: pattern
@@ -566,6 +568,12 @@ const parsePackageSpecifier = (packageSpecifier) => {
566
568
  }
567
569
  const packageName = packageSpecifier.slice(0, firstSlashIndex);
568
570
  const afterFirstSlash = packageSpecifier.slice(firstSlashIndex + 1);
571
+ if (afterFirstSlash === "") {
572
+ return {
573
+ packageName,
574
+ packageSubpath: "/",
575
+ };
576
+ }
569
577
  const packageSubpath = `./${afterFirstSlash}`;
570
578
  return {
571
579
  packageName,
@@ -606,6 +614,7 @@ const applyLegacySubpathResolution = (packageSubpath, resolutionContext) => {
606
614
  }
607
615
  return {
608
616
  type: "subpath",
617
+ isMain: packageSubpath === ".",
609
618
  packageDirectoryUrl,
610
619
  packageJson,
611
620
  url: new URL(packageSubpath, packageDirectoryUrl).href,
@@ -623,6 +632,7 @@ const applyLegacyMainResolution = (packageSubpath, resolutionContext) => {
623
632
  if (resolved) {
624
633
  return {
625
634
  type: resolved.type,
635
+ isMain: resolved.isMain,
626
636
  packageDirectoryUrl,
627
637
  packageJson,
628
638
  url: new URL(resolved.path, packageDirectoryUrl).href,
@@ -631,6 +641,7 @@ const applyLegacyMainResolution = (packageSubpath, resolutionContext) => {
631
641
  }
632
642
  return {
633
643
  type: "field:main", // the absence of "main" field
644
+ isMain: true,
634
645
  packageDirectoryUrl,
635
646
  packageJson,
636
647
  url: new URL("index.js", packageDirectoryUrl).href,
@@ -639,13 +650,13 @@ const applyLegacyMainResolution = (packageSubpath, resolutionContext) => {
639
650
  const mainLegacyResolvers = {
640
651
  import: ({ packageJson }) => {
641
652
  if (typeof packageJson.module === "string") {
642
- return { type: "field:module", path: packageJson.module };
653
+ return { type: "field:module", isMain: true, path: packageJson.module };
643
654
  }
644
655
  if (typeof packageJson.jsnext === "string") {
645
- return { type: "field:jsnext", path: packageJson.jsnext };
656
+ return { type: "field:jsnext", isMain: true, path: packageJson.jsnext };
646
657
  }
647
658
  if (typeof packageJson.main === "string") {
648
- return { type: "field:main", path: packageJson.main };
659
+ return { type: "field:main", isMain: true, path: packageJson.main };
649
660
  }
650
661
  return null;
651
662
  },
@@ -667,6 +678,7 @@ const mainLegacyResolvers = {
667
678
  if (typeof packageJson.module === "string") {
668
679
  return {
669
680
  type: "field:module",
681
+ isMain: true,
670
682
  path: packageJson.module,
671
683
  };
672
684
  }
@@ -678,6 +690,7 @@ const mainLegacyResolvers = {
678
690
  ) {
679
691
  return {
680
692
  type: "field:browser",
693
+ isMain: true,
681
694
  path: browserMain,
682
695
  };
683
696
  }
@@ -690,20 +703,27 @@ const mainLegacyResolvers = {
690
703
  ) {
691
704
  return {
692
705
  type: "field:module",
706
+ isMain: true,
693
707
  path: packageJson.module,
694
708
  };
695
709
  }
696
710
  return {
697
711
  type: "field:browser",
712
+ isMain: true,
698
713
  path: browserMain,
699
714
  };
700
715
  },
701
- node: ({ packageJson }) => {
716
+ node: ({ packageJson, conditions }) => {
717
+ if (conditions.includes("import")) {
718
+ if (typeof packageJson.module === "string") {
719
+ return { type: "field:module", isMain: true, path: packageJson.module };
720
+ }
721
+ if (typeof packageJson.jsnext === "string") {
722
+ return { type: "field:jsnext", isMain: true, path: packageJson.jsnext };
723
+ }
724
+ }
702
725
  if (typeof packageJson.main === "string") {
703
- return {
704
- type: "field:main",
705
- path: packageJson.main,
706
- };
726
+ return { type: "field:main", isMain: true, path: packageJson.main };
707
727
  }
708
728
  return null;
709
729
  },