@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
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Internal - PACKAGE_NAME_REGEX
|
|
3
|
-
* @module mlly/internal/PACKAGE_NAME_REGEX
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Regex pattern matching package names.
|
|
7
|
-
*
|
|
8
|
-
* @see https://regex101.com/r/BHcJfc
|
|
9
|
-
*
|
|
10
|
-
* @const {RegExp} PACKAGE_NAME_REGEX
|
|
11
|
-
*/
|
|
12
|
-
declare const PACKAGE_NAME_REGEX: RegExp;
|
|
13
|
-
export default PACKAGE_NAME_REGEX;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Internal - PACKAGE_PATH_REGEX
|
|
3
|
-
* @module mlly/internal/PACKAGE_PATH_REGEX
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Regex pattern matching bare specifiers beginning with valid package names.
|
|
7
|
-
*
|
|
8
|
-
* **Note**: Does **not** match specifiers beginning with `'node_modules'`.
|
|
9
|
-
*
|
|
10
|
-
* @see https://regex101.com/r/z0MPgj
|
|
11
|
-
*
|
|
12
|
-
* @const {RegExp} PACKAGE_PATH_REGEX
|
|
13
|
-
*/
|
|
14
|
-
declare const PACKAGE_PATH_REGEX: RegExp;
|
|
15
|
-
export default PACKAGE_PATH_REGEX;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
const PACKAGE_PATH_REGEX = /^(?!\S+:|node_modules)(?<pkg>(?:(?:(?<scope>@[\d*a-z~-][\w*.~-]*)\/)?[\da-z~-][\w.~-]*))@?(?<version_prefix>v)?(?<version>(?:(?:0|[1-9]\d*)\.){2}(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?)?(?<subpath>\/.*)?(?<!.*(?:%2[Ff]|%5[Cc]))/;
|
|
2
|
-
var regex_package_path_default = PACKAGE_PATH_REGEX;
|
|
3
|
-
export {
|
|
4
|
-
regex_package_path_default as default
|
|
5
|
-
};
|
|
6
|
-
//# sourceMappingURL=regex-package-path.mjs.map
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Internal - Resolver
|
|
3
|
-
* @module mlly/internal/Resolver
|
|
4
|
-
*/
|
|
5
|
-
/// <reference types="node" />
|
|
6
|
-
import type { ModuleId } from '../types/index.mjs';
|
|
7
|
-
import type { Exports, PackageJson } from '@flex-development/pkg-types';
|
|
8
|
-
import { type Nullable } from '@flex-development/tutils';
|
|
9
|
-
import { URL } from 'node:url';
|
|
10
|
-
/**
|
|
11
|
-
* ECMAScript (ES) module resolver.
|
|
12
|
-
*
|
|
13
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm
|
|
14
|
-
*
|
|
15
|
-
* @class
|
|
16
|
-
*/
|
|
17
|
-
declare class Resolver {
|
|
18
|
-
/**
|
|
19
|
-
* Resolves `specifier` according to the [ESM Resolver algorithm][1].
|
|
20
|
-
*
|
|
21
|
-
* [1]: https://nodejs.org/api/esm.html#esm_resolver_algorithm
|
|
22
|
-
*
|
|
23
|
-
* @public
|
|
24
|
-
*
|
|
25
|
-
* @param {string} specifier - Module specifier to resolve
|
|
26
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
27
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
28
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
29
|
-
* @param {boolean?} [preserveSymlinks=false] - Skip resolving symlinks
|
|
30
|
-
* @return {URL} Resolved module URL
|
|
31
|
-
* @throws {NodeError}
|
|
32
|
-
*/
|
|
33
|
-
resolveModule(specifier: string, parent: ModuleId, condition?: string, conditions?: Set<string>, preserveSymlinks?: boolean): URL;
|
|
34
|
-
/**
|
|
35
|
-
* Resolves a package path using a combination of the following algorithms:
|
|
36
|
-
*
|
|
37
|
-
* - `PACKAGE_RESOLVE`
|
|
38
|
-
* - `PACKAGE_SELF_RESOLVE`
|
|
39
|
-
*
|
|
40
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
41
|
-
*
|
|
42
|
-
* @public
|
|
43
|
-
*
|
|
44
|
-
* @param {string} specifier - Module specifier to resolve
|
|
45
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
46
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
47
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
48
|
-
* @return {URL} Resolved package path URL
|
|
49
|
-
* @throws {NodeError}
|
|
50
|
-
*/
|
|
51
|
-
resolvePackage(specifier: string, parent: ModuleId, condition?: string, conditions?: Set<string>): URL;
|
|
52
|
-
/**
|
|
53
|
-
* Resolves a subpath export according to the `PACKAGE_EXPORTS_RESOLVE`
|
|
54
|
-
* algorithm.
|
|
55
|
-
*
|
|
56
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
57
|
-
* @see https://nodejs.org/api/packages.html#subpath-exports
|
|
58
|
-
*
|
|
59
|
-
* @public
|
|
60
|
-
*
|
|
61
|
-
* @param {string} specifier - Module specifier containing subpath
|
|
62
|
-
* @param {ModuleId} pkg - URL of relevant `package.json` file
|
|
63
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
64
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
65
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
66
|
-
* @return {URL} Resolved package export URL
|
|
67
|
-
* @throws {NodeError<Error | TypeError>}
|
|
68
|
-
*/
|
|
69
|
-
resolvePackageExport(specifier: string, pkg: ModuleId, parent: ModuleId, condition?: string, conditions?: Set<string>): URL;
|
|
70
|
-
/**
|
|
71
|
-
* Resolves a subpath import according to the `PACKAGE_IMPORTS_RESOLVE`
|
|
72
|
-
* algorithm.
|
|
73
|
-
*
|
|
74
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
75
|
-
* @see https://nodejs.org/api/packages.html#subpath-imports
|
|
76
|
-
*
|
|
77
|
-
* @public
|
|
78
|
-
*
|
|
79
|
-
* @param {string} specifier - Module specifier containing subpath
|
|
80
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
81
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
82
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
83
|
-
* @return {URL} Resolved package import URL
|
|
84
|
-
* @throws {NodeError<Error | TypeError>}
|
|
85
|
-
*/
|
|
86
|
-
resolvePackageImport(specifier: string, parent: ModuleId, condition?: string, conditions?: Set<string>): URL;
|
|
87
|
-
/**
|
|
88
|
-
* Resolves a package entry point using the legacy CommonJS `main` resolution
|
|
89
|
-
* alogirthm:
|
|
90
|
-
*
|
|
91
|
-
* 1. let M = pkgdir `pkgjson.main`
|
|
92
|
-
* 2. TRY(M, M.js, M.json, M.node, M/index.js, M/index.json, M/index.node)
|
|
93
|
-
* 4. TRY(pkgdir/index.js, pkgdir/index.json, pkgdir/index.node)
|
|
94
|
-
* 5. ERR_MODULE_NOT_FOUND
|
|
95
|
-
*
|
|
96
|
-
* @todo emit deprecation messages
|
|
97
|
-
*
|
|
98
|
-
* @public
|
|
99
|
-
*
|
|
100
|
-
* @param {ModuleId} pkg - URL of relevant `package.json` file
|
|
101
|
-
* @param {PackageJson} pkgjson - Relevant `package.json` object
|
|
102
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
103
|
-
* @return {URL} Package entry point URL
|
|
104
|
-
* @throws {NodeError} If package entry point is not found
|
|
105
|
-
*/
|
|
106
|
-
resolvePackageMain(pkg: ModuleId, pkgjson: PackageJson, parent: ModuleId): URL;
|
|
107
|
-
/**
|
|
108
|
-
* Resolves a package target according to the `PACKAGE_TARGET_RESOLVE`
|
|
109
|
-
* algorithm.
|
|
110
|
-
*
|
|
111
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
112
|
-
*
|
|
113
|
-
* @todo emit deprecation messages
|
|
114
|
-
*
|
|
115
|
-
* @public
|
|
116
|
-
*
|
|
117
|
-
* @param {ModuleId} dir - URL of directory containing relevant `package.json`
|
|
118
|
-
* @param {Exports | undefined} target - Package `exports` or `imports` target
|
|
119
|
-
* @param {string} subpath - Package subpath without entry prefix (`key`)
|
|
120
|
-
* @param {string} key - Subpath defined in relevant `package.json` file
|
|
121
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
122
|
-
* @param {boolean?} [internal=false] - Package `imports` hint
|
|
123
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
124
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
125
|
-
* @return {Nullable<URL>} Resolved package target URL or `null`
|
|
126
|
-
* @throws {NodeError<Error | TypeError>}
|
|
127
|
-
*/
|
|
128
|
-
resolvePackageTarget(dir: ModuleId, target: Exports | undefined, subpath: string, key: string, parent: ModuleId, internal?: boolean, condition?: string, conditions?: Set<string>): Nullable<URL>;
|
|
129
|
-
}
|
|
130
|
-
export default Resolver;
|
|
@@ -1,500 +0,0 @@
|
|
|
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";
|
|
11
|
-
import {
|
|
12
|
-
ERR_INVALID_MODULE_SPECIFIER,
|
|
13
|
-
ERR_INVALID_PACKAGE_CONFIG,
|
|
14
|
-
ERR_INVALID_PACKAGE_TARGET,
|
|
15
|
-
ERR_MODULE_NOT_FOUND,
|
|
16
|
-
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
17
|
-
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
18
|
-
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
19
|
-
ErrorCode
|
|
20
|
-
} from "@flex-development/errnode";
|
|
21
|
-
import { isBuiltin } from "@flex-development/is-builtin";
|
|
22
|
-
import pathe from "@flex-development/pathe";
|
|
23
|
-
import { isNIL } from "@flex-development/tutils";
|
|
24
|
-
import fs from "node:fs";
|
|
25
|
-
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
|
-
import PACKAGE_NAME_REGEX from "./regex-package-name.mjs";
|
|
31
|
-
import PACKAGE_PATH_REGEX from "./regex-package-path.mjs";
|
|
32
|
-
class Resolver {
|
|
33
|
-
/**
|
|
34
|
-
* Resolves `specifier` according to the [ESM Resolver algorithm][1].
|
|
35
|
-
*
|
|
36
|
-
* [1]: https://nodejs.org/api/esm.html#esm_resolver_algorithm
|
|
37
|
-
*
|
|
38
|
-
* @public
|
|
39
|
-
*
|
|
40
|
-
* @param {string} specifier - Module specifier to resolve
|
|
41
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
42
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
43
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
44
|
-
* @param {boolean?} [preserveSymlinks=false] - Skip resolving symlinks
|
|
45
|
-
* @return {URL} Resolved module URL
|
|
46
|
-
* @throws {NodeError}
|
|
47
|
-
*/
|
|
48
|
-
resolveModule(specifier, parent, condition = "default", conditions = CONDITIONS, preserveSymlinks = false) {
|
|
49
|
-
parent = toURL(parent);
|
|
50
|
-
const remote = /^https?:$/.test(parent.protocol);
|
|
51
|
-
let error = new ERR_MODULE_NOT_FOUND(
|
|
52
|
-
specifier,
|
|
53
|
-
remote ? parent.href : fileURLToPath(parent),
|
|
54
|
-
PACKAGE_PATH_REGEX.test(specifier) ? "package" : "module"
|
|
55
|
-
);
|
|
56
|
-
let url = null;
|
|
57
|
-
try {
|
|
58
|
-
switch (true) {
|
|
59
|
-
case isRelativeSpecifier(specifier):
|
|
60
|
-
case pathe.isAbsolute(specifier):
|
|
61
|
-
url = new URL(specifier, parent);
|
|
62
|
-
break;
|
|
63
|
-
case (!remote && specifier.startsWith("#")):
|
|
64
|
-
url = this.resolvePackageImport(
|
|
65
|
-
specifier,
|
|
66
|
-
parent,
|
|
67
|
-
condition,
|
|
68
|
-
conditions
|
|
69
|
-
);
|
|
70
|
-
break;
|
|
71
|
-
default:
|
|
72
|
-
try {
|
|
73
|
-
url = new URL(specifier);
|
|
74
|
-
} catch {
|
|
75
|
-
if (!remote) {
|
|
76
|
-
url = this.resolvePackage(
|
|
77
|
-
specifier,
|
|
78
|
-
parent,
|
|
79
|
-
condition,
|
|
80
|
-
conditions
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
if (url && url.protocol === "file:") {
|
|
87
|
-
const path = fileURLToPath(url);
|
|
88
|
-
if (!isFile(path)) {
|
|
89
|
-
throw isDirectory(path) ? new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(parent)) : new ERR_MODULE_NOT_FOUND(path, fileURLToPath(parent), "module");
|
|
90
|
-
}
|
|
91
|
-
if (!preserveSymlinks) {
|
|
92
|
-
const { hash, search } = url;
|
|
93
|
-
url = pathToFileURL(fs.realpathSync(path));
|
|
94
|
-
url.hash = hash;
|
|
95
|
-
url.search = search;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
} catch (e) {
|
|
99
|
-
error = e;
|
|
100
|
-
url = null;
|
|
101
|
-
}
|
|
102
|
-
if (!url)
|
|
103
|
-
throw error;
|
|
104
|
-
return url;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Resolves a package path using a combination of the following algorithms:
|
|
108
|
-
*
|
|
109
|
-
* - `PACKAGE_RESOLVE`
|
|
110
|
-
* - `PACKAGE_SELF_RESOLVE`
|
|
111
|
-
*
|
|
112
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
113
|
-
*
|
|
114
|
-
* @public
|
|
115
|
-
*
|
|
116
|
-
* @param {string} specifier - Module specifier to resolve
|
|
117
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
118
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
119
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
120
|
-
* @return {URL} Resolved package path URL
|
|
121
|
-
* @throws {NodeError}
|
|
122
|
-
*/
|
|
123
|
-
resolvePackage(specifier, parent, condition = "default", conditions = CONDITIONS) {
|
|
124
|
-
const id = parseModuleId(specifier, {
|
|
125
|
-
parent,
|
|
126
|
-
pkgname: !isBuiltin(specifier)
|
|
127
|
-
});
|
|
128
|
-
if (isBuiltin(id.raw))
|
|
129
|
-
return new URL(toNodeURL(id.raw));
|
|
130
|
-
const stopdir = pathToFileURL("." + pathe.sep);
|
|
131
|
-
let scope = lookupPackageScope(
|
|
132
|
-
parent,
|
|
133
|
-
stopdir,
|
|
134
|
-
specifier,
|
|
135
|
-
parent
|
|
136
|
-
);
|
|
137
|
-
if ((scope == null ? void 0 : scope.pkgjson.name) === id.pkg && !isNIL(scope.pkgjson.exports)) {
|
|
138
|
-
return this.resolvePackageExport(
|
|
139
|
-
id.raw,
|
|
140
|
-
scope.pkg,
|
|
141
|
-
parent,
|
|
142
|
-
condition,
|
|
143
|
-
conditions
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
let url = null;
|
|
147
|
-
if (scope) {
|
|
148
|
-
let { dir: pkgdir } = scope;
|
|
149
|
-
while (pkgdir !== ".") {
|
|
150
|
-
scope = lookupPackageScope(
|
|
151
|
-
new URL(`node_modules/${id.raw}`, pkgdir + pathe.sep),
|
|
152
|
-
stopdir,
|
|
153
|
-
specifier,
|
|
154
|
-
parent
|
|
155
|
-
);
|
|
156
|
-
if (scope)
|
|
157
|
-
break;
|
|
158
|
-
pkgdir = pathe.dirname(pkgdir);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
switch (true) {
|
|
162
|
-
case (scope && !isNIL(scope.pkgjson.exports)):
|
|
163
|
-
url = this.resolvePackageExport(
|
|
164
|
-
specifier,
|
|
165
|
-
scope.pkg,
|
|
166
|
-
parent,
|
|
167
|
-
condition,
|
|
168
|
-
conditions
|
|
169
|
-
);
|
|
170
|
-
break;
|
|
171
|
-
case (scope && id.path === "."):
|
|
172
|
-
url = this.resolvePackageMain(scope.pkg, scope.pkgjson, parent);
|
|
173
|
-
break;
|
|
174
|
-
case !!scope:
|
|
175
|
-
url = new URL(id.path, scope.pkg);
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
if (!url)
|
|
179
|
-
throw new ERR_MODULE_NOT_FOUND(id.pkg, fileURLToPath(parent));
|
|
180
|
-
return url;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Resolves a subpath export according to the `PACKAGE_EXPORTS_RESOLVE`
|
|
184
|
-
* algorithm.
|
|
185
|
-
*
|
|
186
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
187
|
-
* @see https://nodejs.org/api/packages.html#subpath-exports
|
|
188
|
-
*
|
|
189
|
-
* @public
|
|
190
|
-
*
|
|
191
|
-
* @param {string} specifier - Module specifier containing subpath
|
|
192
|
-
* @param {ModuleId} pkg - URL of relevant `package.json` file
|
|
193
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
194
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
195
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
196
|
-
* @return {URL} Resolved package export URL
|
|
197
|
-
* @throws {NodeError<Error | TypeError>}
|
|
198
|
-
*/
|
|
199
|
-
resolvePackageExport(specifier, pkg, parent, condition = "default", conditions = CONDITIONS) {
|
|
200
|
-
const dir = new URL(".", pkg);
|
|
201
|
-
const pkgjson = readPackageJson(
|
|
202
|
-
dir,
|
|
203
|
-
specifier,
|
|
204
|
-
parent
|
|
205
|
-
);
|
|
206
|
-
let exports = pkgjson == null ? void 0 : pkgjson.exports;
|
|
207
|
-
const subpath = parseSubpath(specifier, exports, {
|
|
208
|
-
dir,
|
|
209
|
-
parent
|
|
210
|
-
});
|
|
211
|
-
if (!subpath.internal && isExportsSugar(exports, pkg, parent)) {
|
|
212
|
-
exports = { ".": exports };
|
|
213
|
-
}
|
|
214
|
-
const url = this.resolvePackageTarget(
|
|
215
|
-
dir,
|
|
216
|
-
exports == null ? void 0 : exports[subpath.key],
|
|
217
|
-
subpath.base,
|
|
218
|
-
subpath.key,
|
|
219
|
-
parent,
|
|
220
|
-
subpath.internal,
|
|
221
|
-
condition,
|
|
222
|
-
conditions
|
|
223
|
-
);
|
|
224
|
-
if (!url) {
|
|
225
|
-
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
226
|
-
fileURLToPath(dir),
|
|
227
|
-
subpath.raw,
|
|
228
|
-
fileURLToPath(parent)
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
return url;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Resolves a subpath import according to the `PACKAGE_IMPORTS_RESOLVE`
|
|
235
|
-
* algorithm.
|
|
236
|
-
*
|
|
237
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
238
|
-
* @see https://nodejs.org/api/packages.html#subpath-imports
|
|
239
|
-
*
|
|
240
|
-
* @public
|
|
241
|
-
*
|
|
242
|
-
* @param {string} specifier - Module specifier containing subpath
|
|
243
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
244
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
245
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
246
|
-
* @return {URL} Resolved package import URL
|
|
247
|
-
* @throws {NodeError<Error | TypeError>}
|
|
248
|
-
*/
|
|
249
|
-
resolvePackageImport(specifier, parent, condition = "default", conditions = CONDITIONS) {
|
|
250
|
-
const id = parseModuleId(specifier, {
|
|
251
|
-
internal: true,
|
|
252
|
-
parent
|
|
253
|
-
});
|
|
254
|
-
const scope = lookupPackageScope(
|
|
255
|
-
parent,
|
|
256
|
-
pathToFileURL("."),
|
|
257
|
-
specifier,
|
|
258
|
-
parent
|
|
259
|
-
);
|
|
260
|
-
let url = null;
|
|
261
|
-
if (scope) {
|
|
262
|
-
const imports = scope.pkgjson.imports;
|
|
263
|
-
const subpath = parseSubpath(id.raw, imports, {
|
|
264
|
-
dir: scope.dir,
|
|
265
|
-
internal: true,
|
|
266
|
-
parent
|
|
267
|
-
});
|
|
268
|
-
url = this.resolvePackageTarget(
|
|
269
|
-
scope.dir,
|
|
270
|
-
imports == null ? void 0 : imports[subpath.key],
|
|
271
|
-
subpath.base,
|
|
272
|
-
subpath.key,
|
|
273
|
-
parent,
|
|
274
|
-
subpath.internal,
|
|
275
|
-
condition,
|
|
276
|
-
conditions
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
if (!url) {
|
|
280
|
-
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
281
|
-
specifier,
|
|
282
|
-
fileURLToPath(parent),
|
|
283
|
-
/* c8 ignore next */
|
|
284
|
-
(scope == null ? void 0 : scope.dir) ? fileURLToPath(scope.dir) : void 0
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
return url;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Resolves a package entry point using the legacy CommonJS `main` resolution
|
|
291
|
-
* alogirthm:
|
|
292
|
-
*
|
|
293
|
-
* 1. let M = pkgdir `pkgjson.main`
|
|
294
|
-
* 2. TRY(M, M.js, M.json, M.node, M/index.js, M/index.json, M/index.node)
|
|
295
|
-
* 4. TRY(pkgdir/index.js, pkgdir/index.json, pkgdir/index.node)
|
|
296
|
-
* 5. ERR_MODULE_NOT_FOUND
|
|
297
|
-
*
|
|
298
|
-
* @todo emit deprecation messages
|
|
299
|
-
*
|
|
300
|
-
* @public
|
|
301
|
-
*
|
|
302
|
-
* @param {ModuleId} pkg - URL of relevant `package.json` file
|
|
303
|
-
* @param {PackageJson} pkgjson - Relevant `package.json` object
|
|
304
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
305
|
-
* @return {URL} Package entry point URL
|
|
306
|
-
* @throws {NodeError} If package entry point is not found
|
|
307
|
-
*/
|
|
308
|
-
resolvePackageMain(pkg, pkgjson, parent) {
|
|
309
|
-
const tries = [
|
|
310
|
-
...pkgjson.main ? [
|
|
311
|
-
pkgjson.main,
|
|
312
|
-
`./${pkgjson.main}.js`,
|
|
313
|
-
`./${pkgjson.main}.json`,
|
|
314
|
-
`./${pkgjson.main}.node`,
|
|
315
|
-
`./${pkgjson.main}/index.js`,
|
|
316
|
-
`./${pkgjson.main}/index.json`,
|
|
317
|
-
`./${pkgjson.main}/index.node`
|
|
318
|
-
] : [],
|
|
319
|
-
"./index.js",
|
|
320
|
-
"./index.json",
|
|
321
|
-
"./index.node"
|
|
322
|
-
];
|
|
323
|
-
let url = null;
|
|
324
|
-
for (const input of tries) {
|
|
325
|
-
if (isFile(url = new URL(input, pkg)))
|
|
326
|
-
break;
|
|
327
|
-
url = null;
|
|
328
|
-
}
|
|
329
|
-
if (!url) {
|
|
330
|
-
throw new ERR_MODULE_NOT_FOUND(
|
|
331
|
-
fileURLToPath(new URL(".", pkg)),
|
|
332
|
-
fileURLToPath(parent)
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
return url;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Resolves a package target according to the `PACKAGE_TARGET_RESOLVE`
|
|
339
|
-
* algorithm.
|
|
340
|
-
*
|
|
341
|
-
* @see https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
342
|
-
*
|
|
343
|
-
* @todo emit deprecation messages
|
|
344
|
-
*
|
|
345
|
-
* @public
|
|
346
|
-
*
|
|
347
|
-
* @param {ModuleId} dir - URL of directory containing relevant `package.json`
|
|
348
|
-
* @param {Exports | undefined} target - Package `exports` or `imports` target
|
|
349
|
-
* @param {string} subpath - Package subpath without entry prefix (`key`)
|
|
350
|
-
* @param {string} key - Subpath defined in relevant `package.json` file
|
|
351
|
-
* @param {ModuleId} parent - URL of module to resolve from
|
|
352
|
-
* @param {boolean?} [internal=false] - Package `imports` hint
|
|
353
|
-
* @param {string?} [condition='default'] - Export condition to apply
|
|
354
|
-
* @param {Set<string>?} [conditions=CONDITIONS] - Export conditions
|
|
355
|
-
* @return {Nullable<URL>} Resolved package target URL or `null`
|
|
356
|
-
* @throws {NodeError<Error | TypeError>}
|
|
357
|
-
*/
|
|
358
|
-
resolvePackageTarget(dir, target, subpath, key, parent, internal = false, condition = "default", conditions = CONDITIONS) {
|
|
359
|
-
let url = null;
|
|
360
|
-
switch (true) {
|
|
361
|
-
case target === null:
|
|
362
|
-
break;
|
|
363
|
-
case Array.isArray(target):
|
|
364
|
-
let error;
|
|
365
|
-
for (const item of target) {
|
|
366
|
-
try {
|
|
367
|
-
url = this.resolvePackageTarget(
|
|
368
|
-
dir,
|
|
369
|
-
item,
|
|
370
|
-
subpath,
|
|
371
|
-
key,
|
|
372
|
-
parent,
|
|
373
|
-
internal,
|
|
374
|
-
condition,
|
|
375
|
-
conditions
|
|
376
|
-
);
|
|
377
|
-
} catch (e) {
|
|
378
|
-
error = e;
|
|
379
|
-
if (error.code !== ErrorCode.ERR_INVALID_PACKAGE_TARGET)
|
|
380
|
-
throw error;
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
if (url)
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
if (error && !url)
|
|
387
|
-
throw error;
|
|
388
|
-
break;
|
|
389
|
-
case typeof target === "object":
|
|
390
|
-
target = target;
|
|
391
|
-
for (const prop of Object.getOwnPropertyNames(target)) {
|
|
392
|
-
if (isArrayIndex(prop)) {
|
|
393
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
394
|
-
fileURLToPath(dir),
|
|
395
|
-
fileURLToPath(parent),
|
|
396
|
-
'"exports" cannot contain numeric property keys'
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
if (prop === condition || conditions.has(prop)) {
|
|
400
|
-
url = this.resolvePackageTarget(
|
|
401
|
-
dir,
|
|
402
|
-
target[prop],
|
|
403
|
-
subpath,
|
|
404
|
-
key,
|
|
405
|
-
parent,
|
|
406
|
-
internal,
|
|
407
|
-
condition,
|
|
408
|
-
conditions
|
|
409
|
-
);
|
|
410
|
-
if (url)
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
break;
|
|
415
|
-
case typeof target === "string":
|
|
416
|
-
target = target;
|
|
417
|
-
const pattern = key.includes(PATTERN_CHARACTER);
|
|
418
|
-
switch (true) {
|
|
419
|
-
case (subpath && !pattern && !target.endsWith(pathe.sep)):
|
|
420
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
421
|
-
fileURLToPath(dir),
|
|
422
|
-
key,
|
|
423
|
-
target,
|
|
424
|
-
internal,
|
|
425
|
-
fileURLToPath(parent)
|
|
426
|
-
);
|
|
427
|
-
case (internal && PACKAGE_NAME_REGEX.test(target)):
|
|
428
|
-
url = this.resolvePackage(target, parent, condition, conditions);
|
|
429
|
-
break;
|
|
430
|
-
case target.startsWith("." + pathe.sep):
|
|
431
|
-
const invalidSegmentRegex = (type) => {
|
|
432
|
-
return new RegExp(
|
|
433
|
-
`(^|\\\\|\\/)((\\.|%2e)(\\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))${type === "deprecated" ? "" : "?"}(\\\\|\\/|$)`,
|
|
434
|
-
"i"
|
|
435
|
-
);
|
|
436
|
-
};
|
|
437
|
-
if (invalidSegmentRegex().test(target.slice(2))) {
|
|
438
|
-
if (invalidSegmentRegex("deprecated").test(target.slice(2))) {
|
|
439
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
440
|
-
fileURLToPath(dir),
|
|
441
|
-
key,
|
|
442
|
-
target,
|
|
443
|
-
internal,
|
|
444
|
-
fileURLToPath(parent)
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
url = new URL(
|
|
449
|
-
target,
|
|
450
|
-
pathToFileURL(fileURLToPath(dir).replace(/\/$/, "") + pathe.sep)
|
|
451
|
-
);
|
|
452
|
-
if (subpath) {
|
|
453
|
-
if (invalidSegmentRegex().test(subpath)) {
|
|
454
|
-
if (invalidSegmentRegex("deprecated").test(subpath)) {
|
|
455
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
456
|
-
key.replace(PATTERN_CHARACTER, subpath),
|
|
457
|
-
[
|
|
458
|
-
`request is not a valid match in pattern "${key}" for`,
|
|
459
|
-
`the "${internal ? "imports" : "exports"}" resolution`,
|
|
460
|
-
`of ${fileURLToPath(dir).replace(/\/$/, "")}/package.json`
|
|
461
|
-
].join(" "),
|
|
462
|
-
fileURLToPath(parent)
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
url = new URL(
|
|
467
|
-
url.href.replace(
|
|
468
|
-
new RegExp(regexp(PATTERN_CHARACTER), "g"),
|
|
469
|
-
subpath
|
|
470
|
-
)
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
break;
|
|
474
|
-
default:
|
|
475
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
476
|
-
fileURLToPath(dir),
|
|
477
|
-
key,
|
|
478
|
-
target,
|
|
479
|
-
internal,
|
|
480
|
-
fileURLToPath(parent)
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
|
-
break;
|
|
484
|
-
default:
|
|
485
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
486
|
-
fileURLToPath(dir),
|
|
487
|
-
key,
|
|
488
|
-
target,
|
|
489
|
-
internal,
|
|
490
|
-
fileURLToPath(parent)
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
return url;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
var resolver_default = Resolver;
|
|
497
|
-
export {
|
|
498
|
-
resolver_default as default
|
|
499
|
-
};
|
|
500
|
-
//# sourceMappingURL=resolver.mjs.map
|