@flex-development/mlly 1.0.0-alpha.14 → 1.0.0-alpha.16

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 (239) hide show
  1. package/CHANGELOG.md +203 -0
  2. package/README.md +1 -0
  3. package/dist/enums/assert-type.mjs +1 -7
  4. package/dist/enums/format.mjs +1 -10
  5. package/dist/enums/index.mjs +0 -1
  6. package/dist/enums/kind-specifier-syntax.mjs +1 -7
  7. package/dist/enums/kind-specifier.mjs +1 -8
  8. package/dist/enums/kind-statement-syntax.mjs +1 -15
  9. package/dist/enums/kind-statement.mjs +1 -8
  10. package/dist/index.mjs.map +5 -2
  11. package/dist/interfaces/import-dynamic.d.mts +1 -3
  12. package/dist/interfaces/import-static.d.mts +1 -3
  13. package/dist/interfaces/index.mjs +0 -1
  14. package/dist/interfaces/options-find-subpath.d.mts +4 -3
  15. package/dist/interfaces/options-get-format.d.mts +7 -7
  16. package/dist/interfaces/options-get-source.d.mts +5 -4
  17. package/dist/interfaces/options-parse-module-id.d.mts +4 -3
  18. package/dist/interfaces/options-parse-subpath.d.mts +4 -3
  19. package/dist/interfaces/options-resolve-alias.d.mts +5 -5
  20. package/dist/interfaces/options-resolve-module.d.mts +6 -6
  21. package/dist/internal/dequote.d.mts +14 -0
  22. package/dist/internal/dequote.mjs +6 -0
  23. package/dist/internal/format-type-map.d.mts +2 -0
  24. package/dist/internal/format-type-map.mjs +0 -1
  25. package/dist/internal/get-specifier-kind.d.mts +2 -0
  26. package/dist/internal/get-specifier-kind.mjs +3 -7
  27. package/dist/internal/get-subpaths.d.mts +5 -2
  28. package/dist/internal/get-subpaths.mjs +2 -5
  29. package/dist/internal/regex-encoded-sep.d.mts +2 -0
  30. package/dist/internal/regex-encoded-sep.mjs +0 -1
  31. package/dist/internal/regex-internal-specifier.d.mts +2 -0
  32. package/dist/internal/regex-internal-specifier.mjs +0 -1
  33. package/dist/internal/regex-invalid-segment.d.mts +2 -0
  34. package/dist/internal/regex-invalid-segment.mjs +4 -7
  35. package/dist/internal/regex-package-name.d.mts +2 -0
  36. package/dist/internal/regex-package-name.mjs +0 -1
  37. package/dist/internal/regex-package-path.d.mts +2 -0
  38. package/dist/internal/regex-package-path.mjs +0 -1
  39. package/dist/internal/resolver.d.mts +5 -3
  40. package/dist/internal/resolver.mjs +115 -130
  41. package/dist/internal/validate-array-set.d.mts +7 -5
  42. package/dist/internal/validate-array-set.mjs +5 -5
  43. package/dist/internal/validate-boolean.d.mts +4 -2
  44. package/dist/internal/validate-boolean.mjs +3 -3
  45. package/dist/internal/validate-map.d.mts +10 -7
  46. package/dist/internal/validate-map.mjs +5 -5
  47. package/dist/internal/validate-object.d.mts +9 -9
  48. package/dist/internal/validate-object.mjs +3 -3
  49. package/dist/internal/validate-set.d.mts +7 -5
  50. package/dist/internal/validate-set.mjs +5 -5
  51. package/dist/internal/validate-string.d.mts +5 -2
  52. package/dist/internal/validate-string.mjs +3 -3
  53. package/dist/internal/validate-url-string.d.mts +4 -2
  54. package/dist/internal/validate-url-string.mjs +3 -3
  55. package/dist/types/fn-change-ext.d.mts +7 -4
  56. package/dist/types/index.mjs +0 -1
  57. package/dist/utils/compare-subpaths.mjs +5 -10
  58. package/dist/utils/compare-subpaths.mjs.map +6 -3
  59. package/dist/utils/conditions.mjs.map +5 -2
  60. package/dist/utils/detect-syntax.mjs +1 -2
  61. package/dist/utils/detect-syntax.mjs.map +6 -3
  62. package/dist/utils/extension-format-map.mjs.map +5 -2
  63. package/dist/utils/extract-statements.mjs +6 -7
  64. package/dist/utils/extract-statements.mjs.map +6 -3
  65. package/dist/utils/fill-modules.mjs +43 -46
  66. package/dist/utils/fill-modules.mjs.map +9 -4
  67. package/dist/utils/find-dynamic-imports.mjs +23 -26
  68. package/dist/utils/find-dynamic-imports.mjs.map +9 -4
  69. package/dist/utils/find-exports.mjs +15 -20
  70. package/dist/utils/find-exports.mjs.map +9 -4
  71. package/dist/utils/find-requires.mjs +5 -5
  72. package/dist/utils/find-requires.mjs.map +9 -4
  73. package/dist/utils/find-static-imports.mjs +17 -21
  74. package/dist/utils/find-static-imports.mjs.map +9 -4
  75. package/dist/utils/find-subpath.d.mts +3 -3
  76. package/dist/utils/find-subpath.mjs +52 -74
  77. package/dist/utils/find-subpath.mjs.map +10 -4
  78. package/dist/utils/get-format.mjs +18 -33
  79. package/dist/utils/get-format.mjs.map +9 -4
  80. package/dist/utils/get-source.d.mts +3 -2
  81. package/dist/utils/get-source.mjs +10 -19
  82. package/dist/utils/get-source.mjs.map +6 -3
  83. package/dist/utils/has-cjs-syntax.mjs.map +5 -2
  84. package/dist/utils/has-esm-syntax.mjs.map +5 -2
  85. package/dist/utils/index.d.mts +2 -0
  86. package/dist/utils/index.mjs +46 -42
  87. package/dist/utils/index.mjs.map +9 -4
  88. package/dist/utils/is-absolute-specifier.mjs +5 -6
  89. package/dist/utils/is-absolute-specifier.mjs.map +6 -3
  90. package/dist/utils/is-bare-specifier.mjs +2 -4
  91. package/dist/utils/is-bare-specifier.mjs.map +6 -3
  92. package/dist/utils/is-directory.mjs +14 -0
  93. package/dist/utils/is-directory.mjs.map +9 -0
  94. package/dist/utils/is-exports-sugar.d.mts +3 -2
  95. package/dist/utils/is-exports-sugar.mjs +16 -13
  96. package/dist/utils/is-exports-sugar.mjs.map +6 -3
  97. package/dist/utils/is-file.mjs +14 -0
  98. package/dist/utils/is-file.mjs.map +9 -0
  99. package/dist/utils/is-relative-specifier.d.mts +0 -1
  100. package/dist/utils/is-relative-specifier.mjs +2 -4
  101. package/dist/utils/is-relative-specifier.mjs.map +6 -3
  102. package/dist/utils/lookup-package-scope.d.mts +1 -1
  103. package/dist/utils/lookup-package-scope.mjs +4 -8
  104. package/dist/utils/lookup-package-scope.mjs.map +6 -3
  105. package/dist/utils/parse-data-url.mjs +4 -4
  106. package/dist/utils/parse-data-url.mjs.map +6 -3
  107. package/dist/utils/parse-module-id.mjs +22 -24
  108. package/dist/utils/parse-module-id.mjs.map +10 -4
  109. package/dist/utils/parse-subpath.d.mts +3 -2
  110. package/dist/utils/parse-subpath.mjs +40 -55
  111. package/dist/utils/parse-subpath.mjs.map +9 -4
  112. package/dist/utils/pattern-character.mjs.map +5 -2
  113. package/dist/utils/read-package-json.mjs +12 -9
  114. package/dist/utils/read-package-json.mjs.map +6 -3
  115. package/dist/utils/resolve-alias.mjs +28 -34
  116. package/dist/utils/resolve-alias.mjs.map +10 -4
  117. package/dist/utils/resolve-aliases.mjs +15 -17
  118. package/dist/utils/resolve-aliases.mjs.map +6 -3
  119. package/dist/utils/resolve-extensions.mjs.map +5 -2
  120. package/dist/utils/resolve-module.mjs +10 -26
  121. package/dist/utils/resolve-module.mjs.map +6 -3
  122. package/dist/utils/resolve-modules.mjs +12 -15
  123. package/dist/utils/resolve-modules.mjs.map +6 -3
  124. package/dist/utils/to-absolute-specifier.mjs.map +5 -2
  125. package/dist/utils/to-bare-specifier.mjs +18 -34
  126. package/dist/utils/to-bare-specifier.mjs.map +6 -3
  127. package/dist/utils/to-data-url.mjs +1 -5
  128. package/dist/utils/to-data-url.mjs.map +6 -3
  129. package/dist/utils/to-node-url.mjs +1 -4
  130. package/dist/utils/to-node-url.mjs.map +6 -3
  131. package/dist/utils/to-relative-specifier.mjs +2 -16
  132. package/dist/utils/to-relative-specifier.mjs.map +6 -3
  133. package/dist/utils/to-url.mjs +1 -5
  134. package/dist/utils/to-url.mjs.map +6 -3
  135. package/dist/utils/validate-assertions.d.mts +2 -2
  136. package/dist/utils/validate-assertions.mjs +14 -21
  137. package/dist/utils/validate-assertions.mjs.map +9 -4
  138. package/dist/utils/validate-exports.d.mts +3 -2
  139. package/dist/utils/validate-exports.mjs +25 -24
  140. package/dist/utils/validate-exports.mjs.map +6 -3
  141. package/package.json +89 -81
  142. package/src/interfaces/import-dynamic.ts +1 -3
  143. package/src/interfaces/import-static.ts +1 -5
  144. package/src/interfaces/options-find-subpath.ts +4 -3
  145. package/src/interfaces/options-get-format.ts +7 -7
  146. package/src/interfaces/options-get-source.ts +5 -4
  147. package/src/interfaces/options-parse-module-id.ts +4 -3
  148. package/src/interfaces/options-parse-subpath.ts +4 -3
  149. package/src/interfaces/options-resolve-alias.ts +5 -5
  150. package/src/interfaces/options-resolve-module.ts +6 -6
  151. package/src/internal/dequote.ts +18 -0
  152. package/src/internal/format-type-map.ts +2 -0
  153. package/src/internal/get-specifier-kind.ts +7 -4
  154. package/src/internal/get-subpaths.ts +7 -5
  155. package/src/internal/regex-encoded-sep.ts +2 -0
  156. package/src/internal/regex-internal-specifier.ts +2 -0
  157. package/src/internal/regex-invalid-segment.ts +2 -0
  158. package/src/internal/regex-package-name.ts +2 -0
  159. package/src/internal/regex-package-path.ts +2 -0
  160. package/src/internal/resolver.ts +71 -49
  161. package/src/internal/validate-array-set.ts +10 -7
  162. package/src/internal/validate-boolean.ts +6 -3
  163. package/src/internal/validate-map.ts +12 -9
  164. package/src/internal/validate-object.ts +10 -10
  165. package/src/internal/validate-set.ts +9 -9
  166. package/src/internal/validate-string.ts +7 -3
  167. package/src/internal/validate-url-string.ts +6 -3
  168. package/src/types/fn-change-ext.ts +7 -7
  169. package/src/utils/extract-statements.ts +11 -7
  170. package/src/utils/fill-modules.ts +70 -62
  171. package/src/utils/find-dynamic-imports.ts +6 -6
  172. package/src/utils/find-exports.ts +19 -29
  173. package/src/utils/find-requires.ts +6 -6
  174. package/src/utils/find-static-imports.ts +11 -14
  175. package/src/utils/find-subpath.ts +140 -139
  176. package/src/utils/get-format.ts +27 -21
  177. package/src/utils/get-source.ts +5 -5
  178. package/src/utils/index.ts +2 -0
  179. package/src/utils/is-bare-specifier.ts +2 -1
  180. package/src/{internal → utils}/is-directory.ts +1 -1
  181. package/src/utils/is-exports-sugar.ts +16 -9
  182. package/src/{internal → utils}/is-file.ts +1 -1
  183. package/src/utils/is-relative-specifier.ts +5 -6
  184. package/src/utils/lookup-package-scope.ts +2 -2
  185. package/src/utils/parse-data-url.ts +3 -3
  186. package/src/utils/parse-module-id.ts +16 -8
  187. package/src/utils/parse-subpath.ts +32 -19
  188. package/src/utils/read-package-json.ts +13 -6
  189. package/src/utils/resolve-alias.ts +19 -15
  190. package/src/utils/resolve-aliases.ts +25 -25
  191. package/src/utils/resolve-module.ts +4 -5
  192. package/src/utils/resolve-modules.ts +19 -21
  193. package/src/utils/to-bare-specifier.ts +22 -10
  194. package/src/utils/to-relative-specifier.ts +2 -1
  195. package/src/utils/validate-assertions.ts +12 -7
  196. package/src/utils/validate-exports.ts +25 -18
  197. package/dist/enums/assert-type.mjs.map +0 -6
  198. package/dist/enums/format.mjs.map +0 -6
  199. package/dist/enums/index.mjs.map +0 -6
  200. package/dist/enums/kind-specifier-syntax.mjs.map +0 -6
  201. package/dist/enums/kind-specifier.mjs.map +0 -6
  202. package/dist/enums/kind-statement-syntax.mjs.map +0 -6
  203. package/dist/enums/kind-statement.mjs.map +0 -6
  204. package/dist/interfaces/index.mjs.map +0 -6
  205. package/dist/internal/escape-reg-exp.d.mts +0 -16
  206. package/dist/internal/escape-reg-exp.mjs +0 -10
  207. package/dist/internal/escape-reg-exp.mjs.map +0 -6
  208. package/dist/internal/format-type-map.mjs.map +0 -6
  209. package/dist/internal/get-specifier-kind.mjs.map +0 -6
  210. package/dist/internal/get-subpaths.mjs.map +0 -6
  211. package/dist/internal/is-array-index.d.mts +0 -15
  212. package/dist/internal/is-array-index.mjs +0 -9
  213. package/dist/internal/is-array-index.mjs.map +0 -6
  214. package/dist/internal/is-directory.mjs +0 -16
  215. package/dist/internal/is-directory.mjs.map +0 -6
  216. package/dist/internal/is-file.mjs +0 -16
  217. package/dist/internal/is-file.mjs.map +0 -6
  218. package/dist/internal/is-function.d.mts +0 -12
  219. package/dist/internal/is-function.mjs +0 -8
  220. package/dist/internal/is-function.mjs.map +0 -6
  221. package/dist/internal/regex-encoded-sep.mjs.map +0 -6
  222. package/dist/internal/regex-internal-specifier.mjs.map +0 -6
  223. package/dist/internal/regex-invalid-segment.mjs.map +0 -6
  224. package/dist/internal/regex-package-name.mjs.map +0 -6
  225. package/dist/internal/regex-package-path.mjs.map +0 -6
  226. package/dist/internal/resolver.mjs.map +0 -6
  227. package/dist/internal/validate-array-set.mjs.map +0 -6
  228. package/dist/internal/validate-boolean.mjs.map +0 -6
  229. package/dist/internal/validate-map.mjs.map +0 -6
  230. package/dist/internal/validate-object.mjs.map +0 -6
  231. package/dist/internal/validate-set.mjs.map +0 -6
  232. package/dist/internal/validate-string.mjs.map +0 -6
  233. package/dist/internal/validate-url-string.mjs.map +0 -6
  234. package/dist/types/index.mjs.map +0 -6
  235. package/src/internal/escape-reg-exp.ts +0 -24
  236. package/src/internal/is-array-index.ts +0 -28
  237. package/src/internal/is-function.ts +0 -16
  238. /package/dist/{internal → utils}/is-directory.d.mts +0 -0
  239. /package/dist/{internal → utils}/is-file.d.mts +0 -0
@@ -1,13 +1,17 @@
1
- import CONDITIONS from "../utils/conditions.mjs";
2
- import isExportsSugar from "../utils/is-exports-sugar.mjs";
3
- import isRelativeSpecifier from "../utils/is-relative-specifier.mjs";
4
- import lookupPackageScope from "../utils/lookup-package-scope.mjs";
5
- import parseModuleId from "../utils/parse-module-id.mjs";
6
- import parseSubpath from "../utils/parse-subpath.mjs";
7
- import PATTERN_CHARACTER from "../utils/pattern-character.mjs";
8
- import readPackageJson from "../utils/read-package-json.mjs";
9
- import toNodeURL from "../utils/to-node-url.mjs";
10
- import toURL from "../utils/to-url.mjs";
1
+ import {
2
+ CONDITIONS,
3
+ PATTERN_CHARACTER,
4
+ isDirectory,
5
+ isExportsSugar,
6
+ isFile,
7
+ isRelativeSpecifier,
8
+ lookupPackageScope,
9
+ parseModuleId,
10
+ parseSubpath,
11
+ readPackageJson,
12
+ toNodeURL,
13
+ toURL
14
+ } from "../utils/index.mjs";
11
15
  import {
12
16
  ERR_INVALID_MODULE_SPECIFIER,
13
17
  ERR_INVALID_PACKAGE_CONFIG,
@@ -20,13 +24,23 @@ import {
20
24
  } from "@flex-development/errnode";
21
25
  import { isBuiltin } from "@flex-development/is-builtin";
22
26
  import pathe from "@flex-development/pathe";
23
- import { isNIL } from "@flex-development/tutils";
27
+ import {
28
+ DOT,
29
+ cast,
30
+ get,
31
+ ifelse,
32
+ includes,
33
+ isArray,
34
+ isArrayIndex,
35
+ isNIL,
36
+ isNull,
37
+ isObjectCurly,
38
+ isString,
39
+ join,
40
+ regexp
41
+ } from "@flex-development/tutils";
24
42
  import fs from "node:fs";
25
43
  import { URL, fileURLToPath, pathToFileURL } from "node:url";
26
- import regexp from "./escape-reg-exp.mjs";
27
- import isArrayIndex from "./is-array-index.mjs";
28
- import isDirectory from "./is-directory.mjs";
29
- import isFile from "./is-file.mjs";
30
44
  import invalidSegmentRegex from "./regex-invalid-segment.mjs";
31
45
  import PACKAGE_NAME_REGEX from "./regex-package-name.mjs";
32
46
  import PACKAGE_PATH_REGEX from "./regex-package-path.mjs";
@@ -46,17 +60,16 @@ class Resolver {
46
60
  * @return {URL} Resolved module URL
47
61
  * @throws {NodeError}
48
62
  */
49
- resolveModule(specifier, parent, condition = "default", conditions = CONDITIONS, preserveSymlinks = false) {
63
+ resolveModule(specifier, parent, condition = "default", conditions = CONDITIONS, preserveSymlinks = !1) {
50
64
  parent = toURL(parent);
51
65
  const remote = /^https?:$/.test(parent.protocol);
52
66
  let error = new ERR_MODULE_NOT_FOUND(
53
67
  specifier,
54
68
  remote ? parent.href : fileURLToPath(parent),
55
69
  PACKAGE_PATH_REGEX.test(specifier) ? "package" : "module"
56
- );
57
- let url = null;
70
+ ), url = null;
58
71
  try {
59
- switch (true) {
72
+ switch (!0) {
60
73
  case isRelativeSpecifier(specifier):
61
74
  case pathe.isAbsolute(specifier):
62
75
  url = new URL(specifier, parent);
@@ -73,32 +86,26 @@ class Resolver {
73
86
  try {
74
87
  url = new URL(specifier);
75
88
  } catch {
76
- if (!remote) {
77
- url = this.resolvePackage(
78
- specifier,
79
- parent,
80
- condition,
81
- conditions
82
- );
83
- }
89
+ remote || (url = this.resolvePackage(
90
+ specifier,
91
+ parent,
92
+ condition,
93
+ conditions
94
+ ));
84
95
  }
85
96
  break;
86
97
  }
87
98
  if (url && url.protocol === "file:") {
88
99
  const path = fileURLToPath(url);
89
- if (!isFile(path)) {
100
+ if (!isFile(path))
90
101
  throw isDirectory(path) ? new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(parent)) : new ERR_MODULE_NOT_FOUND(path, fileURLToPath(parent), "module");
91
- }
92
102
  if (!preserveSymlinks) {
93
103
  const { hash, search } = url;
94
- url = pathToFileURL(fs.realpathSync(path));
95
- url.hash = hash;
96
- url.search = search;
104
+ url = pathToFileURL(fs.realpathSync(path)), url.hash = hash, url.search = search;
97
105
  }
98
106
  }
99
107
  } catch (e) {
100
- error = e;
101
- url = null;
108
+ error = cast(e), url = null;
102
109
  }
103
110
  if (!url)
104
111
  throw error;
@@ -128,14 +135,14 @@ class Resolver {
128
135
  });
129
136
  if (isBuiltin(id.raw))
130
137
  return new URL(toNodeURL(id.raw));
131
- const stopdir = pathToFileURL("." + pathe.sep);
138
+ const stopdir = pathToFileURL(DOT + pathe.sep);
132
139
  let scope = lookupPackageScope(
133
140
  parent,
134
141
  stopdir,
135
142
  specifier,
136
143
  parent
137
144
  );
138
- if ((scope == null ? void 0 : scope.pkgjson.name) === id.pkg && !isNIL(scope.pkgjson.exports)) {
145
+ if (scope?.pkgjson.name === id.pkg && !isNIL(scope.pkgjson.exports))
139
146
  return this.resolvePackageExport(
140
147
  id.raw,
141
148
  scope.pkg,
@@ -143,23 +150,18 @@ class Resolver {
143
150
  condition,
144
151
  conditions
145
152
  );
146
- }
147
153
  let url = null;
148
154
  if (scope) {
149
155
  let { dir: pkgdir } = scope;
150
- while (pkgdir !== ".") {
151
- scope = lookupPackageScope(
152
- new URL(`node_modules/${id.raw}`, pkgdir + pathe.sep),
153
- stopdir,
154
- specifier,
155
- parent
156
- );
157
- if (scope)
158
- break;
156
+ for (; pkgdir !== DOT && (scope = lookupPackageScope(
157
+ new URL(`node_modules/${id.raw}`, pkgdir + pathe.sep),
158
+ stopdir,
159
+ specifier,
160
+ parent
161
+ ), !scope); )
159
162
  pkgdir = pathe.dirname(pkgdir);
160
- }
161
163
  }
162
- switch (true) {
164
+ switch (!0) {
163
165
  case (scope && !isNIL(scope.pkgjson.exports)):
164
166
  url = this.resolvePackageExport(
165
167
  specifier,
@@ -169,7 +171,7 @@ class Resolver {
169
171
  conditions
170
172
  );
171
173
  break;
172
- case (scope && id.path === "."):
174
+ case (scope && id.path === DOT):
173
175
  url = this.resolvePackageMain(scope.pkg, scope.pkgjson, parent);
174
176
  break;
175
177
  case !!scope:
@@ -198,23 +200,20 @@ class Resolver {
198
200
  * @throws {NodeError<Error | TypeError>}
199
201
  */
200
202
  resolvePackageExport(specifier, pkg, parent, condition = "default", conditions = CONDITIONS) {
201
- const dir = new URL(".", pkg);
202
- const pkgjson = readPackageJson(
203
+ const dir = new URL(DOT, pkg);
204
+ let exports = readPackageJson(
203
205
  dir,
204
206
  specifier,
205
207
  parent
206
- );
207
- let exports = pkgjson == null ? void 0 : pkgjson.exports;
208
+ )?.exports;
208
209
  const subpath = parseSubpath(specifier, exports, {
209
210
  dir,
210
211
  parent
211
212
  });
212
- if (!subpath.internal && isExportsSugar(exports, pkg, parent)) {
213
- exports = { ".": exports };
214
- }
213
+ !subpath.internal && isExportsSugar(exports, pkg, parent) && (exports = cast({ [DOT]: exports }));
215
214
  const url = this.resolvePackageTarget(
216
215
  dir,
217
- exports == null ? void 0 : exports[subpath.key],
216
+ get(exports, subpath.key),
218
217
  subpath.base,
219
218
  subpath.key,
220
219
  parent,
@@ -222,13 +221,12 @@ class Resolver {
222
221
  condition,
223
222
  conditions
224
223
  );
225
- if (!url) {
224
+ if (!url)
226
225
  throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
227
226
  fileURLToPath(dir),
228
227
  subpath.raw,
229
228
  fileURLToPath(parent)
230
229
  );
231
- }
232
230
  return url;
233
231
  }
234
232
  /**
@@ -249,26 +247,24 @@ class Resolver {
249
247
  */
250
248
  resolvePackageImport(specifier, parent, condition = "default", conditions = CONDITIONS) {
251
249
  const id = parseModuleId(specifier, {
252
- internal: true,
250
+ internal: !0,
253
251
  parent
254
- });
255
- const scope = lookupPackageScope(
252
+ }), scope = lookupPackageScope(
256
253
  parent,
257
- pathToFileURL("."),
254
+ pathToFileURL(DOT),
258
255
  specifier,
259
256
  parent
260
257
  );
261
258
  let url = null;
262
259
  if (scope) {
263
- const imports = scope.pkgjson.imports;
264
- const subpath = parseSubpath(id.raw, imports, {
260
+ const imports = scope.pkgjson.imports, subpath = parseSubpath(id.raw, imports, {
265
261
  dir: scope.dir,
266
- internal: true,
262
+ internal: !0,
267
263
  parent
268
264
  });
269
265
  url = this.resolvePackageTarget(
270
266
  scope.dir,
271
- imports == null ? void 0 : imports[subpath.key],
267
+ get(imports, cast(subpath.key)),
272
268
  subpath.base,
273
269
  subpath.key,
274
270
  parent,
@@ -277,14 +273,13 @@ class Resolver {
277
273
  conditions
278
274
  );
279
275
  }
280
- if (!url) {
276
+ if (!url)
281
277
  throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
282
278
  specifier,
283
279
  fileURLToPath(parent),
284
280
  /* c8 ignore next */
285
- (scope == null ? void 0 : scope.dir) ? fileURLToPath(scope.dir) : void 0
281
+ scope?.dir ? fileURLToPath(scope.dir) : void 0
286
282
  );
287
- }
288
283
  return url;
289
284
  }
290
285
  /**
@@ -327,12 +322,11 @@ class Resolver {
327
322
  break;
328
323
  url = null;
329
324
  }
330
- if (!url) {
325
+ if (!url)
331
326
  throw new ERR_MODULE_NOT_FOUND(
332
- fileURLToPath(new URL(".", pkg)),
327
+ fileURLToPath(new URL(DOT, pkg)),
333
328
  fileURLToPath(parent)
334
329
  );
335
- }
336
330
  return url;
337
331
  }
338
332
  /**
@@ -346,7 +340,7 @@ class Resolver {
346
340
  * @public
347
341
  *
348
342
  * @param {ModuleId} dir - URL of directory containing relevant `package.json`
349
- * @param {Exports | undefined} target - Package `exports` or `imports` target
343
+ * @param {Optional<Exports>} target - Package `exports` or `imports` target
350
344
  * @param {string} subpath - Package subpath without entry prefix (`key`)
351
345
  * @param {string} key - Subpath defined in relevant `package.json` file
352
346
  * @param {ModuleId} parent - URL of module to resolve from
@@ -356,14 +350,14 @@ class Resolver {
356
350
  * @return {Nullable<URL>} Resolved package target URL or `null`
357
351
  * @throws {NodeError<Error | TypeError>}
358
352
  */
359
- resolvePackageTarget(dir, target, subpath, key, parent, internal = false, condition = "default", conditions = CONDITIONS) {
353
+ resolvePackageTarget(dir, target, subpath, key, parent, internal = !1, condition = "default", conditions = CONDITIONS) {
360
354
  let url = null;
361
- switch (true) {
362
- case target === null:
355
+ switch (!0) {
356
+ case isNull(target):
363
357
  break;
364
- case Array.isArray(target):
358
+ case isArray(target):
365
359
  let error;
366
- for (const item of target) {
360
+ for (const item of cast(target)) {
367
361
  try {
368
362
  url = this.resolvePackageTarget(
369
363
  dir,
@@ -376,8 +370,7 @@ class Resolver {
376
370
  conditions
377
371
  );
378
372
  } catch (e) {
379
- error = e;
380
- if (error.code !== ErrorCode.ERR_INVALID_PACKAGE_TARGET)
373
+ if (error = cast(e), error.code !== ErrorCode.ERR_INVALID_PACKAGE_TARGET)
381
374
  throw error;
382
375
  continue;
383
376
  }
@@ -389,36 +382,32 @@ class Resolver {
389
382
  if (error)
390
383
  throw error;
391
384
  break;
392
- case typeof target === "object":
393
- target = target;
385
+ case isObjectCurly(target):
386
+ target = cast(target);
394
387
  for (const prop of Object.getOwnPropertyNames(target)) {
395
- if (isArrayIndex(prop)) {
388
+ if (isArrayIndex(prop))
396
389
  throw new ERR_INVALID_PACKAGE_CONFIG(
397
390
  fileURLToPath(dir).replace(/\/$/, "") + "/package.json",
398
391
  fileURLToPath(parent),
399
392
  '"exports" cannot contain numeric property keys'
400
393
  );
401
- }
402
- if (prop === condition || conditions.has(prop)) {
403
- url = this.resolvePackageTarget(
404
- dir,
405
- target[prop],
406
- subpath,
407
- key,
408
- parent,
409
- internal,
410
- condition,
411
- conditions
412
- );
413
- if (url)
414
- break;
415
- }
394
+ if ((prop === condition || conditions.has(prop)) && (url = this.resolvePackageTarget(
395
+ dir,
396
+ get(target, prop),
397
+ subpath,
398
+ key,
399
+ parent,
400
+ internal,
401
+ condition,
402
+ conditions
403
+ ), url))
404
+ break;
416
405
  }
417
406
  break;
418
- case typeof target === "string":
419
- target = target;
420
- const pattern = key.includes(PATTERN_CHARACTER);
421
- switch (true) {
407
+ case isString(target):
408
+ target = cast(target);
409
+ const pattern = includes(key, PATTERN_CHARACTER);
410
+ switch (!0) {
422
411
  case (subpath && !pattern && !target.endsWith(pathe.sep)):
423
412
  throw new ERR_INVALID_PACKAGE_TARGET(
424
413
  fileURLToPath(dir),
@@ -430,36 +419,33 @@ class Resolver {
430
419
  case (internal && PACKAGE_NAME_REGEX.test(target)):
431
420
  url = this.resolvePackage(target, parent, condition, conditions);
432
421
  break;
433
- case target.startsWith("." + pathe.sep):
434
- if (invalidSegmentRegex().test(target.slice(2))) {
435
- if (invalidSegmentRegex("deprecated").test(target.slice(2))) {
436
- throw new ERR_INVALID_PACKAGE_TARGET(
437
- fileURLToPath(dir),
438
- key,
439
- target,
440
- internal,
441
- fileURLToPath(parent)
442
- );
443
- }
444
- }
445
- url = new URL(
422
+ case target.startsWith(DOT + pathe.sep):
423
+ if (invalidSegmentRegex().test(target.slice(2)) && invalidSegmentRegex("deprecated").test(target.slice(2)))
424
+ throw new ERR_INVALID_PACKAGE_TARGET(
425
+ fileURLToPath(dir),
426
+ key,
427
+ target,
428
+ internal,
429
+ fileURLToPath(parent)
430
+ );
431
+ if (url = new URL(
446
432
  target,
447
433
  pathToFileURL(fileURLToPath(dir).replace(/\/$/, "") + pathe.sep)
448
- );
449
- if (subpath) {
450
- if (invalidSegmentRegex().test(subpath)) {
451
- if (invalidSegmentRegex("deprecated").test(subpath)) {
452
- throw new ERR_INVALID_MODULE_SPECIFIER(
453
- key.replace(PATTERN_CHARACTER, subpath),
434
+ ), subpath) {
435
+ if (invalidSegmentRegex().test(subpath) && invalidSegmentRegex("deprecated").test(subpath))
436
+ throw new ERR_INVALID_MODULE_SPECIFIER(
437
+ key.replace(PATTERN_CHARACTER, subpath),
438
+ join(
454
439
  [
455
440
  `request is not a valid match in pattern "${key}" for`,
456
- `the "${internal ? "imports" : "exports"}" resolution`,
457
- `of ${fileURLToPath(dir).replace(/\/$/, "")}/package.json`
458
- ].join(" "),
459
- fileURLToPath(parent)
460
- );
461
- }
462
- }
441
+ `the "${ifelse(internal, "imports", "exports")}"`,
442
+ "resolution of",
443
+ `${fileURLToPath(dir).replace(/\/$/, "")}/package.json`
444
+ ],
445
+ " "
446
+ ),
447
+ fileURLToPath(parent)
448
+ );
463
449
  url = new URL(
464
450
  url.href.replace(
465
451
  new RegExp(regexp(PATTERN_CHARACTER), "g"),
@@ -494,4 +480,3 @@ var resolver_default = Resolver;
494
480
  export {
495
481
  resolver_default as default
496
482
  };
497
- //# sourceMappingURL=resolver.mjs.map
@@ -3,7 +3,7 @@
3
3
  * @module mlly/internal/validateArraySet
4
4
  */
5
5
  /**
6
- * Checks if given `value` is an array or a {@linkcode Set}.
6
+ * Checks if `value` is an array or an instance of {@linkcode Set}.
7
7
  *
8
8
  * Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is of neither type.
9
9
  *
@@ -11,12 +11,14 @@
11
11
  *
12
12
  * @see {@linkcode ERR_INVALID_ARG_TYPE}
13
13
  *
14
- * @template T - Item type(s)
14
+ * @internal
15
+ *
16
+ * @template T - Item type
15
17
  *
16
18
  * @param {unknown} value - Value supplied by user
17
19
  * @param {string} name - Name of invalid argument or property
18
- * @return {value is Set<T> | T[]} `true` if `value` is array or {@linkcode Set}
19
- * @throws {NodeError<TypeError>} If `value` is not an array or {@linkcode Set}
20
+ * @return {value is Set<T> | T[]} `true` if `value` is array or `Set`
21
+ * @throws {NodeError<TypeError>} If `value` is not an array or `Set`
20
22
  */
21
- declare function validateArraySet<T = unknown>(value: unknown, name: string): value is Set<T> | T[];
23
+ declare const validateArraySet: <T>(value: unknown, name: string) => value is Set<T> | T[];
22
24
  export default validateArraySet;
@@ -1,11 +1,11 @@
1
1
  import { ERR_INVALID_ARG_TYPE } from "@flex-development/errnode";
2
- function validateArraySet(value, name) {
3
- if (Array.isArray(value) || value instanceof Set)
4
- return true;
2
+ import { isArray, isSet } from "@flex-development/tutils";
3
+ const validateArraySet = (value, name) => {
4
+ if (isArray(value) || isSet(value))
5
+ return !0;
5
6
  throw new ERR_INVALID_ARG_TYPE(name, ["Array", "Set"], value);
6
- }
7
+ };
7
8
  var validate_array_set_default = validateArraySet;
8
9
  export {
9
10
  validate_array_set_default as default
10
11
  };
11
- //# sourceMappingURL=validate-array-set.mjs.map
@@ -3,14 +3,16 @@
3
3
  * @module mlly/internal/validateBoolean
4
4
  */
5
5
  /**
6
- * Checks if given `value` is a boolean.
6
+ * Checks if `value` is a boolean.
7
7
  *
8
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not a boolean.
8
+ * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a boolean.
9
9
  *
10
10
  * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
11
11
  *
12
12
  * @see {@linkcode ERR_INVALID_ARG_TYPE}
13
13
  *
14
+ * @internal
15
+ *
14
16
  * @param {unknown} value - Value supplied by user
15
17
  * @param {string} name - Name of invalid argument or property
16
18
  * @return {value is boolean} `true` if `value` is a boolean
@@ -1,11 +1,11 @@
1
1
  import { ERR_INVALID_ARG_TYPE } from "@flex-development/errnode";
2
+ import { isBoolean } from "@flex-development/tutils";
2
3
  const validateBoolean = (value, name) => {
3
- if (typeof value === "boolean")
4
- return true;
4
+ if (isBoolean(value))
5
+ return !0;
5
6
  throw new ERR_INVALID_ARG_TYPE(name, "boolean", value);
6
7
  };
7
8
  var validate_boolean_default = validateBoolean;
8
9
  export {
9
10
  validate_boolean_default as default
10
11
  };
11
- //# sourceMappingURL=validate-boolean.mjs.map
@@ -2,22 +2,25 @@
2
2
  * @file Internal - validateMap
3
3
  * @module mlly/internal/validateMap
4
4
  */
5
+ import { type PropertyKey } from '@flex-development/tutils';
5
6
  /**
6
- * Checks if given `value` is a {@linkcode Map}.
7
+ * Checks if `value` is a {@linkcode Map} instance.
7
8
  *
8
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not a {@linkcode Map}.
9
+ * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a {@linkcode Map}.
9
10
  *
10
11
  * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
11
12
  *
12
13
  * @see {@linkcode ERR_INVALID_ARG_TYPE}
13
14
  *
14
- * @template K - Map key type(s)
15
- * @template V - Item type(s)
15
+ * @internal
16
+ *
17
+ * @template K - Map key type
18
+ * @template V - Map item type
16
19
  *
17
20
  * @param {unknown} value - Value supplied by user
18
21
  * @param {string} name - Name of invalid argument or property
19
- * @return {value is Map<K, V>} `true` if `value` is a {@linkcode Map}
20
- * @throws {NodeError<TypeError>} If `value` is not a {@linkcode Map}
22
+ * @return {value is Map<K, V>} `true` if `value` is a `Map`
23
+ * @throws {NodeError<TypeError>} If `value` is not a `Map`
21
24
  */
22
- declare function validateMap<K extends string = string, V = unknown>(value: unknown, name: string): value is Map<K, V>;
25
+ declare const validateMap: <K = PropertyKey, V = unknown>(value: unknown, name: string) => value is Map<K, V>;
23
26
  export default validateMap;
@@ -1,11 +1,11 @@
1
1
  import { ERR_INVALID_ARG_TYPE } from "@flex-development/errnode";
2
- function validateMap(value, name) {
3
- if (value instanceof Map)
4
- return true;
2
+ import { isMap } from "@flex-development/tutils";
3
+ const validateMap = (value, name) => {
4
+ if (isMap(value))
5
+ return !0;
5
6
  throw new ERR_INVALID_ARG_TYPE(name, ["Map"], value);
6
- }
7
+ };
7
8
  var validate_map_default = validateMap;
8
9
  export {
9
10
  validate_map_default as default
10
11
  };
11
- //# sourceMappingURL=validate-map.mjs.map
@@ -2,22 +2,22 @@
2
2
  * @file Internal - validateObject
3
3
  * @module mlly/internal/validateObject
4
4
  */
5
- import type { ObjectPlain } from '@flex-development/tutils';
5
+ import { type ObjectCurly } from '@flex-development/tutils';
6
6
  /**
7
- * Checks if given `value` is an object.
7
+ * Checks if `value` is a curly-braced object.
8
8
  *
9
- * **Note**: Array values are not considered objects.
10
- *
11
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not an object.
9
+ * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a curly-braced object.
12
10
  *
13
11
  * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
14
12
  *
15
- * @see {@linkcode ERR_INVALID_ARG_TYPE}
13
+ * @see {@linkcode isObjectCurly}
14
+ *
15
+ * @internal
16
16
  *
17
17
  * @param {unknown} value - Value supplied by user
18
18
  * @param {string} name - Name of invalid argument or property
19
- * @return {value is ObjectPlain} `true` if `value` is an object
20
- * @throws {NodeError<TypeError>} If `value` is not an object
19
+ * @return {value is ObjectCurly} `true` if `value` is a curly-braced object
20
+ * @throws {NodeError<TypeError>} If `value` is not a curly-braced object
21
21
  */
22
- declare const validateObject: (value: unknown, name: string) => value is ObjectPlain;
22
+ declare const validateObject: (value: unknown, name: string) => value is ObjectCurly;
23
23
  export default validateObject;
@@ -1,11 +1,11 @@
1
1
  import { ERR_INVALID_ARG_TYPE } from "@flex-development/errnode";
2
+ import { isObjectCurly } from "@flex-development/tutils";
2
3
  const validateObject = (value, name) => {
3
- if (typeof value === "object" && value && !Array.isArray(value))
4
- return true;
4
+ if (isObjectCurly(value))
5
+ return !0;
5
6
  throw new ERR_INVALID_ARG_TYPE(name, "object", value);
6
7
  };
7
8
  var validate_object_default = validateObject;
8
9
  export {
9
10
  validate_object_default as default
10
11
  };
11
- //# sourceMappingURL=validate-object.mjs.map
@@ -5,18 +5,20 @@
5
5
  /**
6
6
  * Checks if given `value` is a {@linkcode Set}.
7
7
  *
8
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not a {@linkcode Set}.
8
+ * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a {@linkcode Set}.
9
9
  *
10
10
  * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
11
11
  *
12
12
  * @see {@linkcode ERR_INVALID_ARG_TYPE}
13
13
  *
14
- * @template T - Item type(s)
14
+ * @internal
15
+ *
16
+ * @template T - Set item type
15
17
  *
16
18
  * @param {unknown} value - Value supplied by user
17
19
  * @param {string} name - Name of invalid argument or property
18
- * @return {value is Set<T>} `true` if `value` is a {@linkcode Set}
19
- * @throws {NodeError<TypeError>} If `value` is not a {@linkcode Set}
20
+ * @return {value is Set<T>} `true` if `value` is a `Set`
21
+ * @throws {NodeError<TypeError>} If `value` is not a `Set`
20
22
  */
21
- declare function validateSet<T = unknown>(value: unknown, name: string): value is Set<T>;
23
+ declare const validateSet: <T>(value: unknown, name: string) => value is Set<T>;
22
24
  export default validateSet;
@@ -1,11 +1,11 @@
1
1
  import { ERR_INVALID_ARG_TYPE } from "@flex-development/errnode";
2
- function validateSet(value, name) {
3
- if (value instanceof Set)
4
- return true;
2
+ import { isSet } from "@flex-development/tutils";
3
+ const validateSet = (value, name) => {
4
+ if (isSet(value))
5
+ return !0;
5
6
  throw new ERR_INVALID_ARG_TYPE(name, ["Set"], value);
6
- }
7
+ };
7
8
  var validate_set_default = validateSet;
8
9
  export {
9
10
  validate_set_default as default
10
11
  };
11
- //# sourceMappingURL=validate-set.mjs.map