@flex-development/mlly 1.0.0-alpha.18 → 1.0.0-alpha.19

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 (301) hide show
  1. package/CHANGELOG.md +810 -709
  2. package/README.md +173 -12
  3. package/dist/index.d.mts +3 -4
  4. package/dist/index.mjs +1 -3
  5. package/dist/interfaces/aliases.d.mts +11 -0
  6. package/dist/interfaces/context-get-source.d.mts +52 -0
  7. package/dist/interfaces/file-system.d.mts +57 -0
  8. package/dist/interfaces/index.d.mts +11 -21
  9. package/dist/interfaces/main-field-map.d.mts +13 -0
  10. package/dist/interfaces/module-format-map.d.mts +17 -0
  11. package/dist/interfaces/options-get-source.d.mts +22 -29
  12. package/dist/interfaces/options-resolve-alias.d.mts +14 -26
  13. package/dist/interfaces/options-resolve-module.d.mts +38 -27
  14. package/dist/interfaces/protocol-map.d.mts +35 -0
  15. package/dist/interfaces/stats.d.mts +28 -0
  16. package/dist/internal/chars.mjs +11 -0
  17. package/dist/internal/check-invalid-segments.mjs +19 -0
  18. package/dist/internal/fs.browser.mjs +36 -0
  19. package/dist/internal/fs.d.mts +7 -0
  20. package/dist/internal/invalid-package-target.mjs +18 -0
  21. package/dist/internal/invalid-subpath.mjs +16 -0
  22. package/dist/internal/process.browser.mjs +7 -0
  23. package/dist/internal/process.d.mts +4 -0
  24. package/dist/lib/can-parse-url.d.mts +21 -0
  25. package/dist/lib/can-parse-url.mjs +12 -0
  26. package/dist/lib/cwd.d.mts +12 -0
  27. package/dist/lib/cwd.mjs +8 -0
  28. package/dist/lib/default-conditions.d.mts +15 -0
  29. package/dist/lib/default-conditions.mjs +5 -0
  30. package/dist/lib/default-extensions.d.mts +14 -0
  31. package/dist/lib/default-extensions.mjs +21 -0
  32. package/dist/lib/default-main-fields.d.mts +14 -0
  33. package/dist/lib/default-main-fields.mjs +5 -0
  34. package/dist/lib/extension-format-map.d.mts +16 -0
  35. package/dist/lib/extension-format-map.mjs +21 -0
  36. package/dist/lib/formats.d.mts +21 -0
  37. package/dist/lib/formats.mjs +14 -0
  38. package/dist/lib/get-source.d.mts +26 -0
  39. package/dist/lib/get-source.mjs +70 -0
  40. package/dist/lib/index.d.mts +40 -0
  41. package/dist/lib/index.mjs +53 -0
  42. package/dist/lib/is-absolute-specifier.d.mts +23 -0
  43. package/dist/lib/is-absolute-specifier.mjs +9 -0
  44. package/dist/lib/is-array-index.d.mts +17 -0
  45. package/dist/lib/is-array-index.mjs +11 -0
  46. package/dist/lib/is-bare-specifier.d.mts +23 -0
  47. package/dist/lib/is-bare-specifier.mjs +11 -0
  48. package/dist/lib/is-directory.d.mts +22 -0
  49. package/dist/lib/is-directory.mjs +13 -0
  50. package/dist/lib/is-file.d.mts +22 -0
  51. package/dist/lib/is-file.mjs +13 -0
  52. package/dist/lib/is-imports-subpath.d.mts +19 -0
  53. package/dist/lib/is-imports-subpath.mjs +8 -0
  54. package/dist/lib/is-relative-specifier.d.mts +21 -0
  55. package/dist/lib/is-relative-specifier.mjs +16 -0
  56. package/dist/lib/lookup-package-scope.d.mts +26 -0
  57. package/dist/lib/lookup-package-scope.mjs +16 -0
  58. package/dist/lib/pattern-key-compare.d.mts +31 -0
  59. package/dist/lib/pattern-key-compare.mjs +18 -0
  60. package/dist/lib/pattern-match.d.mts +19 -0
  61. package/dist/lib/pattern-match.mjs +36 -0
  62. package/dist/lib/read-package-json.d.mts +35 -0
  63. package/dist/lib/read-package-json.mjs +29 -0
  64. package/dist/lib/resolve-alias.d.mts +19 -0
  65. package/dist/lib/resolve-alias.mjs +50 -0
  66. package/dist/lib/resolve-module.d.mts +37 -0
  67. package/dist/lib/resolve-module.mjs +75 -0
  68. package/dist/lib/resolver.d.mts +280 -0
  69. package/dist/lib/resolver.mjs +462 -0
  70. package/dist/lib/root.d.mts +11 -0
  71. package/dist/lib/root.mjs +6 -0
  72. package/dist/lib/to-relative-specifier.d.mts +25 -0
  73. package/dist/lib/to-relative-specifier.mjs +26 -0
  74. package/dist/lib/to-url.d.mts +24 -0
  75. package/dist/lib/to-url.mjs +10 -0
  76. package/dist/types/awaitable.d.mts +14 -0
  77. package/dist/types/change-ext-fn.d.mts +29 -0
  78. package/dist/types/get-source-handler.d.mts +21 -0
  79. package/dist/types/get-source-handlers.d.mts +14 -0
  80. package/dist/types/index.d.mts +12 -10
  81. package/dist/types/main-field.d.mts +13 -0
  82. package/dist/types/module-format.d.mts +13 -0
  83. package/dist/types/module-id.d.mts +2 -4
  84. package/dist/types/numeric.d.mts +9 -0
  85. package/dist/types/pattern-key-compare-result.d.mts +9 -0
  86. package/dist/types/pattern-match.d.mts +10 -0
  87. package/dist/types/protocol.d.mts +6 -7
  88. package/package.json +227 -155
  89. package/dist/enums/assert-type.d.mts +0 -21
  90. package/dist/enums/assert-type.mjs +0 -4
  91. package/dist/enums/format.d.mts +0 -17
  92. package/dist/enums/format.mjs +0 -4
  93. package/dist/enums/index.d.mts +0 -10
  94. package/dist/enums/index.mjs +0 -14
  95. package/dist/enums/kind-specifier-syntax.d.mts +0 -14
  96. package/dist/enums/kind-specifier-syntax.mjs +0 -4
  97. package/dist/enums/kind-specifier.d.mts +0 -17
  98. package/dist/enums/kind-specifier.mjs +0 -4
  99. package/dist/enums/kind-statement-syntax.d.mts +0 -22
  100. package/dist/enums/kind-statement-syntax.mjs +0 -4
  101. package/dist/enums/kind-statement.d.mts +0 -15
  102. package/dist/enums/kind-statement.mjs +0 -4
  103. package/dist/index.mjs.map +0 -8
  104. package/dist/interfaces/import-assertions.d.mts +0 -20
  105. package/dist/interfaces/import-dynamic.d.mts +0 -41
  106. package/dist/interfaces/import-static.d.mts +0 -35
  107. package/dist/interfaces/options-fill-module.d.mts +0 -23
  108. package/dist/interfaces/options-find-subpath.d.mts +0 -50
  109. package/dist/interfaces/options-get-format.d.mts +0 -73
  110. package/dist/interfaces/options-parse-module-id.d.mts +0 -34
  111. package/dist/interfaces/options-parse-subpath.d.mts +0 -50
  112. package/dist/interfaces/options-resolve.d.mts +0 -15
  113. package/dist/interfaces/package-scope.d.mts +0 -25
  114. package/dist/interfaces/parsed-data-url.d.mts +0 -56
  115. package/dist/interfaces/parsed-module-id.d.mts +0 -80
  116. package/dist/interfaces/parsed-subpath.d.mts +0 -44
  117. package/dist/interfaces/statement-export.d.mts +0 -44
  118. package/dist/interfaces/statement-import.d.mts +0 -38
  119. package/dist/interfaces/statement-require.d.mts +0 -38
  120. package/dist/interfaces/statement.d.mts +0 -49
  121. package/dist/internal/dequote.d.mts +0 -14
  122. package/dist/internal/dequote.mjs +0 -7
  123. package/dist/internal/dequote.mjs.map +0 -8
  124. package/dist/internal/format-type-map.d.mts +0 -19
  125. package/dist/internal/format-type-map.mjs +0 -13
  126. package/dist/internal/format-type-map.mjs.map +0 -8
  127. package/dist/internal/get-specifier-kind.d.mts +0 -19
  128. package/dist/internal/get-specifier-kind.mjs +0 -11
  129. package/dist/internal/get-specifier-kind.mjs.map +0 -8
  130. package/dist/internal/get-subpaths.d.mts +0 -28
  131. package/dist/internal/get-subpaths.mjs +0 -8
  132. package/dist/internal/get-subpaths.mjs.map +0 -8
  133. package/dist/internal/regex-encoded-sep.d.mts +0 -15
  134. package/dist/internal/regex-encoded-sep.mjs +0 -6
  135. package/dist/internal/regex-encoded-sep.mjs.map +0 -8
  136. package/dist/internal/regex-internal-specifier.d.mts +0 -16
  137. package/dist/internal/regex-internal-specifier.mjs +0 -6
  138. package/dist/internal/regex-internal-specifier.mjs.map +0 -8
  139. package/dist/internal/regex-invalid-segment.d.mts +0 -16
  140. package/dist/internal/regex-invalid-segment.mjs +0 -9
  141. package/dist/internal/regex-invalid-segment.mjs.map +0 -8
  142. package/dist/internal/regex-package-name.d.mts +0 -15
  143. package/dist/internal/regex-package-name.mjs +0 -6
  144. package/dist/internal/regex-package-name.mjs.map +0 -8
  145. package/dist/internal/regex-package-path.d.mts +0 -17
  146. package/dist/internal/regex-package-path.mjs +0 -6
  147. package/dist/internal/regex-package-path.mjs.map +0 -8
  148. package/dist/internal/resolver.d.mts +0 -132
  149. package/dist/internal/resolver.mjs +0 -483
  150. package/dist/internal/resolver.mjs.map +0 -8
  151. package/dist/internal/validate-array-set.d.mts +0 -24
  152. package/dist/internal/validate-array-set.mjs +0 -12
  153. package/dist/internal/validate-array-set.mjs.map +0 -8
  154. package/dist/internal/validate-boolean.d.mts +0 -22
  155. package/dist/internal/validate-boolean.mjs +0 -12
  156. package/dist/internal/validate-boolean.mjs.map +0 -8
  157. package/dist/internal/validate-map.d.mts +0 -26
  158. package/dist/internal/validate-map.mjs +0 -12
  159. package/dist/internal/validate-map.mjs.map +0 -8
  160. package/dist/internal/validate-object.d.mts +0 -23
  161. package/dist/internal/validate-object.mjs +0 -12
  162. package/dist/internal/validate-object.mjs.map +0 -8
  163. package/dist/internal/validate-set.d.mts +0 -24
  164. package/dist/internal/validate-set.mjs +0 -12
  165. package/dist/internal/validate-set.mjs.map +0 -8
  166. package/dist/internal/validate-string.d.mts +0 -23
  167. package/dist/internal/validate-string.mjs +0 -12
  168. package/dist/internal/validate-string.mjs.map +0 -8
  169. package/dist/internal/validate-url-string.d.mts +0 -24
  170. package/dist/internal/validate-url-string.mjs +0 -13
  171. package/dist/internal/validate-url-string.mjs.map +0 -8
  172. package/dist/types/declaration.d.mts +0 -9
  173. package/dist/types/fn-change-ext.d.mts +0 -31
  174. package/dist/types/mime-type.d.mts +0 -13
  175. package/dist/types/module-specifier-type.d.mts +0 -11
  176. package/dist/types/syntax-kind-export.d.mts +0 -12
  177. package/dist/types/syntax-kind-import.d.mts +0 -12
  178. package/dist/types/syntax-kind-require.d.mts +0 -12
  179. package/dist/utils/compare-subpaths.d.mts +0 -25
  180. package/dist/utils/compare-subpaths.mjs +0 -19
  181. package/dist/utils/compare-subpaths.mjs.map +0 -8
  182. package/dist/utils/conditions.d.mts +0 -13
  183. package/dist/utils/conditions.mjs +0 -6
  184. package/dist/utils/conditions.mjs.map +0 -8
  185. package/dist/utils/detect-syntax.d.mts +0 -21
  186. package/dist/utils/detect-syntax.mjs +0 -11
  187. package/dist/utils/detect-syntax.mjs.map +0 -8
  188. package/dist/utils/extension-format-map.d.mts +0 -16
  189. package/dist/utils/extension-format-map.mjs +0 -22
  190. package/dist/utils/extension-format-map.mjs.map +0 -8
  191. package/dist/utils/extract-statements.d.mts +0 -21
  192. package/dist/utils/extract-statements.mjs +0 -20
  193. package/dist/utils/extract-statements.mjs.map +0 -8
  194. package/dist/utils/fill-modules.d.mts +0 -24
  195. package/dist/utils/fill-modules.mjs +0 -67
  196. package/dist/utils/fill-modules.mjs.map +0 -8
  197. package/dist/utils/find-dynamic-imports.d.mts +0 -18
  198. package/dist/utils/find-dynamic-imports.mjs +0 -36
  199. package/dist/utils/find-dynamic-imports.mjs.map +0 -8
  200. package/dist/utils/find-exports.d.mts +0 -21
  201. package/dist/utils/find-exports.mjs +0 -92
  202. package/dist/utils/find-exports.mjs.map +0 -8
  203. package/dist/utils/find-requires.d.mts +0 -18
  204. package/dist/utils/find-requires.mjs +0 -32
  205. package/dist/utils/find-requires.mjs.map +0 -8
  206. package/dist/utils/find-static-imports.d.mts +0 -18
  207. package/dist/utils/find-static-imports.mjs +0 -30
  208. package/dist/utils/find-static-imports.mjs.map +0 -8
  209. package/dist/utils/find-subpath.d.mts +0 -31
  210. package/dist/utils/find-subpath.mjs +0 -86
  211. package/dist/utils/find-subpath.mjs.map +0 -8
  212. package/dist/utils/get-format.d.mts +0 -31
  213. package/dist/utils/get-format.mjs +0 -107
  214. package/dist/utils/get-format.mjs.map +0 -8
  215. package/dist/utils/get-source.d.mts +0 -30
  216. package/dist/utils/get-source.mjs +0 -61
  217. package/dist/utils/get-source.mjs.map +0 -8
  218. package/dist/utils/has-cjs-syntax.d.mts +0 -25
  219. package/dist/utils/has-cjs-syntax.mjs +0 -11
  220. package/dist/utils/has-cjs-syntax.mjs.map +0 -8
  221. package/dist/utils/has-esm-syntax.d.mts +0 -21
  222. package/dist/utils/has-esm-syntax.mjs +0 -11
  223. package/dist/utils/has-esm-syntax.mjs.map +0 -8
  224. package/dist/utils/index.d.mts +0 -44
  225. package/dist/utils/index.mjs +0 -83
  226. package/dist/utils/index.mjs.map +0 -8
  227. package/dist/utils/is-absolute-specifier.d.mts +0 -20
  228. package/dist/utils/is-absolute-specifier.mjs +0 -26
  229. package/dist/utils/is-absolute-specifier.mjs.map +0 -8
  230. package/dist/utils/is-bare-specifier.d.mts +0 -20
  231. package/dist/utils/is-bare-specifier.mjs +0 -10
  232. package/dist/utils/is-bare-specifier.mjs.map +0 -8
  233. package/dist/utils/is-directory.d.mts +0 -13
  234. package/dist/utils/is-directory.mjs +0 -14
  235. package/dist/utils/is-directory.mjs.map +0 -8
  236. package/dist/utils/is-exports-sugar.d.mts +0 -26
  237. package/dist/utils/is-exports-sugar.mjs +0 -29
  238. package/dist/utils/is-exports-sugar.mjs.map +0 -8
  239. package/dist/utils/is-file.d.mts +0 -13
  240. package/dist/utils/is-file.mjs +0 -14
  241. package/dist/utils/is-file.mjs.map +0 -8
  242. package/dist/utils/is-relative-specifier.d.mts +0 -19
  243. package/dist/utils/is-relative-specifier.mjs +0 -9
  244. package/dist/utils/is-relative-specifier.mjs.map +0 -8
  245. package/dist/utils/lookup-package-scope.d.mts +0 -26
  246. package/dist/utils/lookup-package-scope.mjs +0 -34
  247. package/dist/utils/lookup-package-scope.mjs.map +0 -8
  248. package/dist/utils/parse-data-url.d.mts +0 -25
  249. package/dist/utils/parse-data-url.mjs +0 -25
  250. package/dist/utils/parse-data-url.mjs.map +0 -8
  251. package/dist/utils/parse-module-id.d.mts +0 -20
  252. package/dist/utils/parse-module-id.mjs +0 -123
  253. package/dist/utils/parse-module-id.mjs.map +0 -8
  254. package/dist/utils/parse-subpath.d.mts +0 -35
  255. package/dist/utils/parse-subpath.mjs +0 -149
  256. package/dist/utils/parse-subpath.mjs.map +0 -8
  257. package/dist/utils/pattern-character.d.mts +0 -11
  258. package/dist/utils/pattern-character.mjs +0 -6
  259. package/dist/utils/pattern-character.mjs.map +0 -8
  260. package/dist/utils/read-package-json.d.mts +0 -26
  261. package/dist/utils/read-package-json.mjs +0 -48
  262. package/dist/utils/read-package-json.mjs.map +0 -8
  263. package/dist/utils/resolve-alias.d.mts +0 -20
  264. package/dist/utils/resolve-alias.mjs +0 -101
  265. package/dist/utils/resolve-alias.mjs.map +0 -8
  266. package/dist/utils/resolve-aliases.d.mts +0 -19
  267. package/dist/utils/resolve-aliases.mjs +0 -26
  268. package/dist/utils/resolve-aliases.mjs.map +0 -8
  269. package/dist/utils/resolve-extensions.d.mts +0 -14
  270. package/dist/utils/resolve-extensions.mjs +0 -22
  271. package/dist/utils/resolve-extensions.mjs.map +0 -8
  272. package/dist/utils/resolve-module.d.mts +0 -39
  273. package/dist/utils/resolve-module.mjs +0 -63
  274. package/dist/utils/resolve-module.mjs.map +0 -8
  275. package/dist/utils/resolve-modules.d.mts +0 -25
  276. package/dist/utils/resolve-modules.mjs +0 -23
  277. package/dist/utils/resolve-modules.mjs.map +0 -8
  278. package/dist/utils/to-absolute-specifier.d.mts +0 -22
  279. package/dist/utils/to-absolute-specifier.mjs +0 -8
  280. package/dist/utils/to-absolute-specifier.mjs.map +0 -8
  281. package/dist/utils/to-bare-specifier.d.mts +0 -42
  282. package/dist/utils/to-bare-specifier.mjs +0 -79
  283. package/dist/utils/to-bare-specifier.mjs.map +0 -8
  284. package/dist/utils/to-data-url.d.mts +0 -30
  285. package/dist/utils/to-data-url.mjs +0 -7
  286. package/dist/utils/to-data-url.mjs.map +0 -8
  287. package/dist/utils/to-node-url.d.mts +0 -19
  288. package/dist/utils/to-node-url.mjs +0 -7
  289. package/dist/utils/to-node-url.mjs.map +0 -8
  290. package/dist/utils/to-relative-specifier.d.mts +0 -24
  291. package/dist/utils/to-relative-specifier.mjs +0 -10
  292. package/dist/utils/to-relative-specifier.mjs.map +0 -8
  293. package/dist/utils/to-url.d.mts +0 -21
  294. package/dist/utils/to-url.mjs +0 -8
  295. package/dist/utils/to-url.mjs.map +0 -8
  296. package/dist/utils/validate-assertions.d.mts +0 -23
  297. package/dist/utils/validate-assertions.mjs +0 -47
  298. package/dist/utils/validate-assertions.mjs.map +0 -8
  299. package/dist/utils/validate-exports.d.mts +0 -25
  300. package/dist/utils/validate-exports.mjs +0 -73
  301. package/dist/utils/validate-exports.mjs.map +0 -8
package/README.md CHANGED
@@ -1,20 +1,181 @@
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
+ [![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)
4
4
  [![npm](https://img.shields.io/npm/v/@flex-development/mlly.svg)](https://npmjs.com/package/@flex-development/mlly)
5
- [![codecov](https://codecov.io/gh/flex-development/mlly/branch/main/graph/badge.svg?token=36NUNRH6FW)](https://codecov.io/gh/flex-development/mlly)
5
+ [![codecov](https://codecov.io/gh/flex-development/mlly/graph/badge.svg?token=36NUNRH6FW)](https://codecov.io/gh/flex-development/mlly)
6
6
  [![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
7
7
  [![license](https://img.shields.io/github/license/flex-development/mlly.svg)](LICENSE.md)
8
- [![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits&logoColor=ffffff)](https://conventionalcommits.org/)
9
- [![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript&logoColor=ffffff)](https://typescriptlang.org/)
10
- [![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat&logo=vitest&logoColor=ffffff)](https://vitest.dev/)
11
- [![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat&logo=yarn&logoColor=ffffff)](https://yarnpkg.com/)
8
+ [![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits\&logoColor=ffffff)](https://conventionalcommits.org)
9
+ [![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\&logoColor=ffffff)](https://typescriptlang.org)
10
+ [![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\&logo=vitest\&logoColor=ffffff)](https://vitest.dev)
11
+ [![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\&logo=yarn\&logoColor=ffffff)](https://yarnpkg.com)
12
12
 
13
- > [ECMAScript module][1] utilities.
13
+ [ECMAScript module][node-esm] utilities.
14
14
 
15
- ## Getting Started
15
+ ## Contents
16
16
 
17
- See the [docs][2] for install and usage instructions.
17
+ - [What is this?](#what-is-this)
18
+ - [Install](#install)
19
+ - [Use](#use)
20
+ - [API](#api)
21
+ - [Types](#types)
22
+ - [Contribute](#contribute)
18
23
 
19
- [1]: https://nodejs.org/api/esm.html
20
- [2]: https://mlly.vercel.app/
24
+ ## What is this?
25
+
26
+ `mlly` is a set of [ECMAScript module][node-esm] (ESM) utilities. It exposes several tools to bridge the gap between
27
+ developer experience and the current state of ECMAScript modules.
28
+
29
+ ## Install
30
+
31
+ This package is [ESM only][esm].
32
+
33
+ In Node.js (version 18+) with [yarn][]:
34
+
35
+ ```sh
36
+ yarn add @flex-development/mlly
37
+ ```
38
+
39
+ <blockquote>
40
+ <small>
41
+ See <a href='https://yarnpkg.com/protocol/git'>Git - Protocols | Yarn</a>
42
+ &nbsp;for details regarding installing from Git.
43
+ </small>
44
+ </blockquote>
45
+
46
+ In Deno with [`esm.sh`][esmsh]:
47
+
48
+ ```ts
49
+ import { resolveModule } from 'https://esm.sh/@flex-development/mlly'
50
+ ```
51
+
52
+ In browsers with [`esm.sh`][esmsh]:
53
+
54
+ ```html
55
+ <script type="module">
56
+ import { resolveModule } from 'https://esm.sh/@flex-development/mlly'
57
+ </script>
58
+ ```
59
+
60
+ ## Use
61
+
62
+ ```js
63
+ import {
64
+ canParseUrl,
65
+ cwd,
66
+ defaultConditions,
67
+ defaultExtensions,
68
+ defaultMainFields,
69
+ extensionFormatMap,
70
+ formats,
71
+ getSource,
72
+ isAbsoluteSpecifier,
73
+ isArrayIndex,
74
+ isBareSpecifier,
75
+ isDirectory,
76
+ isFile,
77
+ isImportsSubpath,
78
+ isRelativeSpecifier,
79
+ legacyMainResolve,
80
+ lookupPackageScope,
81
+ moduleResolve,
82
+ packageExportsResolve,
83
+ packageImportsExportsResolve,
84
+ packageImportsResolve,
85
+ packageResolve,
86
+ packageSelfResolve,
87
+ packageTargetResolve,
88
+ patternKeyCompare,
89
+ patternMatch,
90
+ readPackageJson,
91
+ resolveAlias,
92
+ resolveModule,
93
+ resolver,
94
+ root,
95
+ toRelativeSpecifier,
96
+ toUrl
97
+ } from '@flex-development/mlly'
98
+ ```
99
+
100
+ ## API
101
+
102
+ This package exports the following identifiers:
103
+
104
+ - [`canParseUrl`](./src/lib/can-parse-url.mts)
105
+ - [`cwd`](./src/lib/cwd.mts)
106
+ - [`defaultConditions`](./src/lib/default-conditions.mts)
107
+ - [`defaultExtensions`](./src/lib/default-extensions.mts)
108
+ - [`defaultMainFields`](./src/lib/default-main-fields.mts)
109
+ - [`extensionFormatMap`](./src/lib/extension-format-map.mts)
110
+ - [`formats`](./src/lib/formats.mts)
111
+ - [`getSource`](./src/lib/get-source.mts)
112
+ - [`isAbsoluteSpecifier`](./src/lib/is-absolute-specifier.mts)
113
+ - [`isArrayIndex`](./src/lib/is-array-index.mts)
114
+ - [`isBareSpecifier`](./src/lib/is-bare-specifier.mts)
115
+ - [`isDirectory`](./src/lib/is-directory.mts)
116
+ - [`isFile`](./src/lib/is-file.mts)
117
+ - [`isImportsSubpath`](./src/lib/is-imports-subpath.mts)
118
+ - [`isRelativeSpecifier`](./src/lib/is-relative-specifier.mts)
119
+ - [`lookupPackageScope`](./src/lib/lookup-package-scope.mts)
120
+ - [`patternKeyCompare`](./src/lib/pattern-key-compare.mts)
121
+ - [`patternMatch`](./src/lib/pattern-match.mts)
122
+ - [`readPackageJson`](./src/lib/read-package-json.mts)
123
+ - [`resolveAlias`](./src/lib/resolve-alias.mts)
124
+ - [`resolveModule`](./src/lib/resolve-module.mts)
125
+ - [`resolver`](./src/lib/resolver.mts)
126
+ - `legacyMainResolve`
127
+ - `moduleResolve`
128
+ - `packageExportsResolve`
129
+ - `packageImportsExportsResolve`
130
+ - `packageImportsResolve`
131
+ - `packageResolve`
132
+ - `packageSelfResolve`
133
+ - `packageTargetResolve`
134
+ - [`root`](./src/lib/root.mts)
135
+ - [`toRelativeSpecifier`](./src/lib/to-relative-specifier.mts)
136
+ - [`toUrl`](./src/lib/to-url.mts)
137
+
138
+ There is no default export.
139
+
140
+ ## Types
141
+
142
+ This package is fully typed with [TypeScript][].
143
+
144
+ ### Interfaces
145
+
146
+ - [`Aliases`](src/interfaces/aliases.mts)
147
+ - [`FileSystem`](src/interfaces/file-system.mts)
148
+ - [`MainFieldMap`](src/interfaces/main-field-map.mts)
149
+ - [`ModuleFormatMap`](src/interfaces/module-format-map.mts)
150
+ - [`ResolveAliasOptions`](src/interfaces/options-resolve-alias.mts)
151
+ - [`ResolveModuleOptions`](src/interfaces/options-resolve-module.mts)
152
+ - [`ProtocolMap`](src/interfaces/protocol-map.mts)
153
+ - [`Stats`](src/interfaces/stats.mts)
154
+
155
+ ### Type Aliases
156
+
157
+ - [`ChangeExtFn`](src/types/change-ext-fn.mts)
158
+ - [`MainField`](src/types/main-field.mts)
159
+ - [`ModuleFormat`](src/types/module-format.mts)
160
+ - [`ModuleId`](src/types/module-id.mts)
161
+ - [`Numeric`](src/types/numeric.mts)
162
+ - [`PatternKeyCompareResult`](src/types/pattern-key-compare-result.mts)
163
+ - [`PatternMatch`](src/types/pattern-match.mts)
164
+ - [`Protocol`](src/types/protocol.mts)
165
+
166
+ ## Contribute
167
+
168
+ See [`CONTRIBUTING.md`](CONTRIBUTING.md).
169
+
170
+ This project has a [code of conduct](./CODE_OF_CONDUCT.md). By interacting with this repository, organization, or
171
+ community you agree to abide by its terms.
172
+
173
+ [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
174
+
175
+ [esmsh]: https://esm.sh
176
+
177
+ [node-esm]: https://nodejs.org/api/esm.html
178
+
179
+ [typescript]: https://www.typescriptlang.org
180
+
181
+ [yarn]: https://yarnpkg.com
package/dist/index.d.mts CHANGED
@@ -2,7 +2,6 @@
2
2
  * @file Package Entry Point
3
3
  * @module mlly
4
4
  */
5
- export * from './enums/index.mjs';
6
- export type * from './interfaces/index.mjs';
7
- export type * from './types/index.mjs';
8
- export * from './utils/index.mjs';
5
+ export type * from '#interfaces/index';
6
+ export * from '#lib/index';
7
+ export type * from '#types/index';
package/dist/index.mjs CHANGED
@@ -1,3 +1 @@
1
- export * from "./enums/index.mjs";
2
- export * from "./utils/index.mjs";
3
- //# sourceMappingURL=index.mjs.map
1
+ export * from "#lib/index";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file Interfaces - Aliases
3
+ * @module mlly/interfaces/Aliases
4
+ */
5
+ /**
6
+ * Path aliases.
7
+ */
8
+ interface Aliases {
9
+ [alias: string]: (string | null | undefined)[] | string | null | undefined;
10
+ }
11
+ export type { Aliases as default };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @file Interfaces - GetSourceContext
3
+ * @module mlly/interfaces/GetSourceContext
4
+ */
5
+ import type { FileSystem, GetSourceHandlers, GetSourceOptions } from '@flex-development/mlly';
6
+ /**
7
+ * Source code retrieval context.
8
+ *
9
+ * @see {@linkcode GetSourceOptions}
10
+ *
11
+ * @extends {GetSourceOptions}
12
+ */
13
+ interface GetSourceContext extends GetSourceOptions {
14
+ /**
15
+ * Throw [`ERR_UNSUPPORTED_ESM_URL_SCHEME`][err]?
16
+ *
17
+ * [err]: https://nodejs.org/api/errors.html#err_unsupported_esm_url_scheme
18
+ */
19
+ error: boolean;
20
+ /**
21
+ * File system API.
22
+ *
23
+ * @see {@linkcode FileSystem}
24
+ *
25
+ * @override
26
+ */
27
+ fs: FileSystem;
28
+ /**
29
+ * URL handler map.
30
+ *
31
+ * @see {@linkcode GetSourceHandlers}
32
+ *
33
+ * @override
34
+ */
35
+ handlers: GetSourceHandlers;
36
+ /**
37
+ * Request options for network based modules.
38
+ *
39
+ * > 👉 **Note**: Only applicable if {@linkcode network} is
40
+ * > enabled.
41
+ *
42
+ * @override
43
+ */
44
+ req: RequestInit;
45
+ /**
46
+ * List of supported URL schemes.
47
+ *
48
+ * @override
49
+ */
50
+ schemes: Set<string>;
51
+ }
52
+ export type { GetSourceContext as default };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @file Interfaces - FileSystem
3
+ * @module mlly/interfaces/FileSystem
4
+ */
5
+ import type { Awaitable, ModuleId, Stats } from '@flex-development/mlly';
6
+ /**
7
+ * File system API.
8
+ */
9
+ interface FileSystem {
10
+ /**
11
+ * Get the contents of `id`.
12
+ *
13
+ * @see {@linkcode Awaitable}
14
+ * @see {@linkcode Buffer}
15
+ * @see {@linkcode ModuleId}
16
+ * @see https://nodejs.org/api/fs.html#fsreadfilepath-options-callback
17
+ *
18
+ * @this {void}
19
+ *
20
+ * @param {ModuleId} id
21
+ * The path or `file:` URL to handle
22
+ * @return {Awaitable<Buffer | string>}
23
+ * File contents
24
+ */
25
+ readFile(this: void, id: ModuleId): Awaitable<Buffer | string>;
26
+ /**
27
+ * Get the resolved pathname for `id`.
28
+ *
29
+ * @see {@linkcode Awaitable}
30
+ * @see {@linkcode ModuleId}
31
+ * @see https://nodejs.org/api/fs.html#fsrealpathpath-options-callback
32
+ *
33
+ * @this {void}
34
+ *
35
+ * @param {ModuleId} id
36
+ * The path or `file:` URL to handle
37
+ * @return {Awaitable<string>}
38
+ * Resolved pathname
39
+ */
40
+ realpath(this: void, id: ModuleId): Awaitable<string>;
41
+ /**
42
+ * Get information about a directory or file.
43
+ *
44
+ * @see {@linkcode Awaitable}
45
+ * @see {@linkcode ModuleId}
46
+ * @see {@linkcode Stats}
47
+ *
48
+ * @this {void}
49
+ *
50
+ * @param {ModuleId} id
51
+ * The path or `file:` URL to handle
52
+ * @return {Awaitable<Stats>}
53
+ * Info about `id`
54
+ */
55
+ stat(this: void, id: ModuleId): Awaitable<Stats>;
56
+ }
57
+ export type { FileSystem as default };
@@ -1,24 +1,14 @@
1
1
  /**
2
- * @file Interfaces
2
+ * @file Entry Point - Interfaces
3
3
  * @module mlly/interfaces
4
4
  */
5
- export type { default as ImportAssertions } from './import-assertions.mjs';
6
- export type { default as DynamicImport } from './import-dynamic.mjs';
7
- export type { default as StaticImport } from './import-static.mjs';
8
- export type { default as FillModuleOptions } from './options-fill-module.mjs';
9
- export type { default as FindSubpathOptions } from './options-find-subpath.mjs';
10
- export type { default as GetFormatOptions } from './options-get-format.mjs';
11
- export type { default as GetSourceOptions } from './options-get-source.mjs';
12
- export type { default as ParseModuleIdOptions } from './options-parse-module-id.mjs';
13
- export type { default as ParseSubpathOptions } from './options-parse-subpath.mjs';
14
- export type { default as ResolveOptions } from './options-resolve.mjs';
15
- export type { default as ResolveAliasOptions } from './options-resolve-alias.mjs';
16
- export type { default as ResolveModuleOptions } from './options-resolve-module.mjs';
17
- export type { default as PackageScope } from './package-scope.mjs';
18
- export type { default as ParsedDataUrl } from './parsed-data-url.mjs';
19
- export type { default as ParsedModuleId } from './parsed-module-id.mjs';
20
- export type { default as ParsedSubpath } from './parsed-subpath.mjs';
21
- export type { default as Statement } from './statement.mjs';
22
- export type { default as ExportStatement } from './statement-export.mjs';
23
- export type { default as ImportStatement } from './statement-import.mjs';
24
- export type { default as RequireStatement } from './statement-require.mjs';
5
+ export type { default as Aliases } from '#interfaces/aliases';
6
+ export type { default as GetSourceContext } from '#interfaces/context-get-source';
7
+ export type { default as FileSystem } from '#interfaces/file-system';
8
+ export type { default as MainFieldMap } from '#interfaces/main-field-map';
9
+ export type { default as ModuleFormatMap } from '#interfaces/module-format-map';
10
+ export type { default as GetSourceOptions } from '#interfaces/options-get-source';
11
+ export type { default as ResolveAliasOptions } from '#interfaces/options-resolve-alias';
12
+ export type { default as ResolveModuleOptions } from '#interfaces/options-resolve-module';
13
+ export type { default as ProtocolMap } from '#interfaces/protocol-map';
14
+ export type { default as Stats } from '#interfaces/stats';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file Interfaces - MainFieldMap
3
+ * @module mlly/interfaces/MainFieldMap
4
+ */
5
+ /**
6
+ * Main fields registry.
7
+ */
8
+ interface MainFieldMap {
9
+ main: 'main';
10
+ module: 'module';
11
+ types: 'types';
12
+ }
13
+ export type { MainFieldMap as default };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @file Interfaces - ModuleFormatMap
3
+ * @module mlly/interfaces/ModuleFormatMap
4
+ */
5
+ /**
6
+ * Module format registry.
7
+ */
8
+ interface ModuleFormatMap {
9
+ builtin: 'builtin';
10
+ commonjs: 'commonjs';
11
+ cts: 'commonjs-typescript';
12
+ json: 'json';
13
+ module: 'module';
14
+ mts: 'module-typescript';
15
+ wasm: 'wasm';
16
+ }
17
+ export type { ModuleFormatMap as default };
@@ -2,53 +2,46 @@
2
2
  * @file Interfaces - GetSourceOptions
3
3
  * @module mlly/interfaces/GetSourceOptions
4
4
  */
5
- import type { Format } from '../enums/index.mjs';
6
- import type { Optional, OrLowercase } from '@flex-development/tutils';
5
+ import type { FileSystem, GetSourceHandlers, ModuleFormat } from '@flex-development/mlly';
7
6
  /**
8
7
  * Source code retrieval options.
9
- *
10
- * @see {@linkcode Format}
11
- * @see {@linkcode RequestInit}
12
8
  */
13
9
  interface GetSourceOptions {
14
10
  /**
15
- * Enable support for network based modules.
16
- *
17
- * **Note**: Requires [`node-fetch`][1].
18
- *
19
- * [1]: https://github.com/node-fetch/node-fetch
20
- *
21
- * @see https://nodejs.org/docs/latest-v16.x/api/esm.html#https-and-http-imports
11
+ * Module format hint.
22
12
  *
23
- * @default false
13
+ * @see {@linkcode ModuleFormat}
24
14
  */
25
- experimental_network_imports?: Optional<boolean>;
15
+ format?: ModuleFormat | null | undefined;
26
16
  /**
27
- * Module format hint.
28
- *
29
- * @see {@linkcode Format}
17
+ * File system API.
30
18
  *
31
- * @default undefined
19
+ * @see {@linkcode FileSystem}
32
20
  */
33
- format?: Optional<OrLowercase<Format>>;
21
+ fs?: FileSystem | null | undefined;
34
22
  /**
35
- * Ignore [`ERR_UNSUPPORTED_ESM_URL_SCHEME`][1] if thrown.
23
+ * URL handler map.
36
24
  *
37
- * [1]: https://nodejs.org/api/errors.html#err_unsupported_esm_url_scheme
25
+ * @see {@linkcode GetSourceHandlers}
26
+ */
27
+ handlers?: GetSourceHandlers | null | undefined;
28
+ /**
29
+ * Ignore [`ERR_UNSUPPORTED_ESM_URL_SCHEME`][err] if thrown.
38
30
  *
39
- * @default false
31
+ * [err]: https://nodejs.org/api/errors.html#err_unsupported_esm_url_scheme
40
32
  */
41
- ignore_errors?: Optional<boolean>;
33
+ ignoreErrors?: boolean | null | undefined;
42
34
  /**
43
35
  * Request options for network based modules.
44
36
  *
45
- * Only applicable if {@linkcode experimental_network_imports} is enabled.
46
- *
47
- * @see {@linkcode RequestInit}
37
+ * > 👉 **Note**: Only applicable if {@linkcode network} is enabled.
38
+ */
39
+ req?: RequestInit | null | undefined;
40
+ /**
41
+ * List of supported URL schemes.
48
42
  *
49
- * @default {}
43
+ * @default ['data','file','http','https','node']
50
44
  */
51
- // @ts-ignore peer dependency
52
- req?: Optional<import('node-fetch').RequestInit>;
45
+ schemes?: Set<string> | readonly string[] | null | undefined;
53
46
  }
54
47
  export type { GetSourceOptions as default };
@@ -2,52 +2,40 @@
2
2
  * @file Interfaces - ResolveAliasOptions
3
3
  * @module mlly/interfaces/ResolveAliasOptions
4
4
  */
5
- import type { ModuleId } from '../types/index.mjs';
6
- import type { MapLike, OneOrMany, Optional } from '@flex-development/tutils';
7
- import type ResolveModuleOptions from './options-resolve-module.mjs';
5
+ import type { Aliases, ModuleId } from '@flex-development/mlly';
8
6
  /**
9
7
  * Path alias resolution options.
10
- *
11
- * @see {@linkcode ModuleId}
12
- *
13
- * @extends {ResolveModuleOptions}
14
8
  */
15
- interface ResolveAliasOptions extends ResolveModuleOptions {
9
+ interface ResolveAliasOptions {
16
10
  /**
17
11
  * Return resolved module URL as absolute specifier (a [`file:` URL][1]).
18
12
  *
19
- * If `false`, return resolved module URL as bare or relative specifier.
20
- *
21
13
  * [1]: https://nodejs.org/api/esm.html#file-urls
22
14
  *
23
15
  * @see https://nodejs.org/api/esm.html#terminology
24
- *
25
- * @default true
26
16
  */
27
- absolute?: Optional<boolean>;
17
+ absolute?: boolean | null | undefined;
28
18
  /**
29
19
  * Path mappings.
30
20
  *
31
- * **Note**: Paths should be relative to {@linkcode cwd}.
21
+ * > 👉 **Note**: Paths should be relative to {@linkcode cwd}.
32
22
  *
33
- * @default {}
23
+ * @see {@linkcode Aliases}
34
24
  */
35
- aliases?: Optional<MapLike<OneOrMany<string>>>;
25
+ aliases?: Aliases | null | undefined;
36
26
  /**
37
- * Directory to resolve non-absolute modules from.
27
+ * URL of directory to resolve non-absolute modules from.
28
+ *
29
+ * @see {@linkcode ModuleId}
38
30
  *
39
- * @default pathToFileURL('.')
31
+ * @default cwd()
40
32
  */
41
- cwd?: Optional<ModuleId>;
33
+ cwd?: ModuleId | null | undefined;
42
34
  /**
43
- * Id of module to resolve from.
44
- *
45
- * **Note**: Should be an absolute path or [`file:` URL][1].
46
- *
47
- * [1]: https://nodejs.org/api/esm.html#file-urls
35
+ * URL of parent module.
48
36
  *
49
- * @default import.meta.url
37
+ * @see {@linkcode ModuleId}
50
38
  */
51
- parent?: Optional<ModuleId>;
39
+ parent?: ModuleId | null | undefined;
52
40
  }
53
41
  export type { ResolveAliasOptions as default };
@@ -2,63 +2,74 @@
2
2
  * @file Interfaces - ResolveModuleOptions
3
3
  * @module mlly/interfaces/ResolveModuleOptions
4
4
  */
5
- import type { ChangeExtFn, ModuleId } from '../types/index.mjs';
6
- import type { Nilable, Optional } from '@flex-development/tutils';
5
+ import type { Aliases, ChangeExtFn, FileSystem, MainField, ModuleId } from '@flex-development/mlly';
6
+ import type { Condition } from '@flex-development/pkg-types';
7
7
  /**
8
8
  * Module resolution options.
9
- *
10
- * @see {@linkcode ChangeExtFn}
11
- * @see {@linkcode ModuleId}
12
9
  */
13
10
  interface ResolveModuleOptions {
14
11
  /**
15
- * Export condition to apply.
12
+ * Path mappings.
16
13
  *
17
- * @see https://nodejs.org/api/packages.html#conditional-exports
14
+ * > 👉 **Note**: Paths should be relative to {@linkcode cwd}.
18
15
  *
19
- * @default 'default'
16
+ * @see {@linkcode Aliases}
20
17
  */
21
- condition?: Optional<string>;
18
+ aliases?: Aliases | null | undefined;
22
19
  /**
23
- * Export conditions.
20
+ * List of export/import conditions.
24
21
  *
25
- * **Note**: Should be sorted by priority.
22
+ * > 👉 **Note**: Should be sorted by priority.
26
23
  *
24
+ * @see {@linkcode Condition}
27
25
  * @see https://nodejs.org/api/packages.html#conditional-exports
28
26
  *
29
- * @default CONDITIONS
27
+ * @default defaultConditions
28
+ */
29
+ conditions?: Condition[] | Set<Condition> | null | undefined;
30
+ /**
31
+ * URL of directory to resolve path aliases from.
32
+ *
33
+ * @see {@linkcode ModuleId}
34
+ *
35
+ * @default cwd()
30
36
  */
31
- conditions?: Optional<Set<string> | string[]>;
37
+ cwd?: ModuleId | null | undefined;
32
38
  /**
33
39
  * Replacement file extension or function that returns a file extension.
34
40
  *
35
- * An empty string (`''`) will remove a file extension; `null` or `undefined`
36
- * will skip extension replacement.
41
+ * An empty string (`''`) or `null` will remove a file extension.
37
42
  *
38
- * @default undefined
43
+ * @see {@linkcode ChangeExtFn}
39
44
  */
40
- ext?: ChangeExtFn | Nilable<string>;
45
+ ext?: ChangeExtFn | string | null | undefined;
41
46
  /**
42
47
  * Module extensions to probe for.
43
48
  *
44
- * **Note**: Should be sorted by priority.
49
+ * > 👉 **Note**: Should be sorted by priority.
45
50
  *
46
- * @default RESOLVE_EXTENSIONS
51
+ * @default defaultExtensions
47
52
  */
48
- extensions?: Optional<Set<string> | string[]>;
53
+ extensions?: Set<string> | string[] | null | undefined;
49
54
  /**
50
- * URL of module to resolve from.
55
+ * File system API.
51
56
  *
52
- * @see {@linkcode ModuleId}
57
+ * @see {@linkcode FileSystem}
58
+ */
59
+ fs?: FileSystem | null | undefined;
60
+ /**
61
+ * List of legacy `main` fields.
53
62
  *
54
- * @default import.meta.url
63
+ * > 👉 **Note**: Should be sorted by priority.
64
+ *
65
+ * @see {@linkcode MainField}
66
+ *
67
+ * @default defaultMainFields
55
68
  */
56
- parent?: Optional<ModuleId>;
69
+ mainFields?: MainField[] | Set<MainField> | null | undefined;
57
70
  /**
58
71
  * Keep symlinks instead of resolving them.
59
- *
60
- * @default false
61
72
  */
62
- preserveSymlinks?: Optional<boolean>;
73
+ preserveSymlinks?: boolean | null | undefined;
63
74
  }
64
75
  export type { ResolveModuleOptions as default };