@flex-development/mlly 1.0.0-alpha.17 → 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 (303) hide show
  1. package/CHANGELOG.md +829 -681
  2. package/README.md +173 -12
  3. package/dist/index.d.mts +3 -4
  4. package/dist/index.mjs +1 -5
  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/index.mjs +0 -0
  108. package/dist/interfaces/options-fill-module.d.mts +0 -23
  109. package/dist/interfaces/options-find-subpath.d.mts +0 -50
  110. package/dist/interfaces/options-get-format.d.mts +0 -73
  111. package/dist/interfaces/options-parse-module-id.d.mts +0 -34
  112. package/dist/interfaces/options-parse-subpath.d.mts +0 -50
  113. package/dist/interfaces/options-resolve.d.mts +0 -15
  114. package/dist/interfaces/package-scope.d.mts +0 -25
  115. package/dist/interfaces/parsed-data-url.d.mts +0 -56
  116. package/dist/interfaces/parsed-module-id.d.mts +0 -80
  117. package/dist/interfaces/parsed-subpath.d.mts +0 -44
  118. package/dist/interfaces/statement-export.d.mts +0 -44
  119. package/dist/interfaces/statement-import.d.mts +0 -38
  120. package/dist/interfaces/statement-require.d.mts +0 -38
  121. package/dist/interfaces/statement.d.mts +0 -49
  122. package/dist/internal/dequote.d.mts +0 -14
  123. package/dist/internal/dequote.mjs +0 -7
  124. package/dist/internal/dequote.mjs.map +0 -8
  125. package/dist/internal/format-type-map.d.mts +0 -19
  126. package/dist/internal/format-type-map.mjs +0 -13
  127. package/dist/internal/format-type-map.mjs.map +0 -8
  128. package/dist/internal/get-specifier-kind.d.mts +0 -19
  129. package/dist/internal/get-specifier-kind.mjs +0 -11
  130. package/dist/internal/get-specifier-kind.mjs.map +0 -8
  131. package/dist/internal/get-subpaths.d.mts +0 -28
  132. package/dist/internal/get-subpaths.mjs +0 -8
  133. package/dist/internal/get-subpaths.mjs.map +0 -8
  134. package/dist/internal/regex-encoded-sep.d.mts +0 -15
  135. package/dist/internal/regex-encoded-sep.mjs +0 -6
  136. package/dist/internal/regex-encoded-sep.mjs.map +0 -8
  137. package/dist/internal/regex-internal-specifier.d.mts +0 -16
  138. package/dist/internal/regex-internal-specifier.mjs +0 -6
  139. package/dist/internal/regex-internal-specifier.mjs.map +0 -8
  140. package/dist/internal/regex-invalid-segment.d.mts +0 -16
  141. package/dist/internal/regex-invalid-segment.mjs +0 -9
  142. package/dist/internal/regex-invalid-segment.mjs.map +0 -8
  143. package/dist/internal/regex-package-name.d.mts +0 -15
  144. package/dist/internal/regex-package-name.mjs +0 -6
  145. package/dist/internal/regex-package-name.mjs.map +0 -8
  146. package/dist/internal/regex-package-path.d.mts +0 -17
  147. package/dist/internal/regex-package-path.mjs +0 -6
  148. package/dist/internal/regex-package-path.mjs.map +0 -8
  149. package/dist/internal/resolver.d.mts +0 -132
  150. package/dist/internal/resolver.mjs +0 -483
  151. package/dist/internal/resolver.mjs.map +0 -8
  152. package/dist/internal/validate-array-set.d.mts +0 -24
  153. package/dist/internal/validate-array-set.mjs +0 -12
  154. package/dist/internal/validate-array-set.mjs.map +0 -8
  155. package/dist/internal/validate-boolean.d.mts +0 -22
  156. package/dist/internal/validate-boolean.mjs +0 -12
  157. package/dist/internal/validate-boolean.mjs.map +0 -8
  158. package/dist/internal/validate-map.d.mts +0 -26
  159. package/dist/internal/validate-map.mjs +0 -12
  160. package/dist/internal/validate-map.mjs.map +0 -8
  161. package/dist/internal/validate-object.d.mts +0 -23
  162. package/dist/internal/validate-object.mjs +0 -12
  163. package/dist/internal/validate-object.mjs.map +0 -8
  164. package/dist/internal/validate-set.d.mts +0 -24
  165. package/dist/internal/validate-set.mjs +0 -12
  166. package/dist/internal/validate-set.mjs.map +0 -8
  167. package/dist/internal/validate-string.d.mts +0 -23
  168. package/dist/internal/validate-string.mjs +0 -12
  169. package/dist/internal/validate-string.mjs.map +0 -8
  170. package/dist/internal/validate-url-string.d.mts +0 -24
  171. package/dist/internal/validate-url-string.mjs +0 -13
  172. package/dist/internal/validate-url-string.mjs.map +0 -8
  173. package/dist/types/declaration.d.mts +0 -9
  174. package/dist/types/fn-change-ext.d.mts +0 -31
  175. package/dist/types/index.mjs +0 -0
  176. package/dist/types/mime-type.d.mts +0 -13
  177. package/dist/types/module-specifier-type.d.mts +0 -11
  178. package/dist/types/syntax-kind-export.d.mts +0 -12
  179. package/dist/types/syntax-kind-import.d.mts +0 -12
  180. package/dist/types/syntax-kind-require.d.mts +0 -12
  181. package/dist/utils/compare-subpaths.d.mts +0 -25
  182. package/dist/utils/compare-subpaths.mjs +0 -19
  183. package/dist/utils/compare-subpaths.mjs.map +0 -8
  184. package/dist/utils/conditions.d.mts +0 -13
  185. package/dist/utils/conditions.mjs +0 -6
  186. package/dist/utils/conditions.mjs.map +0 -8
  187. package/dist/utils/detect-syntax.d.mts +0 -21
  188. package/dist/utils/detect-syntax.mjs +0 -11
  189. package/dist/utils/detect-syntax.mjs.map +0 -8
  190. package/dist/utils/extension-format-map.d.mts +0 -16
  191. package/dist/utils/extension-format-map.mjs +0 -22
  192. package/dist/utils/extension-format-map.mjs.map +0 -8
  193. package/dist/utils/extract-statements.d.mts +0 -21
  194. package/dist/utils/extract-statements.mjs +0 -20
  195. package/dist/utils/extract-statements.mjs.map +0 -8
  196. package/dist/utils/fill-modules.d.mts +0 -24
  197. package/dist/utils/fill-modules.mjs +0 -67
  198. package/dist/utils/fill-modules.mjs.map +0 -8
  199. package/dist/utils/find-dynamic-imports.d.mts +0 -18
  200. package/dist/utils/find-dynamic-imports.mjs +0 -36
  201. package/dist/utils/find-dynamic-imports.mjs.map +0 -8
  202. package/dist/utils/find-exports.d.mts +0 -21
  203. package/dist/utils/find-exports.mjs +0 -92
  204. package/dist/utils/find-exports.mjs.map +0 -8
  205. package/dist/utils/find-requires.d.mts +0 -18
  206. package/dist/utils/find-requires.mjs +0 -32
  207. package/dist/utils/find-requires.mjs.map +0 -8
  208. package/dist/utils/find-static-imports.d.mts +0 -18
  209. package/dist/utils/find-static-imports.mjs +0 -30
  210. package/dist/utils/find-static-imports.mjs.map +0 -8
  211. package/dist/utils/find-subpath.d.mts +0 -31
  212. package/dist/utils/find-subpath.mjs +0 -86
  213. package/dist/utils/find-subpath.mjs.map +0 -8
  214. package/dist/utils/get-format.d.mts +0 -31
  215. package/dist/utils/get-format.mjs +0 -107
  216. package/dist/utils/get-format.mjs.map +0 -8
  217. package/dist/utils/get-source.d.mts +0 -30
  218. package/dist/utils/get-source.mjs +0 -61
  219. package/dist/utils/get-source.mjs.map +0 -8
  220. package/dist/utils/has-cjs-syntax.d.mts +0 -25
  221. package/dist/utils/has-cjs-syntax.mjs +0 -11
  222. package/dist/utils/has-cjs-syntax.mjs.map +0 -8
  223. package/dist/utils/has-esm-syntax.d.mts +0 -21
  224. package/dist/utils/has-esm-syntax.mjs +0 -11
  225. package/dist/utils/has-esm-syntax.mjs.map +0 -8
  226. package/dist/utils/index.d.mts +0 -44
  227. package/dist/utils/index.mjs +0 -83
  228. package/dist/utils/index.mjs.map +0 -8
  229. package/dist/utils/is-absolute-specifier.d.mts +0 -20
  230. package/dist/utils/is-absolute-specifier.mjs +0 -26
  231. package/dist/utils/is-absolute-specifier.mjs.map +0 -8
  232. package/dist/utils/is-bare-specifier.d.mts +0 -20
  233. package/dist/utils/is-bare-specifier.mjs +0 -10
  234. package/dist/utils/is-bare-specifier.mjs.map +0 -8
  235. package/dist/utils/is-directory.d.mts +0 -13
  236. package/dist/utils/is-directory.mjs +0 -14
  237. package/dist/utils/is-directory.mjs.map +0 -8
  238. package/dist/utils/is-exports-sugar.d.mts +0 -26
  239. package/dist/utils/is-exports-sugar.mjs +0 -29
  240. package/dist/utils/is-exports-sugar.mjs.map +0 -8
  241. package/dist/utils/is-file.d.mts +0 -13
  242. package/dist/utils/is-file.mjs +0 -14
  243. package/dist/utils/is-file.mjs.map +0 -8
  244. package/dist/utils/is-relative-specifier.d.mts +0 -19
  245. package/dist/utils/is-relative-specifier.mjs +0 -9
  246. package/dist/utils/is-relative-specifier.mjs.map +0 -8
  247. package/dist/utils/lookup-package-scope.d.mts +0 -26
  248. package/dist/utils/lookup-package-scope.mjs +0 -34
  249. package/dist/utils/lookup-package-scope.mjs.map +0 -8
  250. package/dist/utils/parse-data-url.d.mts +0 -25
  251. package/dist/utils/parse-data-url.mjs +0 -25
  252. package/dist/utils/parse-data-url.mjs.map +0 -8
  253. package/dist/utils/parse-module-id.d.mts +0 -20
  254. package/dist/utils/parse-module-id.mjs +0 -123
  255. package/dist/utils/parse-module-id.mjs.map +0 -8
  256. package/dist/utils/parse-subpath.d.mts +0 -35
  257. package/dist/utils/parse-subpath.mjs +0 -149
  258. package/dist/utils/parse-subpath.mjs.map +0 -8
  259. package/dist/utils/pattern-character.d.mts +0 -11
  260. package/dist/utils/pattern-character.mjs +0 -6
  261. package/dist/utils/pattern-character.mjs.map +0 -8
  262. package/dist/utils/read-package-json.d.mts +0 -26
  263. package/dist/utils/read-package-json.mjs +0 -48
  264. package/dist/utils/read-package-json.mjs.map +0 -8
  265. package/dist/utils/resolve-alias.d.mts +0 -20
  266. package/dist/utils/resolve-alias.mjs +0 -101
  267. package/dist/utils/resolve-alias.mjs.map +0 -8
  268. package/dist/utils/resolve-aliases.d.mts +0 -19
  269. package/dist/utils/resolve-aliases.mjs +0 -26
  270. package/dist/utils/resolve-aliases.mjs.map +0 -8
  271. package/dist/utils/resolve-extensions.d.mts +0 -14
  272. package/dist/utils/resolve-extensions.mjs +0 -22
  273. package/dist/utils/resolve-extensions.mjs.map +0 -8
  274. package/dist/utils/resolve-module.d.mts +0 -39
  275. package/dist/utils/resolve-module.mjs +0 -63
  276. package/dist/utils/resolve-module.mjs.map +0 -8
  277. package/dist/utils/resolve-modules.d.mts +0 -25
  278. package/dist/utils/resolve-modules.mjs +0 -23
  279. package/dist/utils/resolve-modules.mjs.map +0 -8
  280. package/dist/utils/to-absolute-specifier.d.mts +0 -22
  281. package/dist/utils/to-absolute-specifier.mjs +0 -8
  282. package/dist/utils/to-absolute-specifier.mjs.map +0 -8
  283. package/dist/utils/to-bare-specifier.d.mts +0 -42
  284. package/dist/utils/to-bare-specifier.mjs +0 -72
  285. package/dist/utils/to-bare-specifier.mjs.map +0 -8
  286. package/dist/utils/to-data-url.d.mts +0 -30
  287. package/dist/utils/to-data-url.mjs +0 -7
  288. package/dist/utils/to-data-url.mjs.map +0 -8
  289. package/dist/utils/to-node-url.d.mts +0 -19
  290. package/dist/utils/to-node-url.mjs +0 -7
  291. package/dist/utils/to-node-url.mjs.map +0 -8
  292. package/dist/utils/to-relative-specifier.d.mts +0 -24
  293. package/dist/utils/to-relative-specifier.mjs +0 -10
  294. package/dist/utils/to-relative-specifier.mjs.map +0 -8
  295. package/dist/utils/to-url.d.mts +0 -21
  296. package/dist/utils/to-url.mjs +0 -8
  297. package/dist/utils/to-url.mjs.map +0 -8
  298. package/dist/utils/validate-assertions.d.mts +0 -23
  299. package/dist/utils/validate-assertions.mjs +0 -47
  300. package/dist/utils/validate-assertions.mjs.map +0 -8
  301. package/dist/utils/validate-exports.d.mts +0 -25
  302. package/dist/utils/validate-exports.mjs +0 -73
  303. package/dist/utils/validate-exports.mjs.map +0 -8
@@ -0,0 +1,11 @@
1
+ function isArrayIndex(value) {
2
+ if (typeof value === "string") {
3
+ const num = +value;
4
+ return value === `${num}` && num >= 0 && num < 4294967295;
5
+ }
6
+ return false;
7
+ }
8
+ var is_array_index_default = isArrayIndex;
9
+ export {
10
+ is_array_index_default as default
11
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file isBareSpecifier
3
+ * @module mlly/lib/isBareSpecifier
4
+ */
5
+ import type { ModuleId } from '@flex-development/mlly';
6
+ /**
7
+ * Check if `specifier` is a *bare specifier*.
8
+ *
9
+ * ::: warning
10
+ * Only checks specifier syntax. Does **not** guarantee the specifier references
11
+ * a file that exists.
12
+ * :::
13
+ *
14
+ * @see {@linkcode ModuleId}
15
+ * @see https://nodejs.org/api/esm.html#terminology
16
+ *
17
+ * @param {ModuleId} specifier
18
+ * Specifier to check
19
+ * @return {boolean}
20
+ * `true` if `specifier` is bare specifier, `false` otherwise
21
+ */
22
+ declare function isBareSpecifier(specifier: ModuleId): boolean;
23
+ export default isBareSpecifier;
@@ -0,0 +1,11 @@
1
+ import isAbsoluteSpecifier from "#lib/is-absolute-specifier";
2
+ import isRelativeSpecifier from "#lib/is-relative-specifier";
3
+ import { isBuiltin } from "@flex-development/is-builtin";
4
+ function isBareSpecifier(specifier) {
5
+ if (isBuiltin(specifier)) return true;
6
+ return typeof specifier === "string" && !!specifier.length && !isAbsoluteSpecifier(specifier) && !isRelativeSpecifier(specifier);
7
+ }
8
+ var is_bare_specifier_default = isBareSpecifier;
9
+ export {
10
+ is_bare_specifier_default as default
11
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file isDirectory
3
+ * @module mlly/lib/isDirectory
4
+ */
5
+ import type { FileSystem, ModuleId } from '@flex-development/mlly';
6
+ /**
7
+ * Check if a directory exists at the given module `id`.
8
+ *
9
+ * @see {@linkcode FileSystem}
10
+ * @see {@linkcode ModuleId}
11
+ *
12
+ * @async
13
+ *
14
+ * @param {ModuleId} id
15
+ * Module id to check
16
+ * @param {FileSystem | null | undefined} fs
17
+ * File system API
18
+ * @return {Promise<boolean>}
19
+ * `true` if directory exists at `id`, `false` otherwise
20
+ */
21
+ declare function isDirectory(id: ModuleId, fs?: FileSystem | null | undefined): Promise<boolean>;
22
+ export default isDirectory;
@@ -0,0 +1,13 @@
1
+ import dfs from "#internal/fs";
2
+ async function isDirectory(id, fs) {
3
+ try {
4
+ if (typeof id === "string" && id.startsWith("file:")) id = new URL(id);
5
+ return (await (fs ?? dfs).stat(id)).isDirectory();
6
+ } catch {
7
+ return false;
8
+ }
9
+ }
10
+ var is_directory_default = isDirectory;
11
+ export {
12
+ is_directory_default as default
13
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file isFile
3
+ * @module mlly/lib/isFile
4
+ */
5
+ import type { FileSystem, ModuleId } from '@flex-development/mlly';
6
+ /**
7
+ * Check if a file exists at the given module `id`.
8
+ *
9
+ * @see {@linkcode FileSystem}
10
+ * @see {@linkcode ModuleId}
11
+ *
12
+ * @async
13
+ *
14
+ * @param {ModuleId} id
15
+ * Module id to check
16
+ * @param {FileSystem | null | undefined} fs
17
+ * File system API
18
+ * @return {Promise<boolean>}
19
+ * `true` if file exists at `id`, `false` otherwise
20
+ */
21
+ declare function isFile(id: ModuleId, fs?: FileSystem | null | undefined): Promise<boolean>;
22
+ export default isFile;
@@ -0,0 +1,13 @@
1
+ import dfs from "#internal/fs";
2
+ async function isFile(id, fs) {
3
+ try {
4
+ if (typeof id === "string" && id.startsWith("file:")) id = new URL(id);
5
+ return (await (fs ?? dfs).stat(id)).isFile();
6
+ } catch {
7
+ return false;
8
+ }
9
+ }
10
+ var is_file_default = isFile;
11
+ export {
12
+ is_file_default as default
13
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file isImportsSubpath
3
+ * @module mlly/lib/isImportsSubpath
4
+ */
5
+ import type { ModuleId } from '@flex-development/mlly';
6
+ import type { ImportsSubpath } from '@flex-development/pkg-types';
7
+ /**
8
+ * Check if `specifier` is an `imports` subpath.
9
+ *
10
+ * @see {@linkcode ModuleId}
11
+ * @see https://nodejs.org/api/packages.html#subpath-imports
12
+ *
13
+ * @param {ModuleId} specifier
14
+ * Specifier to check
15
+ * @return {specifier is ImportsSubpath}
16
+ * `true` if `specifier` is `imports` subpath, `false` otherwise
17
+ */
18
+ declare function isImportsSubpath(specifier: ModuleId): specifier is ImportsSubpath;
19
+ export default isImportsSubpath;
@@ -0,0 +1,8 @@
1
+ import chars from "#internal/chars";
2
+ function isImportsSubpath(specifier) {
3
+ return typeof specifier === "string" && specifier[0] === chars.hash;
4
+ }
5
+ var is_imports_subpath_default = isImportsSubpath;
6
+ export {
7
+ is_imports_subpath_default as default
8
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file isRelativeSpecifier
3
+ * @module mlly/lib/isRelativeSpecifier
4
+ */
5
+ /**
6
+ * Check if `specifier` is a *relative specifier*.
7
+ *
8
+ * ::: warning
9
+ * Only checks specifier syntax. Does **not** guarantee the specifier references
10
+ * a file that exists.
11
+ * :::
12
+ *
13
+ * @see https://nodejs.org/api/esm.html#terminology
14
+ *
15
+ * @param {unknown} specifier
16
+ * Specifier to check
17
+ * @return {boolean}
18
+ * `true` if `specifier` is relative specifier, `false` otherwise
19
+ */
20
+ declare function isRelativeSpecifier(specifier: unknown): boolean;
21
+ export default isRelativeSpecifier;
@@ -0,0 +1,16 @@
1
+ import pathe from "@flex-development/pathe";
2
+ function isRelativeSpecifier(specifier) {
3
+ if (typeof specifier === "string") {
4
+ if (specifier[0] === pathe.dot) {
5
+ if (specifier.length === 1 || specifier[1] === pathe.sep) return true;
6
+ if (specifier[1] === pathe.dot && (specifier.length === 2 || specifier[2] === pathe.sep)) {
7
+ return true;
8
+ }
9
+ }
10
+ }
11
+ return false;
12
+ }
13
+ var is_relative_specifier_default = isRelativeSpecifier;
14
+ export {
15
+ is_relative_specifier_default as default
16
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file lookupPackageScope
3
+ * @module mlly/lib/lookupPackageScope
4
+ */
5
+ import type { FileSystem, ModuleId } from '@flex-development/mlly';
6
+ /**
7
+ * Get the package scope URL for the given module `url`.
8
+ *
9
+ * Implements the `LOOKUP_PACKAGE_SCOPE` algorithm.
10
+ *
11
+ * @see {@linkcode FileSystem}
12
+ * @see {@linkcode ModuleId}
13
+ *
14
+ * @async
15
+ *
16
+ * @param {ModuleId} url
17
+ * URL of module to get package scope for
18
+ * @param {ModuleId | null | undefined} [end]
19
+ * URL of directory to end search, defaults to {@linkcode root}
20
+ * @param {FileSystem | null | undefined} [fs]
21
+ * File system API
22
+ * @return {Promise<URL | null>}
23
+ * URL of nearest directory containing `package.json` file or `null`
24
+ */
25
+ declare function lookupPackageScope(url: ModuleId, end?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): Promise<URL | null>;
26
+ export default lookupPackageScope;
@@ -0,0 +1,16 @@
1
+ import isFile from "#lib/is-file";
2
+ import root from "#lib/root";
3
+ import pathe from "@flex-development/pathe";
4
+ async function lookupPackageScope(url, end, fs) {
5
+ let scopeUrl = new URL(url);
6
+ while (String(scopeUrl) !== String(end ?? root)) {
7
+ scopeUrl = /[/\\]$/.test(scopeUrl.pathname) ? new URL(pathe.dot + pathe.dot, scopeUrl) : new URL(pathe.dot, scopeUrl);
8
+ if (/node_modules[/\\]$/.test(scopeUrl.pathname)) break;
9
+ if (await isFile(new URL("package.json", scopeUrl), fs)) return scopeUrl;
10
+ }
11
+ return null;
12
+ }
13
+ var lookup_package_scope_default = lookupPackageScope;
14
+ export {
15
+ lookup_package_scope_default as default
16
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file patternKeyCompare
3
+ * @module mlly/lib/patternKeyCompare
4
+ */
5
+ import type { PatternKeyCompareResult } from '@flex-development/mlly';
6
+ /**
7
+ * Compares two strings that may contain a wildcard character (`'*'`) and
8
+ * returns a value indicating their order:
9
+ *
10
+ * - `-1`: `a` should come before `b`
11
+ * - `0`: `a` and `b` are equal
12
+ * - `1`: `a` should come after `b`
13
+ *
14
+ * Implements the `PATTERN_KEY_COMPARE` algorithm.
15
+ *
16
+ * @see {@linkcode PatternKeyCompareResult}
17
+ *
18
+ * @param {string} a
19
+ * First string to compare
20
+ * @param {string} b
21
+ * Second string to compare
22
+ * @return {PatternKeyCompareResult}
23
+ * Comparsion result
24
+ */
25
+ declare function patternKeyCompare(a: string, b: string): PatternKeyCompareResult;
26
+ declare namespace patternKeyCompare {
27
+ var EQUAL: 0;
28
+ var GREATER_THAN: 1;
29
+ var LESS_THAN: -1;
30
+ }
31
+ export default patternKeyCompare;
@@ -0,0 +1,18 @@
1
+ import chars from "#internal/chars";
2
+ import { ok } from "devlop";
3
+ function patternKeyCompare(a, b) {
4
+ let aPatternIndex = a.indexOf(chars.asterisk);
5
+ let bPatternIndex = b.indexOf(chars.asterisk);
6
+ ok(aPatternIndex === a.lastIndexOf(chars.asterisk), 'expected a single "*"');
7
+ ok(bPatternIndex === b.lastIndexOf(chars.asterisk), 'expected a single "*"');
8
+ const baseLenA = aPatternIndex === patternKeyCompare.LESS_THAN ? a.length : aPatternIndex + 1;
9
+ const baseLenB = bPatternIndex === patternKeyCompare.LESS_THAN ? b.length : bPatternIndex + 1;
10
+ return baseLenA > baseLenB ? patternKeyCompare.LESS_THAN : baseLenB > baseLenA ? patternKeyCompare.GREATER_THAN : aPatternIndex === -1 ? patternKeyCompare.GREATER_THAN : bPatternIndex === -1 ? patternKeyCompare.LESS_THAN : a.length > b.length ? patternKeyCompare.LESS_THAN : b.length > a.length ? patternKeyCompare.GREATER_THAN : patternKeyCompare.EQUAL;
11
+ }
12
+ patternKeyCompare.EQUAL = 0;
13
+ patternKeyCompare.GREATER_THAN = 1;
14
+ patternKeyCompare.LESS_THAN = -1;
15
+ var pattern_key_compare_default = patternKeyCompare;
16
+ export {
17
+ pattern_key_compare_default as default
18
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file patternMatch
3
+ * @module mlly/lib/patternMatch
4
+ */
5
+ import type { PatternMatch } from '@flex-development/mlly';
6
+ /**
7
+ * Get a subpath pattern match for `matchKey`.
8
+ *
9
+ * @see {@linkcode PatternMatch}
10
+ *
11
+ * @param {string} matchKey
12
+ * The string to expand
13
+ * @param {unknown} matchObject
14
+ * Object containing match keys
15
+ * @return {PatternMatch | null}
16
+ * List containing key of `matchObject` and subpath pattern match or `null`
17
+ */
18
+ declare function patternMatch(matchKey: string, matchObject: unknown): PatternMatch | null;
19
+ export default patternMatch;
@@ -0,0 +1,36 @@
1
+ import chars from "#internal/chars";
2
+ import patternKeyCompare from "#lib/pattern-key-compare";
3
+ import { ok } from "devlop";
4
+ function patternMatch(matchKey, matchObject) {
5
+ if (typeof matchObject === "object" && matchObject) {
6
+ if (Object.prototype.hasOwnProperty.call(matchObject, matchKey) && !matchKey.includes(chars.asterisk)) {
7
+ return [matchKey, null];
8
+ }
9
+ const expansionKeys = Object.getOwnPropertyNames(matchObject).filter((expansionKey) => {
10
+ const patternIndex = expansionKey.indexOf(chars.asterisk);
11
+ return patternIndex >= 0 && patternIndex === expansionKey.lastIndexOf(chars.asterisk);
12
+ }).sort(patternKeyCompare);
13
+ for (const expansionKey of expansionKeys) {
14
+ const patternIndex = expansionKey.indexOf(chars.asterisk);
15
+ const patternBase = expansionKey.slice(0, patternIndex);
16
+ ok(patternIndex >= 0, "expected `patternIndex >= 0`");
17
+ if (matchKey !== patternBase && matchKey.startsWith(patternBase)) {
18
+ const patternTrailer = expansionKey.slice(patternIndex + 1);
19
+ if (!patternTrailer.length || matchKey.endsWith(patternTrailer) && (matchKey.length >= expansionKey.length || matchKey === patternBase + patternTrailer)) {
20
+ return [
21
+ expansionKey,
22
+ matchKey.slice(
23
+ patternBase.length,
24
+ matchKey.length - patternTrailer.length
25
+ )
26
+ ];
27
+ }
28
+ }
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+ var pattern_match_default = patternMatch;
34
+ export {
35
+ pattern_match_default as default
36
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @file readPackageJson
3
+ * @module mlly/lib/readPackageJson
4
+ */
5
+ import type { FileSystem, ModuleId } from '@flex-development/mlly';
6
+ import type { PackageJson } from '@flex-development/pkg-types';
7
+ /**
8
+ * Read a `package.json` file.
9
+ *
10
+ * Implements the `READ_PACKAGE_JSON` algorithm.
11
+ *
12
+ * @see {@linkcode ErrInvalidPackageConfig}
13
+ * @see {@linkcode FileSystem}
14
+ * @see {@linkcode ModuleId}
15
+ * @see {@linkcode PackageJson}
16
+ *
17
+ * @async
18
+ *
19
+ * @param {ModuleId} id
20
+ * URL of package directory, `package.json` file, or module in the same
21
+ * directory as a `package.json` file
22
+ * @param {string | null | undefined} [specifier]
23
+ * Module specifier that initiated reading of `package.json` file.\
24
+ * Should be a `file:` URL if `parent` is a not a URL
25
+ * @param {ModuleId | null | undefined} [parent]
26
+ * URL of parent module
27
+ * @param {FileSystem | null | undefined} [fs]
28
+ * File system API
29
+ * @return {Promise<PackageJson | null>}
30
+ * Parsed file contents or `null`
31
+ * @throws {ErrInvalidPackageConfig}
32
+ * If `package.json` file does not parse as valid JSON
33
+ */
34
+ declare function readPackageJson(id: ModuleId, specifier?: string | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): Promise<PackageJson | null>;
35
+ export default readPackageJson;
@@ -0,0 +1,29 @@
1
+ import dfs from "#internal/fs";
2
+ import isFile from "#lib/is-file";
3
+ import {
4
+ ERR_INVALID_PACKAGE_CONFIG
5
+ } from "@flex-development/errnode";
6
+ import pathe from "@flex-development/pathe";
7
+ async function readPackageJson(id, specifier, parent, fs) {
8
+ const url = new URL("package.json", id);
9
+ if (await isFile(url, fs)) {
10
+ const data = String(await (fs ?? dfs).readFile(url));
11
+ try {
12
+ return JSON.parse(data);
13
+ } catch (e) {
14
+ const cause = e;
15
+ const error = new ERR_INVALID_PACKAGE_CONFIG(
16
+ url.pathname,
17
+ parent && specifier ? `"${specifier}" from ${pathe.fileURLToPath(parent)}` : specifier && pathe.fileURLToPath(specifier),
18
+ cause.message
19
+ );
20
+ error.cause = cause;
21
+ throw error;
22
+ }
23
+ }
24
+ return null;
25
+ }
26
+ var read_package_json_default = readPackageJson;
27
+ export {
28
+ read_package_json_default as default
29
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file resolveAlias
3
+ * @module mlly/lib/resolveAlias
4
+ */
5
+ import type { ResolveAliasOptions } from '@flex-development/mlly';
6
+ export default resolveAlias;
7
+ /**
8
+ * Resolve an aliased `specifier`.
9
+ *
10
+ * @see {@linkcode ResolveAliasOptions}
11
+ *
12
+ * @param {string} specifier
13
+ * The module specifier to resolve
14
+ * @param {ResolveAliasOptions | null | undefined} [options]
15
+ * Alias resolution options
16
+ * @return {string | null }
17
+ * Specifier of aliased module or `null` if path alias match is not found
18
+ */
19
+ declare function resolveAlias(specifier: string, options?: ResolveAliasOptions | null | undefined): string | null;
@@ -0,0 +1,50 @@
1
+ import chars from "#internal/chars";
2
+ import cwd from "#lib/cwd";
3
+ import isRelativeSpecifier from "#lib/is-relative-specifier";
4
+ import patternMatch from "#lib/pattern-match";
5
+ import toRelativeSpecifier from "#lib/to-relative-specifier";
6
+ import pathe from "@flex-development/pathe";
7
+ var resolve_alias_default = resolveAlias;
8
+ function resolveAlias(specifier, options) {
9
+ let aliased = null;
10
+ if (options) {
11
+ if (typeof options.aliases === "object" && options.aliases) {
12
+ const match = patternMatch(
13
+ specifier,
14
+ options.aliases
15
+ );
16
+ if (match) {
17
+ aliased = resolveAliasTarget(options.aliases[match[0]], match[1]);
18
+ if (typeof aliased === "string") {
19
+ const url = new URL(aliased, options.cwd ?? cwd());
20
+ if (options.absolute) {
21
+ aliased = url.href;
22
+ } else if (options.parent) {
23
+ aliased = toRelativeSpecifier(url, options.parent);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ return aliased;
30
+ }
31
+ function resolveAliasTarget(target, patternMatch2) {
32
+ if (typeof target === "string") {
33
+ let match = typeof patternMatch2 === "string" ? target.replace(chars.asterisk, patternMatch2) : target;
34
+ if (!isRelativeSpecifier(match)) match = pathe.dot + pathe.sep + match;
35
+ return match;
36
+ }
37
+ if (Array.isArray(target)) {
38
+ for (const targetValue of target) {
39
+ const resolved = resolveAliasTarget(
40
+ targetValue,
41
+ patternMatch2
42
+ );
43
+ if (typeof resolved === "string") return resolved;
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+ export {
49
+ resolve_alias_default as default
50
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @file resolveModule
3
+ * @module mlly/lib/resolveModule
4
+ */
5
+ import type { ModuleId, ResolveModuleOptions } from '@flex-development/mlly';
6
+ export default resolveModule;
7
+ /**
8
+ * Resolve a module `specifier` according to the [ESM Resolver algorithm][esm],
9
+ * mostly 😉.
10
+ *
11
+ * Adds support for:
12
+ *
13
+ * - Changing file extensions
14
+ * - Directory index resolution
15
+ * - Extensionless file resolution
16
+ * - Path alias resolution
17
+ * - Scopeless `@types/*` resolution (i.e. `unist` -> `@types/unist`)
18
+ *
19
+ * [esm]: https://nodejs.org/api/esm.html#esm_resolver_algorithm
20
+ *
21
+ * @see {@linkcode ModuleId}
22
+ * @see {@linkcode NodeError}
23
+ * @see {@linkcode ResolveModuleOptions}
24
+ *
25
+ * @async
26
+ *
27
+ * @param {string} specifier
28
+ * The module specifier to resolve
29
+ * @param {ModuleId} parent
30
+ * URL of parent module
31
+ * @param {ResolveModuleOptions | null | undefined} [options]
32
+ * Resolution options
33
+ * @return {Promise<URL>}
34
+ * Resolved URL
35
+ * @throws {NodeError}
36
+ */
37
+ declare function resolveModule(specifier: string, parent: ModuleId, options?: ResolveModuleOptions | null | undefined): Promise<URL>;
@@ -0,0 +1,75 @@
1
+ import defaultExtensions from "#lib/default-extensions";
2
+ import resolveAlias from "#lib/resolve-alias";
3
+ import { moduleResolve } from "#lib/resolver";
4
+ import {
5
+ codes,
6
+ isNodeError
7
+ } from "@flex-development/errnode";
8
+ import pathe from "@flex-development/pathe";
9
+ var resolve_module_default = resolveModule;
10
+ async function resolveModule(specifier, parent, options) {
11
+ try {
12
+ return changeExt(await moduleResolve(
13
+ resolveAlias(specifier, { ...options, parent }) ?? specifier,
14
+ parent,
15
+ options?.conditions,
16
+ options?.mainFields,
17
+ options?.preserveSymlinks,
18
+ options?.fs
19
+ ), specifier, options?.ext);
20
+ } catch (e) {
21
+ const ignore = /* @__PURE__ */ new Set([
22
+ codes.ERR_MODULE_NOT_FOUND,
23
+ codes.ERR_UNSUPPORTED_DIR_IMPORT
24
+ ]);
25
+ if (isNodeError(e) && ignore.has(e.code)) {
26
+ const extensions = [
27
+ ...options?.extensions ?? defaultExtensions
28
+ ];
29
+ let tries = [];
30
+ if (e.code === codes.ERR_MODULE_NOT_FOUND && !e.url) {
31
+ tries = [
32
+ specifier.startsWith("@types/") ? specifier : "@types/" + specifier
33
+ ].flatMap((specifier2) => [
34
+ specifier2,
35
+ specifier2 + pathe.sep + "index.d.ts",
36
+ specifier2 + pathe.sep + "index.d.mts",
37
+ specifier2 + pathe.sep + "index.d.cts"
38
+ ]);
39
+ }
40
+ if (e.code === codes.ERR_MODULE_NOT_FOUND && e.url) {
41
+ tries = extensions.map((ext) => specifier + pathe.formatExt(ext));
42
+ }
43
+ if (e.code === codes.ERR_UNSUPPORTED_DIR_IMPORT) {
44
+ tries = extensions.map((ext) => {
45
+ return specifier + pathe.sep + "index" + pathe.formatExt(ext);
46
+ });
47
+ }
48
+ for (const attempt of tries) {
49
+ try {
50
+ return changeExt(await moduleResolve(
51
+ attempt,
52
+ parent,
53
+ options?.conditions,
54
+ options?.mainFields,
55
+ options?.preserveSymlinks,
56
+ options?.fs
57
+ ), specifier, options?.ext);
58
+ } catch {
59
+ continue;
60
+ }
61
+ }
62
+ }
63
+ throw e;
64
+ }
65
+ }
66
+ function changeExt(url, specifier, ext) {
67
+ if (url.protocol === "file:" && ext !== void 0) {
68
+ url.href = typeof ext === "function" ? pathe.changeExt(url.href, ext(url, specifier)) : pathe.changeExt(url.href, ext);
69
+ url = new URL(pathe.toPosix(url.href).replace(/\/index$/, pathe.sep));
70
+ }
71
+ return url;
72
+ }
73
+ export {
74
+ resolve_module_default as default
75
+ };