@jsenv/node-esm-resolution 0.1.0 → 0.1.1
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/README.md +1 -1
- package/package.json +4 -5
- package/src/custom_conditions.js +1 -1
- package/src/node_esm_resolution.js +26 -20
- package/src/url_utils.js +6 -9
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/node-esm-resolution",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"directory": "packages/node-esm-resolution"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
|
-
"access": "public"
|
|
12
|
-
"registry": "https://registry.npmjs.org"
|
|
11
|
+
"access": "public"
|
|
13
12
|
},
|
|
14
13
|
"type": "module",
|
|
15
14
|
"exports": {
|
|
@@ -25,6 +24,6 @@
|
|
|
25
24
|
"/main.js"
|
|
26
25
|
],
|
|
27
26
|
"scripts": {
|
|
28
|
-
"test": "node --conditions=development ./
|
|
27
|
+
"test": "node --conditions=development ./tests/test.mjs"
|
|
29
28
|
}
|
|
30
|
-
}
|
|
29
|
+
}
|
package/src/custom_conditions.js
CHANGED
|
@@ -7,7 +7,7 @@ export const readCustomConditionsFromProcessArgs = () => {
|
|
|
7
7
|
packageConditions.push(packageCondition)
|
|
8
8
|
}
|
|
9
9
|
if (arg.includes("--conditions=")) {
|
|
10
|
-
const packageCondition = arg.slice(
|
|
10
|
+
const packageCondition = arg.slice("--conditions=".length)
|
|
11
11
|
packageConditions.push(packageCondition)
|
|
12
12
|
}
|
|
13
13
|
})
|
|
@@ -174,7 +174,7 @@ const applyBrowserFieldResolution = ({
|
|
|
174
174
|
}
|
|
175
175
|
if (url) {
|
|
176
176
|
return {
|
|
177
|
-
type: "browser",
|
|
177
|
+
type: "field:browser",
|
|
178
178
|
packageUrl,
|
|
179
179
|
packageJson,
|
|
180
180
|
url,
|
|
@@ -515,7 +515,7 @@ const applyPackageTargetResolution = ({
|
|
|
515
515
|
})
|
|
516
516
|
}
|
|
517
517
|
return {
|
|
518
|
-
type: internal ? "
|
|
518
|
+
type: internal ? "field:imports" : "field:exports",
|
|
519
519
|
packageUrl,
|
|
520
520
|
packageJson,
|
|
521
521
|
url: pattern
|
|
@@ -768,7 +768,7 @@ const applyLegacyMainResolution = ({ conditions, packageUrl, packageJson }) => {
|
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
770
|
return {
|
|
771
|
-
type: "
|
|
771
|
+
type: "field:main", // the absence of "main" field
|
|
772
772
|
packageUrl,
|
|
773
773
|
packageJson,
|
|
774
774
|
url: new URL("index.js", packageUrl).href,
|
|
@@ -777,28 +777,34 @@ const applyLegacyMainResolution = ({ conditions, packageUrl, packageJson }) => {
|
|
|
777
777
|
const mainLegacyResolvers = {
|
|
778
778
|
import: (packageJson) => {
|
|
779
779
|
if (typeof packageJson.module === "string") {
|
|
780
|
-
return { type: "module", path: packageJson.module }
|
|
780
|
+
return { type: "field:module", path: packageJson.module }
|
|
781
781
|
}
|
|
782
782
|
if (typeof packageJson.jsnext === "string") {
|
|
783
|
-
return { type: "jsnext", path: packageJson.jsnext }
|
|
783
|
+
return { type: "field:jsnext", path: packageJson.jsnext }
|
|
784
784
|
}
|
|
785
785
|
if (typeof packageJson.main === "string") {
|
|
786
|
-
return { type: "main", path: packageJson.main }
|
|
786
|
+
return { type: "field:main", path: packageJson.main }
|
|
787
787
|
}
|
|
788
788
|
return null
|
|
789
789
|
},
|
|
790
790
|
browser: (packageJson, packageUrl) => {
|
|
791
|
-
const browserMain =
|
|
792
|
-
typeof packageJson.browser === "string"
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
791
|
+
const browserMain = (() => {
|
|
792
|
+
if (typeof packageJson.browser === "string") {
|
|
793
|
+
return packageJson.browser
|
|
794
|
+
}
|
|
795
|
+
if (
|
|
796
|
+
typeof packageJson.browser === "object" &&
|
|
797
|
+
packageJson.browser !== null
|
|
798
|
+
) {
|
|
799
|
+
return packageJson.browser["."]
|
|
800
|
+
}
|
|
801
|
+
return ""
|
|
802
|
+
})()
|
|
803
|
+
|
|
798
804
|
if (!browserMain) {
|
|
799
805
|
if (typeof packageJson.module === "string") {
|
|
800
806
|
return {
|
|
801
|
-
type: "module",
|
|
807
|
+
type: "field:module",
|
|
802
808
|
path: packageJson.module,
|
|
803
809
|
}
|
|
804
810
|
}
|
|
@@ -809,7 +815,7 @@ const mainLegacyResolvers = {
|
|
|
809
815
|
packageJson.module === browserMain
|
|
810
816
|
) {
|
|
811
817
|
return {
|
|
812
|
-
type: "browser",
|
|
818
|
+
type: "field:browser",
|
|
813
819
|
path: browserMain,
|
|
814
820
|
}
|
|
815
821
|
}
|
|
@@ -821,19 +827,19 @@ const mainLegacyResolvers = {
|
|
|
821
827
|
/module\.exports\s*=/.test(content)
|
|
822
828
|
) {
|
|
823
829
|
return {
|
|
824
|
-
type: "module",
|
|
830
|
+
type: "field:module",
|
|
825
831
|
path: packageJson.module,
|
|
826
832
|
}
|
|
827
833
|
}
|
|
828
834
|
return {
|
|
829
|
-
type: "browser",
|
|
835
|
+
type: "field:browser",
|
|
830
836
|
path: browserMain,
|
|
831
837
|
}
|
|
832
838
|
},
|
|
833
839
|
node: (packageJson) => {
|
|
834
840
|
if (typeof packageJson.main === "string") {
|
|
835
841
|
return {
|
|
836
|
-
type: "main",
|
|
842
|
+
type: "field:main",
|
|
837
843
|
path: packageJson.main,
|
|
838
844
|
}
|
|
839
845
|
}
|
|
@@ -842,10 +848,10 @@ const mainLegacyResolvers = {
|
|
|
842
848
|
}
|
|
843
849
|
|
|
844
850
|
const comparePatternKeys = (keyA, keyB) => {
|
|
845
|
-
if (!keyA.endsWith("/") && !keyA.
|
|
851
|
+
if (!keyA.endsWith("/") && !keyA.includes("*")) {
|
|
846
852
|
throw new Error("Invalid package configuration")
|
|
847
853
|
}
|
|
848
|
-
if (!keyB.endsWith("/") && !keyB.
|
|
854
|
+
if (!keyB.endsWith("/") && !keyB.includes("*")) {
|
|
849
855
|
throw new Error("Invalid package configuration")
|
|
850
856
|
}
|
|
851
857
|
const aStarIndex = keyA.indexOf("*")
|
package/src/url_utils.js
CHANGED
|
@@ -10,24 +10,21 @@ export const getParentUrl = (url) => {
|
|
|
10
10
|
if (url.startsWith("file://")) {
|
|
11
11
|
// With node.js new URL('../', 'file:///C:/').href
|
|
12
12
|
// returns "file:///C:/" instead of "file:///"
|
|
13
|
-
const
|
|
14
|
-
const slashLastIndex =
|
|
13
|
+
const resource = url.slice("file://".length)
|
|
14
|
+
const slashLastIndex = resource.lastIndexOf("/")
|
|
15
15
|
if (slashLastIndex === -1) {
|
|
16
16
|
return url
|
|
17
17
|
}
|
|
18
|
-
const lastCharIndex =
|
|
18
|
+
const lastCharIndex = resource.length - 1
|
|
19
19
|
if (slashLastIndex === lastCharIndex) {
|
|
20
|
-
const slashBeforeLastIndex =
|
|
21
|
-
"/",
|
|
22
|
-
slashLastIndex - 1,
|
|
23
|
-
)
|
|
20
|
+
const slashBeforeLastIndex = resource.lastIndexOf("/", slashLastIndex - 1)
|
|
24
21
|
if (slashBeforeLastIndex === -1) {
|
|
25
22
|
return url
|
|
26
23
|
}
|
|
27
|
-
return `file://${
|
|
24
|
+
return `file://${resource.slice(0, slashBeforeLastIndex + 1)}`
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
return `file://${
|
|
27
|
+
return `file://${resource.slice(0, slashLastIndex + 1)}`
|
|
31
28
|
}
|
|
32
29
|
return new URL(url.endsWith("/") ? "../" : "./", url).href
|
|
33
30
|
}
|