@flex-development/mlly 1.0.0-alpha.9 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1120 -376
- package/README.md +1555 -12
- package/dist/index.d.mts +3 -4
- package/dist/index.mjs +5 -5
- package/dist/interfaces/aliases.d.mts +21 -0
- package/dist/interfaces/condition-map.d.mts +24 -0
- package/dist/interfaces/file-system.d.mts +29 -0
- package/dist/interfaces/get-source-context.d.mts +44 -0
- package/dist/interfaces/get-source-options.d.mts +48 -0
- package/dist/interfaces/index.d.mts +18 -21
- package/dist/interfaces/is-directory.d.mts +17 -0
- package/dist/interfaces/is-file.d.mts +17 -0
- package/dist/interfaces/main-field-map.d.mts +22 -0
- package/dist/interfaces/module-format-map.d.mts +26 -0
- package/dist/interfaces/pattern-key-comparison-map.d.mts +31 -0
- package/dist/interfaces/protocol-map.d.mts +44 -0
- package/dist/interfaces/read-file.d.mts +28 -0
- package/dist/interfaces/realpath.d.mts +30 -0
- package/dist/interfaces/resolve-alias-options.d.mts +43 -0
- package/dist/interfaces/resolve-module-options.d.mts +79 -0
- package/dist/interfaces/stat.d.mts +28 -0
- package/dist/interfaces/stats.d.mts +23 -0
- package/dist/internal/chain-or-call.mjs +34 -0
- package/dist/internal/chars.mjs +17 -0
- package/dist/internal/check-invalid-segments.mjs +49 -0
- package/dist/internal/constant.mjs +23 -0
- package/dist/internal/fs.browser.mjs +42 -0
- package/dist/internal/fs.node.mjs +16 -0
- package/dist/internal/identity.mjs +23 -0
- package/dist/internal/invalid-package-target.mjs +36 -0
- package/dist/internal/invalid-subpath.mjs +37 -0
- package/dist/internal/is-promise.mjs +26 -0
- package/dist/internal/process.browser.mjs +8 -0
- package/dist/lib/can-parse-url.d.mts +23 -0
- package/dist/lib/can-parse-url.mjs +31 -0
- package/dist/lib/cwd.d.mts +14 -0
- package/dist/lib/cwd.mjs +17 -0
- package/dist/lib/default-conditions.d.mts +15 -0
- package/dist/lib/default-conditions.mjs +14 -0
- package/dist/lib/default-extensions.d.mts +14 -0
- package/dist/lib/default-extensions.mjs +29 -0
- package/dist/lib/default-main-fields.d.mts +14 -0
- package/dist/lib/default-main-fields.mjs +13 -0
- package/dist/lib/extension-format-map.d.mts +16 -0
- package/dist/lib/extension-format-map.mjs +31 -0
- package/dist/lib/formats.d.mts +21 -0
- package/dist/lib/formats.mjs +22 -0
- package/dist/lib/get-source.d.mts +46 -0
- package/dist/lib/get-source.mjs +156 -0
- package/dist/lib/index.d.mts +41 -0
- package/dist/lib/index.mjs +41 -0
- package/dist/lib/is-absolute-specifier.d.mts +23 -0
- package/dist/lib/is-absolute-specifier.mjs +34 -0
- package/dist/lib/is-array-index.d.mts +19 -0
- package/dist/lib/is-array-index.mjs +28 -0
- package/dist/lib/is-bare-specifier.d.mts +23 -0
- package/dist/lib/is-bare-specifier.mjs +33 -0
- package/dist/lib/is-directory.d.mts +27 -0
- package/dist/lib/is-directory.mjs +54 -0
- package/dist/lib/is-file.d.mts +27 -0
- package/dist/lib/is-file.mjs +54 -0
- package/dist/lib/is-imports-subpath.d.mts +26 -0
- package/dist/lib/is-imports-subpath.mjs +28 -0
- package/dist/lib/is-module-id.d.mts +23 -0
- package/dist/lib/is-module-id.mjs +24 -0
- package/dist/lib/is-relative-specifier.d.mts +23 -0
- package/dist/lib/is-relative-specifier.mjs +36 -0
- package/dist/lib/lookup-package-scope.d.mts +49 -0
- package/dist/lib/lookup-package-scope.mjs +102 -0
- package/dist/lib/pattern-key-compare.d.mts +28 -0
- package/dist/lib/pattern-key-compare.mjs +71 -0
- package/dist/lib/pattern-match.d.mts +22 -0
- package/dist/lib/pattern-match.mjs +85 -0
- package/dist/lib/read-package-json.d.mts +63 -0
- package/dist/lib/read-package-json.mjs +115 -0
- package/dist/lib/resolve-alias.d.mts +21 -0
- package/dist/lib/resolve-alias.mjs +102 -0
- package/dist/lib/resolve-module.d.mts +43 -0
- package/dist/lib/resolve-module.mjs +186 -0
- package/dist/lib/resolver.d.mts +346 -0
- package/dist/lib/resolver.mjs +1015 -0
- package/dist/lib/root.d.mts +11 -0
- package/dist/lib/root.mjs +12 -0
- package/dist/lib/to-relative-specifier.d.mts +27 -0
- package/dist/lib/to-relative-specifier.mjs +63 -0
- package/dist/lib/to-url.d.mts +26 -0
- package/dist/lib/to-url.mjs +34 -0
- package/dist/types/awaitable.d.mts +12 -0
- package/dist/types/change-ext-fn.d.mts +29 -0
- package/dist/types/condition.d.mts +13 -0
- package/dist/types/dot.d.mts +9 -0
- package/dist/types/empty-array.d.mts +9 -0
- package/dist/types/empty-object.d.mts +19 -0
- package/dist/types/empty-string.d.mts +9 -0
- package/dist/types/ext.d.mts +12 -0
- package/dist/types/get-source-handler.d.mts +22 -0
- package/dist/types/get-source-handlers.d.mts +15 -0
- package/dist/types/index.d.mts +19 -10
- package/dist/types/list.d.mts +12 -0
- package/dist/types/main-field.d.mts +13 -0
- package/dist/types/module-format.d.mts +13 -0
- package/dist/types/module-id.d.mts +3 -4
- package/dist/types/numeric.d.mts +9 -0
- package/dist/types/pattern-key-comparison.d.mts +14 -0
- package/dist/types/pattern-match.d.mts +10 -0
- package/dist/types/protocol.d.mts +6 -7
- package/package.json +151 -158
- package/changelog.config.ts +0 -404
- package/dist/enums/assert-type.d.mts +0 -21
- package/dist/enums/assert-type.mjs +0 -10
- package/dist/enums/assert-type.mjs.map +0 -6
- package/dist/enums/format.d.mts +0 -17
- package/dist/enums/format.mjs +0 -13
- package/dist/enums/format.mjs.map +0 -6
- package/dist/enums/index.d.mts +0 -10
- package/dist/enums/index.mjs +0 -15
- package/dist/enums/index.mjs.map +0 -6
- package/dist/enums/kind-specifier-syntax.d.mts +0 -14
- package/dist/enums/kind-specifier-syntax.mjs +0 -10
- package/dist/enums/kind-specifier-syntax.mjs.map +0 -6
- package/dist/enums/kind-specifier.d.mts +0 -17
- package/dist/enums/kind-specifier.mjs +0 -11
- package/dist/enums/kind-specifier.mjs.map +0 -6
- package/dist/enums/kind-statement-syntax.d.mts +0 -22
- package/dist/enums/kind-statement-syntax.mjs +0 -18
- package/dist/enums/kind-statement-syntax.mjs.map +0 -6
- package/dist/enums/kind-statement.d.mts +0 -15
- package/dist/enums/kind-statement.mjs +0 -11
- package/dist/enums/kind-statement.mjs.map +0 -6
- package/dist/index.mjs.map +0 -6
- package/dist/interfaces/import-assertions.d.mts +0 -20
- package/dist/interfaces/import-dynamic.d.mts +0 -43
- package/dist/interfaces/import-static.d.mts +0 -37
- package/dist/interfaces/index.mjs +0 -1
- package/dist/interfaces/index.mjs.map +0 -6
- package/dist/interfaces/options-fill-module.d.mts +0 -23
- package/dist/interfaces/options-find-subpath.d.mts +0 -49
- package/dist/interfaces/options-get-format.d.mts +0 -83
- package/dist/interfaces/options-get-source.d.mts +0 -63
- package/dist/interfaces/options-parse-module-id.d.mts +0 -33
- package/dist/interfaces/options-parse-subpath.d.mts +0 -31
- package/dist/interfaces/options-resolve-alias.d.mts +0 -53
- package/dist/interfaces/options-resolve-module.d.mts +0 -64
- package/dist/interfaces/options-resolve.d.mts +0 -15
- package/dist/interfaces/package-scope.d.mts +0 -25
- package/dist/interfaces/parsed-data-url.d.mts +0 -56
- package/dist/interfaces/parsed-module-id.d.mts +0 -80
- package/dist/interfaces/parsed-subpath.d.mts +0 -40
- package/dist/interfaces/statement-export.d.mts +0 -44
- package/dist/interfaces/statement-import.d.mts +0 -38
- package/dist/interfaces/statement-require.d.mts +0 -38
- package/dist/interfaces/statement.d.mts +0 -49
- package/dist/internal/escape-reg-exp.d.mts +0 -16
- package/dist/internal/escape-reg-exp.mjs +0 -10
- package/dist/internal/escape-reg-exp.mjs.map +0 -6
- package/dist/internal/format-type-map.d.mts +0 -17
- package/dist/internal/format-type-map.mjs +0 -13
- package/dist/internal/format-type-map.mjs.map +0 -6
- package/dist/internal/get-specifier-kind.d.mts +0 -17
- package/dist/internal/get-specifier-kind.mjs +0 -14
- package/dist/internal/get-specifier-kind.mjs.map +0 -6
- package/dist/internal/get-subpaths.d.mts +0 -25
- package/dist/internal/get-subpaths.mjs +0 -10
- package/dist/internal/get-subpaths.mjs.map +0 -6
- package/dist/internal/is-array-index.d.mts +0 -15
- package/dist/internal/is-array-index.mjs +0 -9
- package/dist/internal/is-array-index.mjs.map +0 -6
- package/dist/internal/is-directory.d.mts +0 -13
- package/dist/internal/is-directory.mjs +0 -16
- package/dist/internal/is-directory.mjs.map +0 -6
- package/dist/internal/is-file.d.mts +0 -13
- package/dist/internal/is-file.mjs +0 -16
- package/dist/internal/is-file.mjs.map +0 -6
- package/dist/internal/is-function.d.mts +0 -12
- package/dist/internal/is-function.mjs +0 -8
- package/dist/internal/is-function.mjs.map +0 -6
- package/dist/internal/regex-encoded-sep.d.mts +0 -13
- package/dist/internal/regex-encoded-sep.mjs +0 -6
- package/dist/internal/regex-encoded-sep.mjs.map +0 -6
- package/dist/internal/regex-internal-specifier.d.mts +0 -14
- package/dist/internal/regex-internal-specifier.mjs +0 -6
- package/dist/internal/regex-internal-specifier.mjs.map +0 -6
- package/dist/internal/regex-package-name.d.mts +0 -13
- package/dist/internal/regex-package-name.mjs +0 -6
- package/dist/internal/regex-package-name.mjs.map +0 -6
- package/dist/internal/regex-package-path.d.mts +0 -15
- package/dist/internal/regex-package-path.mjs +0 -6
- package/dist/internal/regex-package-path.mjs.map +0 -6
- package/dist/internal/resolver.d.mts +0 -130
- package/dist/internal/resolver.mjs +0 -500
- package/dist/internal/resolver.mjs.map +0 -6
- package/dist/internal/validate-boolean.d.mts +0 -20
- package/dist/internal/validate-boolean.mjs +0 -11
- package/dist/internal/validate-boolean.mjs.map +0 -6
- package/dist/internal/validate-object.d.mts +0 -23
- package/dist/internal/validate-object.mjs +0 -11
- package/dist/internal/validate-object.mjs.map +0 -6
- package/dist/internal/validate-set.d.mts +0 -23
- package/dist/internal/validate-set.mjs +0 -11
- package/dist/internal/validate-set.mjs.map +0 -6
- package/dist/internal/validate-string.d.mts +0 -20
- package/dist/internal/validate-string.mjs +0 -11
- package/dist/internal/validate-string.mjs.map +0 -6
- package/dist/internal/validate-url-string.d.mts +0 -22
- package/dist/internal/validate-url-string.mjs +0 -12
- package/dist/internal/validate-url-string.mjs.map +0 -6
- package/dist/types/declaration.d.mts +0 -9
- package/dist/types/fn-change-ext.d.mts +0 -28
- package/dist/types/index.mjs +0 -1
- package/dist/types/index.mjs.map +0 -6
- package/dist/types/mime-type.d.mts +0 -13
- package/dist/types/module-specifier-type.d.mts +0 -11
- package/dist/types/syntax-kind-export.d.mts +0 -12
- package/dist/types/syntax-kind-import.d.mts +0 -12
- package/dist/types/syntax-kind-require.d.mts +0 -12
- package/dist/utils/compare-subpaths.d.mts +0 -25
- package/dist/utils/compare-subpaths.mjs +0 -24
- package/dist/utils/compare-subpaths.mjs.map +0 -6
- package/dist/utils/conditions.d.mts +0 -13
- package/dist/utils/conditions.mjs +0 -6
- package/dist/utils/conditions.mjs.map +0 -6
- package/dist/utils/detect-syntax.d.mts +0 -21
- package/dist/utils/detect-syntax.mjs +0 -12
- package/dist/utils/detect-syntax.mjs.map +0 -6
- package/dist/utils/extension-format-map.d.mts +0 -16
- package/dist/utils/extension-format-map.mjs +0 -22
- package/dist/utils/extension-format-map.mjs.map +0 -6
- package/dist/utils/extract-statements.d.mts +0 -21
- package/dist/utils/extract-statements.mjs +0 -21
- package/dist/utils/extract-statements.mjs.map +0 -6
- package/dist/utils/fill-modules.d.mts +0 -23
- package/dist/utils/fill-modules.mjs +0 -62
- package/dist/utils/fill-modules.mjs.map +0 -6
- package/dist/utils/find-dynamic-imports.d.mts +0 -18
- package/dist/utils/find-dynamic-imports.mjs +0 -39
- package/dist/utils/find-dynamic-imports.mjs.map +0 -6
- package/dist/utils/find-exports.d.mts +0 -21
- package/dist/utils/find-exports.mjs +0 -95
- package/dist/utils/find-exports.mjs.map +0 -6
- package/dist/utils/find-requires.d.mts +0 -18
- package/dist/utils/find-requires.mjs +0 -32
- package/dist/utils/find-requires.mjs.map +0 -6
- package/dist/utils/find-static-imports.d.mts +0 -18
- package/dist/utils/find-static-imports.mjs +0 -34
- package/dist/utils/find-static-imports.mjs.map +0 -6
- package/dist/utils/find-subpath.d.mts +0 -30
- package/dist/utils/find-subpath.mjs +0 -106
- package/dist/utils/find-subpath.mjs.map +0 -6
- package/dist/utils/get-format.d.mts +0 -24
- package/dist/utils/get-format.mjs +0 -111
- package/dist/utils/get-format.mjs.map +0 -6
- package/dist/utils/get-source.d.mts +0 -22
- package/dist/utils/get-source.mjs +0 -63
- package/dist/utils/get-source.mjs.map +0 -6
- package/dist/utils/has-cjs-syntax.d.mts +0 -25
- package/dist/utils/has-cjs-syntax.mjs +0 -11
- package/dist/utils/has-cjs-syntax.mjs.map +0 -6
- package/dist/utils/has-esm-syntax.d.mts +0 -21
- package/dist/utils/has-esm-syntax.mjs +0 -11
- package/dist/utils/has-esm-syntax.mjs.map +0 -6
- package/dist/utils/index.d.mts +0 -42
- package/dist/utils/index.mjs +0 -79
- package/dist/utils/index.mjs.map +0 -6
- package/dist/utils/is-absolute-specifier.d.mts +0 -19
- package/dist/utils/is-absolute-specifier.mjs +0 -25
- package/dist/utils/is-absolute-specifier.mjs.map +0 -6
- package/dist/utils/is-bare-specifier.d.mts +0 -19
- package/dist/utils/is-bare-specifier.mjs +0 -10
- package/dist/utils/is-bare-specifier.mjs.map +0 -6
- package/dist/utils/is-exports-sugar.d.mts +0 -25
- package/dist/utils/is-exports-sugar.mjs +0 -26
- package/dist/utils/is-exports-sugar.mjs.map +0 -6
- package/dist/utils/is-relative-specifier.d.mts +0 -20
- package/dist/utils/is-relative-specifier.mjs +0 -11
- package/dist/utils/is-relative-specifier.mjs.map +0 -6
- package/dist/utils/lookup-package-scope.d.mts +0 -26
- package/dist/utils/lookup-package-scope.mjs +0 -38
- package/dist/utils/lookup-package-scope.mjs.map +0 -6
- package/dist/utils/parse-data-url.d.mts +0 -25
- package/dist/utils/parse-data-url.mjs +0 -25
- package/dist/utils/parse-data-url.mjs.map +0 -6
- package/dist/utils/parse-module-id.d.mts +0 -22
- package/dist/utils/parse-module-id.mjs +0 -122
- package/dist/utils/parse-module-id.mjs.map +0 -6
- package/dist/utils/parse-subpath.d.mts +0 -35
- package/dist/utils/parse-subpath.mjs +0 -54
- package/dist/utils/parse-subpath.mjs.map +0 -6
- package/dist/utils/pattern-character.d.mts +0 -11
- package/dist/utils/pattern-character.mjs +0 -6
- package/dist/utils/pattern-character.mjs.map +0 -6
- package/dist/utils/read-package-json.d.mts +0 -26
- package/dist/utils/read-package-json.mjs +0 -43
- package/dist/utils/read-package-json.mjs.map +0 -6
- package/dist/utils/resolve-alias.d.mts +0 -20
- package/dist/utils/resolve-alias.mjs +0 -106
- package/dist/utils/resolve-alias.mjs.map +0 -6
- package/dist/utils/resolve-aliases.d.mts +0 -19
- package/dist/utils/resolve-aliases.mjs +0 -28
- package/dist/utils/resolve-aliases.mjs.map +0 -6
- package/dist/utils/resolve-extensions.d.mts +0 -14
- package/dist/utils/resolve-extensions.mjs +0 -22
- package/dist/utils/resolve-extensions.mjs.map +0 -6
- package/dist/utils/resolve-module.d.mts +0 -39
- package/dist/utils/resolve-module.mjs +0 -64
- package/dist/utils/resolve-module.mjs.map +0 -6
- package/dist/utils/resolve-modules.d.mts +0 -25
- package/dist/utils/resolve-modules.mjs +0 -26
- package/dist/utils/resolve-modules.mjs.map +0 -6
- package/dist/utils/to-absolute-specifier.d.mts +0 -22
- package/dist/utils/to-absolute-specifier.mjs +0 -8
- package/dist/utils/to-absolute-specifier.mjs.map +0 -6
- package/dist/utils/to-bare-specifier.d.mts +0 -42
- package/dist/utils/to-bare-specifier.mjs +0 -90
- package/dist/utils/to-bare-specifier.mjs.map +0 -6
- package/dist/utils/to-data-url.d.mts +0 -30
- package/dist/utils/to-data-url.mjs +0 -11
- package/dist/utils/to-data-url.mjs.map +0 -6
- package/dist/utils/to-node-url.d.mts +0 -19
- package/dist/utils/to-node-url.mjs +0 -10
- package/dist/utils/to-node-url.mjs.map +0 -6
- package/dist/utils/to-relative-specifier.d.mts +0 -22
- package/dist/utils/to-relative-specifier.mjs +0 -21
- package/dist/utils/to-relative-specifier.mjs.map +0 -6
- package/dist/utils/to-url.d.mts +0 -22
- package/dist/utils/to-url.mjs +0 -12
- package/dist/utils/to-url.mjs.map +0 -6
- package/dist/utils/validate-assertions.d.mts +0 -23
- package/dist/utils/validate-assertions.mjs +0 -52
- package/dist/utils/validate-assertions.mjs.map +0 -6
- package/dist/utils/validate-exports.d.mts +0 -24
- package/dist/utils/validate-exports.mjs +0 -72
- package/dist/utils/validate-exports.mjs.map +0 -6
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file root
|
|
3
|
+
* @module mlly/lib/root
|
|
4
|
+
*/
|
|
5
|
+
import { dot, parse, pathToFileURL, resolve } from '@flex-development/pathe';
|
|
6
|
+
/**
|
|
7
|
+
* The URL of the file system root.
|
|
8
|
+
*
|
|
9
|
+
* @const {URL} root
|
|
10
|
+
*/
|
|
11
|
+
const root = pathToFileURL(parse(resolve(dot)).root);
|
|
12
|
+
export default root;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file toRelativeSpecifier
|
|
3
|
+
* @module mlly/lib/toRelativeSpecifier
|
|
4
|
+
*/
|
|
5
|
+
import type { ModuleId } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Turn `url` into a *relative specifier*.
|
|
8
|
+
*
|
|
9
|
+
* ::: info
|
|
10
|
+
* The relative specifier will only have a file extension
|
|
11
|
+
* if `specifier` also has an extension.
|
|
12
|
+
* :::
|
|
13
|
+
*
|
|
14
|
+
* @see {@linkcode ModuleId}
|
|
15
|
+
* @see https://nodejs.org/api/esm.html#terminology
|
|
16
|
+
*
|
|
17
|
+
* @this {void}
|
|
18
|
+
*
|
|
19
|
+
* @param {ModuleId} url
|
|
20
|
+
* The `file:` URL to convert
|
|
21
|
+
* @param {ModuleId} parent
|
|
22
|
+
* The parent module id
|
|
23
|
+
* @return {string}
|
|
24
|
+
* The relative specifier
|
|
25
|
+
*/
|
|
26
|
+
declare function toRelativeSpecifier(this: void, url: ModuleId, parent: ModuleId): string;
|
|
27
|
+
export default toRelativeSpecifier;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file toRelativeSpecifier
|
|
3
|
+
* @module mlly/lib/toRelativeSpecifier
|
|
4
|
+
*/
|
|
5
|
+
import pathe from '@flex-development/pathe';
|
|
6
|
+
import { ok } from 'devlop';
|
|
7
|
+
/**
|
|
8
|
+
* Turn `url` into a *relative specifier*.
|
|
9
|
+
*
|
|
10
|
+
* ::: info
|
|
11
|
+
* The relative specifier will only have a file extension
|
|
12
|
+
* if `specifier` also has an extension.
|
|
13
|
+
* :::
|
|
14
|
+
*
|
|
15
|
+
* @see {@linkcode ModuleId}
|
|
16
|
+
* @see https://nodejs.org/api/esm.html#terminology
|
|
17
|
+
*
|
|
18
|
+
* @this {void}
|
|
19
|
+
*
|
|
20
|
+
* @param {ModuleId} url
|
|
21
|
+
* The `file:` URL to convert
|
|
22
|
+
* @param {ModuleId} parent
|
|
23
|
+
* The parent module id
|
|
24
|
+
* @return {string}
|
|
25
|
+
* The relative specifier
|
|
26
|
+
*/
|
|
27
|
+
function toRelativeSpecifier(url, parent) {
|
|
28
|
+
parent = pathe.fileURLToPath(parent);
|
|
29
|
+
url = pathe.fileURLToPath(url);
|
|
30
|
+
/**
|
|
31
|
+
* The directory name of the {@linkcode parent} path.
|
|
32
|
+
*
|
|
33
|
+
* @const {string} dirname
|
|
34
|
+
*/
|
|
35
|
+
const dirname = pathe.dirname(parent);
|
|
36
|
+
/**
|
|
37
|
+
* The relative specifier.
|
|
38
|
+
*
|
|
39
|
+
* @var {string} specifier
|
|
40
|
+
*/
|
|
41
|
+
let specifier;
|
|
42
|
+
if (url.startsWith(parent) && parent.endsWith(pathe.sep)) {
|
|
43
|
+
// inside same directory as parent
|
|
44
|
+
specifier = pathe.dot + pathe.sep + url.slice(parent.length);
|
|
45
|
+
}
|
|
46
|
+
else if (url === dirname || url.startsWith(dirname + pathe.sep)) {
|
|
47
|
+
// directory name of parent or inside same directory as parent
|
|
48
|
+
specifier = pathe.dot + pathe.sep + url.slice(dirname.length + 1);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// outside directory of parent
|
|
52
|
+
specifier = pathe.relative(parent, url);
|
|
53
|
+
ok(specifier.startsWith(pathe.dot), 'expected result to start with `.`');
|
|
54
|
+
/* v8 ignore else -- @preserve */
|
|
55
|
+
if (/(?:\.\.\/){2,}/.test(specifier)) {
|
|
56
|
+
// remove first '../' segment:
|
|
57
|
+
// pathe.relative backs out of an extra directory
|
|
58
|
+
specifier = specifier.slice(specifier.indexOf(pathe.sep) + 1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return specifier;
|
|
62
|
+
}
|
|
63
|
+
export default toRelativeSpecifier;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file toUrl
|
|
3
|
+
* @module mlly/lib/toUrl
|
|
4
|
+
*/
|
|
5
|
+
import type { ModuleId } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Convert `id` to a {@linkcode URL}.
|
|
8
|
+
*
|
|
9
|
+
* > 👉 **Note**: If `id` cannot be parsed as a `URL`, and is also not a
|
|
10
|
+
* > [builtin module][builtin-module], it will be assumed to be a path and
|
|
11
|
+
* > converted to a [`file:` URL][file-url].
|
|
12
|
+
*
|
|
13
|
+
* [builtin-module]: https://nodejs.org/api/esm.html#builtin-modules
|
|
14
|
+
* [file-url]: https://nodejs.org/api/esm.html#file-urls
|
|
15
|
+
*
|
|
16
|
+
* @this {void}
|
|
17
|
+
*
|
|
18
|
+
* @param {ModuleId} id
|
|
19
|
+
* The module id to convert
|
|
20
|
+
* @param {ModuleId | null | undefined} [parent]
|
|
21
|
+
* The base URL to resolve against if `id` is not absolute
|
|
22
|
+
* @return {URL}
|
|
23
|
+
* The new URL
|
|
24
|
+
*/
|
|
25
|
+
declare function toUrl(this: void, id: ModuleId, parent?: ModuleId | null | undefined): URL;
|
|
26
|
+
export default toUrl;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file toUrl
|
|
3
|
+
* @module mlly/lib/toUrl
|
|
4
|
+
*/
|
|
5
|
+
import canParseUrl from '#lib/can-parse-url';
|
|
6
|
+
import { isBuiltin } from '@flex-development/is-builtin';
|
|
7
|
+
import pathe from '@flex-development/pathe';
|
|
8
|
+
/**
|
|
9
|
+
* Convert `id` to a {@linkcode URL}.
|
|
10
|
+
*
|
|
11
|
+
* > 👉 **Note**: If `id` cannot be parsed as a `URL`, and is also not a
|
|
12
|
+
* > [builtin module][builtin-module], it will be assumed to be a path and
|
|
13
|
+
* > converted to a [`file:` URL][file-url].
|
|
14
|
+
*
|
|
15
|
+
* [builtin-module]: https://nodejs.org/api/esm.html#builtin-modules
|
|
16
|
+
* [file-url]: https://nodejs.org/api/esm.html#file-urls
|
|
17
|
+
*
|
|
18
|
+
* @this {void}
|
|
19
|
+
*
|
|
20
|
+
* @param {ModuleId} id
|
|
21
|
+
* The module id to convert
|
|
22
|
+
* @param {ModuleId | null | undefined} [parent]
|
|
23
|
+
* The base URL to resolve against if `id` is not absolute
|
|
24
|
+
* @return {URL}
|
|
25
|
+
* The new URL
|
|
26
|
+
*/
|
|
27
|
+
function toUrl(id, parent) {
|
|
28
|
+
return canParseUrl(id, parent)
|
|
29
|
+
? new URL(id, parent ?? undefined)
|
|
30
|
+
: isBuiltin(id)
|
|
31
|
+
? new URL('node:' + String(id))
|
|
32
|
+
: pathe.pathToFileURL(String(id));
|
|
33
|
+
}
|
|
34
|
+
export default toUrl;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - Awaitable
|
|
3
|
+
* @module mlly/types/Awaitable
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Create a union of `T` and `T` as a promise-like object.
|
|
7
|
+
*
|
|
8
|
+
* @template {any} T
|
|
9
|
+
* The value
|
|
10
|
+
*/
|
|
11
|
+
type Awaitable<T> = PromiseLike<T> | T;
|
|
12
|
+
export type { Awaitable as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - ChangeExtFn
|
|
3
|
+
* @module mlly/types/ChangeExtFn
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get a new file extension for `url`.
|
|
7
|
+
*
|
|
8
|
+
* Returning an empty string (`''`), `null`, or `undefined` will remove the
|
|
9
|
+
* current file extension.
|
|
10
|
+
*
|
|
11
|
+
* ::: info
|
|
12
|
+
* The new file extension need not begin with a dot character (`'.'`).
|
|
13
|
+
* :::
|
|
14
|
+
*
|
|
15
|
+
* @see {@linkcode URL}
|
|
16
|
+
* @see https://github.com/flex-development/pathe/tree/1.0.3#changeextpath-string-ext-nullablestring-string
|
|
17
|
+
*
|
|
18
|
+
* @template {string | null | undefined} Ext
|
|
19
|
+
* The new file extension
|
|
20
|
+
*
|
|
21
|
+
* @param {URL} url
|
|
22
|
+
* The resolved module URL
|
|
23
|
+
* @param {string} specifier
|
|
24
|
+
* The module specifier being resolved
|
|
25
|
+
* @return {Ext}
|
|
26
|
+
* The new file extension
|
|
27
|
+
*/
|
|
28
|
+
type ChangeExtFn<Ext extends string | null | undefined = string | null | undefined> = (this: void, url: URL, specifier: string) => Ext;
|
|
29
|
+
export type { ChangeExtFn as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - Condition
|
|
3
|
+
* @module mlly/types/Condition
|
|
4
|
+
*/
|
|
5
|
+
import type { ConditionMap } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Union of values that can occur where a export/import condition is expected.
|
|
8
|
+
*
|
|
9
|
+
* To register new conditions, augment {@linkcode ConditionMap}.
|
|
10
|
+
* They will be added to this union automatically.
|
|
11
|
+
*/
|
|
12
|
+
type Condition = ConditionMap[keyof ConditionMap];
|
|
13
|
+
export type { Condition as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - EmptyObject
|
|
3
|
+
* @module mlly/types/EmptyObject
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The empty object symbol.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*
|
|
10
|
+
* @const {symbol} tag
|
|
11
|
+
*/
|
|
12
|
+
export declare const tag: unique symbol;
|
|
13
|
+
/**
|
|
14
|
+
* An empty object.
|
|
15
|
+
*/
|
|
16
|
+
type EmptyObject = {
|
|
17
|
+
[tag]?: never;
|
|
18
|
+
};
|
|
19
|
+
export type { EmptyObject as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - GetSourceHandler
|
|
3
|
+
* @module mlly/types/GetSourceHandler
|
|
4
|
+
*/
|
|
5
|
+
import type { Awaitable, GetSourceContext } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Get the source code for a module.
|
|
8
|
+
*
|
|
9
|
+
* @see {@linkcode Awaitable}
|
|
10
|
+
* @see {@linkcode GetSourceContext}
|
|
11
|
+
* @see {@linkcode URL}
|
|
12
|
+
*
|
|
13
|
+
* @this {GetSourceContext}
|
|
14
|
+
* The retrieval context
|
|
15
|
+
*
|
|
16
|
+
* @param {URL} url
|
|
17
|
+
* The module URL
|
|
18
|
+
* @return {Awaitable<Uint8Array | string | null | undefined>}
|
|
19
|
+
* The source code
|
|
20
|
+
*/
|
|
21
|
+
type GetSourceHandler = (this: GetSourceContext, url: URL) => Awaitable<Uint8Array | string | null | undefined>;
|
|
22
|
+
export type { GetSourceHandler as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - GetSourceHandlers
|
|
3
|
+
* @module mlly/types/GetSourceHandlers
|
|
4
|
+
*/
|
|
5
|
+
import type { GetSourceHandler, Protocol } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Record, where key is a URL protocol and each value is a source code handler.
|
|
8
|
+
*
|
|
9
|
+
* @see {@linkcode GetSourceHandler}
|
|
10
|
+
* @see {@linkcode Protocol}
|
|
11
|
+
*/
|
|
12
|
+
type GetSourceHandlers = {
|
|
13
|
+
[H in Protocol]?: GetSourceHandler | null | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type { GetSourceHandlers as default };
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Type
|
|
2
|
+
* @file Entry Point - Type Aliases
|
|
3
3
|
* @module mlly/types
|
|
4
4
|
*/
|
|
5
|
-
export type { default as
|
|
6
|
-
export type { default as ChangeExtFn } from '
|
|
7
|
-
export type { default as
|
|
8
|
-
export type { default as
|
|
9
|
-
export type { default as
|
|
10
|
-
export type { default as
|
|
11
|
-
export type { default as
|
|
12
|
-
export type { default as
|
|
13
|
-
export type { default as
|
|
5
|
+
export type { default as Awaitable } from '#types/awaitable';
|
|
6
|
+
export type { default as ChangeExtFn } from '#types/change-ext-fn';
|
|
7
|
+
export type { default as Condition } from '#types/condition';
|
|
8
|
+
export type { default as Dot } from '#types/dot';
|
|
9
|
+
export type { default as EmptyArray } from '#types/empty-array';
|
|
10
|
+
export type { default as EmptyObject } from '#types/empty-object';
|
|
11
|
+
export type { default as EmptyString } from '#types/empty-string';
|
|
12
|
+
export type { default as Ext } from '#types/ext';
|
|
13
|
+
export type { default as GetSourceHandler } from '#types/get-source-handler';
|
|
14
|
+
export type { default as GetSourceHandlers } from '#types/get-source-handlers';
|
|
15
|
+
export type { default as List } from '#types/list';
|
|
16
|
+
export type { default as MainField } from '#types/main-field';
|
|
17
|
+
export type { default as ModuleFormat } from '#types/module-format';
|
|
18
|
+
export type { default as ModuleId } from '#types/module-id';
|
|
19
|
+
export type { default as Numeric } from '#types/numeric';
|
|
20
|
+
export type { default as PatternKeyComparison } from '#types/pattern-key-comparison';
|
|
21
|
+
export type { default as PatternMatch } from '#types/pattern-match';
|
|
22
|
+
export type { default as Protocol } from '#types/protocol';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - MainField
|
|
3
|
+
* @module mlly/types/MainField
|
|
4
|
+
*/
|
|
5
|
+
import type { MainFieldMap } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Union of values that can occur where a main field is expected.
|
|
8
|
+
*
|
|
9
|
+
* To register new fields, augment {@linkcode MainFieldMap}.
|
|
10
|
+
* They will be added to this union automatically.
|
|
11
|
+
*/
|
|
12
|
+
type MainField = MainFieldMap[keyof MainFieldMap];
|
|
13
|
+
export type { MainField as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - ModuleFormat
|
|
3
|
+
* @module mlly/types/ModuleFormat
|
|
4
|
+
*/
|
|
5
|
+
import type { ModuleFormatMap } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Union of values that can occur where a module format is expected.
|
|
8
|
+
*
|
|
9
|
+
* To register new formats, augment {@linkcode ModuleFormatMap}.
|
|
10
|
+
* They will be added to this union automatically.
|
|
11
|
+
*/
|
|
12
|
+
type ModuleFormat = ModuleFormatMap[keyof ModuleFormatMap];
|
|
13
|
+
export type { ModuleFormat as default };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Type
|
|
2
|
+
* @file Type Aliases - ModuleId
|
|
3
3
|
* @module mlly/types/ModuleId
|
|
4
4
|
*/
|
|
5
|
-
/// <reference types="node" />
|
|
6
|
-
import type { URL } from 'node:url';
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
6
|
+
* Union of values that can occur where a
|
|
7
|
+
* ECMAScript (ES) module identifier is expected.
|
|
9
8
|
*
|
|
10
9
|
* @see {@linkcode URL}
|
|
11
10
|
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - PatternKeyComparison
|
|
3
|
+
* @module mlly/types/PatternKeyComparison
|
|
4
|
+
*/
|
|
5
|
+
import type { PatternKeyComparisonMap } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Union of values that can occur
|
|
8
|
+
* where a `PATTERN_KEY_COMPARE` algorithm result is expected.
|
|
9
|
+
*
|
|
10
|
+
* To register new results, augment {@linkcode PatternKeyComparisonMap}.
|
|
11
|
+
* They will be added to this union automatically.
|
|
12
|
+
*/
|
|
13
|
+
type PatternKeyComparison = PatternKeyComparisonMap[keyof PatternKeyComparisonMap];
|
|
14
|
+
export type { PatternKeyComparison as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - PatternMatch
|
|
3
|
+
* @module mlly/types/PatternMatch
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* List, where the first item is the key of a package `exports` or `imports`
|
|
7
|
+
* target object, and the last is a subpath pattern match.
|
|
8
|
+
*/
|
|
9
|
+
type PatternMatch = [expansionKey: string, patternMatch: string | null];
|
|
10
|
+
export type { PatternMatch as default };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Type
|
|
2
|
+
* @file Type Aliases - Protocol
|
|
3
3
|
* @module mlly/types/Protocol
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { ProtocolMap } from '@flex-development/mlly';
|
|
6
6
|
/**
|
|
7
|
-
* URL
|
|
7
|
+
* Union of values that can occur where a URL protocol is expected.
|
|
8
8
|
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @see https://url.spec.whatwg.org/#special-scheme
|
|
9
|
+
* To register new protocols, augment {@linkcode ProtocolMap}.
|
|
10
|
+
* They will be added to this union automatically.
|
|
12
11
|
*/
|
|
13
|
-
type Protocol =
|
|
12
|
+
type Protocol = ProtocolMap[keyof ProtocolMap];
|
|
14
13
|
export type { Protocol as default };
|