@flex-development/mlly 1.0.0-alpha.8 → 1.0.0-beta.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.
Files changed (332) hide show
  1. package/CHANGELOG.md +1128 -355
  2. package/README.md +1540 -12
  3. package/dist/index.d.mts +3 -4
  4. package/dist/index.mjs +5 -5
  5. package/dist/interfaces/aliases.d.mts +21 -0
  6. package/dist/interfaces/condition-map.d.mts +24 -0
  7. package/dist/interfaces/file-system.d.mts +29 -0
  8. package/dist/interfaces/get-source-context.d.mts +44 -0
  9. package/dist/interfaces/get-source-options.d.mts +48 -0
  10. package/dist/interfaces/index.d.mts +18 -21
  11. package/dist/interfaces/is-directory.d.mts +17 -0
  12. package/dist/interfaces/is-file.d.mts +17 -0
  13. package/dist/interfaces/main-field-map.d.mts +22 -0
  14. package/dist/interfaces/module-format-map.d.mts +26 -0
  15. package/dist/interfaces/pattern-key-comparison-map.d.mts +31 -0
  16. package/dist/interfaces/protocol-map.d.mts +44 -0
  17. package/dist/interfaces/read-file.d.mts +24 -0
  18. package/dist/interfaces/realpath.d.mts +26 -0
  19. package/dist/interfaces/resolve-alias-options.d.mts +43 -0
  20. package/dist/interfaces/resolve-module-options.d.mts +79 -0
  21. package/dist/interfaces/stat.d.mts +24 -0
  22. package/dist/interfaces/stats.d.mts +23 -0
  23. package/dist/internal/chain-or-call.mjs +34 -0
  24. package/dist/internal/chars.mjs +17 -0
  25. package/dist/internal/check-invalid-segments.mjs +49 -0
  26. package/dist/internal/constant.mjs +23 -0
  27. package/dist/internal/fs.browser.mjs +42 -0
  28. package/dist/internal/fs.node.mjs +16 -0
  29. package/dist/internal/identity.mjs +23 -0
  30. package/dist/internal/invalid-package-target.mjs +36 -0
  31. package/dist/internal/invalid-subpath.mjs +37 -0
  32. package/dist/internal/is-promise.mjs +26 -0
  33. package/dist/internal/process.browser.mjs +8 -0
  34. package/dist/lib/can-parse-url.d.mts +23 -0
  35. package/dist/lib/can-parse-url.mjs +31 -0
  36. package/dist/lib/cwd.d.mts +14 -0
  37. package/dist/lib/cwd.mjs +17 -0
  38. package/dist/lib/default-conditions.d.mts +15 -0
  39. package/dist/lib/default-conditions.mjs +14 -0
  40. package/dist/lib/default-extensions.d.mts +14 -0
  41. package/dist/lib/default-extensions.mjs +29 -0
  42. package/dist/lib/default-main-fields.d.mts +14 -0
  43. package/dist/lib/default-main-fields.mjs +13 -0
  44. package/dist/lib/extension-format-map.d.mts +16 -0
  45. package/dist/lib/extension-format-map.mjs +31 -0
  46. package/dist/lib/formats.d.mts +21 -0
  47. package/dist/lib/formats.mjs +22 -0
  48. package/dist/lib/get-source.d.mts +46 -0
  49. package/dist/lib/get-source.mjs +156 -0
  50. package/dist/lib/index.d.mts +41 -0
  51. package/dist/lib/index.mjs +41 -0
  52. package/dist/lib/is-absolute-specifier.d.mts +23 -0
  53. package/dist/lib/is-absolute-specifier.mjs +34 -0
  54. package/dist/lib/is-array-index.d.mts +19 -0
  55. package/dist/lib/is-array-index.mjs +28 -0
  56. package/dist/lib/is-bare-specifier.d.mts +23 -0
  57. package/dist/lib/is-bare-specifier.mjs +33 -0
  58. package/dist/lib/is-directory.d.mts +27 -0
  59. package/dist/lib/is-directory.mjs +54 -0
  60. package/dist/lib/is-file.d.mts +27 -0
  61. package/dist/lib/is-file.mjs +54 -0
  62. package/dist/lib/is-imports-subpath.d.mts +26 -0
  63. package/dist/lib/is-imports-subpath.mjs +28 -0
  64. package/dist/lib/is-module-id.d.mts +23 -0
  65. package/dist/lib/is-module-id.mjs +24 -0
  66. package/dist/lib/is-relative-specifier.d.mts +23 -0
  67. package/dist/lib/is-relative-specifier.mjs +36 -0
  68. package/dist/lib/lookup-package-scope.d.mts +49 -0
  69. package/dist/lib/lookup-package-scope.mjs +102 -0
  70. package/dist/lib/pattern-key-compare.d.mts +28 -0
  71. package/dist/lib/pattern-key-compare.mjs +71 -0
  72. package/dist/lib/pattern-match.d.mts +22 -0
  73. package/dist/lib/pattern-match.mjs +85 -0
  74. package/dist/lib/read-package-json.d.mts +63 -0
  75. package/dist/lib/read-package-json.mjs +115 -0
  76. package/dist/lib/resolve-alias.d.mts +21 -0
  77. package/dist/lib/resolve-alias.mjs +102 -0
  78. package/dist/lib/resolve-module.d.mts +43 -0
  79. package/dist/lib/resolve-module.mjs +186 -0
  80. package/dist/lib/resolver.d.mts +346 -0
  81. package/dist/lib/resolver.mjs +1015 -0
  82. package/dist/lib/root.d.mts +11 -0
  83. package/dist/lib/root.mjs +12 -0
  84. package/dist/lib/to-relative-specifier.d.mts +27 -0
  85. package/dist/lib/to-relative-specifier.mjs +63 -0
  86. package/dist/lib/to-url.d.mts +26 -0
  87. package/dist/lib/to-url.mjs +34 -0
  88. package/dist/types/awaitable.d.mts +12 -0
  89. package/dist/types/change-ext-fn.d.mts +29 -0
  90. package/dist/types/condition.d.mts +13 -0
  91. package/dist/types/dot.d.mts +9 -0
  92. package/dist/types/empty-array.d.mts +9 -0
  93. package/dist/types/empty-object.d.mts +19 -0
  94. package/dist/types/empty-string.d.mts +9 -0
  95. package/dist/types/ext.d.mts +12 -0
  96. package/dist/types/get-source-handler.d.mts +22 -0
  97. package/dist/types/get-source-handlers.d.mts +15 -0
  98. package/dist/types/index.d.mts +19 -10
  99. package/dist/types/list.d.mts +12 -0
  100. package/dist/types/main-field.d.mts +13 -0
  101. package/dist/types/module-format.d.mts +13 -0
  102. package/dist/types/module-id.d.mts +3 -4
  103. package/dist/types/numeric.d.mts +9 -0
  104. package/dist/types/pattern-key-comparison.d.mts +14 -0
  105. package/dist/types/pattern-match.d.mts +10 -0
  106. package/dist/types/protocol.d.mts +6 -7
  107. package/package.json +151 -154
  108. package/changelog.config.ts +0 -404
  109. package/dist/enums/assert-type.d.mts +0 -21
  110. package/dist/enums/assert-type.mjs +0 -10
  111. package/dist/enums/assert-type.mjs.map +0 -6
  112. package/dist/enums/format.d.mts +0 -17
  113. package/dist/enums/format.mjs +0 -13
  114. package/dist/enums/format.mjs.map +0 -6
  115. package/dist/enums/index.d.mts +0 -10
  116. package/dist/enums/index.mjs +0 -15
  117. package/dist/enums/index.mjs.map +0 -6
  118. package/dist/enums/kind-specifier-syntax.d.mts +0 -14
  119. package/dist/enums/kind-specifier-syntax.mjs +0 -10
  120. package/dist/enums/kind-specifier-syntax.mjs.map +0 -6
  121. package/dist/enums/kind-specifier.d.mts +0 -17
  122. package/dist/enums/kind-specifier.mjs +0 -11
  123. package/dist/enums/kind-specifier.mjs.map +0 -6
  124. package/dist/enums/kind-statement-syntax.d.mts +0 -22
  125. package/dist/enums/kind-statement-syntax.mjs +0 -18
  126. package/dist/enums/kind-statement-syntax.mjs.map +0 -6
  127. package/dist/enums/kind-statement.d.mts +0 -15
  128. package/dist/enums/kind-statement.mjs +0 -11
  129. package/dist/enums/kind-statement.mjs.map +0 -6
  130. package/dist/index.mjs.map +0 -6
  131. package/dist/interfaces/import-assertions.d.mts +0 -20
  132. package/dist/interfaces/import-dynamic.d.mts +0 -43
  133. package/dist/interfaces/import-static.d.mts +0 -37
  134. package/dist/interfaces/index.mjs +0 -1
  135. package/dist/interfaces/index.mjs.map +0 -6
  136. package/dist/interfaces/options-fill-module.d.mts +0 -23
  137. package/dist/interfaces/options-find-subpath.d.mts +0 -49
  138. package/dist/interfaces/options-get-format.d.mts +0 -83
  139. package/dist/interfaces/options-get-source.d.mts +0 -63
  140. package/dist/interfaces/options-parse-module-id.d.mts +0 -33
  141. package/dist/interfaces/options-parse-subpath.d.mts +0 -31
  142. package/dist/interfaces/options-resolve-alias.d.mts +0 -53
  143. package/dist/interfaces/options-resolve-module.d.mts +0 -64
  144. package/dist/interfaces/options-resolve.d.mts +0 -15
  145. package/dist/interfaces/package-scope.d.mts +0 -25
  146. package/dist/interfaces/parsed-data-url.d.mts +0 -56
  147. package/dist/interfaces/parsed-module-id.d.mts +0 -80
  148. package/dist/interfaces/parsed-subpath.d.mts +0 -40
  149. package/dist/interfaces/statement-export.d.mts +0 -44
  150. package/dist/interfaces/statement-import.d.mts +0 -38
  151. package/dist/interfaces/statement-require.d.mts +0 -38
  152. package/dist/interfaces/statement.d.mts +0 -49
  153. package/dist/internal/escape-reg-exp.d.mts +0 -16
  154. package/dist/internal/escape-reg-exp.mjs +0 -10
  155. package/dist/internal/escape-reg-exp.mjs.map +0 -6
  156. package/dist/internal/format-type-map.d.mts +0 -17
  157. package/dist/internal/format-type-map.mjs +0 -13
  158. package/dist/internal/format-type-map.mjs.map +0 -6
  159. package/dist/internal/get-specifier-kind.d.mts +0 -17
  160. package/dist/internal/get-specifier-kind.mjs +0 -14
  161. package/dist/internal/get-specifier-kind.mjs.map +0 -6
  162. package/dist/internal/get-subpaths.d.mts +0 -25
  163. package/dist/internal/get-subpaths.mjs +0 -10
  164. package/dist/internal/get-subpaths.mjs.map +0 -6
  165. package/dist/internal/is-array-index.d.mts +0 -15
  166. package/dist/internal/is-array-index.mjs +0 -9
  167. package/dist/internal/is-array-index.mjs.map +0 -6
  168. package/dist/internal/is-directory.d.mts +0 -13
  169. package/dist/internal/is-directory.mjs +0 -16
  170. package/dist/internal/is-directory.mjs.map +0 -6
  171. package/dist/internal/is-file.d.mts +0 -13
  172. package/dist/internal/is-file.mjs +0 -16
  173. package/dist/internal/is-file.mjs.map +0 -6
  174. package/dist/internal/is-function.d.mts +0 -12
  175. package/dist/internal/is-function.mjs +0 -8
  176. package/dist/internal/is-function.mjs.map +0 -6
  177. package/dist/internal/regex-encoded-sep.d.mts +0 -13
  178. package/dist/internal/regex-encoded-sep.mjs +0 -6
  179. package/dist/internal/regex-encoded-sep.mjs.map +0 -6
  180. package/dist/internal/regex-internal-specifier.d.mts +0 -14
  181. package/dist/internal/regex-internal-specifier.mjs +0 -6
  182. package/dist/internal/regex-internal-specifier.mjs.map +0 -6
  183. package/dist/internal/regex-package-name.d.mts +0 -13
  184. package/dist/internal/regex-package-name.mjs +0 -6
  185. package/dist/internal/regex-package-name.mjs.map +0 -6
  186. package/dist/internal/regex-package-path.d.mts +0 -15
  187. package/dist/internal/regex-package-path.mjs +0 -6
  188. package/dist/internal/regex-package-path.mjs.map +0 -6
  189. package/dist/internal/resolver.d.mts +0 -130
  190. package/dist/internal/resolver.mjs +0 -486
  191. package/dist/internal/resolver.mjs.map +0 -6
  192. package/dist/internal/validate-boolean.d.mts +0 -20
  193. package/dist/internal/validate-boolean.mjs +0 -11
  194. package/dist/internal/validate-boolean.mjs.map +0 -6
  195. package/dist/internal/validate-object.d.mts +0 -23
  196. package/dist/internal/validate-object.mjs +0 -11
  197. package/dist/internal/validate-object.mjs.map +0 -6
  198. package/dist/internal/validate-set.d.mts +0 -23
  199. package/dist/internal/validate-set.mjs +0 -11
  200. package/dist/internal/validate-set.mjs.map +0 -6
  201. package/dist/internal/validate-string.d.mts +0 -20
  202. package/dist/internal/validate-string.mjs +0 -11
  203. package/dist/internal/validate-string.mjs.map +0 -6
  204. package/dist/internal/validate-url-string.d.mts +0 -22
  205. package/dist/internal/validate-url-string.mjs +0 -12
  206. package/dist/internal/validate-url-string.mjs.map +0 -6
  207. package/dist/types/declaration.d.mts +0 -9
  208. package/dist/types/fn-change-ext.d.mts +0 -28
  209. package/dist/types/index.mjs +0 -1
  210. package/dist/types/index.mjs.map +0 -6
  211. package/dist/types/mime-type.d.mts +0 -13
  212. package/dist/types/module-specifier-type.d.mts +0 -11
  213. package/dist/types/syntax-kind-export.d.mts +0 -12
  214. package/dist/types/syntax-kind-import.d.mts +0 -12
  215. package/dist/types/syntax-kind-require.d.mts +0 -12
  216. package/dist/utils/compare-subpaths.d.mts +0 -25
  217. package/dist/utils/compare-subpaths.mjs +0 -24
  218. package/dist/utils/compare-subpaths.mjs.map +0 -6
  219. package/dist/utils/conditions.d.mts +0 -13
  220. package/dist/utils/conditions.mjs +0 -6
  221. package/dist/utils/conditions.mjs.map +0 -6
  222. package/dist/utils/detect-syntax.d.mts +0 -21
  223. package/dist/utils/detect-syntax.mjs +0 -12
  224. package/dist/utils/detect-syntax.mjs.map +0 -6
  225. package/dist/utils/extension-format-map.d.mts +0 -16
  226. package/dist/utils/extension-format-map.mjs +0 -22
  227. package/dist/utils/extension-format-map.mjs.map +0 -6
  228. package/dist/utils/extract-statements.d.mts +0 -21
  229. package/dist/utils/extract-statements.mjs +0 -21
  230. package/dist/utils/extract-statements.mjs.map +0 -6
  231. package/dist/utils/fill-modules.d.mts +0 -23
  232. package/dist/utils/fill-modules.mjs +0 -62
  233. package/dist/utils/fill-modules.mjs.map +0 -6
  234. package/dist/utils/find-dynamic-imports.d.mts +0 -18
  235. package/dist/utils/find-dynamic-imports.mjs +0 -39
  236. package/dist/utils/find-dynamic-imports.mjs.map +0 -6
  237. package/dist/utils/find-exports.d.mts +0 -21
  238. package/dist/utils/find-exports.mjs +0 -95
  239. package/dist/utils/find-exports.mjs.map +0 -6
  240. package/dist/utils/find-requires.d.mts +0 -18
  241. package/dist/utils/find-requires.mjs +0 -32
  242. package/dist/utils/find-requires.mjs.map +0 -6
  243. package/dist/utils/find-static-imports.d.mts +0 -18
  244. package/dist/utils/find-static-imports.mjs +0 -34
  245. package/dist/utils/find-static-imports.mjs.map +0 -6
  246. package/dist/utils/find-subpath.d.mts +0 -30
  247. package/dist/utils/find-subpath.mjs +0 -106
  248. package/dist/utils/find-subpath.mjs.map +0 -6
  249. package/dist/utils/get-format.d.mts +0 -24
  250. package/dist/utils/get-format.mjs +0 -111
  251. package/dist/utils/get-format.mjs.map +0 -6
  252. package/dist/utils/get-source.d.mts +0 -22
  253. package/dist/utils/get-source.mjs +0 -63
  254. package/dist/utils/get-source.mjs.map +0 -6
  255. package/dist/utils/has-cjs-syntax.d.mts +0 -25
  256. package/dist/utils/has-cjs-syntax.mjs +0 -11
  257. package/dist/utils/has-cjs-syntax.mjs.map +0 -6
  258. package/dist/utils/has-esm-syntax.d.mts +0 -21
  259. package/dist/utils/has-esm-syntax.mjs +0 -11
  260. package/dist/utils/has-esm-syntax.mjs.map +0 -6
  261. package/dist/utils/index.d.mts +0 -42
  262. package/dist/utils/index.mjs +0 -79
  263. package/dist/utils/index.mjs.map +0 -6
  264. package/dist/utils/is-absolute-specifier.d.mts +0 -19
  265. package/dist/utils/is-absolute-specifier.mjs +0 -25
  266. package/dist/utils/is-absolute-specifier.mjs.map +0 -6
  267. package/dist/utils/is-bare-specifier.d.mts +0 -19
  268. package/dist/utils/is-bare-specifier.mjs +0 -10
  269. package/dist/utils/is-bare-specifier.mjs.map +0 -6
  270. package/dist/utils/is-exports-sugar.d.mts +0 -25
  271. package/dist/utils/is-exports-sugar.mjs +0 -26
  272. package/dist/utils/is-exports-sugar.mjs.map +0 -6
  273. package/dist/utils/is-relative-specifier.d.mts +0 -20
  274. package/dist/utils/is-relative-specifier.mjs +0 -11
  275. package/dist/utils/is-relative-specifier.mjs.map +0 -6
  276. package/dist/utils/lookup-package-scope.d.mts +0 -24
  277. package/dist/utils/lookup-package-scope.mjs +0 -34
  278. package/dist/utils/lookup-package-scope.mjs.map +0 -6
  279. package/dist/utils/parse-data-url.d.mts +0 -25
  280. package/dist/utils/parse-data-url.mjs +0 -25
  281. package/dist/utils/parse-data-url.mjs.map +0 -6
  282. package/dist/utils/parse-module-id.d.mts +0 -22
  283. package/dist/utils/parse-module-id.mjs +0 -122
  284. package/dist/utils/parse-module-id.mjs.map +0 -6
  285. package/dist/utils/parse-subpath.d.mts +0 -35
  286. package/dist/utils/parse-subpath.mjs +0 -54
  287. package/dist/utils/parse-subpath.mjs.map +0 -6
  288. package/dist/utils/pattern-character.d.mts +0 -11
  289. package/dist/utils/pattern-character.mjs +0 -6
  290. package/dist/utils/pattern-character.mjs.map +0 -6
  291. package/dist/utils/read-package-json.d.mts +0 -26
  292. package/dist/utils/read-package-json.mjs +0 -43
  293. package/dist/utils/read-package-json.mjs.map +0 -6
  294. package/dist/utils/resolve-alias.d.mts +0 -20
  295. package/dist/utils/resolve-alias.mjs +0 -106
  296. package/dist/utils/resolve-alias.mjs.map +0 -6
  297. package/dist/utils/resolve-aliases.d.mts +0 -19
  298. package/dist/utils/resolve-aliases.mjs +0 -28
  299. package/dist/utils/resolve-aliases.mjs.map +0 -6
  300. package/dist/utils/resolve-extensions.d.mts +0 -14
  301. package/dist/utils/resolve-extensions.mjs +0 -22
  302. package/dist/utils/resolve-extensions.mjs.map +0 -6
  303. package/dist/utils/resolve-module.d.mts +0 -39
  304. package/dist/utils/resolve-module.mjs +0 -64
  305. package/dist/utils/resolve-module.mjs.map +0 -6
  306. package/dist/utils/resolve-modules.d.mts +0 -25
  307. package/dist/utils/resolve-modules.mjs +0 -26
  308. package/dist/utils/resolve-modules.mjs.map +0 -6
  309. package/dist/utils/to-absolute-specifier.d.mts +0 -22
  310. package/dist/utils/to-absolute-specifier.mjs +0 -8
  311. package/dist/utils/to-absolute-specifier.mjs.map +0 -6
  312. package/dist/utils/to-bare-specifier.d.mts +0 -42
  313. package/dist/utils/to-bare-specifier.mjs +0 -90
  314. package/dist/utils/to-bare-specifier.mjs.map +0 -6
  315. package/dist/utils/to-data-url.d.mts +0 -30
  316. package/dist/utils/to-data-url.mjs +0 -11
  317. package/dist/utils/to-data-url.mjs.map +0 -6
  318. package/dist/utils/to-node-url.d.mts +0 -19
  319. package/dist/utils/to-node-url.mjs +0 -10
  320. package/dist/utils/to-node-url.mjs.map +0 -6
  321. package/dist/utils/to-relative-specifier.d.mts +0 -22
  322. package/dist/utils/to-relative-specifier.mjs +0 -21
  323. package/dist/utils/to-relative-specifier.mjs.map +0 -6
  324. package/dist/utils/to-url.d.mts +0 -22
  325. package/dist/utils/to-url.mjs +0 -12
  326. package/dist/utils/to-url.mjs.map +0 -6
  327. package/dist/utils/validate-assertions.d.mts +0 -23
  328. package/dist/utils/validate-assertions.mjs +0 -52
  329. package/dist/utils/validate-assertions.mjs.map +0 -6
  330. package/dist/utils/validate-exports.d.mts +0 -24
  331. package/dist/utils/validate-exports.mjs +0 -72
  332. package/dist/utils/validate-exports.mjs.map +0 -6
package/README.md CHANGED
@@ -1,19 +1,1547 @@
1
- # mlly
1
+ # \:gear: mlly
2
2
 
3
+ [![github release](https://img.shields.io/github/v/release/flex-development/mlly.svg?include_prereleases\&sort=semver)](https://github.com/flex-development/mlly/releases/latest)
3
4
  [![npm](https://img.shields.io/npm/v/@flex-development/mlly.svg)](https://npmjs.com/package/@flex-development/mlly)
4
- [![codecov](https://codecov.io/gh/flex-development/mlly/branch/main/graph/badge.svg?token=36NUNRH6FW)](https://codecov.io/gh/flex-development/mlly)
5
- [![license](https://img.shields.io/github/license/flex-development/mlly.svg)](LICENSE.md)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@flex-development/mlly.svg)](https://www.npmcharts.com/compare/@flex-development/mlly?interval=30)
6
+ [![install size](https://packagephobia.now.sh/badge?p=@flex-development/mlly)](https://packagephobia.now.sh/result?p=@flex-development/mlly)
7
+ [![codecov](https://codecov.io/gh/flex-development/mlly/graph/badge.svg?token=36NUNRH6FW)](https://codecov.io/gh/flex-development/mlly)
6
8
  [![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
7
- [![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits&logoColor=ffffff)](https://conventionalcommits.org/)
8
- [![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript&logoColor=ffffff)](https://typescriptlang.org/)
9
- [![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat&logo=vitest&logoColor=ffffff)](https://vitest.dev/)
10
- [![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat&logo=yarn&logoColor=ffffff)](https://yarnpkg.com/)
9
+ [![license](https://img.shields.io/github/license/flex-development/mlly.svg)](LICENSE.md)
10
+ [![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits\&logoColor=ffffff)](https://conventionalcommits.org)
11
+ [![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\&logoColor=ffffff)](https://typescriptlang.org)
12
+ [![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\&logo=vitest\&logoColor=ffffff)](https://vitest.dev)
13
+ [![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\&logo=yarn\&logoColor=ffffff)](https://yarnpkg.com)
14
+
15
+ [ECMAScript module][node-esm] utilities.
16
+
17
+ ## Contents
18
+
19
+ - [What is this?](#what-is-this)
20
+ - [Install](#install)
21
+ - [Use](#use)
22
+ - [API](#api)
23
+ - [`canParseUrl(input[, base])`](#canparseurlinput-base)
24
+ - [`cwd()`](#cwd)
25
+ - [`defaultConditions`](#defaultconditions)
26
+ - [`defaultExtensions`](#defaultextensions)
27
+ - [`defaultMainFields`](#defaultmainfields)
28
+ - [`extensionFormatMap`](#extensionformatmap)
29
+ - [`formats`](#formats)
30
+ - [`getSource<T>(id[, options])`](#getsourcetid-options)
31
+ - [`isAbsoluteSpecifier(value)`](#isabsolutespecifiervalue)
32
+ - [`isArrayIndex(value)`](#isarrayindexvalue)
33
+ - [`isBareSpecifier(value)`](#isbarespecifiervalue)
34
+ - [`isDirectory<T>(id[, fs])`](#isdirectorytid-fs)
35
+ - [`isFile<T>(id[, fs])`](#isfiletid-fs)
36
+ - [`isImportsSubpath(value)`](#isimportssubpathvalue)
37
+ - [`isModuleId(value)`](#ismoduleidvalue)
38
+ - [`isRelativeSpecifier(value)`](#isrelativespecifiervalue)
39
+ - [`legacyMainResolve<T>(packageUrl[, manifest][, mainFields][, parent][, fs])`](#legacymainresolvetpackageurl-manifest-mainfields-parent-fs)
40
+ - [`lookupPackageScope<T>(url[, end][, fs])`](#lookuppackagescopeturl-end-fs)
41
+ - [`moduleResolve<T>(specifier, parent[, conditions][, mainFields][, preserveSymlinks][, fs])`](#moduleresolvetspecifier-parent-conditions-mainfields-preservesymlinks-fs)
42
+ - [`packageExportsResolve<T>(packageUrl, subpath, exports[, conditions][, parent][, fs])`](#packageexportsresolvetpackageurl-subpath-exports-conditions-parent-fs)
43
+ - [`packageImportsExportsResolve<T>(matchKey, matchObject, packageUrl[, isImports][, conditions][, mainFields][, parent][, fs])`](#packageimportsexportsresolvetmatchkey-matchobject-packageurl-isimports-conditions-mainfields-parent-fs)
44
+ - [`packageImportsResolve<T>(specifier, parent[, conditions][, mainFields][, fs])`](#packageimportsresolvetspecifier-parent-conditions-mainfields-fs)
45
+ - [`packageResolve<T>(specifier, parent[, conditions][, mainFields][, fs])`](#packageresolvetspecifier-parent-conditions-mainfields-fs)
46
+ - [`packageSelfResolve<T>(name, subpath, parent[, conditions][, fs])`](#packageselfresolvetname-subpath-parent-conditions-fs)
47
+ - [`packageTargetResolve<T>(packageUrl, target, subpath[, patternMatch][, isImports][, conditions][, mainFields][, parent][, fs])`](#packagetargetresolvetpackageurl-target-subpath-patternmatch-isimports-conditions-mainfields-parent-fs)
48
+ - [`patternKeyCompare(a, b)`](#patternkeycomparea-b)
49
+ - [`patternMatch(matchKey, matchObject)`](#patternmatchmatchkey-matchobject)
50
+ - [`readPackageJson<T>(id[, specifier][, parent][, fs])`](#readpackagejsontid-specifier-parent-fs)
51
+ - [`resolveAlias(specifier[, options])`](#resolvealiasspecifier-options)
52
+ - [`resolveModule<T>(specifier, parent[, options])`](#resolvemoduletspecifier-parent-options)
53
+ - [`resolver`](#resolver)
54
+ - [`root`](#root)
55
+ - [`toRelativeSpecifier(url, parent)`](#torelativespecifierurl-parent)
56
+ - [`toUrl(id[, parent])`](#tourlid-parent)
57
+ - [Types](#types)
58
+ - [`Aliases`](#aliases)
59
+ - [`Awaitable<T>`](#awaitablet)
60
+ - [`ChangeExtFn<[Ext]>`](#changeextfnext)
61
+ - [`ConditionMap`](#conditionmap)
62
+ - [`Condition`](#condition)
63
+ - [`Dot`](#dot)
64
+ - [`EmptyArray`](#emptyarray)
65
+ - [`EmptyObject`](#emptyobject)
66
+ - [`EmptyString`](#emptystring)
67
+ - [`Ext`](#ext)
68
+ - [`FileSystem`](#filesystem)
69
+ - [`GetSourceContext`](#getsourcecontext)
70
+ - [`GetSourceHandler`](#getsourcehandler)
71
+ - [`GetSourceHandlers`](#getsourcehandlers)
72
+ - [`GetSourceOptions`](#getsourceoptions)
73
+ - [`IsDirectory`](#isdirectory)
74
+ - [`IsFile`](#isfile)
75
+ - [`List<[T]>`](#listt)
76
+ - [`MainFieldMap`](#mainfieldmap)
77
+ - [`MainField`](#mainfield)
78
+ - [`ModuleFormatMap`](#moduleformatmap)
79
+ - [`ModuleFormat`](#moduleformat)
80
+ - [`ModuleId`](#moduleid)
81
+ - [`Numeric`](#numeric)
82
+ - [`PatternKeyComparisonMap`](#patternkeycomparsionmap)
83
+ - [`PatternKeyComparison`](#patternkeycomparsion)
84
+ - [`PatternMatch`](#patternmatch)
85
+ - [`ProtocolMap`](#protocolmap)
86
+ - [`Protocol`](#protocol)
87
+ - [`ReadFile`](#readfile)
88
+ - [`Realpath`](#realpath)
89
+ - [`ResolveAliasOptions`](#resolvealiasoptions)
90
+ - [`ResolveModuleOptions`](#resolvemoduleoptions)
91
+ - [`Stat`](#stat)
92
+ - [`Stats`](#stats)
93
+ - Additional Documentation
94
+ - [Resolution Algorithm](./docs/resolution-algorithm.md)
95
+ - [Contribute](#contribute)
96
+
97
+ ## What is this?
98
+
99
+ `mlly` is a set of [ECMAScript module][node-esm] (ESM) utilities.\
100
+ It exposes several tools to bridge the gap between developer experience and the current state of ECMAScript modules.
101
+
102
+ ## Install
103
+
104
+ This package is [ESM only][esm].
105
+
106
+ In Node.js (version 20+) with [yarn][]:
107
+
108
+ ```sh
109
+ yarn add @flex-development/mlly
110
+ ```
111
+
112
+ <blockquote>
113
+ <small>
114
+ See <a href='https://yarnpkg.com/protocol/git'>Git - Protocols | Yarn</a>
115
+ &nbsp;for details regarding installing from Git.
116
+ </small>
117
+ </blockquote>
118
+
119
+ In Deno with [`esm.sh`][esmsh]:
120
+
121
+ ```ts
122
+ import { resolveModule } from 'https://esm.sh/@flex-development/mlly'
123
+ ```
124
+
125
+ In browsers with [`esm.sh`][esmsh]:
126
+
127
+ ```html
128
+ <script type="module">
129
+ import { resolveModule } from 'https://esm.sh/@flex-development/mlly'
130
+ </script>
131
+ ```
132
+
133
+ ## Use
134
+
135
+ ```ts
136
+ import {
137
+ lookupPackageScope,
138
+ readPackageJson,
139
+ resolveModule,
140
+ type FileSystem
141
+ } from '@flex-development/mlly'
142
+ import pkg from '@flex-development/mlly/package.json' with { type: 'json' }
143
+ import type { PackageJson } from '@flex-development/pkg-types'
144
+ import nfs from 'node:fs'
145
+
146
+ /**
147
+ * A file system API with both asynchronous and synchronous methods.
148
+ *
149
+ * @const {FileSystem} fs
150
+ */
151
+ const fs: FileSystem = {
152
+ readFile: nfs.promises.readFile,
153
+ realpath: nfs.promises.realpath,
154
+ stat: nfs.statSync
155
+ }
156
+
157
+ /**
158
+ * The URL of the package directory.
159
+ *
160
+ * @const {URL | null} scope
161
+ */
162
+ const scope: URL | null = lookupPackageScope(import.meta.url, null, fs)
163
+
164
+ console.dir(scope) // file:///Users/lex/Projects/flex-development/mlly/
165
+
166
+ /**
167
+ * The package manifest.
168
+ *
169
+ * @const {PackageJson | null} manifest
170
+ */
171
+ const manifest: PackageJson | null = await readPackageJson(
172
+ scope,
173
+ null,
174
+ import.meta.url,
175
+ fs
176
+ )
177
+
178
+ console.dir(manifest?.name === pkg.name) // true
179
+ console.dir(manifest) // `pkg`
180
+
181
+ /**
182
+ * A fully resolved URL.
183
+ *
184
+ * @const {URL} resolved
185
+ */
186
+ const resolved = resolveModule(pkg.name, import.meta.url, {
187
+ conditions: new Set(['mlly']),
188
+ ext: null
189
+ })
190
+
191
+ console.dir(resolved) // file:///Users/lex/Projects/flex-development/mlly/src/
192
+ ```
193
+
194
+ ## API
195
+
196
+ `mlly` exports the identifiers listed below.
197
+
198
+ There is no default export.
199
+
200
+ ### `canParseUrl(input[, base])`
201
+
202
+ Check if `input` can be parsed to a `URL`.
203
+
204
+ > 👉 **Note**: If `input` is relative, `base` is required.
205
+ > If `input` is absolute, `base` is ignored.
206
+
207
+ #### Parameters
208
+
209
+ - `id` (`unknown`)
210
+ — the input url
211
+ - `base` (`unknown`)
212
+ — the base url to resolve against if `input` is not absolute
213
+
214
+ #### Returns
215
+
216
+ (`boolean`) `true` if `input` can be parsed to a `URL`, `false` otherwise
217
+
218
+ ### `cwd()`
219
+
220
+ Get the URL of the current working directory.
221
+
222
+ #### Returns
223
+
224
+ (`URL`) The current working directory URL
225
+
226
+ ### `defaultConditions`
227
+
228
+ [`Set<Condition>`](#condition)
229
+
230
+ The default list of conditions.
231
+
232
+ ### `defaultExtensions`
233
+
234
+ [`Set<Ext>`](#ext)
235
+
236
+ The default list of resolvable file extensions.
237
+
238
+ ### `defaultMainFields`
239
+
240
+ [`Set<MainField>`](#mainfield)
241
+
242
+ The default list of main fields.
243
+
244
+ ### `extensionFormatMap`
245
+
246
+ `Map<Ext, ModuleFormat>`
247
+
248
+ Map, where each key is a [file extension](#ext) and each value is a default [module format](#formats).
249
+
250
+ ### `formats`
251
+
252
+ Default module formats (`const enum`).
253
+
254
+ ```ts
255
+ const enum formats {
256
+ builtin = 'builtin',
257
+ commonjs = 'commonjs',
258
+ cts = 'commonjs-typescript',
259
+ json = 'json',
260
+ module = 'module',
261
+ mts = 'module-typescript',
262
+ wasm = 'wasm'
263
+ }
264
+ ```
265
+
266
+ ### `getSource<T>(id[, options])`
267
+
268
+ Get the source code for a module.
269
+
270
+ > 👉 **Note**: Returns a promise if the [handler](#getsourcehandler) for `id` is async.
271
+
272
+ #### Type Parameters
273
+
274
+ - `T` ([`Awaitable<string | null | undefined>`](#awaitablet))
275
+ — the module source code
276
+
277
+ #### Parameters
278
+
279
+ - `id` ([`ModuleId`](#moduleid) | `null` | `undefined`)
280
+ — the module id
281
+ - `options` ([`GetSourceOptions`](#getsourceoptions) | `null` | `undefined`)
282
+ — source code retrieval options
283
+
284
+ #### Returns
285
+
286
+ (`T`) The module source code
287
+
288
+ #### Throws
289
+
290
+ - [`ERR_UNSUPPORTED_ESM_URL_SCHEME`][err-unsupported-esm-url-scheme]
291
+
292
+ ### `isAbsoluteSpecifier(value)`
293
+
294
+ Check if `value` is an *absolute specifier*.
295
+
296
+ > 👉 **Note**: Only checks specifier syntax.\
297
+ > Does **not** guarantee the specifier references an existing module.
298
+
299
+ #### Parameters
300
+
301
+ - `value` (`unknown`)
302
+ — the value to check
303
+
304
+ #### Returns
305
+
306
+ (`boolean`) `true` if `value` is absolute specifier, `false` otherwise
307
+
308
+ ### `isArrayIndex(value)`
309
+
310
+ Check if `value` is a valid array index.
311
+
312
+ #### Parameters
313
+
314
+ - `value` (`unknown`)
315
+ — the value to check
316
+
317
+ #### Returns
318
+
319
+ ([`value is Numeric`](#numeric)) `true` if `value` is valid array index, `false` otherwise
320
+
321
+ ### `isBareSpecifier(value)`
322
+
323
+ Check if `value` is a *bare specifier*.
324
+
325
+ > 👉 **Note**: Only checks specifier syntax.\
326
+ > Does **not** guarantee the specifier references an existing module.
327
+
328
+ #### Parameters
329
+
330
+ - `value` (`unknown`)
331
+ — the value to check
332
+
333
+ #### Returns
334
+
335
+ (`boolean`) `true` if `value` is bare specifier, `false` otherwise
336
+
337
+ ### `isDirectory<T>(id[, fs])`
338
+
339
+ Check if a directory exists.
340
+
341
+ > 👉 **Note**: Returns a promise if `fs.stat` is async.
342
+
343
+ #### Type Parameters
344
+
345
+ - `T` ([`Awaitable<boolean>`](#awaitablet))
346
+ — the result of the check
347
+
348
+ #### Parameters
349
+
350
+ - `id` ([`ModuleId`](#moduleid))
351
+ — the module id to check
352
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
353
+ — the file system api
354
+
355
+ #### Returns
356
+
357
+ (`T`) `true` if directory exists at `id`, `false` otherwise
358
+
359
+ ### `isFile<T>(id[, fs])`
360
+
361
+ Check if a file exists.
362
+
363
+ > 👉 **Note**: Returns a promise if `fs.stat` is async.
364
+
365
+ #### Type Parameters
366
+
367
+ - `T` ([`Awaitable<boolean>`](#awaitablet))
368
+ — the result of the check
369
+
370
+ #### Parameters
371
+
372
+ - `id` ([`ModuleId`](#moduleid))
373
+ — the module id to check
374
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
375
+ — the file system api
376
+
377
+ #### Returns
378
+
379
+ (`T`) `true` if file exists at `id`, `false` otherwise
380
+
381
+ ### `isImportsSubpath(value)`
382
+
383
+ Check if `value` is an [`imports`][subpath-imports] subpath.
384
+
385
+ > 👉 **Note**: Only checks specifier syntax.\
386
+ > Does **not** guarantee the specifier references an existing module.
387
+
388
+ #### Parameters
389
+
390
+ - `value` (`unknown`)
391
+ — the value to check
392
+
393
+ #### Returns
394
+
395
+ ([`value is ImportsSubpath`][pkg-imports-subpath]) `true` if `value` is `imports` subpath, `false` otherwise
396
+
397
+ ### `isModuleId(value)`
398
+
399
+ Check if `value` is a module id.
400
+
401
+ #### Parameters
402
+
403
+ - `value` (`unknown`)
404
+ — the value to check
405
+
406
+ #### Returns
407
+
408
+ ([`value is ModuleId`](#moduleid)) `true` if `value` is module id, `false` otherwise
409
+
410
+ ### `isRelativeSpecifier(value)`
411
+
412
+ Check if `value` is a *relative specifier*.
413
+
414
+ > 👉 **Note**: Only checks specifier syntax.\
415
+ > Does **not** guarantee the specifier references an existing module.
416
+
417
+ #### Parameters
418
+
419
+ - `value` (`unknown`)
420
+ — the value to check
421
+
422
+ #### Returns
423
+
424
+ (`boolean`) `true` if `value` is relative specifier, `false` otherwise
425
+
426
+ <!--lint disable-->
427
+
428
+ ### `legacyMainResolve<T>(packageUrl[, manifest][, mainFields][, parent][, fs])`
429
+
430
+ <!--lint enable-->
431
+
432
+ Resolve a [`main`][main]-like package entry point.
433
+
434
+ Implements the [`LEGACY_MAIN_RESOLVE`][algorithm-legacy-main-resolve] resolution algorithm.
435
+
436
+ > 👉 **Note**: Returns a promise if `fs.stat` is async.
437
+
438
+ #### Type Parameters
439
+
440
+ - `T` ([`Awaitable<URL>`](#awaitablet))
441
+ — the resolved entry point url
442
+
443
+ #### Parameters
444
+
445
+ - `packageUrl` ([`ModuleId`](#moduleid))
446
+ — the url of the package directory, the `package.json` file, or a module in the same directory as a `package.json`
447
+ - `manifest` ([`PackageJson`][pkg-package-json] | `null` | `undefined`)
448
+ — the package manifest
449
+ - `mainFields` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
450
+ — the list of legacy main fields
451
+ - **default**: [`defaultMainFields`](#defaultmainfields)
452
+ - `parent` ([`ModuleId`](#moduleid) | `null` | `undefined`)
453
+ — the url of the parent module
454
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
455
+ — the file system api
456
+
457
+ #### Returns
458
+
459
+ (`T`) The resolved entry point URL
460
+
461
+ #### Throws
462
+
463
+ - [`ERR_MODULE_NOT_FOUND`][err-module-not-found]
464
+
465
+ ### `lookupPackageScope<T>(url[, end][, fs])`
466
+
467
+ Get the package scope URL for a module `url`.
468
+
469
+ Implements the [`LOOKUP_PACKAGE_SCOPE`][algorithm-lookup-package-scope] algorithm.
470
+
471
+ > 👉 **Note**: Returns a promise if `fs.stat` is async.
472
+
473
+ #### Overloads
474
+
475
+ ```ts
476
+ function lookupPackageScope(
477
+ this: void,
478
+ url: EmptyString | null | undefined,
479
+ end?: ModuleId | null | undefined,
480
+ fs?: FileSystem | null | undefined
481
+ ): null
482
+ ```
483
+
484
+ ```ts
485
+ function lookupPackageScope<T extends Awaitable<URL | null>>(
486
+ this: void,
487
+ url: ModuleId | null | undefined,
488
+ end?: ModuleId | null | undefined,
489
+ fs?: FileSystem | null | undefined
490
+ ): T
491
+ ```
492
+
493
+ #### Type Parameters
494
+
495
+ - `T` ([`Awaitable<URL | null>`](#awaitablet))
496
+ — the resolved package scope url
497
+
498
+ #### Parameters
499
+
500
+ - `id` ([`ModuleId`](#moduleid) | `null` | `undefined`)
501
+ — the url of the module to scope
502
+ - `end` ([`ModuleId`](#moduleid) | `null` | `undefined`)
503
+ — the url of the directory to end search at
504
+ - **default**: [`root`](#root)
505
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
506
+ — the file system api
507
+
508
+ #### Returns
509
+
510
+ (`T`) The URL of nearest directory containing a `package.json` file
511
+
512
+ <!--lint disable-->
513
+
514
+ ### `moduleResolve<T>(specifier, parent[, conditions][, mainFields][, preserveSymlinks][, fs])`
515
+
516
+ <!--lint enable-->
517
+
518
+ Resolve a module `specifier`.
519
+
520
+ Implements the [`ESM_RESOLVE`][algorithm-esm-resolve] algorithm.
521
+
522
+ > 👉 **Note**: Returns a promise if `fs.realpath` or `fs.stat` is async, or one the following methods returns a promise:
523
+ > [`packageImportsResolve`](#packageimportsresolvetspecifier-parent-conditions-mainfields-fs),
524
+ > [`packageResolve`](#packageresolvetspecifier-parent-conditions-mainfields-fs).
525
+
526
+ #### Type Parameters
527
+
528
+ - `T` ([`Awaitable<URL>`](#awaitablet))
529
+ — the resolved url
530
+
531
+ #### Parameters
532
+
533
+ - `specifier` (`string`)
534
+ — the module specifier to resolve
535
+ - `parent` ([`ModuleId`](#moduleid))
536
+ — the url of the parent module
537
+ - `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
538
+ — the list of export/import conditions
539
+ - **default**: [`defaultConditions`](#defaultconditions)
540
+ - `mainFields` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
541
+ — the list of legacy main fields
542
+ - **default**: [`defaultMainFields`](#defaultmainfields)
543
+ - `preserveSymlinks` (`boolean` | `null` | `undefined`)
544
+ — whether to keep symlinks instead of resolving them
545
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
546
+ — the file system api
547
+
548
+ #### Returns
549
+
550
+ (`T`) The resolved URL
551
+
552
+ <!--lint disable-->
553
+
554
+ ### `packageExportsResolve<T>(packageUrl, subpath, exports[, conditions][, parent][, fs])`
555
+
556
+ <!--lint enable-->
557
+
558
+ Resolve a package export.
559
+
560
+ Implements the [`PACKAGE_EXPORTS_RESOLVE`][algorithm-package-exports-resolve] algorithm.
561
+
562
+ > 👉 **Note**: Never returns a promisee.
563
+
564
+ #### Type Parameters
565
+
566
+ - `T` ([`Awaitable<URL>`](#awaitablet))
567
+ — the resolved package export url
568
+
569
+ #### Parameters
570
+
571
+ - `packageUrl` ([`ModuleId`](#moduleid))
572
+ — the url of the package directory, the `package.json` file, or a module in the same directory as a `package.json`
573
+ - `subpath` (`string`)
574
+ — the package subpath
575
+ - `exports` ([`Exports`][pkg-exports] | `undefined`)
576
+ — the package exports
577
+ - `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
578
+ — the list of export/import conditions
579
+ - **default**: [`defaultConditions`](#defaultconditions)
580
+ - `parent` ([`ModuleId`](#moduleid) | `null` | `undefined`)
581
+ — the url of the parent module
582
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
583
+ — the file system api
584
+
585
+ #### Returns
586
+
587
+ (`T`) The resolved package export URL
588
+
589
+ <!--lint disable-->
590
+
591
+ ### `packageImportsExportsResolve<T>(matchKey, matchObject, packageUrl[, isImports][, conditions][, mainFields][, parent][, fs])`
592
+
593
+ <!--lint enable-->
594
+
595
+ Resolve a package export or import.
596
+
597
+ Implements the [`PACKAGE_IMPORTS_EXPORTS_RESOLVE`][algorithm-package-imports-exports-resolve] algorithm.
598
+
599
+ > 👉 **Note**: Returns a promise if
600
+ > [`packageTargetResolve`](#packagetargetresolvetpackageurl-target-subpath-patternmatch-isimports-conditions-mainfields-parent-fs),
601
+ > returns a promise.
602
+
603
+ #### Type Parameters
604
+
605
+ - `T` ([`Awaitable<URL | null | undefined>`](#awaitablet))
606
+ — the resolved package export or import url
607
+
608
+ #### Parameters
609
+
610
+ - `matchKey` (`string`)
611
+ — the package subpath extracted from a module specifier, or a dot character (`.`)
612
+ - `matchObject` ([`ExportsObject`][pkg-exports-object] | [`Imports`][pkg-imports] | `null` | `undefined`)
613
+ — the package exports or imports
614
+ - `packageUrl` ([`ModuleId`](#moduleid))
615
+ — the url of the directory containing the `package.json` file
616
+ - `isImports` (`boolean` | `null` | `undefined`)
617
+ — whether `matchObject` is internal to the package
618
+ - `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
619
+ — the list of export/import conditions
620
+ - **default**: [`defaultConditions`](#defaultconditions)
621
+ - `mainFields` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
622
+ — the list of legacy main fields
623
+ - **default**: [`defaultMainFields`](#defaultmainfields)
624
+ - `parent` ([`ModuleId`](#moduleid) | `null` | `undefined`)
625
+ — the url of the parent module
626
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
627
+ — the file system api
628
+
629
+ #### Returns
630
+
631
+ (`T`) The resolved package export or import URL
632
+
633
+ <!--lint disable-->
634
+
635
+ ### `packageImportsResolve<T>(specifier, parent[, conditions][, mainFields][, fs])`
636
+
637
+ <!--lint enable-->
638
+
639
+ Resolve a package import.
640
+
641
+ Implements the [`PACKAGE_IMPORTS_RESOLVE`][algorithm-package-imports-resolve] algorithm.
642
+
643
+ > 👉 **Note**: Returns a promise if [`lookupPackageScope`](#lookuppackagescopeturl-end-fs),
644
+ > [`packageImportsExportsResolve`](#packageimportsexportsresolvetmatchkey-matchobject-packageurl-isimports-conditions-mainfields-parent-fs),
645
+ > or [`readPackageJson`](#readpackagejsontid-specifier-parent-fs) returns a promise.
646
+
647
+ #### Type Parameters
648
+
649
+ - `T` ([`Awaitable<URL>`](#awaitablet))
650
+ — the resolved package import url
651
+
652
+ #### Parameters
653
+
654
+ - `specifier` (`string`)
655
+ — the import specifier to resolve
656
+ - `parent` ([`ModuleId`](#moduleid))
657
+ — the url of the parent module
658
+ - `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
659
+ — the list of export conditions
660
+ - **default**: [`defaultConditions`](#defaultconditions)
661
+ - `mainFields` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
662
+ — the list of legacy main fields
663
+ - **default**: [`defaultMainFields`](#defaultmainfields)
664
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
665
+ — the file system api
666
+
667
+ #### Returns
668
+
669
+ (`T`) The resolved package import URL
670
+
671
+ #### Throws
672
+
673
+ - [`ERR_INVALID_MODULE_SPECIFIER`][err-invalid-module-specifier]
674
+ - [`ERR_PACKAGE_IMPORT_NOT_DEFINED`][err-package-import-not-defined]
675
+
676
+ <!--lint disable-->
677
+
678
+ ### `packageResolve<T>(specifier, parent[, conditions][, mainFields][, fs])`
679
+
680
+ <!--lint enable-->
681
+
682
+ Resolve a *bare specifier*.
683
+
684
+ Implements the [`PACKAGE_RESOLVE`][algorithm-package-resolve] algorithm.
685
+
686
+ > *Bare specifiers* like `'some-package'` or `'some-package/shuffle'` refer to the main entry point of a package by
687
+ > package name, or a specific feature module within a package prefixed by the package name.
688
+ > Including the file extension is only necessary for packages without an [`exports`][exports] field.
689
+
690
+ > 👉 **Note**: Returns a promise if `fs.stat` is async or one of the following methods returns a promise:
691
+ > [`legacyMainResolve`](#legacymainresolvetpackageurl-manifest-mainfields-parent-fs),
692
+ > [`packageExportsResolve`](#packageexportsresolvetpackageurl-subpath-exports-conditions-parent-fs),
693
+ > [`packageSelfResolve`](#packageselfresolvetname-subpath-parent-conditions-fs), or
694
+ > [`readPackageJson`](#readpackagejsontid-specifier-parent-fs).
695
+
696
+ #### Type Parameters
697
+
698
+ - `T` ([`Awaitable<URL>`](#awaitablet))
699
+ — the resolved package url
700
+
701
+ #### Parameters
702
+
703
+ - `specifier` (`string`)
704
+ — the package specifier
705
+ - `parent` ([`ModuleId`](#moduleid))
706
+ — the url of the parent module
707
+ - `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
708
+ — the list of export conditions
709
+ - **default**: [`defaultConditions`](#defaultconditions)
710
+ - `mainFields` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
711
+ — the list of legacy main fields
712
+ - **default**: [`defaultMainFields`](#defaultmainfields)
713
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
714
+ — the file system api
715
+
716
+ #### Returns
717
+
718
+ (`T`) The resolved package URL
719
+
720
+ #### Throws
721
+
722
+ - [`ERR_INVALID_MODULE_SPECIFIER`][err-invalid-module-specifier]
723
+ - [`ERR_MODULE_NOT_FOUND`][err-module-not-found]
724
+
725
+ <!--lint disable-->
726
+
727
+ ### `packageSelfResolve<T>(name, subpath, parent[, conditions][, fs])`
728
+
729
+ <!--lint enable-->
730
+
731
+ Resolve the self-import of a package.
732
+
733
+ Implements the [`PACKAGE_SELF_RESOLVE`][algorithm-package-self-resolve] algorithm.
734
+
735
+ > 👉 **Note**: Returns a promise if [`lookupPackageScope`](#lookuppackagescopeturl-end-fs),
736
+ > [`packageExportsResolve`](#packageexportsresolvetpackageurl-subpath-exports-conditions-parent-fs),
737
+ > or [`readPackageJson`](#readpackagejsontid-specifier-parent-fs) returns a promise.
738
+
739
+ #### Type Parameters
740
+
741
+ - `T` ([`Awaitable<URL | undefined>`](#awaitablet))
742
+ — the resolved package url
743
+
744
+ #### Parameters
745
+
746
+ - `name` (`string`)
747
+ — the package name
748
+ - `subpath` (`string`)
749
+ — the package subpath
750
+ - `parent` ([`ModuleId`](#moduleid))
751
+ — the url of the parent module
752
+ - `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
753
+ — the list of export conditions
754
+ - **default**: [`defaultConditions`](#defaultconditions)
755
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
756
+ — the file system api
757
+
758
+ #### Returns
759
+
760
+ (`T`) The resolved package URL
761
+
762
+ <!--lint disable-->
763
+
764
+ ### `packageTargetResolve<T>(packageUrl, target, subpath[, patternMatch][, isImports][, conditions][, mainFields][, parent][, fs])`
765
+
766
+ <!--lint enable-->
767
+
768
+ Resolve a package target.
769
+
770
+ Implements the [`PACKAGE_TARGET_RESOLVE`][algorithm-package-target-resolve] algorithm.
771
+
772
+ > 👉 **Note**: Returns a promise if `target` is internal to the package and
773
+ > [`packageResolve`](#packageresolvetspecifier-parent-conditions-mainfields-fs) returns a promise.
774
+
775
+ #### Type Parameters
776
+
777
+ - `T` ([`Awaitable<URL | null | undefined>`](#awaitablet))
778
+ — the resolved package target url
779
+
780
+ #### Parameters
781
+
782
+ - `packageUrl` ([`ModuleId`](#moduleid))
783
+ — the url of the directory containing the `package.json` file
784
+ - `target` (`unknown`)
785
+ — the package target (i.e. a `exports`/`imports` value)
786
+ - `subpath` (`string`)
787
+ — the package subpath (i.e. a `exports`/`imports` key)
788
+ - `patternMatch` (`string` | `null` | `undefined`)
789
+ — the `subpath` pattern match
790
+ - `isImports` (`boolean` | `null` | `undefined`)
791
+ — whether `target` is internal to the package
792
+ - `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
793
+ — the list of export/import conditions
794
+ - **default**: [`defaultConditions`](#defaultconditions)
795
+ - `mainFields` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
796
+ — the list of legacy main fields
797
+ - **default**: [`defaultMainFields`](#defaultmainfields)
798
+ - `parent` ([`ModuleId`](#moduleid))
799
+ — the url of the parent module
800
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
801
+ — the file system api
802
+
803
+ #### Returns
804
+
805
+ (`T`) The resolved package target URL
806
+
807
+ #### Throws
808
+
809
+ - [`ERR_INVALID_PACKAGE_CONFIG`][err-invalid-package-config]
810
+ - [`ERR_INVALID_PACKAGE_TARGET`][err-invalid-package-target]
811
+
812
+ ### `patternKeyCompare(a, b)`
813
+
814
+ Compare two pattern keys and return a value indicating their order.
815
+
816
+ Implements the [`PATTERN_KEY_COMPARE`][algorithm-pattern-key-compare] algorithm.
817
+
818
+ #### Parameters
819
+
820
+ - `a` (`string`)
821
+ — the first key
822
+ - `b` (`string`)
823
+ — the key to compare against `a`
824
+
825
+ #### Returns
826
+
827
+ ([`PatternKeyComparison`](#patternkeycomparsion)) The pattern key comparsion result
828
+
829
+ ### `patternMatch(matchKey, matchObject)`
830
+
831
+ Get a subpath pattern match for `matchKey`.
832
+
833
+ #### Parameters
834
+
835
+ - `matchKey` (`string`)
836
+ — the key to expand
837
+ - `matchObject` (`unknown`)
838
+ — the match keys object
839
+
840
+ #### Returns
841
+
842
+ ([`PatternMatch`](#patternmatch) | `null`) List, where the first item is the key of a package exports or imports target
843
+ object, and the last is a subpath pattern match
844
+
845
+ ### `readPackageJson<T>(id[, specifier][, parent][, fs])`
846
+
847
+ Read a `package.json` file.
848
+
849
+ Implements the [`READ_PACKAGE_JSON`][algorithm-read-package-json] algorithm.
850
+
851
+ > 👉 **Note**: Returns a promise if `fs.readFile` or `fs.stat` is async.
852
+
853
+ #### Overloads
854
+
855
+ ```ts
856
+ function readPackageJson(
857
+ this: void,
858
+ id: EmptyString | null | undefined,
859
+ specifier?: string | null | undefined,
860
+ parent?: ModuleId | null | undefined,
861
+ fs?: FileSystem | null | undefined
862
+ ): null
863
+ ```
864
+
865
+ ```ts
866
+ function readPackageJson<T extends Awaitable<PackageJson | null>>(
867
+ this: void,
868
+ id: ModuleId | null | undefined,
869
+ specifier?: string | null | undefined,
870
+ parent?: ModuleId | null | undefined,
871
+ fs?: FileSystem | null | undefined
872
+ ): T
873
+ ```
874
+
875
+ #### Type Parameters
876
+
877
+ - `T` ([`Awaitable<PackageJson | null>`][pkg-package-json])
878
+ — the parsed file contents
879
+
880
+ #### Parameters
881
+
882
+ - `id` ([`ModuleId`](#moduleid) | `null` | `undefined`)
883
+ — the url of the package directory, the `package.json` file, or a module in the same directory as a `package.json`
884
+ - `specifier` (`string` | `null` | `undefined`)
885
+ — the module specifier that initiated the reading of the `package.json` file
886
+ > 👉 **note**: should be a `file:` url if `parent` is not a url
887
+ - `parent` ([`ModuleId`](#moduleid) | `null` | `undefined`)
888
+ — the url of the parent module
889
+ - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
890
+ — the file system api
891
+
892
+ #### Returns
893
+
894
+ (`T`) The parsed file contents
895
+
896
+ #### Throws
897
+
898
+ - [`ERR_INVALID_PACKAGE_CONFIG`][err-invalid-package-config]
899
+
900
+ ### `resolveAlias(specifier[, options])`
901
+
902
+ Resolve an aliased `specifier`.
903
+
904
+ #### Parameters
905
+
906
+ - `specifier` (`string`)
907
+ — the specifier using an alias
908
+ - `options` ([`ResolveAliasOptions`](#resolvealiasoptions) | `null` | `undefined`)
909
+ — alias resolution options
910
+
911
+ #### Returns
912
+
913
+ (`string` | `null`) The specifier of the aliased module
914
+
915
+ ### `resolveModule<T>(specifier, parent[, options])`
916
+
917
+ Resolve a module `specifier`.
918
+
919
+ Implements the [`ESM_RESOLVE`][algorithm-esm-resolve] algorithm, mostly \:wink:.
920
+
921
+ Adds support for:
922
+
923
+ - Changing file extensions
924
+ - Directory index resolution
925
+ - Extensionless file resolution
926
+ - Path alias resolution
927
+ - Scopeless `@types/*` resolution (i.e. `unist` -> `@types/unist`)
928
+
929
+ > 👉 **Note**: Returns a promise if
930
+ > [`moduleResolve`](#moduleresolvetspecifier-parent-conditions-mainfields-preservesymlinks-fs) returns a promise.
931
+
932
+ #### Type Parameters
933
+
934
+ - `T` ([`Awaitable<URL>`](#awaitablet))
935
+ — the resolved url
936
+
937
+ #### Parameters
938
+
939
+ - `specifier` (`string`)
940
+ — the module specifier to resolve
941
+ - `parent` ([`ModuleId`](#moduleid))
942
+ — the url of the parent module
943
+ - `options` ([`ResolveModuleOptions`](#resolvemoduleoptions))
944
+ — module resolution options
945
+
946
+ #### Returns
947
+
948
+ (`T`) The resolved URL
949
+
950
+ ### `resolver`
951
+
952
+ An object containing resolution algorithm implementations.
953
+
954
+ - [`legacyMainResolve`](#legacymainresolvetpackageurl-manifest-mainfields-parent-fs)
955
+ - [`moduleResolve`](#moduleresolvetspecifier-parent-conditions-mainfields-preservesymlinks-fs)
956
+ - [`packageExportsResolve`](#packageexportsresolvetpackageurl-subpath-exports-conditions-parent-fs)
957
+ - [`packageImportsExportsResolve`](#packageimportsexportsresolvetmatchkey-matchobject-packageurl-isimports-conditions-mainfields-parent-fs)
958
+ - [`packageImportsResolve`](#packageimportsresolvetspecifier-parent-conditions-mainfields-fs)
959
+ - [`packageResolve`](#packageresolvetspecifier-parent-conditions-mainfields-fs)
960
+ - [`packageSelfResolve`](#packageselfresolvetname-subpath-parent-conditions-fs)
961
+ - [`packageTargetResolve`](#packagetargetresolvetpackageurl-target-subpath-patternmatch-isimports-conditions-mainfields-parent-fs)
962
+
963
+ ### `root`
964
+
965
+ `URL`
966
+
967
+ The URL of the file system root.
968
+
969
+ ### `toRelativeSpecifier(url, parent)`
970
+
971
+ Turn `url` into a *relative specifier*.
972
+
973
+ > 👉 **Note**: The relative specifier will only have a file extension if `specifier` also has an extension.
974
+
975
+ #### Parameters
976
+
977
+ - `url` ([`ModuleId`](#moduleid))
978
+ — the `file:` url to convert
979
+ - `parent` ([`ModuleId`](#moduleid))
980
+ — the parent module id
981
+
982
+ #### Returns
983
+
984
+ (`string`) The relative specifier
985
+
986
+ ### `toUrl(id[, parent])`
987
+
988
+ Convert `id` to a `URL`.
989
+
990
+ > 👉 **Note**: If `id` cannot be parsed as a `URL` and is also not a [builtin module][builtin-module],
991
+ > it will be assumed to be a path and converted to a [`file:` URL][file-url].
992
+
993
+ #### Parameters
994
+
995
+ - `id` ([`ModuleId`](#moduleid))
996
+ — the module id to convert
997
+ - `parent` ([`ModuleId`](#moduleid) | `null` | `undefined`)
998
+ — the base url to resolve against if `id` is not absolute
999
+
1000
+ #### Returns
1001
+
1002
+ (`URL`) The new URL
1003
+
1004
+ ## Types
1005
+
1006
+ This package is fully typed with [TypeScript][].
1007
+
1008
+ ### `Aliases`
1009
+
1010
+ Record, where each key is a path alias or pattern
1011
+ and each value is a path mapping configuration (`interface`).
1012
+
1013
+ ```ts
1014
+ interface Aliases {
1015
+ [alias: string]: (string | null | undefined)[] | string | null | undefined
1016
+ }
1017
+ ```
1018
+
1019
+ When developing extensions that use additional aliases, augment `Aliases` to register custom aliases:
1020
+
1021
+ ```ts
1022
+ declare module '@flex-development/mlly' {
1023
+ interface Aliases {
1024
+ custom?: string[] | string | null
1025
+ }
1026
+ }
1027
+ ```
1028
+
1029
+ ### `Awaitable<T>`
1030
+
1031
+ Create a union of `T` and `T` as a promise-like object (`type`).
1032
+
1033
+ ```ts
1034
+ type Awaitable<T> = PromiseLike<T> | T
1035
+ ```
1036
+
1037
+ #### Type Parameters
1038
+
1039
+ - `T` (`any`)
1040
+ - the value
1041
+
1042
+ ### `ChangeExtFn<[Ext]>`
1043
+
1044
+ Get a new file extension for `url` (`type`).
1045
+
1046
+ Returning an empty string (`''`), `null`, or `undefined` will remove the current file extension.
1047
+
1048
+ ```ts
1049
+ type ChangeExtFn<
1050
+ Ext extends string | null | undefined = string | null | undefined
1051
+ > = (this: void, url: URL, specifier: string) => Ext
1052
+ ```
1053
+
1054
+ #### Type Parameters
1055
+
1056
+ - `Ext` (`string` | `null` | `undefined`, optional)
1057
+ — the new file extension
1058
+
1059
+ #### Parameters
1060
+
1061
+ - `url` (`URL`)
1062
+ — the resolved module URL
1063
+ - `specifier` (`string`)
1064
+ — the module specifier being resolved
1065
+
1066
+ #### Returns
1067
+
1068
+ (`Ext`) The new file extension
1069
+
1070
+ ### `ConditionMap`
1071
+
1072
+ Registry of export/import conditions (`interface`).
1073
+
1074
+ When developing extensions that use additional conditions, augment `ConditionMap` to register custom conditions:
1075
+
1076
+ ```ts
1077
+ declare module '@flex-development/mlly' {
1078
+ interface ConditionMap {
1079
+ custom: 'custom'
1080
+ }
1081
+ }
1082
+ ```
1083
+
1084
+ ### `Condition`
1085
+
1086
+ Union of values that can occur where a export/import condition is expected (`type`).
1087
+
1088
+ To register new conditions, augment [`ConditionMap`](#conditionmap).
1089
+ They will be added to this union automatically.
1090
+
1091
+ ```ts
1092
+ type Condition = ConditionMap[keyof ConditionMap]
1093
+ ```
1094
+
1095
+ ### `Dot`
1096
+
1097
+ A dot character (`'.'`) (`type`).
1098
+
1099
+ ```ts
1100
+ type Dot = '.'
1101
+ ```
1102
+
1103
+ ### `EmptyArray`
1104
+
1105
+ An empty array (`type`).
1106
+
1107
+ ```ts
1108
+ type EmptyArray = []
1109
+ ```
1110
+
1111
+ ### `EmptyObject`
1112
+
1113
+ An empty object (`type`).
1114
+
1115
+ ```ts
1116
+ type EmptyObject = { [tag]?: never }
1117
+ ```
1118
+
1119
+ ### `EmptyString`
1120
+
1121
+ An empty string (`type`).
1122
+
1123
+ ```ts
1124
+ type EmptyString = ''
1125
+ ```
1126
+
1127
+ ### `Ext`
1128
+
1129
+ A file extension (`type`).
1130
+
1131
+ ```ts
1132
+ type Ext = `${Dot}${string}`
1133
+ ```
1134
+
1135
+ ### `FileSystem`
1136
+
1137
+ The file system API (`interface`).
1138
+
1139
+ #### Properties
1140
+
1141
+ - `readFile` ([`ReadFile`](#readfile))
1142
+ — read the entire contents of a file
1143
+ - `realpath` ([`Realpath`](#realpath))
1144
+ — compute a canonical pathname by resolving `.`, `..`, and symbolic links
1145
+ - `stat` ([`Stat`](#stat))
1146
+ — get information about a directory or file
1147
+
1148
+ ### `GetSourceContext`
1149
+
1150
+ Source code retrieval context (`interface`).
1151
+
1152
+ #### Extends
1153
+
1154
+ - [`GetSourceOptions`](#getsourceoptions)
1155
+
1156
+ #### Properties
1157
+
1158
+ - `fs` ([`FileSystem`](#filesystem))
1159
+ — the file system api
1160
+ - `handlers` ([`GetSourceHandlers`](#getsourcehandlers))
1161
+ — record, where each key is a url protocol and each value is a source code handler
1162
+ - `req` (`RequestInit`)
1163
+ — request options for network based modules
1164
+ - `schemes` (`Set<string>`)
1165
+ — the list of supported url schemes
1166
+
1167
+ ### `GetSourceHandler`
1168
+
1169
+ Get the source code for a module (`type`).
1170
+
1171
+ ```ts
1172
+ type GetSourceHandler = (
1173
+ this: GetSourceContext,
1174
+ url: URL
1175
+ ) => Awaitable<Uint8Array | string | null | undefined>
1176
+ ```
1177
+
1178
+ #### Parameters
1179
+
1180
+ - **`this`** ([`GetSourceContext`](#getsourcecontext))
1181
+ — the retrieval context
1182
+ - `url` (`URL`)
1183
+ — the module URL
1184
+
1185
+ #### Returns
1186
+
1187
+ ([`Awaitable<Uint8Array | string | null | undefined>`](#awaitablet)) The source code
1188
+
1189
+ ### `GetSourceHandlers`
1190
+
1191
+ Record, where key is a URL protocol and each value is a source code handler (`type`).
1192
+
1193
+ ```ts
1194
+ type GetSourceHandlers = {
1195
+ [H in Protocol]?: GetSourceHandler | null | undefined
1196
+ }
1197
+ ```
1198
+
1199
+ ### `GetSourceOptions`
1200
+
1201
+ Options for retrieving source code (`interface`).
1202
+
1203
+ #### Properties
1204
+
1205
+ - `format?` ([`ModuleFormat`](#moduleformat) | `null` | `undefined`)
1206
+ — the module format hint
1207
+ - `fs?` ([`FileSystem`](#filesystem) | `null` | `undefined`)
1208
+ — the file system api
1209
+ - `handlers?` ([`GetSourceHandlers`](#getsourcehandlers) | `null` | `undefined`)
1210
+ — record, where each key is a url protocol and each value is a source code handler
1211
+ - `ignoreErrors?` (`boolean` | `null` | `undefined`)
1212
+ — whether to ignore [`ERR_UNSUPPORTED_ESM_URL_SCHEME`][err-unsupported-esm-url-scheme] if thrown
1213
+ - `req?` (`RequestInit` | `null` | `undefined`)
1214
+ — request options for network based modules
1215
+ - `schemes?` ([`List<string>`](#listt) | `null` | `undefined`)
1216
+ — the list of supported url schemes
1217
+ - **default**: `['data', 'file', 'http', 'https', 'node']`
1218
+
1219
+ ### `IsDirectory`
1220
+
1221
+ Check if a stats object describes a directory (`interface`).
1222
+
1223
+ #### Returns
1224
+
1225
+ (`boolean`) `true` if stats describes directory, `false` otherwise
1226
+
1227
+ ### `IsFile`
1228
+
1229
+ Check if a stats object describes a file (`interface`).
1230
+
1231
+ #### Returns
1232
+
1233
+ (`boolean`) `true` if stats describes regular file, `false` otherwise
1234
+
1235
+ ### `List<[T]>`
1236
+
1237
+ A list (`type`).
1238
+
1239
+ ```ts
1240
+ type List<T = unknown> = ReadonlySet<T> | readonly T[]
1241
+ ```
1242
+
1243
+ #### Type Parameters
1244
+
1245
+ - `T` (`any`, optional)
1246
+ — list item type
1247
+
1248
+ ### `MainFieldMap`
1249
+
1250
+ Registry of main fields (`interface`).
1251
+
1252
+ When developing extensions that use additional fields, augment `MainFieldMap` to register custom fields:
1253
+
1254
+ ```ts
1255
+ declare module '@flex-development/mlly' {
1256
+ interface MainFieldMap {
1257
+ unpkg: 'unpkg'
1258
+ }
1259
+ }
1260
+ ```
1261
+
1262
+ ### `MainField`
1263
+
1264
+ Union of values that can occur where a main field is expected (`type`).
1265
+
1266
+ To register new main fields, augment [`MainFieldMap`](#mainfieldmap).
1267
+ They will be added to this union automatically.
1268
+
1269
+ ```ts
1270
+ type MainField = MainFieldMap[keyof MainFieldMap]
1271
+ ```
1272
+
1273
+ ### `ModuleFormatMap`
1274
+
1275
+ Registry of module formats (`interface`).
1276
+
1277
+ When developing extensions that use additional formats, augment `ModuleFormatMap` to register custom formats:
1278
+
1279
+ ```ts
1280
+ declare module '@flex-development/mlly' {
1281
+ interface ModuleFormatMap {
1282
+ custom: 'custom'
1283
+ }
1284
+ }
1285
+ ```
1286
+
1287
+ ### `ModuleFormat`
1288
+
1289
+ Union of values that can occur where a module format is expected (`type`).
1290
+
1291
+ To register new main formats, augment [`ModuleFormatMap`](#moduleformatmap).
1292
+ They will be added to this union automatically.
1293
+
1294
+ ```ts
1295
+ type ModuleFormat = ModuleFormatMap[keyof ModuleFormatMap]
1296
+ ```
1297
+
1298
+ ### `ModuleId`
1299
+
1300
+ Union of values that can occur where a ECMAScript (ES) module identifier is expected (`type`).
1301
+
1302
+ ```ts
1303
+ type ModuleId = URL | string
1304
+ ```
1305
+
1306
+ ### `Numeric`
1307
+
1308
+ A string that can be parsed to a valid number (`type`).
1309
+
1310
+ ```ts
1311
+ type Numeric = `${number}`
1312
+ ```
1313
+
1314
+ ### `PatternKeyComparsionMap`
1315
+
1316
+ Registry of [`PATTERN_KEY_COMPARE`][algorithm-pattern-key-compare] algorithm results (`interface`).
1317
+
1318
+ When developing extensions that use additional results, augment `PatternKeyComparsionMap` to register custom results:
1319
+
1320
+ ```ts
1321
+ declare module '@flex-development/mlly' {
1322
+ interface PatternKeyComparsionMap {
1323
+ afterThree: 3
1324
+ }
1325
+ }
1326
+ ```
1327
+
1328
+ ### `PatternKeyComparsion`
1329
+
1330
+ Union of values that can occur where a [`PATTERN_KEY_COMPARE`][algorithm-pattern-key-compare] algorithm result
1331
+ is expected (`type`).
1332
+
1333
+ To register new results, augment [`PatternKeyComparisonMap`](#patternkeycomparsionmap).
1334
+ They will be added to this union automatically.
1335
+
1336
+ ```ts
1337
+ type PatternKeyComparison =
1338
+ PatternKeyComparisonMap[keyof PatternKeyComparisonMap]
1339
+ ```
1340
+
1341
+ ### `PatternMatch`
1342
+
1343
+ List, where the first item is the key of a package `exports` or `imports` target object,
1344
+ and the last is a subpath pattern match (`type`).
1345
+
1346
+ ```ts
1347
+ type PatternMatch = [expansionKey: string, patternMatch: string | null]
1348
+ ```
1349
+
1350
+ ### `ProtocolMap`
1351
+
1352
+ Registry of URL protocols (`interface`).
1353
+
1354
+ When developing extensions that use additional protocols, augment `ProtocolMap` to register custom protocols:
1355
+
1356
+ ```ts
1357
+ declare module '@flex-development/mlly' {
1358
+ interface ProtocolMap {
1359
+ custom: 'custom:'
1360
+ }
1361
+ }
1362
+ ```
1363
+
1364
+ ### `Protocol`
1365
+
1366
+ Union of values that can occur where a URL protocol is expected (`type`).
1367
+
1368
+ To register new results, augment [`ProtocolMap`](#protocolmap).
1369
+ They will be added to this union automatically.
1370
+
1371
+ ```ts
1372
+ type Protocol = ProtocolMap[keyof ProtocolMap]
1373
+ ```
1374
+
1375
+ ### `ReadFile`
1376
+
1377
+ Read the entire contents of a file (`interface`).
1378
+
1379
+ #### Parameters
1380
+
1381
+ - `id` ([`ModuleId`](#moduleid))
1382
+ — the module id
1383
+
1384
+ #### Returns
1385
+
1386
+ ([`Awaitable<Buffer | string>`](#awaitablet)) The file contents
1387
+
1388
+ ### `Realpath`
1389
+
1390
+ Compute a canonical pathname by resolving `.`, `..`, and symbolic links (`interface`).
1391
+
1392
+ > 👉 **Note**: A canonical pathname is not necessarily unique.
1393
+ > Hard links and bind mounts can expose an entity through many pathnames.
1394
+
1395
+ #### Parameters
1396
+
1397
+ - `id` ([`ModuleId`](#moduleid))
1398
+ — the module id
1399
+
1400
+ #### Returns
1401
+
1402
+ ([`Awaitable<string>`](#awaitablet)) The canonical pathname
1403
+
1404
+ ### `ResolveAliasOptions`
1405
+
1406
+ Options for path alias resolution (`interface`).
1407
+
1408
+ #### Properties
1409
+
1410
+ - `absolute?` (`boolean` | `null` | `undefined`)
1411
+ — whether the resolved specifier should be absolute.\
1412
+ if `true`, the resolved specifier will be a [`file:` URL][file-url]
1413
+ - `aliases?` ([`Aliases`](#aliases) | `null` | `undefined`)
1414
+ — the path mappings dictionary
1415
+ > 👉 **note**: paths should be relative to `cwd`
1416
+ - `cwd?` ([`ModuleId`](#moduleid) | `null` | `undefined`)
1417
+ — the url of the directory to resolve non-absolute modules from
1418
+ - **default**: [`cwd()`](#cwd)
1419
+ - `parent?` ([`ModuleId`](#moduleid) | `null` | `undefined`)
1420
+ — the url of the parent module
1421
+
1422
+ ### `ResolveModuleOptions`
1423
+
1424
+ Options for path alias resolution (`interface`).
1425
+
1426
+ #### Properties
1427
+
1428
+ - `aliases?` ([`Aliases`](#aliases) | `null` | `undefined`)
1429
+ — the path mappings dictionary
1430
+ > 👉 **note**: paths should be relative to `cwd`
1431
+ - `conditions?` ([`List<Condition>`](#condition) | `null` | `undefined`)
1432
+ — the list of export/import conditions
1433
+ - **default**: [`defaultConditions`](#defaultconditions)
1434
+ > 👉 **note**: should be sorted by priority
1435
+ - `cwd?` ([`ModuleId`](#moduleid) | `null` | `undefined`)
1436
+ — the url of the directory to resolve path `aliases` from
1437
+ - **default**: [`cwd()`](#cwd)
1438
+ - `ext?` ([`ChangeExtFn`](#changeextfnext) | `string` | `null` | `undefined`)
1439
+ — a replacement file extension or a function that returns a file extension.
1440
+ > 👉 **note**: an empty string (`''`) or `null` will remove a file extension
1441
+ - `extensions?` ([`List<string>`](#listt) | `null` | `undefined`)
1442
+ — the module extensions to probe for
1443
+ - **default**: [`defaultExtensions`](#defaultextensions)
1444
+ > 👉 **note**: should be sorted by priority
1445
+ - `fs?` ([`FileSystem`](#filesystem) | `null` | `undefined`)
1446
+ — the file system api
1447
+ - `mainFields?` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
1448
+ — the list of legacy `main` fields
1449
+ - **default**: [`defaultMainFields`](#defaultmainfields)
1450
+ > 👉 **note**: should be sorted by priority
1451
+ - `preserveSymlinks?` (`boolean` | `null` | `undefined`)
1452
+ — whether to keep symlinks instead of resolving them
1453
+
1454
+ ### `Stat`
1455
+
1456
+ Get information about a directory or file (`interface`).
1457
+
1458
+ #### Parameters
1459
+
1460
+ - `id` ([`ModuleId`](#moduleid))
1461
+ — the module id
1462
+
1463
+ #### Returns
1464
+
1465
+ ([`Awaitable<Stats>`](#stats)) The info
1466
+
1467
+ ### `Stats`
1468
+
1469
+ An object describing a directory or file (`interface`).
1470
+
1471
+ #### Properties
1472
+
1473
+ - `isDirectory` ([`IsDirectory`](#isdirectory))
1474
+ — check if the stats object describes a directory
1475
+ - `isFile` ([`IsFile`](#isfile))
1476
+ — check if the stats object describes a file
1477
+
1478
+ ## Contribute
1479
+
1480
+ See [`CONTRIBUTING.md`](CONTRIBUTING.md).
1481
+
1482
+ This project has a [code of conduct](./CODE_OF_CONDUCT.md). By interacting with this repository, organization, or
1483
+ community you agree to abide by its terms.
1484
+
1485
+ [algorithm-esm-resolve]: ./docs/resolution-algorithm.md#esm_resolvespecifier-parent-conditions-mainfields-preservesymlinks-extensionformatmap
1486
+
1487
+ [algorithm-legacy-main-resolve]: ./docs/resolution-algorithm.md#legacy_main_resolvepackageurl-manifest-mainfields
1488
+
1489
+ [algorithm-lookup-package-scope]: ./docs/resolution-algorithm.md#lookup_package_scopeurl-end
1490
+
1491
+ [algorithm-package-exports-resolve]: ./docs/resolution-algorithm.md#package_exports_resolvepackageurl-subpath-exports-conditions
1492
+
1493
+ [algorithm-package-imports-exports-resolve]: ./docs/resolution-algorithm.md#package_imports_exports_resolvematchkey-matchobject-packageurl-isimports-conditions-mainfields
1494
+
1495
+ [algorithm-package-imports-resolve]: ./docs/resolution-algorithm.md#package_imports_resolvespecifier-parent-conditions-mainfields
1496
+
1497
+ [algorithm-package-resolve]: ./docs/resolution-algorithm.md#package_resolvespecifier-parent-conditions-mainfields
1498
+
1499
+ [algorithm-package-self-resolve]: ./docs/resolution-algorithm.md#package_self_resolvename-subpath-parent-conditions
1500
+
1501
+ [algorithm-package-target-resolve]: ./docs/resolution-algorithm.md#package_target_resolvepackageurl-target-subpath-patternmatch-isimports-conditions-mainfields
1502
+
1503
+ [algorithm-pattern-key-compare]: ./docs/resolution-algorithm.md#pattern_key_comparea-b
1504
+
1505
+ [algorithm-read-package-json]: ./docs/resolution-algorithm.md#read_package_jsonid
1506
+
1507
+ [builtin-module]: https://nodejs.org/api/esm.html#builtin-modules
1508
+
1509
+ [err-invalid-module-specifier]: https://nodejs.org/api/errors.html#err_invalid_module_specifier
1510
+
1511
+ [err-invalid-package-config]: https://nodejs.org/api/errors.html#err_invalid_package_config
1512
+
1513
+ [err-invalid-package-target]: https://nodejs.org/api/errors.html#err_invalid_package_target
1514
+
1515
+ [err-module-not-found]: https://nodejs.org/api/errors.html#err_module_not_found
1516
+
1517
+ [err-package-import-not-defined]: https://nodejs.org/api/errors.html#err_package_import_not_defined
1518
+
1519
+ [err-unsupported-esm-url-scheme]: https://nodejs.org/api/errors.html#err_unsupported_esm_url_scheme
1520
+
1521
+ [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
1522
+
1523
+ [esmsh]: https://esm.sh
1524
+
1525
+ [exports]: https://nodejs.org/api/packages.html#exports
1526
+
1527
+ [file-url]: https://nodejs.org/api/esm.html#file-urls
1528
+
1529
+ [main]: https://github.com/nodejs/node/blob/v22.9.0/doc/api/packages.md#main
1530
+
1531
+ [node-esm]: https://nodejs.org/api/esm.html
1532
+
1533
+ [pkg-exports]: https://github.com/flex-development/pkg-types/blob/main/src/exports.ts
1534
+
1535
+ [pkg-exports-object]: https://github.com/flex-development/pkg-types/blob/main/src/exports-object.ts
1536
+
1537
+ [pkg-imports-subpath]: https://github.com/flex-development/pkg-types/blob/main/src/imports-subpath.ts
1538
+
1539
+ [pkg-imports]: https://github.com/flex-development/pkg-types/blob/main/src/imports.ts
11
1540
 
12
- > [ECMAScript module][1] utilities.
1541
+ [pkg-package-json]: https://github.com/flex-development/pkg-types/blob/main/src/package-json.ts
13
1542
 
14
- ## Getting Started
1543
+ [subpath-imports]: https://nodejs.org/api/packages.html#subpath-imports
15
1544
 
16
- See the [docs][2] for install and usage instructions.
1545
+ [typescript]: https://www.typescriptlang.org
17
1546
 
18
- [1]: https://nodejs.org/api/esm.html
19
- [2]: https://mlly.vercel.app/
1547
+ [yarn]: https://yarnpkg.com