@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.
- package/CHANGELOG.md +203 -0
- package/README.md +1 -0
- package/dist/enums/assert-type.mjs +1 -7
- package/dist/enums/format.mjs +1 -10
- package/dist/enums/index.mjs +0 -1
- package/dist/enums/kind-specifier-syntax.mjs +1 -7
- package/dist/enums/kind-specifier.mjs +1 -8
- package/dist/enums/kind-statement-syntax.mjs +1 -15
- package/dist/enums/kind-statement.mjs +1 -8
- package/dist/index.mjs.map +5 -2
- package/dist/interfaces/import-dynamic.d.mts +1 -3
- package/dist/interfaces/import-static.d.mts +1 -3
- package/dist/interfaces/index.mjs +0 -1
- package/dist/interfaces/options-find-subpath.d.mts +4 -3
- package/dist/interfaces/options-get-format.d.mts +7 -7
- package/dist/interfaces/options-get-source.d.mts +5 -4
- package/dist/interfaces/options-parse-module-id.d.mts +4 -3
- package/dist/interfaces/options-parse-subpath.d.mts +4 -3
- package/dist/interfaces/options-resolve-alias.d.mts +5 -5
- package/dist/interfaces/options-resolve-module.d.mts +6 -6
- package/dist/internal/dequote.d.mts +14 -0
- package/dist/internal/dequote.mjs +6 -0
- package/dist/internal/format-type-map.d.mts +2 -0
- package/dist/internal/format-type-map.mjs +0 -1
- package/dist/internal/get-specifier-kind.d.mts +2 -0
- package/dist/internal/get-specifier-kind.mjs +3 -7
- package/dist/internal/get-subpaths.d.mts +5 -2
- package/dist/internal/get-subpaths.mjs +2 -5
- package/dist/internal/regex-encoded-sep.d.mts +2 -0
- package/dist/internal/regex-encoded-sep.mjs +0 -1
- package/dist/internal/regex-internal-specifier.d.mts +2 -0
- package/dist/internal/regex-internal-specifier.mjs +0 -1
- package/dist/internal/regex-invalid-segment.d.mts +2 -0
- package/dist/internal/regex-invalid-segment.mjs +4 -7
- package/dist/internal/regex-package-name.d.mts +2 -0
- package/dist/internal/regex-package-name.mjs +0 -1
- package/dist/internal/regex-package-path.d.mts +2 -0
- package/dist/internal/regex-package-path.mjs +0 -1
- package/dist/internal/resolver.d.mts +5 -3
- package/dist/internal/resolver.mjs +115 -130
- package/dist/internal/validate-array-set.d.mts +7 -5
- package/dist/internal/validate-array-set.mjs +5 -5
- package/dist/internal/validate-boolean.d.mts +4 -2
- package/dist/internal/validate-boolean.mjs +3 -3
- package/dist/internal/validate-map.d.mts +10 -7
- package/dist/internal/validate-map.mjs +5 -5
- package/dist/internal/validate-object.d.mts +9 -9
- package/dist/internal/validate-object.mjs +3 -3
- package/dist/internal/validate-set.d.mts +7 -5
- package/dist/internal/validate-set.mjs +5 -5
- package/dist/internal/validate-string.d.mts +5 -2
- package/dist/internal/validate-string.mjs +3 -3
- package/dist/internal/validate-url-string.d.mts +4 -2
- package/dist/internal/validate-url-string.mjs +3 -3
- package/dist/types/fn-change-ext.d.mts +7 -4
- package/dist/types/index.mjs +0 -1
- package/dist/utils/compare-subpaths.mjs +5 -10
- package/dist/utils/compare-subpaths.mjs.map +6 -3
- package/dist/utils/conditions.mjs.map +5 -2
- package/dist/utils/detect-syntax.mjs +1 -2
- package/dist/utils/detect-syntax.mjs.map +6 -3
- package/dist/utils/extension-format-map.mjs.map +5 -2
- package/dist/utils/extract-statements.mjs +6 -7
- package/dist/utils/extract-statements.mjs.map +6 -3
- package/dist/utils/fill-modules.mjs +43 -46
- package/dist/utils/fill-modules.mjs.map +9 -4
- package/dist/utils/find-dynamic-imports.mjs +23 -26
- package/dist/utils/find-dynamic-imports.mjs.map +9 -4
- package/dist/utils/find-exports.mjs +15 -20
- package/dist/utils/find-exports.mjs.map +9 -4
- package/dist/utils/find-requires.mjs +5 -5
- package/dist/utils/find-requires.mjs.map +9 -4
- package/dist/utils/find-static-imports.mjs +17 -21
- package/dist/utils/find-static-imports.mjs.map +9 -4
- package/dist/utils/find-subpath.d.mts +3 -3
- package/dist/utils/find-subpath.mjs +52 -74
- package/dist/utils/find-subpath.mjs.map +10 -4
- package/dist/utils/get-format.mjs +18 -33
- package/dist/utils/get-format.mjs.map +9 -4
- package/dist/utils/get-source.d.mts +3 -2
- package/dist/utils/get-source.mjs +10 -19
- package/dist/utils/get-source.mjs.map +6 -3
- package/dist/utils/has-cjs-syntax.mjs.map +5 -2
- package/dist/utils/has-esm-syntax.mjs.map +5 -2
- package/dist/utils/index.d.mts +2 -0
- package/dist/utils/index.mjs +46 -42
- package/dist/utils/index.mjs.map +9 -4
- package/dist/utils/is-absolute-specifier.mjs +5 -6
- package/dist/utils/is-absolute-specifier.mjs.map +6 -3
- package/dist/utils/is-bare-specifier.mjs +2 -4
- package/dist/utils/is-bare-specifier.mjs.map +6 -3
- package/dist/utils/is-directory.mjs +14 -0
- package/dist/utils/is-directory.mjs.map +9 -0
- package/dist/utils/is-exports-sugar.d.mts +3 -2
- package/dist/utils/is-exports-sugar.mjs +16 -13
- package/dist/utils/is-exports-sugar.mjs.map +6 -3
- package/dist/utils/is-file.mjs +14 -0
- package/dist/utils/is-file.mjs.map +9 -0
- package/dist/utils/is-relative-specifier.d.mts +0 -1
- package/dist/utils/is-relative-specifier.mjs +2 -4
- package/dist/utils/is-relative-specifier.mjs.map +6 -3
- package/dist/utils/lookup-package-scope.d.mts +1 -1
- package/dist/utils/lookup-package-scope.mjs +4 -8
- package/dist/utils/lookup-package-scope.mjs.map +6 -3
- package/dist/utils/parse-data-url.mjs +4 -4
- package/dist/utils/parse-data-url.mjs.map +6 -3
- package/dist/utils/parse-module-id.mjs +22 -24
- package/dist/utils/parse-module-id.mjs.map +10 -4
- package/dist/utils/parse-subpath.d.mts +3 -2
- package/dist/utils/parse-subpath.mjs +40 -55
- package/dist/utils/parse-subpath.mjs.map +9 -4
- package/dist/utils/pattern-character.mjs.map +5 -2
- package/dist/utils/read-package-json.mjs +12 -9
- package/dist/utils/read-package-json.mjs.map +6 -3
- package/dist/utils/resolve-alias.mjs +28 -34
- package/dist/utils/resolve-alias.mjs.map +10 -4
- package/dist/utils/resolve-aliases.mjs +15 -17
- package/dist/utils/resolve-aliases.mjs.map +6 -3
- package/dist/utils/resolve-extensions.mjs.map +5 -2
- package/dist/utils/resolve-module.mjs +10 -26
- package/dist/utils/resolve-module.mjs.map +6 -3
- package/dist/utils/resolve-modules.mjs +12 -15
- package/dist/utils/resolve-modules.mjs.map +6 -3
- package/dist/utils/to-absolute-specifier.mjs.map +5 -2
- package/dist/utils/to-bare-specifier.mjs +18 -34
- package/dist/utils/to-bare-specifier.mjs.map +6 -3
- package/dist/utils/to-data-url.mjs +1 -5
- package/dist/utils/to-data-url.mjs.map +6 -3
- package/dist/utils/to-node-url.mjs +1 -4
- package/dist/utils/to-node-url.mjs.map +6 -3
- package/dist/utils/to-relative-specifier.mjs +2 -16
- package/dist/utils/to-relative-specifier.mjs.map +6 -3
- package/dist/utils/to-url.mjs +1 -5
- package/dist/utils/to-url.mjs.map +6 -3
- package/dist/utils/validate-assertions.d.mts +2 -2
- package/dist/utils/validate-assertions.mjs +14 -21
- package/dist/utils/validate-assertions.mjs.map +9 -4
- package/dist/utils/validate-exports.d.mts +3 -2
- package/dist/utils/validate-exports.mjs +25 -24
- package/dist/utils/validate-exports.mjs.map +6 -3
- package/package.json +89 -81
- package/src/interfaces/import-dynamic.ts +1 -3
- package/src/interfaces/import-static.ts +1 -5
- package/src/interfaces/options-find-subpath.ts +4 -3
- package/src/interfaces/options-get-format.ts +7 -7
- package/src/interfaces/options-get-source.ts +5 -4
- package/src/interfaces/options-parse-module-id.ts +4 -3
- package/src/interfaces/options-parse-subpath.ts +4 -3
- package/src/interfaces/options-resolve-alias.ts +5 -5
- package/src/interfaces/options-resolve-module.ts +6 -6
- package/src/internal/dequote.ts +18 -0
- package/src/internal/format-type-map.ts +2 -0
- package/src/internal/get-specifier-kind.ts +7 -4
- package/src/internal/get-subpaths.ts +7 -5
- package/src/internal/regex-encoded-sep.ts +2 -0
- package/src/internal/regex-internal-specifier.ts +2 -0
- package/src/internal/regex-invalid-segment.ts +2 -0
- package/src/internal/regex-package-name.ts +2 -0
- package/src/internal/regex-package-path.ts +2 -0
- package/src/internal/resolver.ts +71 -49
- package/src/internal/validate-array-set.ts +10 -7
- package/src/internal/validate-boolean.ts +6 -3
- package/src/internal/validate-map.ts +12 -9
- package/src/internal/validate-object.ts +10 -10
- package/src/internal/validate-set.ts +9 -9
- package/src/internal/validate-string.ts +7 -3
- package/src/internal/validate-url-string.ts +6 -3
- package/src/types/fn-change-ext.ts +7 -7
- package/src/utils/extract-statements.ts +11 -7
- package/src/utils/fill-modules.ts +70 -62
- package/src/utils/find-dynamic-imports.ts +6 -6
- package/src/utils/find-exports.ts +19 -29
- package/src/utils/find-requires.ts +6 -6
- package/src/utils/find-static-imports.ts +11 -14
- package/src/utils/find-subpath.ts +140 -139
- package/src/utils/get-format.ts +27 -21
- package/src/utils/get-source.ts +5 -5
- package/src/utils/index.ts +2 -0
- package/src/utils/is-bare-specifier.ts +2 -1
- package/src/{internal → utils}/is-directory.ts +1 -1
- package/src/utils/is-exports-sugar.ts +16 -9
- package/src/{internal → utils}/is-file.ts +1 -1
- package/src/utils/is-relative-specifier.ts +5 -6
- package/src/utils/lookup-package-scope.ts +2 -2
- package/src/utils/parse-data-url.ts +3 -3
- package/src/utils/parse-module-id.ts +16 -8
- package/src/utils/parse-subpath.ts +32 -19
- package/src/utils/read-package-json.ts +13 -6
- package/src/utils/resolve-alias.ts +19 -15
- package/src/utils/resolve-aliases.ts +25 -25
- package/src/utils/resolve-module.ts +4 -5
- package/src/utils/resolve-modules.ts +19 -21
- package/src/utils/to-bare-specifier.ts +22 -10
- package/src/utils/to-relative-specifier.ts +2 -1
- package/src/utils/validate-assertions.ts +12 -7
- package/src/utils/validate-exports.ts +25 -18
- package/dist/enums/assert-type.mjs.map +0 -6
- package/dist/enums/format.mjs.map +0 -6
- package/dist/enums/index.mjs.map +0 -6
- package/dist/enums/kind-specifier-syntax.mjs.map +0 -6
- package/dist/enums/kind-specifier.mjs.map +0 -6
- package/dist/enums/kind-statement-syntax.mjs.map +0 -6
- package/dist/enums/kind-statement.mjs.map +0 -6
- package/dist/interfaces/index.mjs.map +0 -6
- package/dist/internal/escape-reg-exp.d.mts +0 -16
- package/dist/internal/escape-reg-exp.mjs +0 -10
- package/dist/internal/escape-reg-exp.mjs.map +0 -6
- package/dist/internal/format-type-map.mjs.map +0 -6
- package/dist/internal/get-specifier-kind.mjs.map +0 -6
- package/dist/internal/get-subpaths.mjs.map +0 -6
- package/dist/internal/is-array-index.d.mts +0 -15
- package/dist/internal/is-array-index.mjs +0 -9
- package/dist/internal/is-array-index.mjs.map +0 -6
- package/dist/internal/is-directory.mjs +0 -16
- package/dist/internal/is-directory.mjs.map +0 -6
- package/dist/internal/is-file.mjs +0 -16
- package/dist/internal/is-file.mjs.map +0 -6
- package/dist/internal/is-function.d.mts +0 -12
- package/dist/internal/is-function.mjs +0 -8
- package/dist/internal/is-function.mjs.map +0 -6
- package/dist/internal/regex-encoded-sep.mjs.map +0 -6
- package/dist/internal/regex-internal-specifier.mjs.map +0 -6
- package/dist/internal/regex-invalid-segment.mjs.map +0 -6
- package/dist/internal/regex-package-name.mjs.map +0 -6
- package/dist/internal/regex-package-path.mjs.map +0 -6
- package/dist/internal/resolver.mjs.map +0 -6
- package/dist/internal/validate-array-set.mjs.map +0 -6
- package/dist/internal/validate-boolean.mjs.map +0 -6
- package/dist/internal/validate-map.mjs.map +0 -6
- package/dist/internal/validate-object.mjs.map +0 -6
- package/dist/internal/validate-set.mjs.map +0 -6
- package/dist/internal/validate-string.mjs.map +0 -6
- package/dist/internal/validate-url-string.mjs.map +0 -6
- package/dist/types/index.mjs.map +0 -6
- package/src/internal/escape-reg-exp.ts +0 -24
- package/src/internal/is-array-index.ts +0 -28
- package/src/internal/is-function.ts +0 -16
- /package/dist/{internal → utils}/is-directory.d.mts +0 -0
- /package/dist/{internal → utils}/is-file.d.mts +0 -0
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 {
|
|
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 =
|
|
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 (
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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(
|
|
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 (
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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 (
|
|
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(
|
|
202
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
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:
|
|
262
|
+
internal: !0,
|
|
267
263
|
parent
|
|
268
264
|
});
|
|
269
265
|
url = this.resolvePackageTarget(
|
|
270
266
|
scope.dir,
|
|
271
|
-
imports
|
|
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
|
-
|
|
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(
|
|
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
|
|
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 =
|
|
353
|
+
resolvePackageTarget(dir, target, subpath, key, parent, internal = !1, condition = "default", conditions = CONDITIONS) {
|
|
360
354
|
let url = null;
|
|
361
|
-
switch (
|
|
362
|
-
case target
|
|
355
|
+
switch (!0) {
|
|
356
|
+
case isNull(target):
|
|
363
357
|
break;
|
|
364
|
-
case
|
|
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
|
|
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
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
|
419
|
-
target = target;
|
|
420
|
-
const pattern =
|
|
421
|
-
switch (
|
|
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(
|
|
434
|
-
if (invalidSegmentRegex().test(target.slice(2)))
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
|
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
|
-
* @
|
|
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
|
|
19
|
-
* @throws {NodeError<TypeError>} If `value` is not an array or
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
6
|
+
* Checks if `value` is a boolean.
|
|
7
7
|
*
|
|
8
|
-
* Throws [`ERR_INVALID_ARG_TYPE`][1] if
|
|
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 (
|
|
4
|
-
return
|
|
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
|
|
7
|
+
* Checks if `value` is a {@linkcode Map} instance.
|
|
7
8
|
*
|
|
8
|
-
* Throws [`ERR_INVALID_ARG_TYPE`][1] if
|
|
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
|
-
* @
|
|
15
|
-
*
|
|
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
|
|
20
|
-
* @throws {NodeError<TypeError>} If `value` is not a
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
5
|
+
import { type ObjectCurly } from '@flex-development/tutils';
|
|
6
6
|
/**
|
|
7
|
-
* Checks if
|
|
7
|
+
* Checks if `value` is a curly-braced object.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
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
|
|
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
|
|
20
|
-
* @throws {NodeError<TypeError>} If `value` is not
|
|
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
|
|
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 (
|
|
4
|
-
return
|
|
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
|
|
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
|
-
* @
|
|
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
|
|
19
|
-
* @throws {NodeError<TypeError>} If `value` is not a
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|