@flex-development/mlly 1.0.0-alpha.1 → 1.0.0-alpha.10

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 (380) hide show
  1. package/CHANGELOG.md +412 -3
  2. package/README.md +6 -4
  3. package/changelog.config.ts +404 -0
  4. package/dist/enums/assert-type.d.mts +21 -0
  5. package/dist/enums/assert-type.mjs +10 -0
  6. package/dist/enums/assert-type.mjs.map +6 -0
  7. package/dist/enums/format.d.mts +17 -0
  8. package/dist/enums/format.mjs +13 -0
  9. package/dist/enums/format.mjs.map +6 -0
  10. package/dist/enums/index.d.mts +10 -0
  11. package/dist/enums/index.mjs +15 -0
  12. package/dist/enums/index.mjs.map +6 -0
  13. package/dist/enums/kind-specifier-syntax.d.mts +14 -0
  14. package/dist/enums/kind-specifier-syntax.mjs +10 -0
  15. package/dist/enums/kind-specifier-syntax.mjs.map +6 -0
  16. package/dist/enums/kind-specifier.d.mts +17 -0
  17. package/dist/enums/kind-specifier.mjs +11 -0
  18. package/dist/enums/kind-specifier.mjs.map +6 -0
  19. package/dist/enums/kind-statement-syntax.d.mts +22 -0
  20. package/dist/enums/kind-statement-syntax.mjs +18 -0
  21. package/dist/enums/kind-statement-syntax.mjs.map +6 -0
  22. package/dist/enums/kind-statement.d.mts +15 -0
  23. package/dist/enums/kind-statement.mjs +11 -0
  24. package/dist/enums/kind-statement.mjs.map +6 -0
  25. package/dist/index.d.mts +2 -2
  26. package/dist/index.mjs +3 -2
  27. package/dist/index.mjs.map +6 -0
  28. package/dist/interfaces/import-assertions.d.mts +20 -0
  29. package/dist/interfaces/import-dynamic.d.mts +26 -6
  30. package/dist/interfaces/import-static.d.mts +22 -4
  31. package/dist/interfaces/index.d.mts +12 -0
  32. package/dist/interfaces/index.mjs +1 -0
  33. package/dist/interfaces/index.mjs.map +6 -0
  34. package/dist/interfaces/options-fill-module.d.mts +23 -0
  35. package/dist/interfaces/options-find-subpath.d.mts +49 -0
  36. package/dist/interfaces/options-get-format.d.mts +83 -0
  37. package/dist/interfaces/options-get-source.d.mts +63 -0
  38. package/dist/interfaces/options-parse-module-id.d.mts +33 -0
  39. package/dist/interfaces/options-parse-subpath.d.mts +31 -0
  40. package/dist/interfaces/options-resolve-alias.d.mts +26 -42
  41. package/dist/interfaces/options-resolve-module.d.mts +64 -0
  42. package/dist/interfaces/options-resolve.d.mts +7 -52
  43. package/dist/interfaces/package-scope.d.mts +25 -0
  44. package/dist/interfaces/parsed-data-url.d.mts +56 -0
  45. package/dist/interfaces/parsed-module-id.d.mts +80 -0
  46. package/dist/interfaces/parsed-subpath.d.mts +40 -0
  47. package/dist/interfaces/statement-export.d.mts +22 -9
  48. package/dist/interfaces/statement-import.d.mts +15 -4
  49. package/dist/interfaces/statement-require.d.mts +15 -4
  50. package/dist/interfaces/statement.d.mts +24 -8
  51. package/dist/internal/escape-reg-exp.d.mts +16 -0
  52. package/dist/internal/escape-reg-exp.mjs +10 -0
  53. package/dist/internal/escape-reg-exp.mjs.map +6 -0
  54. package/dist/internal/format-type-map.d.mts +17 -0
  55. package/dist/internal/format-type-map.mjs +13 -0
  56. package/dist/internal/format-type-map.mjs.map +6 -0
  57. package/dist/internal/get-specifier-kind.d.mts +17 -0
  58. package/dist/internal/get-specifier-kind.mjs +14 -0
  59. package/dist/internal/get-specifier-kind.mjs.map +6 -0
  60. package/dist/internal/get-subpaths.d.mts +25 -0
  61. package/dist/internal/get-subpaths.mjs +10 -0
  62. package/dist/internal/get-subpaths.mjs.map +6 -0
  63. package/dist/internal/is-array-index.d.mts +15 -0
  64. package/dist/internal/is-array-index.mjs +9 -0
  65. package/dist/internal/is-array-index.mjs.map +6 -0
  66. package/dist/internal/is-directory.d.mts +13 -0
  67. package/dist/internal/is-directory.mjs +16 -0
  68. package/dist/internal/is-directory.mjs.map +6 -0
  69. package/dist/internal/is-file.d.mts +13 -0
  70. package/dist/internal/is-file.mjs +16 -0
  71. package/dist/internal/is-file.mjs.map +6 -0
  72. package/dist/internal/is-function.d.mts +12 -0
  73. package/dist/internal/is-function.mjs +8 -0
  74. package/dist/internal/is-function.mjs.map +6 -0
  75. package/dist/internal/regex-encoded-sep.d.mts +13 -0
  76. package/dist/internal/regex-encoded-sep.mjs +6 -0
  77. package/dist/internal/regex-encoded-sep.mjs.map +6 -0
  78. package/dist/internal/regex-internal-specifier.d.mts +14 -0
  79. package/dist/internal/regex-internal-specifier.mjs +6 -0
  80. package/dist/internal/regex-internal-specifier.mjs.map +6 -0
  81. package/dist/internal/regex-package-name.d.mts +13 -0
  82. package/dist/internal/regex-package-name.mjs +6 -0
  83. package/dist/internal/regex-package-name.mjs.map +6 -0
  84. package/dist/internal/regex-package-path.d.mts +15 -0
  85. package/dist/internal/regex-package-path.mjs +6 -0
  86. package/dist/internal/regex-package-path.mjs.map +6 -0
  87. package/dist/internal/resolver.d.mts +130 -0
  88. package/dist/internal/resolver.mjs +500 -0
  89. package/dist/internal/resolver.mjs.map +6 -0
  90. package/dist/internal/validate-boolean.d.mts +20 -0
  91. package/dist/internal/validate-boolean.mjs +11 -0
  92. package/dist/internal/validate-boolean.mjs.map +6 -0
  93. package/dist/internal/validate-object.d.mts +23 -0
  94. package/dist/internal/validate-object.mjs +11 -0
  95. package/dist/internal/validate-object.mjs.map +6 -0
  96. package/dist/internal/validate-set.d.mts +23 -0
  97. package/dist/internal/validate-set.mjs +11 -0
  98. package/dist/internal/validate-set.mjs.map +6 -0
  99. package/dist/internal/validate-string.d.mts +20 -0
  100. package/dist/internal/validate-string.mjs +11 -0
  101. package/dist/internal/validate-string.mjs.map +6 -0
  102. package/dist/internal/validate-url-string.d.mts +22 -0
  103. package/dist/internal/validate-url-string.mjs +12 -0
  104. package/dist/internal/validate-url-string.mjs.map +6 -0
  105. package/dist/types/declaration.d.mts +1 -1
  106. package/dist/types/fn-change-ext.d.mts +28 -0
  107. package/dist/types/index.d.mts +8 -4
  108. package/dist/types/index.mjs +1 -0
  109. package/dist/types/index.mjs.map +6 -0
  110. package/dist/types/mime-type.d.mts +7 -5
  111. package/dist/types/module-id.d.mts +13 -0
  112. package/dist/types/module-specifier-type.d.mts +11 -0
  113. package/dist/types/protocol.d.mts +14 -0
  114. package/dist/types/syntax-kind-export.d.mts +12 -0
  115. package/dist/types/syntax-kind-import.d.mts +12 -0
  116. package/dist/types/syntax-kind-require.d.mts +12 -0
  117. package/dist/utils/compare-subpaths.d.mts +25 -0
  118. package/dist/utils/compare-subpaths.mjs +24 -0
  119. package/dist/utils/compare-subpaths.mjs.map +6 -0
  120. package/dist/utils/conditions.d.mts +13 -0
  121. package/dist/utils/conditions.mjs +6 -0
  122. package/dist/utils/conditions.mjs.map +6 -0
  123. package/dist/{lib → utils}/detect-syntax.d.mts +4 -4
  124. package/dist/{lib → utils}/detect-syntax.mjs +1 -0
  125. package/dist/utils/detect-syntax.mjs.map +6 -0
  126. package/dist/utils/extension-format-map.d.mts +16 -0
  127. package/dist/utils/extension-format-map.mjs +22 -0
  128. package/dist/utils/extension-format-map.mjs.map +6 -0
  129. package/dist/utils/extract-statements.d.mts +21 -0
  130. package/dist/{lib → utils}/extract-statements.mjs +4 -1
  131. package/dist/utils/extract-statements.mjs.map +6 -0
  132. package/dist/utils/fill-modules.d.mts +23 -0
  133. package/dist/utils/fill-modules.mjs +63 -0
  134. package/dist/utils/fill-modules.mjs.map +6 -0
  135. package/dist/utils/find-dynamic-imports.d.mts +18 -0
  136. package/dist/utils/find-dynamic-imports.mjs +39 -0
  137. package/dist/utils/find-dynamic-imports.mjs.map +6 -0
  138. package/dist/utils/find-exports.d.mts +21 -0
  139. package/dist/utils/find-exports.mjs +95 -0
  140. package/dist/utils/find-exports.mjs.map +6 -0
  141. package/dist/utils/find-requires.d.mts +18 -0
  142. package/dist/utils/find-requires.mjs +32 -0
  143. package/dist/utils/find-requires.mjs.map +6 -0
  144. package/dist/utils/find-static-imports.d.mts +18 -0
  145. package/dist/utils/find-static-imports.mjs +34 -0
  146. package/dist/utils/find-static-imports.mjs.map +6 -0
  147. package/dist/utils/find-subpath.d.mts +30 -0
  148. package/dist/utils/find-subpath.mjs +106 -0
  149. package/dist/utils/find-subpath.mjs.map +6 -0
  150. package/dist/utils/get-format.d.mts +24 -0
  151. package/dist/utils/get-format.mjs +111 -0
  152. package/dist/utils/get-format.mjs.map +6 -0
  153. package/dist/utils/get-source.d.mts +22 -0
  154. package/dist/utils/get-source.mjs +63 -0
  155. package/dist/utils/get-source.mjs.map +6 -0
  156. package/dist/{lib → utils}/has-cjs-syntax.d.mts +5 -2
  157. package/dist/utils/has-cjs-syntax.mjs +11 -0
  158. package/dist/utils/has-cjs-syntax.mjs.map +6 -0
  159. package/dist/{lib → utils}/has-esm-syntax.d.mts +5 -2
  160. package/dist/utils/has-esm-syntax.mjs +11 -0
  161. package/dist/utils/has-esm-syntax.mjs.map +6 -0
  162. package/dist/utils/index.d.mts +42 -0
  163. package/dist/utils/index.mjs +79 -0
  164. package/dist/utils/index.mjs.map +6 -0
  165. package/dist/utils/is-absolute-specifier.d.mts +19 -0
  166. package/dist/utils/is-absolute-specifier.mjs +25 -0
  167. package/dist/utils/is-absolute-specifier.mjs.map +6 -0
  168. package/dist/utils/is-bare-specifier.d.mts +19 -0
  169. package/dist/utils/is-bare-specifier.mjs +10 -0
  170. package/dist/utils/is-bare-specifier.mjs.map +6 -0
  171. package/dist/utils/is-exports-sugar.d.mts +25 -0
  172. package/dist/utils/is-exports-sugar.mjs +26 -0
  173. package/dist/utils/is-exports-sugar.mjs.map +6 -0
  174. package/dist/utils/is-relative-specifier.d.mts +20 -0
  175. package/dist/utils/is-relative-specifier.mjs +11 -0
  176. package/dist/utils/is-relative-specifier.mjs.map +6 -0
  177. package/dist/utils/lookup-package-scope.d.mts +26 -0
  178. package/dist/utils/lookup-package-scope.mjs +38 -0
  179. package/dist/utils/lookup-package-scope.mjs.map +6 -0
  180. package/dist/utils/parse-data-url.d.mts +25 -0
  181. package/dist/utils/parse-data-url.mjs +25 -0
  182. package/dist/utils/parse-data-url.mjs.map +6 -0
  183. package/dist/utils/parse-module-id.d.mts +22 -0
  184. package/dist/utils/parse-module-id.mjs +122 -0
  185. package/dist/utils/parse-module-id.mjs.map +6 -0
  186. package/dist/utils/parse-subpath.d.mts +35 -0
  187. package/dist/utils/parse-subpath.mjs +54 -0
  188. package/dist/utils/parse-subpath.mjs.map +6 -0
  189. package/dist/utils/pattern-character.d.mts +11 -0
  190. package/dist/utils/pattern-character.mjs +6 -0
  191. package/dist/utils/pattern-character.mjs.map +6 -0
  192. package/dist/utils/read-package-json.d.mts +26 -0
  193. package/dist/utils/read-package-json.mjs +43 -0
  194. package/dist/utils/read-package-json.mjs.map +6 -0
  195. package/dist/utils/resolve-alias.d.mts +20 -0
  196. package/dist/utils/resolve-alias.mjs +106 -0
  197. package/dist/utils/resolve-alias.mjs.map +6 -0
  198. package/dist/utils/resolve-aliases.d.mts +19 -0
  199. package/dist/utils/resolve-aliases.mjs +28 -0
  200. package/dist/utils/resolve-aliases.mjs.map +6 -0
  201. package/dist/utils/resolve-extensions.d.mts +14 -0
  202. package/dist/utils/resolve-extensions.mjs +22 -0
  203. package/dist/utils/resolve-extensions.mjs.map +6 -0
  204. package/dist/utils/resolve-module.d.mts +39 -0
  205. package/dist/utils/resolve-module.mjs +64 -0
  206. package/dist/utils/resolve-module.mjs.map +6 -0
  207. package/dist/utils/resolve-modules.d.mts +25 -0
  208. package/dist/{lib → utils}/resolve-modules.mjs +7 -10
  209. package/dist/utils/resolve-modules.mjs.map +6 -0
  210. package/dist/{lib → utils}/to-absolute-specifier.d.mts +6 -6
  211. package/dist/utils/to-absolute-specifier.mjs +8 -0
  212. package/dist/utils/to-absolute-specifier.mjs.map +6 -0
  213. package/dist/utils/to-bare-specifier.d.mts +42 -0
  214. package/dist/utils/to-bare-specifier.mjs +90 -0
  215. package/dist/utils/to-bare-specifier.mjs.map +6 -0
  216. package/dist/{lib → utils}/to-data-url.d.mts +6 -5
  217. package/dist/{lib → utils}/to-data-url.mjs +4 -0
  218. package/dist/utils/to-data-url.mjs.map +6 -0
  219. package/dist/utils/to-node-url.d.mts +19 -0
  220. package/dist/utils/to-node-url.mjs +10 -0
  221. package/dist/utils/to-node-url.mjs.map +6 -0
  222. package/dist/{lib → utils}/to-relative-specifier.d.mts +6 -6
  223. package/dist/{lib → utils}/to-relative-specifier.mjs +7 -3
  224. package/dist/utils/to-relative-specifier.mjs.map +6 -0
  225. package/dist/utils/to-url.d.mts +22 -0
  226. package/dist/utils/to-url.mjs +12 -0
  227. package/dist/utils/to-url.mjs.map +6 -0
  228. package/dist/utils/validate-assertions.d.mts +23 -0
  229. package/dist/utils/validate-assertions.mjs +52 -0
  230. package/dist/utils/validate-assertions.mjs.map +6 -0
  231. package/dist/utils/validate-exports.d.mts +24 -0
  232. package/dist/utils/validate-exports.mjs +72 -0
  233. package/dist/utils/validate-exports.mjs.map +6 -0
  234. package/package.json +106 -83
  235. package/src/enums/assert-type.ts +23 -0
  236. package/src/enums/format.ts +19 -0
  237. package/src/enums/index.ts +11 -0
  238. package/src/enums/kind-specifier-syntax.ts +16 -0
  239. package/src/enums/kind-specifier.ts +19 -0
  240. package/src/enums/kind-statement-syntax.ts +24 -0
  241. package/src/enums/kind-statement.ts +17 -0
  242. package/src/index.ts +9 -0
  243. package/src/interfaces/import-assertions.ts +24 -0
  244. package/src/interfaces/import-dynamic.ts +48 -0
  245. package/src/interfaces/import-static.ts +50 -0
  246. package/src/interfaces/index.ts +25 -0
  247. package/src/interfaces/options-fill-module.ts +26 -0
  248. package/src/interfaces/options-find-subpath.ts +56 -0
  249. package/src/interfaces/options-get-format.ts +92 -0
  250. package/src/interfaces/options-get-source.ts +70 -0
  251. package/src/interfaces/options-parse-module-id.ts +38 -0
  252. package/src/interfaces/options-parse-subpath.ts +36 -0
  253. package/src/interfaces/options-resolve-alias.ts +59 -0
  254. package/src/interfaces/options-resolve-module.ts +72 -0
  255. package/src/interfaces/options-resolve.ts +17 -0
  256. package/src/interfaces/package-scope.ts +30 -0
  257. package/src/interfaces/parsed-data-url.ts +63 -0
  258. package/src/interfaces/parsed-module-id.ts +90 -0
  259. package/src/interfaces/parsed-subpath.ts +47 -0
  260. package/src/interfaces/statement-export.ts +52 -0
  261. package/src/interfaces/statement-import.ts +45 -0
  262. package/src/interfaces/statement-require.ts +45 -0
  263. package/src/interfaces/statement.ts +64 -0
  264. package/src/internal/escape-reg-exp.ts +24 -0
  265. package/src/internal/format-type-map.ts +26 -0
  266. package/src/internal/get-specifier-kind.ts +38 -0
  267. package/src/internal/get-subpaths.ts +41 -0
  268. package/src/internal/is-array-index.ts +28 -0
  269. package/src/internal/is-directory.ts +25 -0
  270. package/src/internal/is-file.ts +25 -0
  271. package/src/internal/is-function.ts +16 -0
  272. package/src/internal/regex-encoded-sep.ts +15 -0
  273. package/src/internal/regex-internal-specifier.ts +17 -0
  274. package/src/internal/regex-package-name.ts +16 -0
  275. package/src/internal/regex-package-path.ts +18 -0
  276. package/src/internal/resolver.ts +783 -0
  277. package/src/internal/validate-boolean.ts +27 -0
  278. package/src/internal/validate-object.ts +30 -0
  279. package/src/internal/validate-set.ts +33 -0
  280. package/src/internal/validate-string.ts +27 -0
  281. package/src/internal/validate-url-string.ts +31 -0
  282. package/src/types/declaration.ts +22 -0
  283. package/src/types/fn-change-ext.ts +33 -0
  284. package/src/types/index.ts +14 -0
  285. package/src/types/mime-type.ts +19 -0
  286. package/src/types/module-id.ts +15 -0
  287. package/src/types/module-specifier-type.ts +13 -0
  288. package/src/types/protocol.ts +40 -0
  289. package/src/types/syntax-kind-export.ts +20 -0
  290. package/src/types/syntax-kind-import.ts +22 -0
  291. package/src/types/syntax-kind-require.ts +15 -0
  292. package/src/utils/compare-subpaths.ts +100 -0
  293. package/src/utils/conditions.ts +15 -0
  294. package/src/utils/detect-syntax.ts +40 -0
  295. package/src/utils/extension-format-map.ts +34 -0
  296. package/src/utils/extract-statements.ts +42 -0
  297. package/src/utils/fill-modules.ts +121 -0
  298. package/src/utils/find-dynamic-imports.ts +75 -0
  299. package/src/utils/find-exports.ts +164 -0
  300. package/src/utils/find-requires.ts +75 -0
  301. package/src/utils/find-static-imports.ts +89 -0
  302. package/src/utils/find-subpath.ts +241 -0
  303. package/src/utils/get-format.ts +222 -0
  304. package/src/utils/get-source.ts +129 -0
  305. package/src/utils/has-cjs-syntax.ts +44 -0
  306. package/src/utils/has-esm-syntax.ts +40 -0
  307. package/src/utils/index.ts +43 -0
  308. package/src/utils/is-absolute-specifier.ts +48 -0
  309. package/src/utils/is-bare-specifier.ts +30 -0
  310. package/src/utils/is-exports-sugar.ts +74 -0
  311. package/src/utils/is-relative-specifier.ts +34 -0
  312. package/src/utils/lookup-package-scope.ts +97 -0
  313. package/src/utils/parse-data-url.ts +71 -0
  314. package/src/utils/parse-module-id.ts +186 -0
  315. package/src/utils/parse-subpath.ts +173 -0
  316. package/src/utils/pattern-character.ts +13 -0
  317. package/src/utils/read-package-json.ts +101 -0
  318. package/src/utils/resolve-alias.ts +219 -0
  319. package/src/utils/resolve-aliases.ts +58 -0
  320. package/src/utils/resolve-extensions.ts +33 -0
  321. package/src/utils/resolve-module.ts +153 -0
  322. package/src/utils/resolve-modules.ts +62 -0
  323. package/src/utils/to-absolute-specifier.ts +30 -0
  324. package/src/utils/to-bare-specifier.ts +201 -0
  325. package/src/utils/to-data-url.ts +42 -0
  326. package/src/utils/to-node-url.ts +27 -0
  327. package/src/utils/to-relative-specifier.ts +47 -0
  328. package/src/utils/to-url.ts +31 -0
  329. package/src/utils/validate-assertions.ts +119 -0
  330. package/src/utils/validate-exports.ts +124 -0
  331. package/changelog.config.cts +0 -204
  332. package/dist/constants.d.mts +0 -19
  333. package/dist/constants.mjs +0 -24
  334. package/dist/interfaces/import-dynamic.mjs +0 -0
  335. package/dist/interfaces/import-static.mjs +0 -0
  336. package/dist/interfaces/options-resolve-alias.mjs +0 -0
  337. package/dist/interfaces/options-resolve.mjs +0 -0
  338. package/dist/interfaces/statement-export.mjs +0 -0
  339. package/dist/interfaces/statement-import.mjs +0 -0
  340. package/dist/interfaces/statement-require.mjs +0 -0
  341. package/dist/interfaces/statement.mjs +0 -0
  342. package/dist/internal/compiler-options-json.d.mts +0 -111
  343. package/dist/internal/compiler-options-json.mjs +0 -0
  344. package/dist/internal/constants.d.mts +0 -70
  345. package/dist/internal/constants.mjs +0 -18
  346. package/dist/internal/get-compiler-options.d.mts +0 -21
  347. package/dist/internal/get-compiler-options.mjs +0 -14
  348. package/dist/internal/index.d.mts +0 -7
  349. package/dist/internal/index.mjs +0 -5
  350. package/dist/lib/extract-statements.d.mts +0 -21
  351. package/dist/lib/find-dynamic-imports.d.mts +0 -15
  352. package/dist/lib/find-dynamic-imports.mjs +0 -20
  353. package/dist/lib/find-exports.d.mts +0 -15
  354. package/dist/lib/find-exports.mjs +0 -53
  355. package/dist/lib/find-requires.d.mts +0 -17
  356. package/dist/lib/find-requires.mjs +0 -19
  357. package/dist/lib/find-static-imports.d.mts +0 -15
  358. package/dist/lib/find-static-imports.mjs +0 -20
  359. package/dist/lib/has-cjs-syntax.mjs +0 -6
  360. package/dist/lib/has-esm-syntax.mjs +0 -6
  361. package/dist/lib/index.d.mts +0 -20
  362. package/dist/lib/index.mjs +0 -34
  363. package/dist/lib/resolve-alias.d.mts +0 -20
  364. package/dist/lib/resolve-alias.mjs +0 -41
  365. package/dist/lib/resolve-aliases.d.mts +0 -17
  366. package/dist/lib/resolve-aliases.mjs +0 -34
  367. package/dist/lib/resolve-module.d.mts +0 -31
  368. package/dist/lib/resolve-module.mjs +0 -74
  369. package/dist/lib/resolve-modules.d.mts +0 -19
  370. package/dist/lib/to-absolute-specifier.mjs +0 -20
  371. package/dist/lib/to-bare-specifier.d.mts +0 -28
  372. package/dist/lib/to-bare-specifier.mjs +0 -78
  373. package/dist/types/declaration.mjs +0 -0
  374. package/dist/types/ext.d.mts +0 -9
  375. package/dist/types/ext.mjs +0 -0
  376. package/dist/types/mime-type.mjs +0 -0
  377. package/dist/types/specifier-type.d.mts +0 -11
  378. package/dist/types/specifier-type.mjs +0 -0
  379. package/dist/types/statement-type.d.mts +0 -9
  380. package/dist/types/statement-type.mjs +0 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @file Utilities
3
+ * @module mlly/utils
4
+ */
5
+
6
+ export { default as compareSubpaths } from './compare-subpaths'
7
+ export { default as CONDITIONS } from './conditions'
8
+ export { default as detectSyntax } from './detect-syntax'
9
+ export { default as EXTENSION_FORMAT_MAP } from './extension-format-map'
10
+ export { default as extractStatements } from './extract-statements'
11
+ export { default as fillModules } from './fill-modules'
12
+ export { default as findDynamicImports } from './find-dynamic-imports'
13
+ export { default as findExports } from './find-exports'
14
+ export { default as findRequires } from './find-requires'
15
+ export { default as findStaticImports } from './find-static-imports'
16
+ export { default as findSubpath } from './find-subpath'
17
+ export { default as getFormat } from './get-format'
18
+ export { default as getSource } from './get-source'
19
+ export { default as hasCJSSyntax } from './has-cjs-syntax'
20
+ export { default as hasESMSyntax } from './has-esm-syntax'
21
+ export { default as isAbsoluteSpecifier } from './is-absolute-specifier'
22
+ export { default as isBareSpecifier } from './is-bare-specifier'
23
+ export { default as isExportsSugar } from './is-exports-sugar'
24
+ export { default as isRelativeSpecifier } from './is-relative-specifier'
25
+ export { default as lookupPackageScope } from './lookup-package-scope'
26
+ export { default as parseDataURL } from './parse-data-url'
27
+ export { default as parseModuleId } from './parse-module-id'
28
+ export { default as parseSubpath } from './parse-subpath'
29
+ export { default as PATTERN_CHARACTER } from './pattern-character'
30
+ export { default as readPackageJson } from './read-package-json'
31
+ export { default as resolveAlias } from './resolve-alias'
32
+ export { default as resolveAliases } from './resolve-aliases'
33
+ export { default as RESOLVE_EXTENSIONS } from './resolve-extensions'
34
+ export { default as resolveModule } from './resolve-module'
35
+ export { default as resolveModules } from './resolve-modules'
36
+ export { default as toAbsoluteSpecifier } from './to-absolute-specifier'
37
+ export { default as toBareSpecifier } from './to-bare-specifier'
38
+ export { default as toDataURL } from './to-data-url'
39
+ export { default as toNodeURL } from './to-node-url'
40
+ export { default as toRelativeSpecifier } from './to-relative-specifier'
41
+ export { default as toURL } from './to-url'
42
+ export { default as validateAssertions } from './validate-assertions'
43
+ export { default as validateExports } from './validate-exports'
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @file isAbsoluteSpecifier
3
+ * @module mlly/utils/isAbsoluteSpecifier
4
+ */
5
+
6
+ import pathe from '@flex-development/pathe'
7
+ import { URL } from 'node:url'
8
+
9
+ /**
10
+ * Checks if the given `specifier` is an absolute specifier.
11
+ *
12
+ * ::: warning
13
+ * Only checks specifier syntax. Does **not** guarantee the specifier references
14
+ * a file that exists.
15
+ * :::
16
+ *
17
+ * @see https://nodejs.org/api/esm.html#terminology
18
+ *
19
+ * @param {string} specifier - Specifier to evaluate
20
+ * @return {boolean} `true` if `specifier` is absolute specifier
21
+ */
22
+ const isAbsoluteSpecifier = (specifier: string): boolean => {
23
+ /**
24
+ * Absolute specifier check.
25
+ *
26
+ * @var {string} absolute
27
+ */
28
+ let absolute: boolean = false
29
+
30
+ // check if specifier is absolute path or valid file url
31
+ switch (true) {
32
+ case pathe.isAbsolute(specifier):
33
+ absolute = true
34
+ break
35
+ case specifier.startsWith('file:'):
36
+ try {
37
+ new URL(specifier)
38
+ absolute = true
39
+ } /* c8 ignore next */ catch {}
40
+ break
41
+ default:
42
+ absolute = false
43
+ }
44
+
45
+ return absolute
46
+ }
47
+
48
+ export default isAbsoluteSpecifier
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @file isBareSpecifier
3
+ * @module mlly/utils/isBareSpecifier
4
+ */
5
+
6
+ import isAbsoluteSpecifier from './is-absolute-specifier'
7
+ import isRelativeSpecifier from './is-relative-specifier'
8
+
9
+ /**
10
+ * Checks if the given `specifier` is a bare specifier.
11
+ *
12
+ * ::: warning
13
+ * Only checks specifier syntax. Does **not** guarantee the specifier references
14
+ * a file that exists.
15
+ * :::
16
+ *
17
+ * @see https://nodejs.org/api/esm.html#terminology
18
+ *
19
+ * @param {string} specifier - Specifier to evaluate
20
+ * @return {boolean} `true` if `specifier` is bare specifier
21
+ */
22
+ const isBareSpecifier = (specifier: string): boolean => {
23
+ return (
24
+ specifier.trim().length > 0 &&
25
+ !isAbsoluteSpecifier(specifier) &&
26
+ !isRelativeSpecifier(specifier)
27
+ )
28
+ }
29
+
30
+ export default isBareSpecifier
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @file isExportsSugar
3
+ * @module mlly/utils/isExportsSugar
4
+ */
5
+
6
+ import type { ModuleId } from '#src/types'
7
+ import type { NodeError } from '@flex-development/errnode'
8
+ import type { Exports } from '@flex-development/pkg-types'
9
+ import { isNIL } from '@flex-development/tutils'
10
+ import validateExports from './validate-exports'
11
+
12
+ /**
13
+ * Checks if the given package [`exports`][1] value is using [exports sugar][2].
14
+ *
15
+ * [1]: https://nodejs.org/api/packages.html#exports
16
+ * [2]: https://nodejs.org/api/packages.html#exports-sugar
17
+ *
18
+ * @see {@linkcode Exports}
19
+ * @see {@linkcode ModuleId}
20
+ *
21
+ * @param {Exports | undefined} exports - Package `exports`
22
+ * @param {ModuleId} pkg - URL of relevant `package.json` file
23
+ * @param {ModuleId} parent - URL of module to resolve from
24
+ * @return {boolean} `true` if `exports` is using exports sugar
25
+ * @throws {NodeError<Error | TypeError>} If either `pkg` or `parent` is not an
26
+ * instance of {@linkcode URL} or a string, or if `exports` configuration or
27
+ * schema is invalid
28
+ */
29
+ const isExportsSugar = (
30
+ exports: Exports | undefined,
31
+ pkg: ModuleId,
32
+ parent: ModuleId
33
+ ): boolean => {
34
+ /**
35
+ * [Exports sugar][1] check.
36
+ *
37
+ * [1]: https://nodejs.org/api/packages.html#exports-sugar
38
+ *
39
+ * @var {boolean} sugar
40
+ */
41
+ let sugar: boolean = false
42
+
43
+ // check if exports sugar is being used
44
+ switch (true) {
45
+ case Array.isArray(exports):
46
+ case typeof exports === 'string':
47
+ sugar = true
48
+ break
49
+ case isNIL(exports):
50
+ case typeof exports !== 'object':
51
+ sugar = false
52
+ break
53
+ default:
54
+ exports = exports as Record<string, Exports>
55
+
56
+ /*
57
+ * Validate exports object configuration.
58
+ *
59
+ * This ensures the exports object is either an object of package subpath
60
+ * keys (i.e. keys starting with '.') or an object of main entry condition
61
+ * name keys (i.e. keys not starting with '.') only. An error will be
62
+ * thrown otherwise. This also means only the first key in `keys` needs to
63
+ * be checked for exports sugar usage.
64
+ */
65
+ validateExports(exports, pkg, parent)
66
+
67
+ // check for exports sugar
68
+ sugar = !Object.getOwnPropertyNames(exports)[0]?.startsWith('.')
69
+ }
70
+
71
+ return sugar
72
+ }
73
+
74
+ export default isExportsSugar
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @file isRelativeSpecifier
3
+ * @module mlly/utils/isRelativeSpecifier
4
+ */
5
+
6
+ import validateString from '#src/internal/validate-string'
7
+ import type { NodeError } from '@flex-development/errnode'
8
+ import pathe from '@flex-development/pathe'
9
+
10
+ /**
11
+ * Checks if the given `specifier` is a relative specifier.
12
+ *
13
+ * ::: warning
14
+ * Only checks specifier syntax. Does **not** guarantee the specifier references
15
+ * a file that exists.
16
+ * :::
17
+ *
18
+ * @see https://nodejs.org/api/esm.html#terminology
19
+ *
20
+ * @param {string} specifier - Specifier to evaluate
21
+ * @return {boolean} `true` if `specifier` is relative specifier
22
+ * @throws {NodeError<TypeError>} If `specifier` is not a string
23
+ */
24
+ const isRelativeSpecifier = (specifier: string): boolean => {
25
+ validateString(specifier, 'specifier')
26
+ return specifier.startsWith('.')
27
+ ? specifier.length === 1 || specifier[1] === pathe.sep
28
+ ? true
29
+ : specifier[1] === '.' &&
30
+ (specifier.length === 2 || specifier[2] === pathe.sep)
31
+ : false
32
+ }
33
+
34
+ export default isRelativeSpecifier
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @file lookupPackageScope
3
+ * @module mlly/utils/lookupPackageScope
4
+ */
5
+
6
+ import type { PackageScope } from '#src/interfaces'
7
+ import validateURLString from '#src/internal/validate-url-string'
8
+ import type { ModuleId } from '#src/types'
9
+ import type { NodeError } from '@flex-development/errnode'
10
+ import pathe from '@flex-development/pathe'
11
+ import type { PackageJson } from '@flex-development/pkg-types'
12
+ import type { Nullable } from '@flex-development/tutils'
13
+ import { pathToFileURL } from 'node:url'
14
+ import readPackageJson from './read-package-json'
15
+ import toURL from './to-url'
16
+
17
+ /**
18
+ * Finds a `package.json` file for the given module `id`. Ends the search at the
19
+ * given end point **after** checking for a `package.json` file.
20
+ *
21
+ * Returns `null` if a `package.json` file is not found.
22
+ *
23
+ * @see {@linkcode ModuleId}
24
+ * @see {@linkcode PackageScope}
25
+ *
26
+ * @param {ModuleId} id - Id of module to get package scope for
27
+ * @param {ModuleId?} [stopdir=pathe.sep] - Directory to end search
28
+ * @param {string?} [specifier] - Module specifier passed by user
29
+ * @param {ModuleId?} [parent] - Id of module to resolve from
30
+ * @return {?PackageScope} Package scope result or `null`
31
+ * @throws {NodeError<TypeError>} If either `id` or `stopdir` is not an instance
32
+ * of {@linkcode URL} or a string
33
+ */
34
+ const lookupPackageScope = (
35
+ id: ModuleId,
36
+ stopdir: ModuleId = pathe.sep,
37
+ specifier?: string,
38
+ parent?: ModuleId
39
+ ): Nullable<PackageScope> => {
40
+ validateURLString(id, 'id')
41
+ validateURLString(stopdir, 'stopdir')
42
+
43
+ // ensure search endpoint is a path
44
+ stopdir = toURL(stopdir).pathname
45
+
46
+ /**
47
+ * Path to directory containing `package.json` file.
48
+ *
49
+ * @var {string} dir
50
+ */
51
+ let dir: string = toURL(id).pathname
52
+
53
+ /**
54
+ * Package scope result.
55
+ *
56
+ * @var {Nullable<PackageScope>} scope
57
+ */
58
+ let scope: Nullable<PackageScope> = null
59
+
60
+ // search for package.json
61
+ while (dir && !dir.endsWith('node_modules')) {
62
+ // stop search if outside of endpoint
63
+ if (pathe.relative(stopdir, dir).startsWith('../')) break
64
+
65
+ /**
66
+ * Possible `package.json` object.
67
+ *
68
+ * @const {Nullable<PackageJson>} pkgjson
69
+ */
70
+ const pkgjson: Nullable<PackageJson> = readPackageJson(
71
+ dir,
72
+ specifier,
73
+ parent
74
+ )
75
+
76
+ // stop search if package.json has been found
77
+ if (pkgjson) {
78
+ scope = {
79
+ dir: pathToFileURL((dir = pathe.resolve(process.cwd(), dir))).href,
80
+ pkg: pathToFileURL(pathe.join(dir, 'package.json')).href,
81
+ pkgjson
82
+ }
83
+
84
+ break
85
+ }
86
+
87
+ // stop search if endpoint has been reached
88
+ if (dir === stopdir.replace(/\/$/, '')) break
89
+
90
+ // continue searching for package.json
91
+ dir = pathe.dirname(dir)
92
+ }
93
+
94
+ return scope
95
+ }
96
+
97
+ export default lookupPackageScope
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @file parseDataURL
3
+ * @module mlly/utils/parseDataURL
4
+ */
5
+
6
+ import type { ParsedDataUrl } from '#src/interfaces'
7
+ import {
8
+ ERR_INVALID_URL,
9
+ type ErrInvalidUrl,
10
+ type NodeError
11
+ } from '@flex-development/errnode'
12
+ import type { Nullable } from '@flex-development/tutils'
13
+ import type { URL } from 'node:url'
14
+ import toURL from './to-url'
15
+
16
+ /**
17
+ * Parses a [`data:` URL][1].
18
+ *
19
+ * If valid, returns an object representing the given `url`.
20
+ *
21
+ * **Note**: A [MIME type][2] string is required.
22
+ *
23
+ * [1]: https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
24
+ * [2]: https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types
25
+ *
26
+ * @see https://nodejs.org/api/esm.html#data-imports
27
+ *
28
+ * @param {URL | string} url - URL to evaluate
29
+ * @return {ParsedDataUrl} Object representing `url`
30
+ * @throws {ErrInvalidUrl | NodeError<TypeError>} If `url` is not a string or
31
+ * instance of {@linkcode URL}, or if `url` not a valid `data:` URL
32
+ */
33
+ const parseDataURL = (url: URL | string): ParsedDataUrl => {
34
+ // ensure url is an instance of URL
35
+ url = toURL(url)
36
+
37
+ /**
38
+ * Regex to extract `data:` URL components.
39
+ *
40
+ * @see https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
41
+ * @see https://regex101.com/r/Ie8Doq
42
+ *
43
+ * @const {RegExp} regex
44
+ */
45
+ const regex: RegExp =
46
+ /^(?<protocol>data:)(?<mime>[^/]+\/[^,;]+)[^,]*?(?:;(?<base64>base64))?,(?<data>[\S\s]*?)$/
47
+
48
+ /**
49
+ * `data:` URL match.
50
+ *
51
+ * @const {Nullable<RegExpExecArray>} match
52
+ */
53
+ const match: Nullable<RegExpExecArray> = regex.exec(url.href)
54
+
55
+ // throw if url is not data url
56
+ if (!match) throw new ERR_INVALID_URL(url.href)
57
+
58
+ // get data url components
59
+ const [, , mime = '', base64, data = ''] = match
60
+
61
+ return {
62
+ base64: !!base64,
63
+ data: data.trim(),
64
+ href: url.href,
65
+ mime,
66
+ pathname: url.pathname,
67
+ protocol: url.protocol as ParsedDataUrl['protocol']
68
+ }
69
+ }
70
+
71
+ export default parseDataURL
@@ -0,0 +1,186 @@
1
+ /**
2
+ * @file parseModuleId
3
+ * @module mlly/lib/parseModuleId
4
+ */
5
+
6
+ import type { ParseModuleIdOptions, ParsedModuleId } from '#src/interfaces'
7
+ import ENCODED_SEP_REGEX from '#src/internal/regex-encoded-sep'
8
+ import INTERNAL_SPECIFIER_REGEX from '#src/internal/regex-internal-specifier'
9
+ import PACKAGE_PATH_REGEX from '#src/internal/regex-package-path'
10
+ import validateURLString from '#src/internal/validate-url-string'
11
+ import type { ModuleId } from '#src/types'
12
+ import {
13
+ ERR_INVALID_MODULE_SPECIFIER,
14
+ type NodeError
15
+ } from '@flex-development/errnode'
16
+ import { isBuiltin } from '@flex-development/is-builtin'
17
+ import pathe from '@flex-development/pathe'
18
+ import { URL, fileURLToPath } from 'node:url'
19
+ import isBareSpecifier from './is-bare-specifier'
20
+ import isRelativeSpecifier from './is-relative-specifier'
21
+ import toNodeURL from './to-node-url'
22
+
23
+ /**
24
+ * Creates an object representation the given module `id`.
25
+ *
26
+ * @see {@linkcode ModuleId}
27
+ * @see {@linkcode ParseModuleIdOptions}
28
+ * @see {@linkcode ParsedModuleId}
29
+ *
30
+ * @param {ModuleId} id - Module id to parse
31
+ * @param {ParseModuleIdOptions?} [options={}] - Parsing options
32
+ * @return {ParsedModuleId} Object representing `id`
33
+ * @throws {NodeError<TypeError>} If `id` is not an instance of {@linkcode URL}
34
+ * or a string, if `id` includes encoded path separators, or if `id` is invalid
35
+ * according to `options.internal` or `options.pkgname`
36
+ */
37
+ const parseModuleId = (
38
+ id: ModuleId,
39
+ options: ParseModuleIdOptions = {}
40
+ ): ParsedModuleId => {
41
+ const {
42
+ internal = id instanceof URL ? false : id.startsWith('#'),
43
+ pkgname = false
44
+ } = options
45
+
46
+ // ensure id is an instance of URL or a string
47
+ validateURLString(id, 'id')
48
+
49
+ // ensure id a string without leading and trailing spaces
50
+ id = id instanceof URL ? id.href : id.trim()
51
+
52
+ /**
53
+ * Reason for [`ERR_INVALID_MODULE_SPECIFIER`][1], if any.
54
+ *
55
+ * [1]: https://nodejs.org/api/errors.html#err_invalid_module_specifier
56
+ *
57
+ * @const {string | undefined} error
58
+ */
59
+ let error: string | undefined
60
+
61
+ /**
62
+ * Object representing `id`.
63
+ *
64
+ * @var {ParsedModuleId} parsed
65
+ */
66
+ let parsed: ParsedModuleId = {
67
+ internal: false,
68
+ path: id,
69
+ pkg: '',
70
+ protocol: '',
71
+ raw: id,
72
+ scope: '',
73
+ version: '',
74
+ version_prefix: ''
75
+ }
76
+
77
+ // try parsing module id
78
+ switch (true) {
79
+ case ENCODED_SEP_REGEX.test(id):
80
+ error = `must not include encoded '${pathe.sep}' or '\\' characters`
81
+ break
82
+ case isBuiltin(id):
83
+ const { href, protocol, pathname } = new URL(toNodeURL(id))
84
+
85
+ parsed = {
86
+ internal: false,
87
+ path: pathname.replace(/^\S+?(?=\/|$)/, ''),
88
+ pkg: href.replace(/\/.*$/, ''),
89
+ protocol: id.startsWith('node:') ? protocol : '',
90
+ raw: id,
91
+ scope: '',
92
+ version: '',
93
+ version_prefix: ''
94
+ }
95
+
96
+ break
97
+ case INTERNAL_SPECIFIER_REGEX.test(id):
98
+ const [, root = ''] = INTERNAL_SPECIFIER_REGEX.exec(id)!
99
+
100
+ parsed = {
101
+ internal: true,
102
+ path: id,
103
+ pkg: root,
104
+ protocol: '',
105
+ raw: id,
106
+ scope: '',
107
+ version: '',
108
+ version_prefix: ''
109
+ }
110
+
111
+ break
112
+ case PACKAGE_PATH_REGEX.test(id):
113
+ const [
114
+ ,
115
+ pkg = '',
116
+ scope = '',
117
+ version_prefix = '',
118
+ version = '',
119
+ subpath = ''
120
+ ] = PACKAGE_PATH_REGEX.exec(id)!
121
+
122
+ parsed = {
123
+ internal: false,
124
+ path: '.' + subpath,
125
+ pkg,
126
+ protocol: '',
127
+ raw: id,
128
+ scope,
129
+ version,
130
+ version_prefix
131
+ }
132
+
133
+ break
134
+ case /^[\w-]{2,}:/.test(id):
135
+ try {
136
+ const { host, protocol, pathname } = new URL(id)
137
+
138
+ parsed = {
139
+ internal: false,
140
+ path: host + pathname,
141
+ pkg: '',
142
+ protocol,
143
+ raw: id,
144
+ scope: '',
145
+ version: '',
146
+ version_prefix: ''
147
+ }
148
+ } catch {
149
+ error = 'is not a valid URL'
150
+ }
151
+
152
+ break
153
+ case isBareSpecifier(id as string):
154
+ case isRelativeSpecifier(id as string):
155
+ case pathe.isAbsolute(id):
156
+ break
157
+ default:
158
+ error = ''
159
+ break
160
+ }
161
+
162
+ // reset error reason
163
+ error = ENCODED_SEP_REGEX.test(id)
164
+ ? error
165
+ : internal && !INTERNAL_SPECIFIER_REGEX.test(id)
166
+ ? 'is not a valid internal imports specifier name'
167
+ : pkgname && !PACKAGE_PATH_REGEX.test(id)
168
+ ? 'does not start with a valid package name'
169
+ : error
170
+
171
+ // throw if module specifier is invalid
172
+ if (error !== undefined) {
173
+ let { parent } = options
174
+
175
+ if (parent !== undefined) {
176
+ validateURLString(parent, 'options.parent')
177
+ parent = fileURLToPath(parent)
178
+ }
179
+
180
+ throw new ERR_INVALID_MODULE_SPECIFIER(id, error, parent)
181
+ }
182
+
183
+ return parsed
184
+ }
185
+
186
+ export default parseModuleId