@jsenv/node-esm-resolution 0.0.10 → 0.1.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/main.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export { applyNodeEsmResolution } from "./src/node_esm_resolution.js"
2
2
  export { determineModuleSystem } from "./src/determine_module_system.js"
3
- export { applyFileSystemMagicResolution } from "./src/filesystem_magic_resolution.js"
3
+ export {
4
+ applyFileSystemMagicResolution,
5
+ getExtensionsToTry,
6
+ } from "./src/filesystem_magic_resolution.js"
4
7
  export { defaultLookupPackageScope } from "./src/default_lookup_package_scope.js"
5
8
  export { defaultReadPackageJson } from "./src/default_read_package_json.js"
6
9
  export { readCustomConditionsFromProcessArgs } from "./src/custom_conditions.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/node-esm-resolution",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,6 +25,6 @@
25
25
  "/main.js"
26
26
  ],
27
27
  "scripts": {
28
- "test": "node ./test/test.mjs"
28
+ "test": "node --conditions=development ./test/test.mjs"
29
29
  }
30
30
  }
@@ -1,6 +1,6 @@
1
1
  import { statSync } from "node:fs"
2
2
 
3
- import { urlToFilename } from "./url_utils.js"
3
+ import { urlToFilename, urlToExtension } from "./url_utils.js"
4
4
 
5
5
  export const applyFileSystemMagicResolution = (
6
6
  fileUrl,
@@ -69,3 +69,19 @@ export const applyFileSystemMagicResolution = (
69
69
  lastENOENTError,
70
70
  }
71
71
  }
72
+
73
+ export const getExtensionsToTry = (magicExtensions, importer) => {
74
+ if (!magicExtensions) {
75
+ return []
76
+ }
77
+ const extensionsSet = new Set()
78
+ magicExtensions.forEach((magicExtension) => {
79
+ if (magicExtension === "inherit") {
80
+ const importerExtension = urlToExtension(importer)
81
+ extensionsSet.add(importerExtension)
82
+ } else {
83
+ extensionsSet.add(magicExtension)
84
+ }
85
+ })
86
+ return Array.from(extensionsSet.values())
87
+ }
package/src/url_utils.js CHANGED
@@ -54,3 +54,12 @@ export const urlToFilename = (url) => {
54
54
  : pathnameBeforeLastSlash.slice(slashLastIndex + 1)
55
55
  return filename
56
56
  }
57
+
58
+ export const urlToExtension = (url) => {
59
+ const filename = urlToFilename(url)
60
+ const dotLastIndex = filename.lastIndexOf(".")
61
+ if (dotLastIndex === -1) return ""
62
+ // if (dotLastIndex === pathname.length - 1) return ""
63
+ const extension = filename.slice(dotLastIndex)
64
+ return extension
65
+ }