@flex-development/mlly 1.0.0-alpha.9 → 1.0.0-beta.2

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 +1120 -376
  2. package/README.md +1555 -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 +28 -0
  18. package/dist/interfaces/realpath.d.mts +30 -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 +28 -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 -158
  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 -500
  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 -26
  277. package/dist/utils/lookup-package-scope.mjs +0 -38
  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
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @file resolveAlias
3
+ * @module mlly/lib/resolveAlias
4
+ */
5
+ import chars from '#internal/chars';
6
+ import cwd from '#lib/cwd';
7
+ import isRelativeSpecifier from '#lib/is-relative-specifier';
8
+ import patternMatch from '#lib/pattern-match';
9
+ import toRelativeSpecifier from '#lib/to-relative-specifier';
10
+ import pathe from '@flex-development/pathe';
11
+ import { ok } from 'devlop';
12
+ export default resolveAlias;
13
+ /**
14
+ * Resolve an aliased `specifier`.
15
+ *
16
+ * @see {@linkcode ResolveAliasOptions}
17
+ *
18
+ * @this {void}
19
+ *
20
+ * @param {string} specifier
21
+ * The specifier using an alias
22
+ * @param {ResolveAliasOptions | null | undefined} [options]
23
+ * Alias resolution options
24
+ * @return {string | null}
25
+ * The specifier of the aliased module
26
+ */
27
+ function resolveAlias(specifier, options) {
28
+ /**
29
+ * The expansion key and pattern match.
30
+ *
31
+ * @const {PatternMatch | null} match
32
+ */
33
+ const match = patternMatch(specifier, options?.aliases);
34
+ /**
35
+ * The resolved alias.
36
+ *
37
+ * @var {string | null} aliased
38
+ */
39
+ let aliased = null;
40
+ if (match) {
41
+ ok(options, 'expected `options`');
42
+ ok(options.aliases, 'expected `options.aliases`');
43
+ aliased = resolveAliasTarget(options.aliases[match[0]], match[1]);
44
+ if (typeof aliased === 'string') {
45
+ /**
46
+ * The URL of the aliased module.
47
+ *
48
+ * @const {URL} url
49
+ */
50
+ const url = new URL(aliased, options.cwd ?? cwd());
51
+ if (options.absolute) {
52
+ aliased = url.href;
53
+ }
54
+ else if (options.parent) {
55
+ aliased = toRelativeSpecifier(url, options.parent);
56
+ }
57
+ }
58
+ }
59
+ return aliased;
60
+ }
61
+ /**
62
+ * Resolve a path alias target.
63
+ *
64
+ * @internal
65
+ *
66
+ * @this {void}
67
+ *
68
+ * @param {unknown} target
69
+ * The path alias target to resolve
70
+ * @param {string | null | undefined} [patternMatch]
71
+ * The pattern match, replaces `*` in `target`
72
+ * @return {string | null}
73
+ * The matched alias
74
+ */
75
+ function resolveAliasTarget(target, patternMatch) {
76
+ if (typeof target === 'string') {
77
+ /**
78
+ * The matched alias.
79
+ *
80
+ * @var {string} match
81
+ */
82
+ let match = typeof patternMatch === 'string'
83
+ ? target.replace(chars.asterisk, patternMatch)
84
+ : target;
85
+ if (!isRelativeSpecifier(match))
86
+ match = pathe.dot + pathe.sep + match;
87
+ return match;
88
+ }
89
+ if (Array.isArray(target)) {
90
+ for (const targetValue of target) {
91
+ /**
92
+ * The resolved path alias.
93
+ *
94
+ * @const {string | null} resolved
95
+ */
96
+ const resolved = resolveAliasTarget(targetValue, patternMatch);
97
+ if (typeof resolved === 'string')
98
+ return resolved;
99
+ }
100
+ }
101
+ return null;
102
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @file resolveModule
3
+ * @module mlly/lib/resolveModule
4
+ */
5
+ import type { Awaitable, ModuleId, ResolveModuleOptions } from '@flex-development/mlly';
6
+ export default resolveModule;
7
+ /**
8
+ * Resolve a module `specifier`.
9
+ *
10
+ * Implements the `ESM_RESOLVE` algorithm, mostly 😉.
11
+ *
12
+ * Adds support for:
13
+ *
14
+ * - Changing file extensions
15
+ * - Directory index resolution
16
+ * - Extensionless file resolution
17
+ * - Path alias resolution
18
+ * - Scopeless `@types/*` resolution (i.e. `unist` -> `@types/unist`)
19
+ *
20
+ * > 👉 **Note**: Returns a promise if {@linkcode moduleResolve}
21
+ * > returns a promise.
22
+ *
23
+ * @see {@linkcode Awaitable}
24
+ * @see {@linkcode ModuleId}
25
+ * @see {@linkcode NodeError}
26
+ * @see {@linkcode ResolveModuleOptions}
27
+ *
28
+ * @template {Awaitable<URL>} T
29
+ * The resolved URL
30
+ *
31
+ * @this {void}
32
+ *
33
+ * @param {string} specifier
34
+ * The module specifier to resolve
35
+ * @param {ModuleId} parent
36
+ * The URL of the parent module
37
+ * @param {ResolveModuleOptions | null | undefined} [options]
38
+ * Module resolution options
39
+ * @return {T}
40
+ * The resolved URL
41
+ * @throws {NodeError}
42
+ */
43
+ declare function resolveModule<T extends Awaitable<URL>>(this: void, specifier: string, parent: ModuleId, options?: ResolveModuleOptions | null | undefined): T;
@@ -0,0 +1,186 @@
1
+ /**
2
+ * @file resolveModule
3
+ * @module mlly/lib/resolveModule
4
+ */
5
+ import constant from '#internal/constant';
6
+ import identity from '#internal/identity';
7
+ import isPromise from '#internal/is-promise';
8
+ import defaultExtensions from '#lib/default-extensions';
9
+ import resolveAlias from '#lib/resolve-alias';
10
+ import { moduleResolve } from '#lib/resolver';
11
+ import { codes, isNodeError } from '@flex-development/errnode';
12
+ import pathe from '@flex-development/pathe';
13
+ export default resolveModule;
14
+ /**
15
+ * Resolve a module `specifier`.
16
+ *
17
+ * Implements the `ESM_RESOLVE` algorithm, mostly 😉.
18
+ *
19
+ * Adds support for:
20
+ *
21
+ * - Changing file extensions
22
+ * - Directory index resolution
23
+ * - Extensionless file resolution
24
+ * - Path alias resolution
25
+ * - Scopeless `@types/*` resolution (i.e. `unist` -> `@types/unist`)
26
+ *
27
+ * > 👉 **Note**: Returns a promise if {@linkcode moduleResolve}
28
+ * > returns a promise.
29
+ *
30
+ * @see {@linkcode Awaitable}
31
+ * @see {@linkcode ModuleId}
32
+ * @see {@linkcode NodeError}
33
+ * @see {@linkcode ResolveModuleOptions}
34
+ *
35
+ * @this {void}
36
+ *
37
+ * @param {string} specifier
38
+ * The module specifier to resolve
39
+ * @param {ModuleId} parent
40
+ * The URL of the parent module
41
+ * @param {ResolveModuleOptions | null | undefined} [options]
42
+ * Resolution options
43
+ * @return {Awaitable<URL>}
44
+ * The resolved URL
45
+ * @throws {NodeError}
46
+ */
47
+ function resolveModule(specifier, parent, options) {
48
+ /**
49
+ * The resolved URL.
50
+ *
51
+ * @var {Awaitable<URL>} resolved
52
+ */
53
+ let resolved;
54
+ try {
55
+ resolved = moduleResolve(resolveAlias(specifier, { ...options, parent }) ?? specifier, parent, options?.conditions, options?.mainFields, options?.preserveSymlinks, options?.fs);
56
+ }
57
+ catch (e) {
58
+ return retry(e, specifier, parent, options);
59
+ }
60
+ if (isPromise(resolved)) {
61
+ return resolved.then((url) => changeExt(url, specifier, options?.ext), (e) => retry(e, specifier, parent, options));
62
+ }
63
+ return changeExt(resolved, specifier, options?.ext);
64
+ }
65
+ /**
66
+ * @this {void}
67
+ *
68
+ * @param {URL} url
69
+ * The resolved URL
70
+ * @param {string} specifier
71
+ * The module specifier being resolved
72
+ * @param {ChangeExtFn | string | null | undefined} [ext]
73
+ * The replacement file extension or a function that returns a file extension
74
+ * @return {URL}
75
+ * The modified `url`
76
+ */
77
+ function changeExt(url, specifier, ext) {
78
+ if (url.protocol === 'file:' && ext !== undefined) {
79
+ url.href = typeof ext === 'function'
80
+ ? pathe.changeExt(url.href, ext(url, specifier))
81
+ : pathe.changeExt(url.href, ext);
82
+ url = new URL(pathe.toPosix(url.href).replace(/\/index$/, pathe.sep));
83
+ }
84
+ return url;
85
+ }
86
+ /**
87
+ * @this {void}
88
+ *
89
+ * @param {unknown} e
90
+ * The error to handle
91
+ * @param {string} specifier
92
+ * The module specifier to resolve
93
+ * @param {ModuleId} parent
94
+ * The URL of the parent module
95
+ * @param {ResolveModuleOptions | null | undefined} [options]
96
+ * Resolution options
97
+ * @return {Awaitable<URL>}
98
+ * The resolved URL
99
+ * @throws {NodeError}
100
+ */
101
+ function retry(e, specifier, parent, options) {
102
+ /**
103
+ * The list of error codes to ignore.
104
+ *
105
+ * @const {Set<Code>} ignore
106
+ */
107
+ const ignore = new Set([
108
+ codes.ERR_MODULE_NOT_FOUND,
109
+ codes.ERR_UNSUPPORTED_DIR_IMPORT
110
+ ]);
111
+ if (isNodeError(e) && ignore.has(e.code)) {
112
+ /**
113
+ * The module extensions to probe for.
114
+ *
115
+ * @const {string[]} extensions
116
+ */
117
+ const extensions = [...(options?.extensions ?? defaultExtensions)];
118
+ /**
119
+ * The promises to resolve.
120
+ *
121
+ * > 👉 **Note**: Only used if {@linkcode moduleResolve} returns a promise.
122
+ *
123
+ * @const {Awaitable<URL | undefined>} promises
124
+ */
125
+ const promises = [];
126
+ /**
127
+ * The resolved URL.
128
+ *
129
+ * @var {Awaitable<URL>} resolved
130
+ */
131
+ let resolved;
132
+ /**
133
+ * The module specifiers to try resolving.
134
+ *
135
+ * @var {string[]} tries
136
+ */
137
+ let tries = [];
138
+ // add @types resolution attempts if package resolution failed.
139
+ if (e.code === codes.ERR_MODULE_NOT_FOUND &&
140
+ !e.url) {
141
+ tries = [
142
+ specifier.startsWith('@types/') ? specifier : '@types/' + specifier
143
+ ].flatMap(specifier => [
144
+ specifier,
145
+ specifier + pathe.sep + 'index.d.ts',
146
+ specifier + pathe.sep + 'index.d.mts',
147
+ specifier + pathe.sep + 'index.d.cts'
148
+ ]);
149
+ }
150
+ // add extensionless file resolution attempts if file resolution failed.
151
+ if (e.code === codes.ERR_MODULE_NOT_FOUND &&
152
+ e.url) {
153
+ tries = extensions.map(ext => specifier + pathe.formatExt(ext));
154
+ }
155
+ // add directory index resolution attempts if directory resolution failed.
156
+ if (e.code === codes.ERR_UNSUPPORTED_DIR_IMPORT) {
157
+ tries = extensions.map(ext => {
158
+ return specifier + pathe.sep + 'index' + pathe.formatExt(ext);
159
+ });
160
+ }
161
+ // try module resolution attempts.
162
+ for (let attempt of tries) {
163
+ try {
164
+ resolved = moduleResolve(attempt, parent, options?.conditions, options?.mainFields, options?.preserveSymlinks, options?.fs);
165
+ if (!isPromise(resolved)) {
166
+ return changeExt(resolved, specifier, options?.ext);
167
+ }
168
+ }
169
+ catch {
170
+ continue; // swallow error to continue resolution attempts.
171
+ }
172
+ // collect promises to resolve.
173
+ promises.push(resolved.then(identity, constant(undefined)));
174
+ }
175
+ if (promises.length) {
176
+ return Promise.all(promises).then(resolved => {
177
+ for (const url of resolved) {
178
+ if (url)
179
+ return changeExt(url, specifier, options?.ext);
180
+ }
181
+ throw e; // could not resolve specifier.
182
+ });
183
+ }
184
+ }
185
+ throw e;
186
+ }
@@ -0,0 +1,346 @@
1
+ /**
2
+ * @file resolver
3
+ * @module mlly/lib/resolver
4
+ */
5
+ import type { Awaitable, Condition, FileSystem, List, MainField, ModuleId } from '@flex-development/mlly';
6
+ import type { Exports, ExportsObject, Imports, PackageJson } from '@flex-development/pkg-types';
7
+ declare module '@flex-development/errnode' {
8
+ interface ErrUnsupportedDirImport {
9
+ /**
10
+ * The directory URL.
11
+ */
12
+ url?: string | null | undefined;
13
+ }
14
+ }
15
+ export { legacyMainResolve, moduleResolve, packageExportsResolve, packageImportsExportsResolve, packageImportsResolve, packageResolve, packageSelfResolve, packageTargetResolve };
16
+ /**
17
+ * Resolve a [`main`][main]-like package entry point.
18
+ *
19
+ * Implements the `LEGACY_MAIN_RESOLVE` algorithm.
20
+ *
21
+ * > 👉 **Note**: Returns a promise if `fs.stat` is async.
22
+ *
23
+ * [main]: https://github.com/nodejs/node/blob/v22.9.0/doc/api/packages.md#main
24
+ *
25
+ * @see {@linkcode Awaitable}
26
+ * @see {@linkcode ErrModuleNotFound}
27
+ * @see {@linkcode FileSystem}
28
+ * @see {@linkcode List}
29
+ * @see {@linkcode MainField}
30
+ * @see {@linkcode ModuleId}
31
+ * @see {@linkcode PackageJson}
32
+ *
33
+ * @template {Awaitable<URL>} T
34
+ * The resolved entry point URL
35
+ *
36
+ * @this {void}
37
+ *
38
+ * @param {ModuleId} packageUrl
39
+ * The URL of the package directory, the `package.json` file,
40
+ * or a module in the same directory as a `package.json`
41
+ * @param {PackageJson | null | undefined} [manifest]
42
+ * The package manifest
43
+ * @param {List<MainField> | null | undefined} [mainFields]
44
+ * The list of legacy main fields
45
+ * @param {ModuleId | null | undefined} [parent]
46
+ * The URL of the parent module
47
+ * @param {FileSystem | null | undefined} [fs]
48
+ * The file system API
49
+ * @return {Awaitable<URL>}
50
+ * The resolved entry point URL
51
+ * @throws {ErrModuleNotFound}
52
+ * If the entry point cannot be resolved
53
+ */
54
+ declare function legacyMainResolve<T extends Awaitable<URL>>(this: void, packageUrl: ModuleId, manifest?: PackageJson | null | undefined, mainFields?: List<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): T;
55
+ /**
56
+ * Resolve a module `specifier`.
57
+ *
58
+ * Implements the `ESM_RESOLVE` algorithm.
59
+ *
60
+ * > 👉 **Note**: Returns a promise if `fs.realpath` or `fs.stat` is async,
61
+ * > or one of the following methods returns a promise:
62
+ * > {@linkcode packageImportsResolve}, {@linkcode packageResolve}.
63
+ *
64
+ * @see {@linkcode Awaitable}
65
+ * @see {@linkcode Condition}
66
+ * @see {@linkcode ErrInvalidModuleSpecifier}
67
+ * @see {@linkcode ErrModuleNotFound}
68
+ * @see {@linkcode ErrUnsupportedDirImport}
69
+ * @see {@linkcode FileSystem}
70
+ * @see {@linkcode List}
71
+ * @see {@linkcode ModuleId}
72
+ *
73
+ * @template {Awaitable<URL>} T
74
+ * The resolved URL
75
+ *
76
+ * @this {void}
77
+ *
78
+ * @param {string} specifier
79
+ * The module specifier to resolve
80
+ * @param {ModuleId} parent
81
+ * The URL of the parent module
82
+ * @param {List<Condition> | null | undefined} [conditions]
83
+ * The list of export/import conditions
84
+ * @param {List<MainField> | null | undefined} [mainFields]
85
+ * The list of legacy main fields
86
+ * @param {boolean | null | undefined} [preserveSymlinks]
87
+ * Whether to keep symlinks instead of resolving them
88
+ * @param {FileSystem | null | undefined} [fs]
89
+ * The file system API
90
+ * @return {T}
91
+ * The resolved URL
92
+ * @throws {ErrInvalidModuleSpecifier}
93
+ * @throws {ErrModuleNotFound}
94
+ * @throws {ErrUnsupportedDirImport}
95
+ */
96
+ declare function moduleResolve<T extends Awaitable<URL>>(this: void, specifier: string, parent: ModuleId, conditions?: List<Condition> | null | undefined, mainFields?: List<MainField> | null | undefined, preserveSymlinks?: boolean | null | undefined, fs?: FileSystem | null | undefined): T;
97
+ /**
98
+ * Resolve a package export.
99
+ *
100
+ * Implements the `PACKAGE_EXPORTS_RESOLVE` algorithm.
101
+ *
102
+ * > 👉 **Note**: Never returns a promise.
103
+ *
104
+ * @see {@linkcode Awaitable}
105
+ * @see {@linkcode Condition}
106
+ * @see {@linkcode ErrInvalidPackageConfig}
107
+ * @see {@linkcode ErrPackagePathNotExported}
108
+ * @see {@linkcode Exports}
109
+ * @see {@linkcode FileSystem}
110
+ * @see {@linkcode Imports}
111
+ * @see {@linkcode List}
112
+ * @see {@linkcode ModuleId}
113
+ *
114
+ * @template {Awaitable<URL>} T
115
+ * The resolved package export URL
116
+ *
117
+ * @this {void}
118
+ *
119
+ * @param {ModuleId} packageUrl
120
+ * The URL of the package directory, the `package.json` file,
121
+ * or a module in the same directory as a `package.json`
122
+ * @param {string} subpath
123
+ * The package subpath
124
+ * @param {Exports | undefined} exports
125
+ * The package exports
126
+ * @param {List<Condition> | null | undefined} [conditions]
127
+ * The list of export/import conditions
128
+ * @param {ModuleId | null | undefined} [parent]
129
+ * The URL of the parent module
130
+ * @param {FileSystem | null | undefined} [fs]
131
+ * The file system API
132
+ * @return {Awaitable<URL>}
133
+ * The resolved package export URL
134
+ * @throws {ErrInvalidPackageConfig}
135
+ * @throws {ErrPackagePathNotExported}
136
+ */
137
+ declare function packageExportsResolve<T extends Awaitable<URL>>(this: void, packageUrl: ModuleId, subpath: string, // eslint-disable-next-line unicorn/prefer-module
138
+ exports: Exports | undefined, conditions?: List<Condition> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): T;
139
+ /**
140
+ * Resolve a package export or import.
141
+ *
142
+ * Implements the `PACKAGE_IMPORTS_EXPORTS_RESOLVE` algorithm.
143
+ *
144
+ * > 👉 **Note**: Returns a promise if {@linkcode packageTargetResolve}
145
+ * > returns a promise.
146
+ *
147
+ * @see {@linkcode Awaitable}
148
+ * @see {@linkcode Condition}
149
+ * @see {@linkcode ExportsObject}
150
+ * @see {@linkcode FileSystem}
151
+ * @see {@linkcode Imports}
152
+ * @see {@linkcode List}
153
+ * @see {@linkcode ModuleId}
154
+ *
155
+ * @template {Awaitable<URL | null | undefined>} T
156
+ * The resolved package export or import URL
157
+ *
158
+ * @this {void}
159
+ *
160
+ * @param {string} matchKey
161
+ * The package subpath extracted from a module specifier,
162
+ * or a dot character (`.`)
163
+ * @param {ExportsObject | Imports | null | undefined} matchObject
164
+ * The package exports or imports
165
+ * @param {ModuleId} packageUrl
166
+ * The URL of the directory containing the `package.json` file
167
+ * @param {boolean | null | undefined} [isImports]
168
+ * Whether `matchObject` is internal to the package
169
+ * @param {List<Condition> | null | undefined} [conditions]
170
+ * The list of export/import conditions
171
+ * @param {List<MainField> | null | undefined} [mainFields]
172
+ * The list of legacy main fields
173
+ * @param {ModuleId | null | undefined} [parent]
174
+ * The URL of the parent module
175
+ * @param {FileSystem | null | undefined} [fs]
176
+ * The file system API
177
+ * @return {T}
178
+ * The resolved package export or import URL
179
+ */
180
+ declare function packageImportsExportsResolve<T extends Awaitable<URL | null | undefined>>(this: void, matchKey: string, matchObject: ExportsObject | Imports | null | undefined, packageUrl: ModuleId, isImports?: boolean | null | undefined, conditions?: List<Condition> | null | undefined, mainFields?: List<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): T;
181
+ /**
182
+ * Resolve a package import.
183
+ *
184
+ * Implements the `PACKAGE_IMPORTS_RESOLVE` algorithm.
185
+ *
186
+ * > 👉 **Note**: Returns a promise if {@linkcode lookupPackageScope},
187
+ * > {@linkcode packageImportsExportsResolve}, or {@linkcode readPackageJson}
188
+ * > returns a promise.
189
+ *
190
+ * @see {@linkcode Awaitable}
191
+ * @see {@linkcode Condition}
192
+ * @see {@linkcode ErrInvalidModuleSpecifier}
193
+ * @see {@linkcode ErrPackageImportNotDefined}
194
+ * @see {@linkcode FileSystem}
195
+ * @see {@linkcode List}
196
+ * @see {@linkcode ModuleId}
197
+ *
198
+ * @template {Awaitable<URL>} T
199
+ * The resolved package import URL
200
+ *
201
+ * @this {void}
202
+ *
203
+ * @param {string} specifier
204
+ * The import specifier to resolve
205
+ * @param {ModuleId} parent
206
+ * The URL of the parent module
207
+ * @param {List<Condition> | null | undefined} [conditions]
208
+ * The list of export/import conditions
209
+ * @param {List<MainField> | null | undefined} [mainFields]
210
+ * The list of legacy main fields
211
+ * @param {FileSystem | null | undefined} [fs]
212
+ * The file system API
213
+ * @return {T}
214
+ * The resolved package import URL
215
+ * @throws {ErrInvalidModuleSpecifier}
216
+ * @throws {ErrPackageImportNotDefined}
217
+ */
218
+ declare function packageImportsResolve<T extends Awaitable<URL>>(this: void, specifier: string, parent: ModuleId, conditions?: List<Condition> | null | undefined, mainFields?: List<MainField> | null | undefined, fs?: FileSystem | null | undefined): T;
219
+ /**
220
+ * Resolve a *bare specifier*.
221
+ *
222
+ * Implements the `PACKAGE_RESOLVE` algorithm.
223
+ *
224
+ * > *Bare specifiers* like `'some-package'` or `'some-package/shuffle'` refer
225
+ * > to the main entry point of a package by package name, or a specific feature
226
+ * > module within a package prefixed by the package name. Including the file
227
+ * > extension is only necessary for packages without an [`"exports"`][exports]
228
+ * > field.
229
+ *
230
+ * > 👉 **Note**: Returns a promise if `fs.stat` is async or one of the
231
+ * > following methods returns a promise: {@linkcode legacyMainResolve},
232
+ * > {@linkcode packageExportsResolve}, {@linkcode packageSelfResolve},
233
+ * > {@linkcode readPackageJson}.
234
+ *
235
+ * [exports]: https://nodejs.org/api/packages.html#exports
236
+ *
237
+ * @see {@linkcode Awaitable}
238
+ * @see {@linkcode Condition}
239
+ * @see {@linkcode ErrInvalidModuleSpecifier}
240
+ * @see {@linkcode ErrModuleNotFound}
241
+ * @see {@linkcode FileSystem}
242
+ * @see {@linkcode List}
243
+ * @see {@linkcode MainField}
244
+ * @see {@linkcode ModuleId}
245
+ *
246
+ * @template {Awaitable<URL>} T
247
+ * The resolved package URL
248
+ *
249
+ * @this {void}
250
+ *
251
+ * @param {string} specifier
252
+ * The package specifier
253
+ * @param {ModuleId} parent
254
+ * The URL of the parent module
255
+ * @param {List<Condition> | null | undefined} [conditions]
256
+ * The list of export conditions
257
+ * @param {List<MainField> | null | undefined} [mainFields]
258
+ * The list of legacy main fields
259
+ * @param {FileSystem | null | undefined} [fs]
260
+ * The file system API
261
+ * @return {T}
262
+ * The resolved package URL
263
+ * @throws {ErrInvalidModuleSpecifier}
264
+ * @throws {ErrModuleNotFound}
265
+ */
266
+ declare function packageResolve<T extends Awaitable<URL>>(this: void, specifier: string, parent: ModuleId, conditions?: List<Condition> | null | undefined, mainFields?: List<MainField> | null | undefined, fs?: FileSystem | null | undefined): T;
267
+ /**
268
+ * Resolve the self-import of a package.
269
+ *
270
+ * Implements the `PACKAGE_SELF_RESOLVE` algorithm.
271
+ *
272
+ * > 👉 **Note**: Returns a promise if {@linkcode lookupPackageScope},
273
+ * > {@linkcode packageExportsResolve}, or {@linkcode readPackageJson}
274
+ * > returns a promise.
275
+ *
276
+ * @see {@linkcode Awaitable}
277
+ * @see {@linkcode Condition}
278
+ * @see {@linkcode FileSystem}
279
+ * @see {@linkcode List}
280
+ * @see {@linkcode ModuleId}
281
+ *
282
+ * @template {Awaitable<URL | undefined>} T
283
+ * The resolved package URL
284
+ *
285
+ * @this {void}
286
+ *
287
+ * @param {string} name
288
+ * The package name
289
+ * @param {string} subpath
290
+ * The package subpath
291
+ * @param {ModuleId} parent
292
+ * The URL of the parent module
293
+ * @param {List<Condition> | null | undefined} [conditions]
294
+ * The list of export conditions
295
+ * @param {FileSystem | null | undefined} [fs]
296
+ * The file system API
297
+ * @return {T}
298
+ * The resolved package URL
299
+ */
300
+ declare function packageSelfResolve<T extends Awaitable<URL | undefined>>(this: void, name: string, subpath: string, parent: ModuleId, conditions?: List<Condition> | null | undefined, fs?: FileSystem | null | undefined): T;
301
+ /**
302
+ * Resolve a package target.
303
+ *
304
+ * Implements the `PACKAGE_TARGET_RESOLVE` algorithm.
305
+ *
306
+ * > 👉 **Note**: Returns a promise if `target` is internal to the package and
307
+ * > {@linkcode packageResolve} returns a promise.
308
+ *
309
+ * @see {@linkcode Awaitable}
310
+ * @see {@linkcode Condition}
311
+ * @see {@linkcode ErrInvalidPackageConfig}
312
+ * @see {@linkcode ErrInvalidPackageTarget}
313
+ * @see {@linkcode FileSystem}
314
+ * @see {@linkcode List}
315
+ * @see {@linkcode ModuleId}
316
+ * @see {@linkcode Target}
317
+ *
318
+ * @template {Awaitable<URL | null | undefined>} T
319
+ * The resolved package target URL
320
+ *
321
+ * @this {void}
322
+ *
323
+ * @param {ModuleId} packageUrl
324
+ * The URL of the directory containing the `package.json` file
325
+ * @param {unknown} target
326
+ * The package target (i.e. a `exports`/`imports` value)
327
+ * @param {string} subpath
328
+ * The package subpath (i.e. a `exports`/`imports` key)
329
+ * @param {string | null | undefined} [patternMatch]
330
+ * The `subpath` pattern match
331
+ * @param {boolean | null | undefined} [isImports]
332
+ * Whether `target` is internal to the package
333
+ * @param {List<Condition> | null | undefined} [conditions]
334
+ * The list of export/import conditions
335
+ * @param {List<MainField> | null | undefined} [mainFields]
336
+ * The list of legacy main fields
337
+ * @param {ModuleId | null | undefined} [parent]
338
+ * The URL of the parent module
339
+ * @param {FileSystem | null | undefined} [fs]
340
+ * The file system API
341
+ * @return {T}
342
+ * The resolved package target URL
343
+ * @throws {ErrInvalidPackageConfig}
344
+ * @throws {ErrInvalidPackageTarget}
345
+ */
346
+ declare function packageTargetResolve<T extends Awaitable<URL | null | undefined>>(this: void, packageUrl: ModuleId, target: unknown, subpath: string, patternMatch?: string | null | undefined, isImports?: boolean | null | undefined, conditions?: List<Condition> | null | undefined, mainFields?: List<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): T;