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