@flex-development/mlly 1.0.0-alpha.17 → 1.0.0-alpha.19
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 +829 -681
- package/README.md +173 -12
- package/dist/index.d.mts +3 -4
- package/dist/index.mjs +1 -5
- package/dist/interfaces/aliases.d.mts +11 -0
- package/dist/interfaces/context-get-source.d.mts +52 -0
- package/dist/interfaces/file-system.d.mts +57 -0
- package/dist/interfaces/index.d.mts +11 -21
- package/dist/interfaces/main-field-map.d.mts +13 -0
- package/dist/interfaces/module-format-map.d.mts +17 -0
- package/dist/interfaces/options-get-source.d.mts +22 -29
- package/dist/interfaces/options-resolve-alias.d.mts +14 -26
- package/dist/interfaces/options-resolve-module.d.mts +38 -27
- package/dist/interfaces/protocol-map.d.mts +35 -0
- package/dist/interfaces/stats.d.mts +28 -0
- package/dist/internal/chars.mjs +11 -0
- package/dist/internal/check-invalid-segments.mjs +19 -0
- package/dist/internal/fs.browser.mjs +36 -0
- package/dist/internal/fs.d.mts +7 -0
- package/dist/internal/invalid-package-target.mjs +18 -0
- package/dist/internal/invalid-subpath.mjs +16 -0
- package/dist/internal/process.browser.mjs +7 -0
- package/dist/internal/process.d.mts +4 -0
- package/dist/lib/can-parse-url.d.mts +21 -0
- package/dist/lib/can-parse-url.mjs +12 -0
- package/dist/lib/cwd.d.mts +12 -0
- package/dist/lib/cwd.mjs +8 -0
- package/dist/lib/default-conditions.d.mts +15 -0
- package/dist/lib/default-conditions.mjs +5 -0
- package/dist/lib/default-extensions.d.mts +14 -0
- package/dist/lib/default-extensions.mjs +21 -0
- package/dist/lib/default-main-fields.d.mts +14 -0
- package/dist/lib/default-main-fields.mjs +5 -0
- package/dist/lib/extension-format-map.d.mts +16 -0
- package/dist/lib/extension-format-map.mjs +21 -0
- package/dist/lib/formats.d.mts +21 -0
- package/dist/lib/formats.mjs +14 -0
- package/dist/lib/get-source.d.mts +26 -0
- package/dist/lib/get-source.mjs +70 -0
- package/dist/lib/index.d.mts +40 -0
- package/dist/lib/index.mjs +53 -0
- package/dist/lib/is-absolute-specifier.d.mts +23 -0
- package/dist/lib/is-absolute-specifier.mjs +9 -0
- package/dist/lib/is-array-index.d.mts +17 -0
- package/dist/lib/is-array-index.mjs +11 -0
- package/dist/lib/is-bare-specifier.d.mts +23 -0
- package/dist/lib/is-bare-specifier.mjs +11 -0
- package/dist/lib/is-directory.d.mts +22 -0
- package/dist/lib/is-directory.mjs +13 -0
- package/dist/lib/is-file.d.mts +22 -0
- package/dist/lib/is-file.mjs +13 -0
- package/dist/lib/is-imports-subpath.d.mts +19 -0
- package/dist/lib/is-imports-subpath.mjs +8 -0
- package/dist/lib/is-relative-specifier.d.mts +21 -0
- package/dist/lib/is-relative-specifier.mjs +16 -0
- package/dist/lib/lookup-package-scope.d.mts +26 -0
- package/dist/lib/lookup-package-scope.mjs +16 -0
- package/dist/lib/pattern-key-compare.d.mts +31 -0
- package/dist/lib/pattern-key-compare.mjs +18 -0
- package/dist/lib/pattern-match.d.mts +19 -0
- package/dist/lib/pattern-match.mjs +36 -0
- package/dist/lib/read-package-json.d.mts +35 -0
- package/dist/lib/read-package-json.mjs +29 -0
- package/dist/lib/resolve-alias.d.mts +19 -0
- package/dist/lib/resolve-alias.mjs +50 -0
- package/dist/lib/resolve-module.d.mts +37 -0
- package/dist/lib/resolve-module.mjs +75 -0
- package/dist/lib/resolver.d.mts +280 -0
- package/dist/lib/resolver.mjs +462 -0
- package/dist/lib/root.d.mts +11 -0
- package/dist/lib/root.mjs +6 -0
- package/dist/lib/to-relative-specifier.d.mts +25 -0
- package/dist/lib/to-relative-specifier.mjs +26 -0
- package/dist/lib/to-url.d.mts +24 -0
- package/dist/lib/to-url.mjs +10 -0
- package/dist/types/awaitable.d.mts +14 -0
- package/dist/types/change-ext-fn.d.mts +29 -0
- package/dist/types/get-source-handler.d.mts +21 -0
- package/dist/types/get-source-handlers.d.mts +14 -0
- package/dist/types/index.d.mts +12 -10
- 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 +2 -4
- package/dist/types/numeric.d.mts +9 -0
- package/dist/types/pattern-key-compare-result.d.mts +9 -0
- package/dist/types/pattern-match.d.mts +10 -0
- package/dist/types/protocol.d.mts +6 -7
- package/package.json +227 -155
- package/dist/enums/assert-type.d.mts +0 -21
- package/dist/enums/assert-type.mjs +0 -4
- package/dist/enums/format.d.mts +0 -17
- package/dist/enums/format.mjs +0 -4
- package/dist/enums/index.d.mts +0 -10
- package/dist/enums/index.mjs +0 -14
- package/dist/enums/kind-specifier-syntax.d.mts +0 -14
- package/dist/enums/kind-specifier-syntax.mjs +0 -4
- package/dist/enums/kind-specifier.d.mts +0 -17
- package/dist/enums/kind-specifier.mjs +0 -4
- package/dist/enums/kind-statement-syntax.d.mts +0 -22
- package/dist/enums/kind-statement-syntax.mjs +0 -4
- package/dist/enums/kind-statement.d.mts +0 -15
- package/dist/enums/kind-statement.mjs +0 -4
- package/dist/index.mjs.map +0 -8
- package/dist/interfaces/import-assertions.d.mts +0 -20
- package/dist/interfaces/import-dynamic.d.mts +0 -41
- package/dist/interfaces/import-static.d.mts +0 -35
- package/dist/interfaces/index.mjs +0 -0
- package/dist/interfaces/options-fill-module.d.mts +0 -23
- package/dist/interfaces/options-find-subpath.d.mts +0 -50
- package/dist/interfaces/options-get-format.d.mts +0 -73
- package/dist/interfaces/options-parse-module-id.d.mts +0 -34
- package/dist/interfaces/options-parse-subpath.d.mts +0 -50
- 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 -44
- 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/dequote.d.mts +0 -14
- package/dist/internal/dequote.mjs +0 -7
- package/dist/internal/dequote.mjs.map +0 -8
- package/dist/internal/format-type-map.d.mts +0 -19
- package/dist/internal/format-type-map.mjs +0 -13
- package/dist/internal/format-type-map.mjs.map +0 -8
- package/dist/internal/get-specifier-kind.d.mts +0 -19
- package/dist/internal/get-specifier-kind.mjs +0 -11
- package/dist/internal/get-specifier-kind.mjs.map +0 -8
- package/dist/internal/get-subpaths.d.mts +0 -28
- package/dist/internal/get-subpaths.mjs +0 -8
- package/dist/internal/get-subpaths.mjs.map +0 -8
- package/dist/internal/regex-encoded-sep.d.mts +0 -15
- package/dist/internal/regex-encoded-sep.mjs +0 -6
- package/dist/internal/regex-encoded-sep.mjs.map +0 -8
- package/dist/internal/regex-internal-specifier.d.mts +0 -16
- package/dist/internal/regex-internal-specifier.mjs +0 -6
- package/dist/internal/regex-internal-specifier.mjs.map +0 -8
- package/dist/internal/regex-invalid-segment.d.mts +0 -16
- package/dist/internal/regex-invalid-segment.mjs +0 -9
- package/dist/internal/regex-invalid-segment.mjs.map +0 -8
- package/dist/internal/regex-package-name.d.mts +0 -15
- package/dist/internal/regex-package-name.mjs +0 -6
- package/dist/internal/regex-package-name.mjs.map +0 -8
- package/dist/internal/regex-package-path.d.mts +0 -17
- package/dist/internal/regex-package-path.mjs +0 -6
- package/dist/internal/regex-package-path.mjs.map +0 -8
- package/dist/internal/resolver.d.mts +0 -132
- package/dist/internal/resolver.mjs +0 -483
- package/dist/internal/resolver.mjs.map +0 -8
- package/dist/internal/validate-array-set.d.mts +0 -24
- package/dist/internal/validate-array-set.mjs +0 -12
- package/dist/internal/validate-array-set.mjs.map +0 -8
- package/dist/internal/validate-boolean.d.mts +0 -22
- package/dist/internal/validate-boolean.mjs +0 -12
- package/dist/internal/validate-boolean.mjs.map +0 -8
- package/dist/internal/validate-map.d.mts +0 -26
- package/dist/internal/validate-map.mjs +0 -12
- package/dist/internal/validate-map.mjs.map +0 -8
- package/dist/internal/validate-object.d.mts +0 -23
- package/dist/internal/validate-object.mjs +0 -12
- package/dist/internal/validate-object.mjs.map +0 -8
- package/dist/internal/validate-set.d.mts +0 -24
- package/dist/internal/validate-set.mjs +0 -12
- package/dist/internal/validate-set.mjs.map +0 -8
- package/dist/internal/validate-string.d.mts +0 -23
- package/dist/internal/validate-string.mjs +0 -12
- package/dist/internal/validate-string.mjs.map +0 -8
- package/dist/internal/validate-url-string.d.mts +0 -24
- package/dist/internal/validate-url-string.mjs +0 -13
- package/dist/internal/validate-url-string.mjs.map +0 -8
- package/dist/types/declaration.d.mts +0 -9
- package/dist/types/fn-change-ext.d.mts +0 -31
- package/dist/types/index.mjs +0 -0
- 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 -19
- package/dist/utils/compare-subpaths.mjs.map +0 -8
- package/dist/utils/conditions.d.mts +0 -13
- package/dist/utils/conditions.mjs +0 -6
- package/dist/utils/conditions.mjs.map +0 -8
- package/dist/utils/detect-syntax.d.mts +0 -21
- package/dist/utils/detect-syntax.mjs +0 -11
- package/dist/utils/detect-syntax.mjs.map +0 -8
- 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 -8
- package/dist/utils/extract-statements.d.mts +0 -21
- package/dist/utils/extract-statements.mjs +0 -20
- package/dist/utils/extract-statements.mjs.map +0 -8
- package/dist/utils/fill-modules.d.mts +0 -24
- package/dist/utils/fill-modules.mjs +0 -67
- package/dist/utils/fill-modules.mjs.map +0 -8
- package/dist/utils/find-dynamic-imports.d.mts +0 -18
- package/dist/utils/find-dynamic-imports.mjs +0 -36
- package/dist/utils/find-dynamic-imports.mjs.map +0 -8
- package/dist/utils/find-exports.d.mts +0 -21
- package/dist/utils/find-exports.mjs +0 -92
- package/dist/utils/find-exports.mjs.map +0 -8
- 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 -8
- package/dist/utils/find-static-imports.d.mts +0 -18
- package/dist/utils/find-static-imports.mjs +0 -30
- package/dist/utils/find-static-imports.mjs.map +0 -8
- package/dist/utils/find-subpath.d.mts +0 -31
- package/dist/utils/find-subpath.mjs +0 -86
- package/dist/utils/find-subpath.mjs.map +0 -8
- package/dist/utils/get-format.d.mts +0 -31
- package/dist/utils/get-format.mjs +0 -107
- package/dist/utils/get-format.mjs.map +0 -8
- package/dist/utils/get-source.d.mts +0 -30
- package/dist/utils/get-source.mjs +0 -61
- package/dist/utils/get-source.mjs.map +0 -8
- 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 -8
- 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 -8
- package/dist/utils/index.d.mts +0 -44
- package/dist/utils/index.mjs +0 -83
- package/dist/utils/index.mjs.map +0 -8
- package/dist/utils/is-absolute-specifier.d.mts +0 -20
- package/dist/utils/is-absolute-specifier.mjs +0 -26
- package/dist/utils/is-absolute-specifier.mjs.map +0 -8
- package/dist/utils/is-bare-specifier.d.mts +0 -20
- package/dist/utils/is-bare-specifier.mjs +0 -10
- package/dist/utils/is-bare-specifier.mjs.map +0 -8
- package/dist/utils/is-directory.d.mts +0 -13
- package/dist/utils/is-directory.mjs +0 -14
- package/dist/utils/is-directory.mjs.map +0 -8
- package/dist/utils/is-exports-sugar.d.mts +0 -26
- package/dist/utils/is-exports-sugar.mjs +0 -29
- package/dist/utils/is-exports-sugar.mjs.map +0 -8
- package/dist/utils/is-file.d.mts +0 -13
- package/dist/utils/is-file.mjs +0 -14
- package/dist/utils/is-file.mjs.map +0 -8
- package/dist/utils/is-relative-specifier.d.mts +0 -19
- package/dist/utils/is-relative-specifier.mjs +0 -9
- package/dist/utils/is-relative-specifier.mjs.map +0 -8
- package/dist/utils/lookup-package-scope.d.mts +0 -26
- package/dist/utils/lookup-package-scope.mjs +0 -34
- package/dist/utils/lookup-package-scope.mjs.map +0 -8
- 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 -8
- package/dist/utils/parse-module-id.d.mts +0 -20
- package/dist/utils/parse-module-id.mjs +0 -123
- package/dist/utils/parse-module-id.mjs.map +0 -8
- package/dist/utils/parse-subpath.d.mts +0 -35
- package/dist/utils/parse-subpath.mjs +0 -149
- package/dist/utils/parse-subpath.mjs.map +0 -8
- 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 -8
- package/dist/utils/read-package-json.d.mts +0 -26
- package/dist/utils/read-package-json.mjs +0 -48
- package/dist/utils/read-package-json.mjs.map +0 -8
- package/dist/utils/resolve-alias.d.mts +0 -20
- package/dist/utils/resolve-alias.mjs +0 -101
- package/dist/utils/resolve-alias.mjs.map +0 -8
- package/dist/utils/resolve-aliases.d.mts +0 -19
- package/dist/utils/resolve-aliases.mjs +0 -26
- package/dist/utils/resolve-aliases.mjs.map +0 -8
- 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 -8
- package/dist/utils/resolve-module.d.mts +0 -39
- package/dist/utils/resolve-module.mjs +0 -63
- package/dist/utils/resolve-module.mjs.map +0 -8
- package/dist/utils/resolve-modules.d.mts +0 -25
- package/dist/utils/resolve-modules.mjs +0 -23
- package/dist/utils/resolve-modules.mjs.map +0 -8
- 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 -8
- package/dist/utils/to-bare-specifier.d.mts +0 -42
- package/dist/utils/to-bare-specifier.mjs +0 -72
- package/dist/utils/to-bare-specifier.mjs.map +0 -8
- package/dist/utils/to-data-url.d.mts +0 -30
- package/dist/utils/to-data-url.mjs +0 -7
- package/dist/utils/to-data-url.mjs.map +0 -8
- package/dist/utils/to-node-url.d.mts +0 -19
- package/dist/utils/to-node-url.mjs +0 -7
- package/dist/utils/to-node-url.mjs.map +0 -8
- package/dist/utils/to-relative-specifier.d.mts +0 -24
- package/dist/utils/to-relative-specifier.mjs +0 -10
- package/dist/utils/to-relative-specifier.mjs.map +0 -8
- package/dist/utils/to-url.d.mts +0 -21
- package/dist/utils/to-url.mjs +0 -8
- package/dist/utils/to-url.mjs.map +0 -8
- package/dist/utils/validate-assertions.d.mts +0 -23
- package/dist/utils/validate-assertions.mjs +0 -47
- package/dist/utils/validate-assertions.mjs.map +0 -8
- package/dist/utils/validate-exports.d.mts +0 -25
- package/dist/utils/validate-exports.mjs +0 -73
- package/dist/utils/validate-exports.mjs.map +0 -8
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file parseSubpath
|
|
3
|
-
* @module mlly/utils/parseSubpath
|
|
4
|
-
*/
|
|
5
|
-
import type { ParseSubpathOptions, ParsedSubpath } from '../interfaces/index.mjs';
|
|
6
|
-
import type { Exports, Imports } from '@flex-development/pkg-types';
|
|
7
|
-
import { type Optional } from '@flex-development/tutils';
|
|
8
|
-
/**
|
|
9
|
-
* Creates an object representation of a subpath export or import from the given
|
|
10
|
-
* module `specifier` after ensuring the subpath defined in `specifier` is also
|
|
11
|
-
* defined in the given package `context`, a `package.json` [`exports`][1] or
|
|
12
|
-
* [`imports`][2] field.
|
|
13
|
-
*
|
|
14
|
-
* ::: warning
|
|
15
|
-
* Does **not** guarantee `specifier` resolves to an existing module.
|
|
16
|
-
* :::
|
|
17
|
-
*
|
|
18
|
-
* [1]: https://nodejs.org/api/packages.html#exports
|
|
19
|
-
* [2]: https://nodejs.org/api/packages.html#imports
|
|
20
|
-
*
|
|
21
|
-
* @see {@linkcode Exports}
|
|
22
|
-
* @see {@linkcode Imports}
|
|
23
|
-
* @see {@linkcode ParseSubpathOptions}
|
|
24
|
-
* @see {@linkcode ParsedSubpath}
|
|
25
|
-
* @see https://nodejs.org/api/packages.html#subpath-exports
|
|
26
|
-
* @see https://nodejs.org/api/packages.html#subpath-imports
|
|
27
|
-
*
|
|
28
|
-
* @param {string} specifier - Module specifier to evaluate
|
|
29
|
-
* @param {Optional<Exports | Imports>} context - Package context
|
|
30
|
-
* @param {ParseSubpathOptions} options - Parsing options
|
|
31
|
-
* @return {ParsedSubpath} Object representing package subpath
|
|
32
|
-
* @throws {NodeError<Error | TypeError>}
|
|
33
|
-
*/
|
|
34
|
-
declare const parseSubpath: (specifier: string, context: Optional<Exports | Imports>, options: ParseSubpathOptions) => ParsedSubpath;
|
|
35
|
-
export default parseSubpath;
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import getSubpaths from "../internal/get-subpaths.mjs";
|
|
2
|
-
import invalidSegmentRegex from "../internal/regex-invalid-segment.mjs";
|
|
3
|
-
import PACKAGE_NAME_REGEX from "../internal/regex-package-name.mjs";
|
|
4
|
-
import validateArraySet from "../internal/validate-array-set.mjs";
|
|
5
|
-
import validateBoolean from "../internal/validate-boolean.mjs";
|
|
6
|
-
import validateString from "../internal/validate-string.mjs";
|
|
7
|
-
import validateURLString from "../internal/validate-url-string.mjs";
|
|
8
|
-
import {
|
|
9
|
-
ERR_INVALID_PACKAGE_CONFIG,
|
|
10
|
-
ERR_INVALID_PACKAGE_TARGET,
|
|
11
|
-
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
12
|
-
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
13
|
-
ErrorCode
|
|
14
|
-
} from "@flex-development/errnode";
|
|
15
|
-
import pathe from "@flex-development/pathe";
|
|
16
|
-
import {
|
|
17
|
-
CompareResult,
|
|
18
|
-
DOT,
|
|
19
|
-
cast,
|
|
20
|
-
get,
|
|
21
|
-
isArray,
|
|
22
|
-
isArrayIndex,
|
|
23
|
-
isNIL,
|
|
24
|
-
isNull,
|
|
25
|
-
isObjectCurly,
|
|
26
|
-
isString
|
|
27
|
-
} from "@flex-development/tutils";
|
|
28
|
-
import { URL, fileURLToPath, pathToFileURL } from "node:url";
|
|
29
|
-
import compareSubpaths from "./compare-subpaths.mjs";
|
|
30
|
-
import CONDITIONS from "./conditions.mjs";
|
|
31
|
-
import isExportsSugar from "./is-exports-sugar.mjs";
|
|
32
|
-
import parseModuleId from "./parse-module-id.mjs";
|
|
33
|
-
import PATTERN_CHARACTER from "./pattern-character.mjs";
|
|
34
|
-
const parseSubpath = (specifier, context, options) => {
|
|
35
|
-
const {
|
|
36
|
-
condition = "default",
|
|
37
|
-
conditions = CONDITIONS,
|
|
38
|
-
dir,
|
|
39
|
-
internal = specifier.startsWith("#"),
|
|
40
|
-
parent
|
|
41
|
-
} = options;
|
|
42
|
-
validateString(specifier, "specifier"), validateString(condition, "options.condition"), validateArraySet(conditions, "options.conditions"), validateURLString(dir, "options.dir"), validateBoolean(internal, "options.internal"), validateURLString(parent, "options.parent");
|
|
43
|
-
const id = parseModuleId(specifier, {
|
|
44
|
-
internal,
|
|
45
|
-
parent,
|
|
46
|
-
pkgname: !internal
|
|
47
|
-
}), pkgdir = fileURLToPath(dir).replace(/\/$/, "") + pathe.sep, pkg = new URL("package.json", pathToFileURL(pkgdir)), keys = getSubpaths(context, id.internal, pkg, parent);
|
|
48
|
-
let key = null, base = "";
|
|
49
|
-
for (const pkgsubpath of keys) {
|
|
50
|
-
const pattern = pkgsubpath.indexOf(PATTERN_CHARACTER);
|
|
51
|
-
if (pattern === -1 && pkgsubpath === id.path) {
|
|
52
|
-
key = pkgsubpath;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
if (pattern !== -1 && id.path.startsWith(pkgsubpath.slice(0, pattern))) {
|
|
56
|
-
const trailer = pkgsubpath.slice(pattern + 1);
|
|
57
|
-
id.path.length >= pkgsubpath.length && id.path.endsWith(trailer) && compareSubpaths(key ?? "", pkgsubpath) === CompareResult.GREATER_THAN && pkgsubpath.lastIndexOf(PATTERN_CHARACTER) === pattern && (key = pkgsubpath, base = id.path.slice(pattern, id.path.length - trailer.length));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (isNull(key)) {
|
|
61
|
-
let { parent: parent2 } = options;
|
|
62
|
-
throw parent2 = fileURLToPath(parent2), internal ? new ERR_PACKAGE_IMPORT_NOT_DEFINED(id.path, parent2, pkgdir) : new ERR_PACKAGE_PATH_NOT_EXPORTED(pkgdir, id.path, parent2);
|
|
63
|
-
}
|
|
64
|
-
const findPackageTarget = (data) => {
|
|
65
|
-
let target = null;
|
|
66
|
-
switch (!0) {
|
|
67
|
-
case isNIL(data):
|
|
68
|
-
target = null;
|
|
69
|
-
break;
|
|
70
|
-
case isArray(data):
|
|
71
|
-
let error;
|
|
72
|
-
for (const item of cast(data)) {
|
|
73
|
-
try {
|
|
74
|
-
target = findPackageTarget(item);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
if (error = cast(e), error.code !== ErrorCode.ERR_INVALID_PACKAGE_TARGET)
|
|
77
|
-
throw error;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (target) {
|
|
81
|
-
error = void 0;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (error)
|
|
86
|
-
throw error;
|
|
87
|
-
break;
|
|
88
|
-
case isObjectCurly(data):
|
|
89
|
-
data = cast(data);
|
|
90
|
-
for (const property of Object.getOwnPropertyNames(data)) {
|
|
91
|
-
if (isArrayIndex(property))
|
|
92
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
93
|
-
fileURLToPath(pkg),
|
|
94
|
-
fileURLToPath(parent),
|
|
95
|
-
'"exports" cannot contain numeric property keys'
|
|
96
|
-
);
|
|
97
|
-
if ((property === condition || new Set(conditions).has(property)) && (target = findPackageTarget(data[property]), target))
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
case isString(data):
|
|
102
|
-
switch (target = cast(data), !0) {
|
|
103
|
-
case (internal && PACKAGE_NAME_REGEX.test(target)):
|
|
104
|
-
break;
|
|
105
|
-
case target.startsWith(DOT + pathe.sep):
|
|
106
|
-
if (invalidSegmentRegex().test(target.slice(2)) && invalidSegmentRegex("deprecated").test(target.slice(2)))
|
|
107
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
108
|
-
fileURLToPath(dir),
|
|
109
|
-
key,
|
|
110
|
-
target,
|
|
111
|
-
internal,
|
|
112
|
-
fileURLToPath(parent)
|
|
113
|
-
);
|
|
114
|
-
break;
|
|
115
|
-
default:
|
|
116
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
117
|
-
fileURLToPath(dir),
|
|
118
|
-
key,
|
|
119
|
-
target,
|
|
120
|
-
internal,
|
|
121
|
-
fileURLToPath(parent)
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
|
-
default:
|
|
126
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
127
|
-
fileURLToPath(dir),
|
|
128
|
-
key,
|
|
129
|
-
data,
|
|
130
|
-
internal,
|
|
131
|
-
fileURLToPath(parent)
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
return target;
|
|
135
|
-
};
|
|
136
|
-
return !internal && isExportsSugar(context, pkg, parent) && (context = cast({ [DOT]: context })), {
|
|
137
|
-
base,
|
|
138
|
-
internal,
|
|
139
|
-
key,
|
|
140
|
-
raw: id.path,
|
|
141
|
-
specifier: id.raw,
|
|
142
|
-
target: findPackageTarget(get(context, key))
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
var parse_subpath_default = parseSubpath;
|
|
146
|
-
export {
|
|
147
|
-
parse_subpath_default as default
|
|
148
|
-
};
|
|
149
|
-
//# sourceMappingURL=parse-subpath.mjs.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/parse-subpath.ts"],
|
|
4
|
-
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file parseSubpath\n * @module mlly/utils/parseSubpath\n */\n\nimport type {\n ParseSubpathOptions,\n ParsedModuleId,\n ParsedSubpath\n} from '#src/interfaces'\nimport getSubpaths from '#src/internal/get-subpaths'\nimport invalidSegmentRegex from '#src/internal/regex-invalid-segment'\nimport PACKAGE_NAME_REGEX from '#src/internal/regex-package-name'\nimport validateArraySet from '#src/internal/validate-array-set'\nimport validateBoolean from '#src/internal/validate-boolean'\nimport validateString from '#src/internal/validate-string'\nimport validateURLString from '#src/internal/validate-url-string'\nimport {\n ERR_INVALID_PACKAGE_CONFIG,\n ERR_INVALID_PACKAGE_TARGET,\n ERR_PACKAGE_IMPORT_NOT_DEFINED,\n ERR_PACKAGE_PATH_NOT_EXPORTED,\n ErrorCode,\n type NodeError\n} from '@flex-development/errnode'\nimport pathe from '@flex-development/pathe'\nimport type { Exports, Imports } from '@flex-development/pkg-types'\nimport {\n CompareResult,\n DOT,\n cast,\n get,\n isArray,\n isArrayIndex,\n isNIL,\n isNull,\n isObjectCurly,\n isString,\n type Dot,\n type Nullable,\n type Optional\n} from '@flex-development/tutils'\nimport { URL, fileURLToPath, pathToFileURL } from 'node:url'\nimport compareSubpaths from './compare-subpaths'\nimport CONDITIONS from './conditions'\nimport isExportsSugar from './is-exports-sugar'\nimport parseModuleId from './parse-module-id'\nimport PATTERN_CHARACTER from './pattern-character'\n\n/**\n * Creates an object representation of a subpath export or import from the given\n * module `specifier` after ensuring the subpath defined in `specifier` is also\n * defined in the given package `context`, a `package.json` [`exports`][1] or\n * [`imports`][2] field.\n *\n * ::: warning\n * Does **not** guarantee `specifier` resolves to an existing module.\n * :::\n *\n * [1]: https://nodejs.org/api/packages.html#exports\n * [2]: https://nodejs.org/api/packages.html#imports\n *\n * @see {@linkcode Exports}\n * @see {@linkcode Imports}\n * @see {@linkcode ParseSubpathOptions}\n * @see {@linkcode ParsedSubpath}\n * @see https://nodejs.org/api/packages.html#subpath-exports\n * @see https://nodejs.org/api/packages.html#subpath-imports\n *\n * @param {string} specifier - Module specifier to evaluate\n * @param {Optional<Exports | Imports>} context - Package context\n * @param {ParseSubpathOptions} options - Parsing options\n * @return {ParsedSubpath} Object representing package subpath\n * @throws {NodeError<Error | TypeError>}\n */\nconst parseSubpath = (\n specifier: string,\n context: Optional<Exports | Imports>,\n options: ParseSubpathOptions\n): ParsedSubpath => {\n const {\n condition = 'default',\n conditions = CONDITIONS,\n dir,\n internal = specifier.startsWith('#'),\n parent\n } = options\n\n // ensure specifier is a string\n validateString(specifier, 'specifier')\n\n // ensure option schemas\n validateString(condition, 'options.condition')\n validateArraySet(conditions, 'options.conditions')\n validateURLString(dir, 'options.dir')\n validateBoolean(internal, 'options.internal')\n validateURLString(parent, 'options.parent')\n\n /**\n * Parsed module id.\n *\n * **Note**: Ensures {@linkcode specifier} begins with a valid package name or\n * is a valid [subpath import][1].\n *\n * [1]: https://nodejs.org/api/packages.html#subpath-imports\n *\n * @const {ParsedModuleId} id\n */\n const id: ParsedModuleId = parseModuleId(specifier, {\n internal,\n parent,\n pkgname: !internal\n })\n\n /**\n * Absolute path to directory containing relevant `package.json` file.\n *\n * @const {string} pkgdir\n */\n const pkgdir: string = fileURLToPath(dir).replace(/\\/$/, '') + pathe.sep\n\n /**\n * URL of relevant `package.json` file.\n *\n * @const {URL} pkg\n */\n const pkg: URL = new URL('package.json', pathToFileURL(pkgdir))\n\n /**\n * Subpaths defined in {@linkcode context}.\n *\n * @const {string[]} keys\n */\n const keys: string[] = getSubpaths(context, id.internal, pkg, parent)\n\n /**\n * Subpath defined in {@linkcode context} that maps to {@linkcode specifier}.\n *\n * @var {Nullable<string>} key\n */\n let key: Nullable<string> = null\n\n /**\n * Subpath without entry prefix ({@linkcode key}).\n *\n * @var {string} base\n */\n let base: string = ''\n\n // match specifier to subpath defined in context\n for (const pkgsubpath of keys) {\n /**\n * Index of {@linkcode PATTERN_CHARACTER} in {@linkcode pkgsubpath}.\n *\n * @const {number} pattern\n */\n const pattern: number = pkgsubpath.indexOf(PATTERN_CHARACTER)\n\n // no pattern character => subpath must be exact match\n if (pattern === -1 && pkgsubpath === id.path) {\n key = pkgsubpath\n break\n }\n\n // pattern character => try finding best match for subpath\n if (pattern !== -1 && id.path.startsWith(pkgsubpath.slice(0, pattern))) {\n /**\n * Everything after pattern character (`*`) in {@linkcode pkgsubpath}.\n *\n * @const {string} trailer\n */\n const trailer: string = pkgsubpath.slice(pattern + 1)\n\n // best match found => reset key and base of subpath\n if (\n id.path.length >= pkgsubpath.length &&\n id.path.endsWith(trailer) &&\n compareSubpaths(key ?? '', pkgsubpath) === CompareResult.GREATER_THAN &&\n pkgsubpath.lastIndexOf(PATTERN_CHARACTER) === pattern\n ) {\n key = pkgsubpath\n base = id.path.slice(pattern, id.path.length - trailer.length)\n }\n }\n }\n\n // throw if defined subpath was not found\n if (isNull(key)) {\n let { parent } = options\n\n // ensure parent is a path\n parent = fileURLToPath(parent)\n\n throw internal\n ? new ERR_PACKAGE_IMPORT_NOT_DEFINED(id.path, parent, pkgdir)\n : new ERR_PACKAGE_PATH_NOT_EXPORTED(pkgdir, id.path, parent)\n }\n\n /**\n * Finds the package target string specified by {@linkcode key}.\n *\n * @param {Optional<Exports>} data - Initial package target\n * @return {Nullable<string>} Package target string or `null`\n * @throws {NodeError<Error | TypeError>}\n */\n const findPackageTarget = (data: Optional<Exports>): Nullable<string> => {\n /**\n * Package target.\n *\n * @var {Nullable<string>} target\n */\n let target: Nullable<string> = null\n\n switch (true) {\n case isNIL(data):\n target = null\n break\n case isArray(data):\n /**\n * Possible package target search error.\n *\n * @var {Optional<NodeError>} error\n */\n let error: Optional<NodeError>\n\n // try finding package target based on first match in search context\n for (const item of cast<string[]>(data)) {\n try {\n target = findPackageTarget(item)\n } catch (e: unknown) {\n error = cast<NodeError>(e)\n\n /* c8 ignore next */\n if (error.code !== ErrorCode.ERR_INVALID_PACKAGE_TARGET) throw error\n\n continue\n }\n\n // stop search attempts if target was found\n if (target) {\n error = undefined\n break\n }\n }\n\n // throw if error was encountered\n if (error) throw error\n\n break\n case isObjectCurly(data):\n data = cast<Record<string, Exports>>(data)\n\n // try finding package target based on condition\n for (const property of Object.getOwnPropertyNames(data)) {\n if (isArrayIndex(property)) {\n throw new ERR_INVALID_PACKAGE_CONFIG(\n fileURLToPath(pkg),\n fileURLToPath(parent),\n '\"exports\" cannot contain numeric property keys'\n )\n }\n\n // check conditions\n if (property === condition || new Set(conditions).has(property)) {\n target = findPackageTarget(data[property])\n if (target) break\n }\n }\n\n break\n case isString(data):\n target = cast<string>(data)\n\n switch (true) {\n case internal && PACKAGE_NAME_REGEX.test(target):\n break\n case target.startsWith(DOT + pathe.sep):\n // check target for invalid segments\n if (invalidSegmentRegex().test(target.slice(2))) {\n if (invalidSegmentRegex('deprecated').test(target.slice(2))) {\n throw new ERR_INVALID_PACKAGE_TARGET(\n fileURLToPath(dir),\n key!,\n target,\n internal,\n fileURLToPath(parent)\n )\n }\n }\n\n break\n default:\n throw new ERR_INVALID_PACKAGE_TARGET(\n fileURLToPath(dir),\n key!,\n target,\n internal,\n fileURLToPath(parent)\n )\n }\n\n break\n default:\n throw new ERR_INVALID_PACKAGE_TARGET(\n fileURLToPath(dir),\n key!,\n data,\n internal,\n fileURLToPath(parent)\n )\n }\n\n return target\n }\n\n // convert exports to object if using exports main sugar\n if (!internal && isExportsSugar(context, pkg, parent)) {\n context = cast<Record<Dot, Exports>>({ [DOT]: context })\n }\n\n return {\n base,\n internal,\n key,\n raw: id.path,\n specifier: id.raw,\n target: findPackageTarget(get(context, key))\n }\n}\n\nexport default parseSubpath\n"],
|
|
6
|
-
"mappings": "A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0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/pattern-character.ts"],
|
|
4
|
-
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file PATTERN_CHARACTER\n * @module mlly/utils/PATTERN_CHARACTER\n */\n\n/**\n * Character representing a subpath pattern.\n *\n * @const {string} PATTERN_CHARACTER\n */\nconst PATTERN_CHARACTER: string = '*'\n\nexport default PATTERN_CHARACTER\n"],
|
|
6
|
-
"mappings": "AAUA,MAAM,oBAA4B;AAElC,IAAO,4BAAQ;",
|
|
7
|
-
"names": []
|
|
8
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file readPackageJson
|
|
3
|
-
* @module mlly/utils/readPackageJson
|
|
4
|
-
*/
|
|
5
|
-
import type { ModuleId } from '../types/index.mjs';
|
|
6
|
-
import type { PackageJson } from '@flex-development/pkg-types';
|
|
7
|
-
import { type Nullable } from '@flex-development/tutils';
|
|
8
|
-
/**
|
|
9
|
-
* Reads a `package.json` file from the given directory.
|
|
10
|
-
*
|
|
11
|
-
* Returns `null` if a file is not found.
|
|
12
|
-
*
|
|
13
|
-
* @see {@linkcode ModuleId}
|
|
14
|
-
* @see {@linkcode PackageJson}
|
|
15
|
-
*
|
|
16
|
-
* @param {ModuleId} [dir='.'] - Id of directory containing `package.json` file
|
|
17
|
-
* @param {string?} [specifier] - Module specifier passed by user to initiate
|
|
18
|
-
* reading of `package.json` file
|
|
19
|
-
* @param {ModuleId?} [parent] - Id of module to resolve from
|
|
20
|
-
* @return {?PackageJson} `package.json` object or `null` if file is not found
|
|
21
|
-
* @throws {NodeError<Error | TypeError>} If `dir` is not a string or instance
|
|
22
|
-
* of {@linkcode URL}, if `specifier` is not a string, if `parent` is not a
|
|
23
|
-
* string, or if a `package.json` is file found and does not contain valid JSON
|
|
24
|
-
*/
|
|
25
|
-
declare const readPackageJson: (dir?: ModuleId, specifier?: string, parent?: ModuleId) => Nullable<PackageJson>;
|
|
26
|
-
export default readPackageJson;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import validateString from "../internal/validate-string.mjs";
|
|
2
|
-
import validateURLString from "../internal/validate-url-string.mjs";
|
|
3
|
-
import {
|
|
4
|
-
ERR_INVALID_PACKAGE_CONFIG
|
|
5
|
-
} from "@flex-development/errnode";
|
|
6
|
-
import pathe from "@flex-development/pathe";
|
|
7
|
-
import {
|
|
8
|
-
DOT,
|
|
9
|
-
cast,
|
|
10
|
-
isEmptyString,
|
|
11
|
-
isNIL,
|
|
12
|
-
isUndefined
|
|
13
|
-
} from "@flex-development/tutils";
|
|
14
|
-
import fs from "node:fs";
|
|
15
|
-
import { fileURLToPath } from "node:url";
|
|
16
|
-
import isFile from "./is-file.mjs";
|
|
17
|
-
import toURL from "./to-url.mjs";
|
|
18
|
-
const readPackageJson = (dir = DOT, specifier, parent) => {
|
|
19
|
-
validateURLString(dir, "dir"), !isUndefined(specifier) && validateString(specifier, "specifier"), !isUndefined(parent) && validateURLString(parent, "parent"), dir = fileURLToPath(toURL(dir));
|
|
20
|
-
const path = pathe.toNamespacedPath(pathe.join(dir, "package.json"));
|
|
21
|
-
if (!isFile(path))
|
|
22
|
-
return null;
|
|
23
|
-
let pkg;
|
|
24
|
-
try {
|
|
25
|
-
pkg = JSON.parse(fs.readFileSync(path, "utf8"));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
let base;
|
|
28
|
-
switch (!0) {
|
|
29
|
-
case (specifier && !isNIL(parent) && !isEmptyString(parent)):
|
|
30
|
-
base = `'${specifier}' from ${fileURLToPath(toURL(parent))}`;
|
|
31
|
-
break;
|
|
32
|
-
case specifier?.startsWith("file:"):
|
|
33
|
-
base = fileURLToPath(specifier);
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
37
|
-
path,
|
|
38
|
-
base,
|
|
39
|
-
cast(e).message
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return pkg;
|
|
43
|
-
};
|
|
44
|
-
var read_package_json_default = readPackageJson;
|
|
45
|
-
export {
|
|
46
|
-
read_package_json_default as default
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=read-package-json.mjs.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/read-package-json.ts"],
|
|
4
|
-
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file readPackageJson\n * @module mlly/utils/readPackageJson\n */\n\nimport validateString from '#src/internal/validate-string'\nimport validateURLString from '#src/internal/validate-url-string'\nimport type { ModuleId } from '#src/types'\nimport {\n ERR_INVALID_PACKAGE_CONFIG,\n type NodeError\n} from '@flex-development/errnode'\nimport pathe from '@flex-development/pathe'\nimport type { PackageJson } from '@flex-development/pkg-types'\nimport {\n DOT,\n cast,\n isEmptyString,\n isNIL,\n isUndefined,\n type Nullable,\n type Optional\n} from '@flex-development/tutils'\nimport fs from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport isFile from './is-file'\nimport toURL from './to-url'\n\n/**\n * Reads a `package.json` file from the given directory.\n *\n * Returns `null` if a file is not found.\n *\n * @see {@linkcode ModuleId}\n * @see {@linkcode PackageJson}\n *\n * @param {ModuleId} [dir='.'] - Id of directory containing `package.json` file\n * @param {string?} [specifier] - Module specifier passed by user to initiate\n * reading of `package.json` file\n * @param {ModuleId?} [parent] - Id of module to resolve from\n * @return {?PackageJson} `package.json` object or `null` if file is not found\n * @throws {NodeError<Error | TypeError>} If `dir` is not a string or instance\n * of {@linkcode URL}, if `specifier` is not a string, if `parent` is not a\n * string, or if a `package.json` is file found and does not contain valid JSON\n */\nconst readPackageJson = (\n dir: ModuleId = DOT,\n specifier?: string,\n parent?: ModuleId\n): Nullable<PackageJson> => {\n // ensure dir is an instance of URL or a string\n validateURLString(dir, 'dir')\n\n // ensure specifier is a string\n !isUndefined(specifier) && validateString(specifier, 'specifier')\n\n // ensure parent is an instance of URL or a string\n !isUndefined(parent) && validateURLString(parent, 'parent')\n\n // ensure dir is a path\n dir = fileURLToPath(toURL(dir))\n\n /**\n * Absolute path to `package.json` file.\n *\n * @const {string} path\n */\n const path: string = pathe.toNamespacedPath(pathe.join(dir, 'package.json'))\n\n // return null if package.json file does not exist\n if (!isFile(path)) return null\n\n /**\n * Possible `package.json` object.\n *\n * @var {PackageJson} pkg\n */\n let pkg: PackageJson\n\n // try parsing package.json file\n try {\n pkg = JSON.parse(fs.readFileSync(path, 'utf8'))\n } catch (e: unknown) {\n /**\n * String containing module specifier passed by user to initiate reading of\n * `package.json` file and the location the module specifier was imported\n * from.\n *\n * @var {Optional<string>} base\n */\n let base: Optional<string>\n\n // get base\n switch (true) {\n case specifier && !isNIL(parent) && !isEmptyString(parent):\n base = `'${specifier}' from ${fileURLToPath(toURL(parent!))}`\n break\n case specifier?.startsWith('file:'):\n base = fileURLToPath(specifier!)\n break\n }\n\n throw new ERR_INVALID_PACKAGE_CONFIG(\n path,\n base,\n cast<SyntaxError>(e).message\n )\n }\n\n return pkg\n}\n\nexport default readPackageJson\n"],
|
|
6
|
-
"mappings": "AAKA,OAAO,oBAAoB;AAC3B,OAAO,uBAAuB;AAE9B;AAAA,EACE;AAAA,OAEK;AACP,OAAO,WAAW;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,OAAO,QAAQ;AACf,SAAS,qBAAqB;AAC9B,OAAO,YAAY;AACnB,OAAO,WAAW;AAmBlB,MAAM,kBAAkB,CACtB,MAAgB,KAChB,WACA,WAC0B;AAE1B,oBAAkB,KAAK,KAAK,GAG5B,CAAC,YAAY,SAAS,KAAK,eAAe,WAAW,WAAW,GAGhE,CAAC,YAAY,MAAM,KAAK,kBAAkB,QAAQ,QAAQ,GAG1D,MAAM,cAAc,MAAM,GAAG,CAAC;AAO9B,QAAM,OAAe,MAAM,iBAAiB,MAAM,KAAK,KAAK,cAAc,CAAC;AAG3E,MAAI,CAAC,OAAO,IAAI;AAAG,WAAO;AAO1B,MAAI;AAGJ,MAAI;AACF,UAAM,KAAK,MAAM,GAAG,aAAa,MAAM,MAAM,CAAC;AAAA,EAChD,SAAS,GAAY;AAQnB,QAAI;AAGJ,YAAQ,IAAM;AAAA,MACZ,MAAK,aAAa,CAAC,MAAM,MAAM,KAAK,CAAC,cAAc,MAAM;AACvD,eAAO,IAAI,SAAS,UAAU,cAAc,MAAM,MAAO,CAAC,CAAC;AAC3D;AAAA,MACF,KAAK,WAAW,WAAW,OAAO;AAChC,eAAO,cAAc,SAAU;AAC/B;AAAA,IACJ;AAEA,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA,KAAkB,CAAC,EAAE;AAAA,IACvB;AAAA,EACF;AAEA,SAAO;AACT;AAEA,IAAO,4BAAQ;",
|
|
7
|
-
"names": []
|
|
8
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file resolveAlias
|
|
3
|
-
* @module mlly/utils/resolveAlias
|
|
4
|
-
*/
|
|
5
|
-
import type { ResolveAliasOptions } from '../interfaces/index.mjs';
|
|
6
|
-
/**
|
|
7
|
-
* Resolves a path alias in the given module `specifier`; does nothing if a path
|
|
8
|
-
* match isn't found.
|
|
9
|
-
*
|
|
10
|
-
* @see {@linkcode ResolveAliasOptions}
|
|
11
|
-
*
|
|
12
|
-
* @async
|
|
13
|
-
*
|
|
14
|
-
* @param {string} specifier - Module specifier to evaluate
|
|
15
|
-
* @param {ResolveAliasOptions} [options={}] - Resolution options
|
|
16
|
-
* @return {Promise<string>} Resolved specifier or original module specifier
|
|
17
|
-
* @throws {NodeError}
|
|
18
|
-
*/
|
|
19
|
-
declare const resolveAlias: (specifier: string, options?: ResolveAliasOptions) => Promise<string>;
|
|
20
|
-
export default resolveAlias;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import validateArraySet from "../internal/validate-array-set.mjs";
|
|
2
|
-
import validateBoolean from "../internal/validate-boolean.mjs";
|
|
3
|
-
import validateObject from "../internal/validate-object.mjs";
|
|
4
|
-
import validateString from "../internal/validate-string.mjs";
|
|
5
|
-
import validateURLString from "../internal/validate-url-string.mjs";
|
|
6
|
-
import pathe from "@flex-development/pathe";
|
|
7
|
-
import {
|
|
8
|
-
CompareResult,
|
|
9
|
-
DOT,
|
|
10
|
-
flat,
|
|
11
|
-
get,
|
|
12
|
-
includes,
|
|
13
|
-
isNIL,
|
|
14
|
-
isNull,
|
|
15
|
-
keys,
|
|
16
|
-
regexp,
|
|
17
|
-
sort
|
|
18
|
-
} from "@flex-development/tutils";
|
|
19
|
-
import { URL, pathToFileURL } from "node:url";
|
|
20
|
-
import compareSubpaths from "./compare-subpaths.mjs";
|
|
21
|
-
import CONDITIONS from "./conditions.mjs";
|
|
22
|
-
import parseModuleId from "./parse-module-id.mjs";
|
|
23
|
-
import PATTERN_CHARACTER from "./pattern-character.mjs";
|
|
24
|
-
import RESOLVE_EXTENSIONS from "./resolve-extensions.mjs";
|
|
25
|
-
import resolveModule from "./resolve-module.mjs";
|
|
26
|
-
import toBareSpecifier from "./to-bare-specifier.mjs";
|
|
27
|
-
import toRelativeSpecifier from "./to-relative-specifier.mjs";
|
|
28
|
-
import toURL from "./to-url.mjs";
|
|
29
|
-
const resolveAlias = async (specifier, options = {}) => {
|
|
30
|
-
const {
|
|
31
|
-
absolute = !0,
|
|
32
|
-
aliases = {},
|
|
33
|
-
condition = "default",
|
|
34
|
-
conditions = CONDITIONS,
|
|
35
|
-
cwd = pathToFileURL(DOT),
|
|
36
|
-
ext,
|
|
37
|
-
extensions = RESOLVE_EXTENSIONS,
|
|
38
|
-
parent = import.meta.url,
|
|
39
|
-
preserveSymlinks = !1
|
|
40
|
-
} = options;
|
|
41
|
-
validateString(specifier, "specifier"), validateBoolean(absolute, "options.absolute"), validateObject(aliases, "options.aliases"), validateString(condition, "options.condition"), validateArraySet(conditions, "options.conditions"), validateURLString(cwd, "options.cwd"), validateArraySet(extensions, "options.extensions"), validateURLString(parent, "options.parent"), validateBoolean(preserveSymlinks, "options.preserveSymlinks");
|
|
42
|
-
const id = parseModuleId(specifier, {
|
|
43
|
-
parent: toURL(parent),
|
|
44
|
-
pkgname: !1
|
|
45
|
-
});
|
|
46
|
-
let alias = null, trail = "";
|
|
47
|
-
for (const key of sort(keys(aliases), compareSubpaths)) {
|
|
48
|
-
const pattern = key.indexOf(PATTERN_CHARACTER);
|
|
49
|
-
if (pattern === -1 && key === id.raw) {
|
|
50
|
-
alias = key;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
if (pattern !== -1 && id.raw.startsWith(key.slice(0, pattern))) {
|
|
54
|
-
const trailer = key.slice(pattern + 1);
|
|
55
|
-
id.raw.length >= key.length && id.raw.endsWith(trailer) && compareSubpaths(alias ?? "", key) === CompareResult.GREATER_THAN && key.lastIndexOf(PATTERN_CHARACTER) === pattern && (alias = key, trail = id.raw.slice(pattern, id.raw.length - trailer.length));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (isNull(alias) || isNIL(aliases[alias]))
|
|
59
|
-
return specifier;
|
|
60
|
-
const base = toURL(cwd).href.replace(/\/$/, "") + pathe.sep;
|
|
61
|
-
let url = null;
|
|
62
|
-
for (let segment of flat([get(aliases, alias, [])])) {
|
|
63
|
-
includes(segment, PATTERN_CHARACTER) && (segment = segment.replace(
|
|
64
|
-
new RegExp(`${regexp(PATTERN_CHARACTER)}$`),
|
|
65
|
-
trail
|
|
66
|
-
));
|
|
67
|
-
let tries = new Set(
|
|
68
|
-
[
|
|
69
|
-
"",
|
|
70
|
-
...[...extensions].map((ext2) => pathe.formatExt(ext2)),
|
|
71
|
-
...[...extensions].map((ext2) => "/index" + pathe.formatExt(ext2))
|
|
72
|
-
].map((suffix) => segment + suffix).filter((segment2) => !!segment2.length).map((segment2) => new URL(segment2, base).pathname)
|
|
73
|
-
);
|
|
74
|
-
if (segment.startsWith("node_modules")) {
|
|
75
|
-
const [trypath = ""] = [...tries];
|
|
76
|
-
tries = /* @__PURE__ */ new Set([trypath.replace(/.*\/node_modules\//, ""), ...tries]);
|
|
77
|
-
}
|
|
78
|
-
for (const trypath of tries)
|
|
79
|
-
try {
|
|
80
|
-
url = await resolveModule(trypath, {
|
|
81
|
-
condition,
|
|
82
|
-
conditions,
|
|
83
|
-
ext,
|
|
84
|
-
extensions,
|
|
85
|
-
parent: toURL(parent),
|
|
86
|
-
preserveSymlinks
|
|
87
|
-
});
|
|
88
|
-
break;
|
|
89
|
-
} catch {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (url)
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
return url ? absolute ? url.href : /\/node_modules\//.test(url.href) ? toBareSpecifier(url, toURL(parent), new Set(conditions)) : toRelativeSpecifier(url, toURL(parent)) : specifier;
|
|
96
|
-
};
|
|
97
|
-
var resolve_alias_default = resolveAlias;
|
|
98
|
-
export {
|
|
99
|
-
resolve_alias_default as default
|
|
100
|
-
};
|
|
101
|
-
//# sourceMappingURL=resolve-alias.mjs.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/resolve-alias.ts"],
|
|
4
|
-
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file resolveAlias\n * @module mlly/utils/resolveAlias\n */\n\nimport type { ParsedModuleId, ResolveAliasOptions } from '#src/interfaces'\nimport validateArraySet from '#src/internal/validate-array-set'\nimport validateBoolean from '#src/internal/validate-boolean'\nimport validateObject from '#src/internal/validate-object'\nimport validateString from '#src/internal/validate-string'\nimport validateURLString from '#src/internal/validate-url-string'\nimport type { NodeError } from '@flex-development/errnode'\nimport pathe from '@flex-development/pathe'\nimport {\n CompareResult,\n DOT,\n flat,\n get,\n includes,\n isNIL,\n isNull,\n keys,\n regexp,\n sort,\n type Nullable\n} from '@flex-development/tutils'\nimport { URL, pathToFileURL } from 'node:url'\nimport compareSubpaths from './compare-subpaths'\nimport CONDITIONS from './conditions'\nimport parseModuleId from './parse-module-id'\nimport PATTERN_CHARACTER from './pattern-character'\nimport RESOLVE_EXTENSIONS from './resolve-extensions'\nimport resolveModule from './resolve-module'\nimport toBareSpecifier from './to-bare-specifier'\nimport toRelativeSpecifier from './to-relative-specifier'\nimport toURL from './to-url'\n\n/**\n * Resolves a path alias in the given module `specifier`; does nothing if a path\n * match isn't found.\n *\n * @see {@linkcode ResolveAliasOptions}\n *\n * @async\n *\n * @param {string} specifier - Module specifier to evaluate\n * @param {ResolveAliasOptions} [options={}] - Resolution options\n * @return {Promise<string>} Resolved specifier or original module specifier\n * @throws {NodeError}\n */\nconst resolveAlias = async (\n specifier: string,\n options: ResolveAliasOptions = {}\n): Promise<string> => {\n const {\n absolute = true,\n aliases = {},\n condition = 'default',\n conditions = CONDITIONS,\n cwd = pathToFileURL(DOT),\n ext,\n extensions = RESOLVE_EXTENSIONS,\n parent = import.meta.url,\n preserveSymlinks = false\n } = options\n\n // ensure specifier is a string\n validateString(specifier, 'specifier')\n\n // ensure option schemas\n validateBoolean(absolute, 'options.absolute')\n validateObject(aliases, 'options.aliases')\n validateString(condition, 'options.condition')\n validateArraySet(conditions, 'options.conditions')\n validateURLString(cwd, 'options.cwd')\n validateArraySet(extensions, 'options.extensions')\n validateURLString(parent, 'options.parent')\n validateBoolean(preserveSymlinks, 'options.preserveSymlinks')\n\n /**\n * Parsed module id.\n *\n * **Note**: Ensures {@linkcode specifier} is a valid module specifier.\n *\n * @const {ParsedModuleId} id\n */\n const id: ParsedModuleId = parseModuleId(specifier, {\n parent: toURL(parent),\n pkgname: false\n })\n\n /**\n * Path alias in {@linkcode aliases} that maps to {@linkcode specifier}.\n *\n * @var {Nullable<string>} key\n */\n let alias: Nullable<string> = null\n\n /**\n * Everything after {@linkcode alias} in {@linkcode specifier}.\n *\n * @var {string} trail\n */\n let trail: string = ''\n\n // match specifier to alias\n for (const key of sort(keys(aliases), compareSubpaths)) {\n /**\n * Index of {@linkcode PATTERN_CHARACTER} in {@linkcode key}.\n *\n * @const {number} p\n */\n const pattern: number = key.indexOf(PATTERN_CHARACTER)\n\n // no pattern character => need exact match for alias\n if (pattern === -1 && key === id.raw) {\n alias = key\n break\n }\n\n // pattern character => need best match for alias\n if (pattern !== -1 && id.raw.startsWith(key.slice(0, pattern))) {\n /**\n * Everything after pattern character (`*`) in {@linkcode key}.\n *\n * @const {string} trailer\n */\n const trailer: string = key.slice(pattern + 1)\n\n // best match found => reset key and base\n if (\n id.raw.length >= key.length &&\n id.raw.endsWith(trailer) &&\n compareSubpaths(alias ?? '', key) === CompareResult.GREATER_THAN &&\n key.lastIndexOf(PATTERN_CHARACTER) === pattern\n ) {\n alias = key\n trail = id.raw.slice(pattern, id.raw.length - trailer.length)\n }\n }\n }\n\n // exit early if alias was not found or alias does not map any paths\n if (isNull(alias) || isNIL(aliases[alias])) return specifier\n\n /**\n * URL of directory to resolve non-absolute modules from.\n *\n * @const {string} base\n */\n const base: string = toURL(cwd).href.replace(/\\/$/, '') + pathe.sep\n\n /**\n * Resolved module URL.\n *\n * @var {Nullable<URL>} url\n */\n let url: Nullable<URL> = null\n\n // try resolving path alias\n for (let segment of flat([get(aliases, alias, [])])) {\n // replace pattern character in segment with trail of specifier\n if (includes(segment, PATTERN_CHARACTER)) {\n segment = segment.replace(\n new RegExp(`${regexp(PATTERN_CHARACTER)}$`),\n trail\n )\n }\n\n /**\n * Absolute paths to modules to try resolving.\n *\n * @var {Set<string>} tries\n */\n let tries: Set<string> = new Set(\n [\n '',\n ...[...extensions].map(ext => pathe.formatExt(ext)),\n ...[...extensions].map(ext => '/index' + pathe.formatExt(ext))\n ]\n .map((suffix: string) => segment + suffix)\n .filter((segment: string) => !!segment.length)\n .map((segment: string) => new URL(segment, base).pathname)\n )\n\n // add attempt to resolve possible package export\n if (segment.startsWith('node_modules')) {\n const [trypath = ''] = [...tries]\n tries = new Set([trypath.replace(/.*\\/node_modules\\//, ''), ...tries])\n }\n\n // find first resolvable module\n for (const trypath of tries) {\n try {\n url = await resolveModule(trypath, {\n condition,\n conditions,\n ext,\n extensions,\n parent: toURL(parent),\n preserveSymlinks\n })\n\n // exit if module was resolved\n break\n } catch {\n continue\n }\n }\n\n // stop checking path segments if path alias was resolved\n if (url) break\n }\n\n return url\n ? absolute\n ? url.href\n : /\\/node_modules\\//.test(url.href)\n ? toBareSpecifier(url, toURL(parent), new Set(conditions))\n : toRelativeSpecifier(url, toURL(parent))\n : specifier\n}\n\nexport default resolveAlias\n"],
|
|
6
|
-
"mappings": "AAMA,OAAO,sBAAsB;AAC7B,OAAO,qBAAqB;AAC5B,OAAO,oBAAoB;AAC3B,OAAO,oBAAoB;AAC3B,OAAO,uBAAuB;AAE9B,OAAO,WAAW;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,KAAK,qBAAqB;AACnC,OAAO,qBAAqB;AAC5B,OAAO,gBAAgB;AACvB,OAAO,mBAAmB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,wBAAwB;AAC/B,OAAO,mBAAmB;AAC1B,OAAO,qBAAqB;AAC5B,OAAO,yBAAyB;AAChC,OAAO,WAAW;AAelB,MAAM,eAAe,OACnB,WACA,UAA+B,CAAC,MACZ;AACpB,QAAM;AAAA,IACJ,WAAW;AAAA,IACX,UAAU,CAAC;AAAA,IACX,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,MAAM,cAAc,GAAG;AAAA,IACvB;AAAA,IACA,aAAa;AAAA,IACb,SAAS,YAAY;AAAA,IACrB,mBAAmB;AAAA,EACrB,IAAI;AAGJ,iBAAe,WAAW,WAAW,GAGrC,gBAAgB,UAAU,kBAAkB,GAC5C,eAAe,SAAS,iBAAiB,GACzC,eAAe,WAAW,mBAAmB,GAC7C,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AAA,QACE;AAAA,QACA,GAAG,CAAC,GAAG,UAAU,EAAE,IAAI,CAAAA,SAAO,MAAM,UAAUA,IAAG,CAAC;AAAA,QAClD,GAAG,CAAC,GAAG,UAAU,EAAE,IAAI,CAAAA,SAAO,WAAW,MAAM,UAAUA,IAAG,CAAC;AAAA,MAC/D,EACG,IAAI,CAAC,WAAmB,UAAU,MAAM,EACxC,OAAO,CAACC,aAAoB,CAAC,CAACA,SAAQ,MAAM,EAC5C,IAAI,CAACA,aAAoB,IAAI,IAAIA,UAAS,IAAI,EAAE,QAAQ;AAAA,IAC7D;AAGA,QAAI,QAAQ,WAAW,cAAc,GAAG;AACtC,YAAM,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,KAAK;AAChC,cAAQ,oBAAI,IAAI,CAAC,QAAQ,QAAQ,sBAAsB,EAAE,GAAG,GAAG,KAAK,CAAC;AAAA,IACvE;AAGA,eAAW,WAAW;AACpB,UAAI;AACF,cAAM,MAAM,cAAc,SAAS;AAAA,UACjC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,QAAQ,MAAM,MAAM;AAAA,UACpB;AAAA,QACF,CAAC;AAGD;AAAA,MACF,QAAQ;AACN;AAAA,MACF;AAIF,QAAI;AAAK;AAAA,EACX;AAEA,SAAO,MACH,WACE,IAAI,OACJ,mBAAmB,KAAK,IAAI,IAAI,IAChC,gBAAgB,KAAK,MAAM,MAAM,GAAG,IAAI,IAAI,UAAU,CAAC,IACvD,oBAAoB,KAAK,MAAM,MAAM,CAAC,IACxC;AACN;AAEA,IAAO,wBAAQ;",
|
|
7
|
-
"names": ["ext", "segment"]
|
|
8
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file resolveAliases
|
|
3
|
-
* @module mlly/utils/resolveAliases
|
|
4
|
-
*/
|
|
5
|
-
import type { ResolveAliasOptions } from '../interfaces/index.mjs';
|
|
6
|
-
/**
|
|
7
|
-
* Resolves path aliases in the given piece of source `code`.
|
|
8
|
-
*
|
|
9
|
-
* @see {@linkcode ResolveAliasOptions}
|
|
10
|
-
* @see {@linkcode resolveAlias}
|
|
11
|
-
*
|
|
12
|
-
* @async
|
|
13
|
-
*
|
|
14
|
-
* @param {string} code - Code to evaluate
|
|
15
|
-
* @param {ResolveAliasOptions} [options={}] - Resolve alias options
|
|
16
|
-
* @return {Promise<string>} `code` unmodified or with path aliases resolved
|
|
17
|
-
*/
|
|
18
|
-
declare const resolveAliases: (code: string, options?: ResolveAliasOptions) => Promise<string>;
|
|
19
|
-
export default resolveAliases;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { SpecifierSyntaxKind } from "../enums/index.mjs";
|
|
2
|
-
import { regexp } from "@flex-development/tutils";
|
|
3
|
-
import extractStatements from "./extract-statements.mjs";
|
|
4
|
-
import resolveAlias from "./resolve-alias.mjs";
|
|
5
|
-
const resolveAliases = async (code, options = {}) => {
|
|
6
|
-
for (const statement of extractStatements(code))
|
|
7
|
-
if (statement.specifier && statement.specifier_syntax !== SpecifierSyntaxKind.DYNAMIC) {
|
|
8
|
-
const specifier = await resolveAlias(
|
|
9
|
-
statement.specifier,
|
|
10
|
-
options
|
|
11
|
-
);
|
|
12
|
-
specifier !== statement.specifier && (code = code.replace(
|
|
13
|
-
statement.code,
|
|
14
|
-
statement.code.replace(
|
|
15
|
-
new RegExp(`(?<=["'])${regexp(statement.specifier)}(?=["'])`),
|
|
16
|
-
specifier
|
|
17
|
-
)
|
|
18
|
-
));
|
|
19
|
-
}
|
|
20
|
-
return code;
|
|
21
|
-
};
|
|
22
|
-
var resolve_aliases_default = resolveAliases;
|
|
23
|
-
export {
|
|
24
|
-
resolve_aliases_default as default
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=resolve-aliases.mjs.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/resolve-aliases.ts"],
|
|
4
|
-
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file resolveAliases\n * @module mlly/utils/resolveAliases\n */\n\nimport { SpecifierSyntaxKind } from '#src/enums'\nimport type { ResolveAliasOptions } from '#src/interfaces'\nimport { regexp } from '@flex-development/tutils'\nimport extractStatements from './extract-statements'\nimport resolveAlias from './resolve-alias'\n\n/**\n * Resolves path aliases in the given piece of source `code`.\n *\n * @see {@linkcode ResolveAliasOptions}\n * @see {@linkcode resolveAlias}\n *\n * @async\n *\n * @param {string} code - Code to evaluate\n * @param {ResolveAliasOptions} [options={}] - Resolve alias options\n * @return {Promise<string>} `code` unmodified or with path aliases resolved\n */\nconst resolveAliases = async (\n code: string,\n options: ResolveAliasOptions = {}\n): Promise<string> => {\n for (const statement of extractStatements(code)) {\n if (statement.specifier) {\n if (statement.specifier_syntax !== SpecifierSyntaxKind.DYNAMIC) {\n /**\n * Resolved module specifier.\n *\n * @const {string} specifier\n */\n const specifier: string = await resolveAlias(\n statement.specifier,\n options\n )\n\n // replace path alias\n if (specifier !== statement.specifier) {\n code = code.replace(\n statement.code,\n statement.code.replace(\n new RegExp(`(?<=[\"'])${regexp(statement.specifier)}(?=[\"'])`),\n specifier\n )\n )\n }\n }\n }\n }\n\n return code\n}\n\nexport default resolveAliases\n"],
|
|
6
|
-
"mappings": "AAKA,SAAS,2BAA2B;AAEpC,SAAS,cAAc;AACvB,OAAO,uBAAuB;AAC9B,OAAO,kBAAkB;AAczB,MAAM,iBAAiB,OACrB,MACA,UAA+B,CAAC,MACZ;AACpB,aAAW,aAAa,kBAAkB,IAAI;AAC5C,QAAI,UAAU,aACR,UAAU,qBAAqB,oBAAoB,SAAS;AAM9D,YAAM,YAAoB,MAAM;AAAA,QAC9B,UAAU;AAAA,QACV;AAAA,MACF;AAGA,MAAI,cAAc,UAAU,cAC1B,OAAO,KAAK;AAAA,QACV,UAAU;AAAA,QACV,UAAU,KAAK;AAAA,UACb,IAAI,OAAO,YAAY,OAAO,UAAU,SAAS,CAAC,UAAU;AAAA,UAC5D;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAIJ,SAAO;AACT;AAEA,IAAO,0BAAQ;",
|
|
7
|
-
"names": []
|
|
8
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file RESOLVE_EXTENSIONS
|
|
3
|
-
* @module mlly/utils/RESOLVE_EXTENSIONS
|
|
4
|
-
*/
|
|
5
|
-
import type { Ext } from '@flex-development/pathe';
|
|
6
|
-
/**
|
|
7
|
-
* Default resolvable file extensions.
|
|
8
|
-
*
|
|
9
|
-
* @see {@linkcode Ext}
|
|
10
|
-
*
|
|
11
|
-
* @const {Set<Ext>} RESOLVE_EXTENSIONS
|
|
12
|
-
*/
|
|
13
|
-
declare const RESOLVE_EXTENSIONS: Set<Ext>;
|
|
14
|
-
export default RESOLVE_EXTENSIONS;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const RESOLVE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2
|
-
".mjs",
|
|
3
|
-
".mts",
|
|
4
|
-
".cjs",
|
|
5
|
-
".cts",
|
|
6
|
-
".js",
|
|
7
|
-
".ts",
|
|
8
|
-
".jsx",
|
|
9
|
-
".tsx",
|
|
10
|
-
".css",
|
|
11
|
-
".json",
|
|
12
|
-
".node",
|
|
13
|
-
".wasm",
|
|
14
|
-
".d.mts",
|
|
15
|
-
".d.cts",
|
|
16
|
-
".d.ts"
|
|
17
|
-
]);
|
|
18
|
-
var resolve_extensions_default = RESOLVE_EXTENSIONS;
|
|
19
|
-
export {
|
|
20
|
-
resolve_extensions_default as default
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=resolve-extensions.mjs.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/resolve-extensions.ts"],
|
|
4
|
-
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file RESOLVE_EXTENSIONS\n * @module mlly/utils/RESOLVE_EXTENSIONS\n */\n\nimport type { Ext } from '@flex-development/pathe'\n\n/**\n * Default resolvable file extensions.\n *\n * @see {@linkcode Ext}\n *\n * @const {Set<Ext>} RESOLVE_EXTENSIONS\n */\nconst RESOLVE_EXTENSIONS: Set<Ext> = new Set([\n '.mjs',\n '.mts',\n '.cjs',\n '.cts',\n '.js',\n '.ts',\n '.jsx',\n '.tsx',\n '.css',\n '.json',\n '.node',\n '.wasm',\n '.d.mts',\n '.d.cts',\n '.d.ts'\n])\n\nexport default RESOLVE_EXTENSIONS\n"],
|
|
6
|
-
"mappings": "AAcA,MAAM,qBAA+B,oBAAI,IAAI;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAO,6BAAQ;",
|
|
7
|
-
"names": []
|
|
8
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file resolveModule
|
|
3
|
-
* @module mlly/utils/resolveModule
|
|
4
|
-
*/
|
|
5
|
-
import type { ResolveModuleOptions } from '../interfaces/index.mjs';
|
|
6
|
-
import { URL } from 'node:url';
|
|
7
|
-
/**
|
|
8
|
-
* Resolves `specifier` according to the [ESM Resolver algorithm][1], mostly 😉.
|
|
9
|
-
*
|
|
10
|
-
* Adds support for:
|
|
11
|
-
*
|
|
12
|
-
* - Extensionless file and directory index resolution
|
|
13
|
-
* - Replacing file extensions
|
|
14
|
-
*
|
|
15
|
-
* Other differences between Node.js:
|
|
16
|
-
*
|
|
17
|
-
* - [Subpath import][2] targets (that are strings) must be relative to the
|
|
18
|
-
* current working directory (e.g. `'./src/index.ts'`, `'./src/*.ts'`) or
|
|
19
|
-
* start with a [NPM valid package name][3]. See [`nodejs/node#40579`][4] for
|
|
20
|
-
* details.
|
|
21
|
-
*
|
|
22
|
-
* [1]: https://nodejs.org/api/esm.html#esm_resolver_algorithm
|
|
23
|
-
* [2]: https://nodejs.org/api/packages.html#subpath-imports
|
|
24
|
-
* [3]: https://regex101.com/r/BHcJfc
|
|
25
|
-
* [4]: https://github.com/nodejs/node/issues/40579
|
|
26
|
-
*
|
|
27
|
-
* @see {@linkcode NodeError}
|
|
28
|
-
* @see {@linkcode ResolveModuleOptions}
|
|
29
|
-
* @see {@linkcode URL}
|
|
30
|
-
*
|
|
31
|
-
* @async
|
|
32
|
-
*
|
|
33
|
-
* @param {string} specifier - Module specifier to resolve
|
|
34
|
-
* @param {ResolveModuleOptions} [options={}] - Module resolution options
|
|
35
|
-
* @return {Promise<URL>} Resolved module URL
|
|
36
|
-
* @throws {NodeError}
|
|
37
|
-
*/
|
|
38
|
-
declare const resolveModule: (specifier: string, options?: ResolveModuleOptions) => Promise<URL>;
|
|
39
|
-
export default resolveModule;
|