@flex-development/mlly 1.0.0-alpha.19 → 1.0.0-alpha.20
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 +20 -0
- package/README.md +16 -0
- package/dist/interfaces/file-system.d.mts +7 -10
- package/dist/internal/fs.browser.mjs +6 -6
- package/dist/lib/get-source.mjs +2 -2
- package/dist/lib/is-directory.d.mts +2 -4
- package/dist/lib/is-directory.mjs +2 -2
- package/dist/lib/is-file.d.mts +2 -4
- package/dist/lib/is-file.mjs +2 -2
- package/dist/lib/lookup-package-scope.d.mts +2 -4
- package/dist/lib/lookup-package-scope.mjs +2 -2
- package/dist/lib/read-package-json.d.mts +2 -2
- package/dist/lib/read-package-json.mjs +3 -3
- package/dist/lib/resolver.d.mts +254 -1
- package/dist/lib/resolver.mjs +129 -24
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [1.0.0-alpha.20](https://github.com/flex-development/mlly/compare/1.0.0-alpha.19...1.0.0-alpha.20) (2024-12-29)
|
|
2
|
+
|
|
3
|
+
### ⚠ BREAKING CHANGES
|
|
4
|
+
|
|
5
|
+
- **lib:** [`resolver`] synchronous methods
|
|
6
|
+
|
|
7
|
+
### :package: Build
|
|
8
|
+
|
|
9
|
+
- [[`a466da3`](https://github.com/flex-development/mlly/commit/a466da3a2220d5bf8b76d5a145c67c7767a4df2e)] **deps-dev:** Bump @stylistic/eslint-plugin from 2.11.0 to 2.12.1 ([#756](https://github.com/flex-development/mlly/issues/756))
|
|
10
|
+
- [[`b55b400`](https://github.com/flex-development/mlly/commit/b55b400e8fd612cb4cd2fae681e82529649fcd69)] **deps-dev:** Bump consola from 3.2.3 to 3.3.1 ([#757](https://github.com/flex-development/mlly/issues/757))
|
|
11
|
+
- [[`156b3d2`](https://github.com/flex-development/mlly/commit/156b3d2f047b07f74fef291f9880fece6635c628)] **deps-dev:** Bump consola from 3.3.1 to 3.3.3 ([#759](https://github.com/flex-development/mlly/issues/759))
|
|
12
|
+
- [[`822d03a`](https://github.com/flex-development/mlly/commit/822d03a715735e4272c3682df634f93aef6630c5)] **deps-dev:** Bump dprint from 0.47.6 to 0.48.0 ([#755](https://github.com/flex-development/mlly/issues/755))
|
|
13
|
+
- [[`51d471a`](https://github.com/flex-development/mlly/commit/51d471af89b6811c7732f73fe22c41a782cec4cb)] **deps-dev:** bump the typescript-eslint group from 8.18.1 to 8.18.3-alpha.5
|
|
14
|
+
- [[`dc82de3`](https://github.com/flex-development/mlly/commit/dc82de388f9387b53a4cd551de44756f99d144fb)] **deps:** Bump @flex-development/pathe from 4.0.0 to 4.0.1 in the flex-development group ([#758](https://github.com/flex-development/mlly/issues/758))
|
|
15
|
+
|
|
16
|
+
### :sparkles: Features
|
|
17
|
+
|
|
18
|
+
- [[`a88c7f8`](https://github.com/flex-development/mlly/commit/a88c7f867397fc061371367c31086693c2f89e4f)] **lib:** [`resolver`] synchronous methods
|
|
19
|
+
|
|
1
20
|
## [1.0.0-alpha.19](https://github.com/flex-development/mlly/compare/1.0.0-alpha.18...1.0.0-alpha.19) (2024-12-20)
|
|
2
21
|
|
|
3
22
|
### ⚠ BREAKING CHANGES
|
|
@@ -1073,3 +1092,4 @@
|
|
|
1073
1092
|
- [[`0266ca9`](https://github.com/flex-development/mlly/commit/0266ca9a5593d0c66e950ba1fe2c8f6df8422ff9)] **resolve:** sort `RESOLVE_EXTENSIONS` according to priority
|
|
1074
1093
|
- [[`36c4b74`](https://github.com/flex-development/mlly/commit/36c4b7475c9bb6c924f5e75c8d6d215a8d23e79c)] **specifiers:** [`toBareSpecifier`] improve `exports` path search
|
|
1075
1094
|
|
|
1095
|
+
|
package/README.md
CHANGED
|
@@ -77,14 +77,22 @@ import {
|
|
|
77
77
|
isImportsSubpath,
|
|
78
78
|
isRelativeSpecifier,
|
|
79
79
|
legacyMainResolve,
|
|
80
|
+
legacyMainResolveSync,
|
|
80
81
|
lookupPackageScope,
|
|
81
82
|
moduleResolve,
|
|
83
|
+
moduleResolveSync,
|
|
82
84
|
packageExportsResolve,
|
|
85
|
+
packageExportsResolveSync,
|
|
83
86
|
packageImportsExportsResolve,
|
|
87
|
+
packageImportsExportsResolveSync,
|
|
84
88
|
packageImportsResolve,
|
|
89
|
+
packageImportsResolveSync,
|
|
85
90
|
packageResolve,
|
|
91
|
+
packageResolveSync,
|
|
86
92
|
packageSelfResolve,
|
|
93
|
+
packageSelfResolveSync,
|
|
87
94
|
packageTargetResolve,
|
|
95
|
+
packageTargetResolveSync,
|
|
88
96
|
patternKeyCompare,
|
|
89
97
|
patternMatch,
|
|
90
98
|
readPackageJson,
|
|
@@ -124,13 +132,21 @@ This package exports the following identifiers:
|
|
|
124
132
|
- [`resolveModule`](./src/lib/resolve-module.mts)
|
|
125
133
|
- [`resolver`](./src/lib/resolver.mts)
|
|
126
134
|
- `legacyMainResolve`
|
|
135
|
+
- `legacyMainResolveSync`
|
|
127
136
|
- `moduleResolve`
|
|
137
|
+
- `moduleResolveSync`
|
|
128
138
|
- `packageExportsResolve`
|
|
139
|
+
- `packageExportsResolveSync`
|
|
129
140
|
- `packageImportsExportsResolve`
|
|
141
|
+
- `packageImportsExportsResolveSync`
|
|
130
142
|
- `packageImportsResolve`
|
|
143
|
+
- `packageImportsResolveSync`
|
|
131
144
|
- `packageResolve`
|
|
145
|
+
- `packageResolveSync`
|
|
132
146
|
- `packageSelfResolve`
|
|
147
|
+
- `packageSelfResolveSync`
|
|
133
148
|
- `packageTargetResolve`
|
|
149
|
+
- `packageTargetResolveSync`
|
|
134
150
|
- [`root`](./src/lib/root.mts)
|
|
135
151
|
- [`toRelativeSpecifier`](./src/lib/to-relative-specifier.mts)
|
|
136
152
|
- [`toUrl`](./src/lib/to-url.mts)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @file Interfaces - FileSystem
|
|
3
3
|
* @module mlly/interfaces/FileSystem
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { ModuleId, Stats } from '@flex-development/mlly';
|
|
6
6
|
/**
|
|
7
7
|
* File system API.
|
|
8
8
|
*/
|
|
@@ -10,7 +10,6 @@ interface FileSystem {
|
|
|
10
10
|
/**
|
|
11
11
|
* Get the contents of `id`.
|
|
12
12
|
*
|
|
13
|
-
* @see {@linkcode Awaitable}
|
|
14
13
|
* @see {@linkcode Buffer}
|
|
15
14
|
* @see {@linkcode ModuleId}
|
|
16
15
|
* @see https://nodejs.org/api/fs.html#fsreadfilepath-options-callback
|
|
@@ -19,14 +18,13 @@ interface FileSystem {
|
|
|
19
18
|
*
|
|
20
19
|
* @param {ModuleId} id
|
|
21
20
|
* The path or `file:` URL to handle
|
|
22
|
-
* @return {
|
|
21
|
+
* @return {Buffer | string}
|
|
23
22
|
* File contents
|
|
24
23
|
*/
|
|
25
|
-
|
|
24
|
+
readFileSync(this: void, id: ModuleId): Buffer | string;
|
|
26
25
|
/**
|
|
27
26
|
* Get the resolved pathname for `id`.
|
|
28
27
|
*
|
|
29
|
-
* @see {@linkcode Awaitable}
|
|
30
28
|
* @see {@linkcode ModuleId}
|
|
31
29
|
* @see https://nodejs.org/api/fs.html#fsrealpathpath-options-callback
|
|
32
30
|
*
|
|
@@ -34,14 +32,13 @@ interface FileSystem {
|
|
|
34
32
|
*
|
|
35
33
|
* @param {ModuleId} id
|
|
36
34
|
* The path or `file:` URL to handle
|
|
37
|
-
* @return {
|
|
35
|
+
* @return {string}
|
|
38
36
|
* Resolved pathname
|
|
39
37
|
*/
|
|
40
|
-
|
|
38
|
+
realpathSync(this: void, id: ModuleId): string;
|
|
41
39
|
/**
|
|
42
40
|
* Get information about a directory or file.
|
|
43
41
|
*
|
|
44
|
-
* @see {@linkcode Awaitable}
|
|
45
42
|
* @see {@linkcode ModuleId}
|
|
46
43
|
* @see {@linkcode Stats}
|
|
47
44
|
*
|
|
@@ -49,9 +46,9 @@ interface FileSystem {
|
|
|
49
46
|
*
|
|
50
47
|
* @param {ModuleId} id
|
|
51
48
|
* The path or `file:` URL to handle
|
|
52
|
-
* @return {
|
|
49
|
+
* @return {Stats}
|
|
53
50
|
* Info about `id`
|
|
54
51
|
*/
|
|
55
|
-
|
|
52
|
+
statSync(this: void, id: ModuleId): Stats;
|
|
56
53
|
}
|
|
57
54
|
export type { FileSystem as default };
|
|
@@ -6,8 +6,8 @@ const fs = {
|
|
|
6
6
|
* Never; not implemented
|
|
7
7
|
* @throws {Error}
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
throw new Error("[
|
|
9
|
+
readFileSync() {
|
|
10
|
+
throw new Error("[readFileSync] not implemented");
|
|
11
11
|
},
|
|
12
12
|
/**
|
|
13
13
|
* Get the resolved pathname of a file.
|
|
@@ -16,8 +16,8 @@ const fs = {
|
|
|
16
16
|
* Never; not implemented
|
|
17
17
|
* @throws {Error}
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
throw new Error("[
|
|
19
|
+
realpathSync() {
|
|
20
|
+
throw new Error("[realpathSync] not implemented");
|
|
21
21
|
},
|
|
22
22
|
/**
|
|
23
23
|
* Get information about a file.
|
|
@@ -26,8 +26,8 @@ const fs = {
|
|
|
26
26
|
* Never; not implemented
|
|
27
27
|
* @throws {Error}
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
throw new Error("[
|
|
29
|
+
statSync() {
|
|
30
|
+
throw new Error("[statSync] not implemented");
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
var fs_browser_default = fs;
|
package/dist/lib/get-source.mjs
CHANGED
|
@@ -52,10 +52,10 @@ function data(url) {
|
|
|
52
52
|
mime.endsWith("base64") ? "base64" : "utf8"
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
function file(url) {
|
|
56
56
|
ok(url.protocol === "file:", "expected `file:` URL");
|
|
57
57
|
let code = null;
|
|
58
|
-
if (
|
|
58
|
+
if (isFile(url, this.fs)) code = this.fs.readFileSync(url);
|
|
59
59
|
return code;
|
|
60
60
|
}
|
|
61
61
|
async function https(url) {
|
|
@@ -9,14 +9,12 @@ import type { FileSystem, ModuleId } from '@flex-development/mlly';
|
|
|
9
9
|
* @see {@linkcode FileSystem}
|
|
10
10
|
* @see {@linkcode ModuleId}
|
|
11
11
|
*
|
|
12
|
-
* @async
|
|
13
|
-
*
|
|
14
12
|
* @param {ModuleId} id
|
|
15
13
|
* Module id to check
|
|
16
14
|
* @param {FileSystem | null | undefined} fs
|
|
17
15
|
* File system API
|
|
18
|
-
* @return {
|
|
16
|
+
* @return {boolean}
|
|
19
17
|
* `true` if directory exists at `id`, `false` otherwise
|
|
20
18
|
*/
|
|
21
|
-
declare function isDirectory(id: ModuleId, fs?: FileSystem | null | undefined):
|
|
19
|
+
declare function isDirectory(id: ModuleId, fs?: FileSystem | null | undefined): boolean;
|
|
22
20
|
export default isDirectory;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import dfs from "#internal/fs";
|
|
2
|
-
|
|
2
|
+
function isDirectory(id, fs) {
|
|
3
3
|
try {
|
|
4
4
|
if (typeof id === "string" && id.startsWith("file:")) id = new URL(id);
|
|
5
|
-
return (
|
|
5
|
+
return (fs ?? dfs).statSync(id).isDirectory();
|
|
6
6
|
} catch {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
package/dist/lib/is-file.d.mts
CHANGED
|
@@ -9,14 +9,12 @@ import type { FileSystem, ModuleId } from '@flex-development/mlly';
|
|
|
9
9
|
* @see {@linkcode FileSystem}
|
|
10
10
|
* @see {@linkcode ModuleId}
|
|
11
11
|
*
|
|
12
|
-
* @async
|
|
13
|
-
*
|
|
14
12
|
* @param {ModuleId} id
|
|
15
13
|
* Module id to check
|
|
16
14
|
* @param {FileSystem | null | undefined} fs
|
|
17
15
|
* File system API
|
|
18
|
-
* @return {
|
|
16
|
+
* @return {boolean}
|
|
19
17
|
* `true` if file exists at `id`, `false` otherwise
|
|
20
18
|
*/
|
|
21
|
-
declare function isFile(id: ModuleId, fs?: FileSystem | null | undefined):
|
|
19
|
+
declare function isFile(id: ModuleId, fs?: FileSystem | null | undefined): boolean;
|
|
22
20
|
export default isFile;
|
package/dist/lib/is-file.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import dfs from "#internal/fs";
|
|
2
|
-
|
|
2
|
+
function isFile(id, fs) {
|
|
3
3
|
try {
|
|
4
4
|
if (typeof id === "string" && id.startsWith("file:")) id = new URL(id);
|
|
5
|
-
return (
|
|
5
|
+
return (fs ?? dfs).statSync(id).isFile();
|
|
6
6
|
} catch {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
@@ -11,16 +11,14 @@ import type { FileSystem, ModuleId } from '@flex-development/mlly';
|
|
|
11
11
|
* @see {@linkcode FileSystem}
|
|
12
12
|
* @see {@linkcode ModuleId}
|
|
13
13
|
*
|
|
14
|
-
* @async
|
|
15
|
-
*
|
|
16
14
|
* @param {ModuleId} url
|
|
17
15
|
* URL of module to get package scope for
|
|
18
16
|
* @param {ModuleId | null | undefined} [end]
|
|
19
17
|
* URL of directory to end search, defaults to {@linkcode root}
|
|
20
18
|
* @param {FileSystem | null | undefined} [fs]
|
|
21
19
|
* File system API
|
|
22
|
-
* @return {
|
|
20
|
+
* @return {URL | null}
|
|
23
21
|
* URL of nearest directory containing `package.json` file or `null`
|
|
24
22
|
*/
|
|
25
|
-
declare function lookupPackageScope(url: ModuleId, end?: ModuleId | null | undefined, fs?: FileSystem | null | undefined):
|
|
23
|
+
declare function lookupPackageScope(url: ModuleId, end?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): URL | null;
|
|
26
24
|
export default lookupPackageScope;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import isFile from "#lib/is-file";
|
|
2
2
|
import root from "#lib/root";
|
|
3
3
|
import pathe from "@flex-development/pathe";
|
|
4
|
-
|
|
4
|
+
function lookupPackageScope(url, end, fs) {
|
|
5
5
|
let scopeUrl = new URL(url);
|
|
6
6
|
while (String(scopeUrl) !== String(end ?? root)) {
|
|
7
7
|
scopeUrl = /[/\\]$/.test(scopeUrl.pathname) ? new URL(pathe.dot + pathe.dot, scopeUrl) : new URL(pathe.dot, scopeUrl);
|
|
8
8
|
if (/node_modules[/\\]$/.test(scopeUrl.pathname)) break;
|
|
9
|
-
if (
|
|
9
|
+
if (isFile(new URL("package.json", scopeUrl), fs)) return scopeUrl;
|
|
10
10
|
}
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
@@ -26,10 +26,10 @@ import type { PackageJson } from '@flex-development/pkg-types';
|
|
|
26
26
|
* URL of parent module
|
|
27
27
|
* @param {FileSystem | null | undefined} [fs]
|
|
28
28
|
* File system API
|
|
29
|
-
* @return {
|
|
29
|
+
* @return {PackageJson | null}
|
|
30
30
|
* Parsed file contents or `null`
|
|
31
31
|
* @throws {ErrInvalidPackageConfig}
|
|
32
32
|
* If `package.json` file does not parse as valid JSON
|
|
33
33
|
*/
|
|
34
|
-
declare function readPackageJson(id: ModuleId, specifier?: string | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined):
|
|
34
|
+
declare function readPackageJson(id: ModuleId, specifier?: string | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): PackageJson | null;
|
|
35
35
|
export default readPackageJson;
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
ERR_INVALID_PACKAGE_CONFIG
|
|
5
5
|
} from "@flex-development/errnode";
|
|
6
6
|
import pathe from "@flex-development/pathe";
|
|
7
|
-
|
|
7
|
+
function readPackageJson(id, specifier, parent, fs) {
|
|
8
8
|
const url = new URL("package.json", id);
|
|
9
|
-
if (
|
|
10
|
-
const data = String(
|
|
9
|
+
if (isFile(url, fs)) {
|
|
10
|
+
const data = String((fs ?? dfs).readFileSync(url));
|
|
11
11
|
try {
|
|
12
12
|
return JSON.parse(data);
|
|
13
13
|
} catch (e) {
|
package/dist/lib/resolver.d.mts
CHANGED
|
@@ -12,7 +12,7 @@ declare module '@flex-development/errnode' {
|
|
|
12
12
|
url?: string | null | undefined;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
export { legacyMainResolve, moduleResolve, packageExportsResolve, packageImportsExportsResolve, packageImportsResolve, packageResolve, packageSelfResolve, packageTargetResolve };
|
|
15
|
+
export { legacyMainResolve, legacyMainResolveSync, moduleResolve, moduleResolveSync, packageExportsResolve, packageExportsResolveSync, packageImportsExportsResolve, packageImportsExportsResolveSync, packageImportsResolve, packageImportsResolveSync, packageResolve, packageResolveSync, packageSelfResolve, packageSelfResolveSync, packageTargetResolve, packageTargetResolveSync };
|
|
16
16
|
/**
|
|
17
17
|
* Resolve the [`main`][main] package entry point using the legacy CommonJS
|
|
18
18
|
* resolution algorithm.
|
|
@@ -43,6 +43,34 @@ export { legacyMainResolve, moduleResolve, packageExportsResolve, packageImports
|
|
|
43
43
|
* @throws {ErrModuleNotFound}
|
|
44
44
|
*/
|
|
45
45
|
declare function legacyMainResolve(packageUrl: ModuleId, manifest?: PackageJson | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): Promise<URL>;
|
|
46
|
+
/**
|
|
47
|
+
* Resolve the [`main`][main] package entry point using the legacy CommonJS
|
|
48
|
+
* resolution algorithm.
|
|
49
|
+
*
|
|
50
|
+
* [main]: https://github.com/nodejs/node/blob/v22.9.0/doc/api/packages.md#main
|
|
51
|
+
*
|
|
52
|
+
* @see {@linkcode ErrModuleNotFound}
|
|
53
|
+
* @see {@linkcode FileSystem}
|
|
54
|
+
* @see {@linkcode MainField}
|
|
55
|
+
* @see {@linkcode ModuleId}
|
|
56
|
+
* @see {@linkcode PackageJson}
|
|
57
|
+
*
|
|
58
|
+
* @param {ModuleId} packageUrl
|
|
59
|
+
* URL of package directory, `package.json` file, or module in the same
|
|
60
|
+
* directory as a `package.json` file
|
|
61
|
+
* @param {PackageJson | null | undefined} [manifest]
|
|
62
|
+
* Package manifest
|
|
63
|
+
* @param {MainField[] | Set<MainField> | null | undefined} [mainFields]
|
|
64
|
+
* List of legacy main fields
|
|
65
|
+
* @param {ModuleId | null | undefined} [parent]
|
|
66
|
+
* URL of parent module
|
|
67
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
68
|
+
* File system API
|
|
69
|
+
* @return {URL}
|
|
70
|
+
* Resolved URL
|
|
71
|
+
* @throws {ErrModuleNotFound}
|
|
72
|
+
*/
|
|
73
|
+
declare function legacyMainResolveSync(packageUrl: ModuleId, manifest?: PackageJson | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): URL;
|
|
46
74
|
/**
|
|
47
75
|
* Resolve a module `specifier`.
|
|
48
76
|
*
|
|
@@ -77,6 +105,38 @@ declare function legacyMainResolve(packageUrl: ModuleId, manifest?: PackageJson
|
|
|
77
105
|
* @throws {ErrUnsupportedDirImport}
|
|
78
106
|
*/
|
|
79
107
|
declare function moduleResolve(specifier: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, preserveSymlinks?: boolean | null | undefined, fs?: FileSystem | null | undefined): Promise<URL>;
|
|
108
|
+
/**
|
|
109
|
+
* Resolve a module `specifier`.
|
|
110
|
+
*
|
|
111
|
+
* Implements the `MODULE_RESOLVE` (`ESM_RESOLVE`) algorithm.
|
|
112
|
+
*
|
|
113
|
+
* @see {@linkcode Condition}
|
|
114
|
+
* @see {@linkcode ErrInvalidModuleSpecifier}
|
|
115
|
+
* @see {@linkcode ErrModuleNotFound}
|
|
116
|
+
* @see {@linkcode ErrUnsupportedDirImport}
|
|
117
|
+
* @see {@linkcode FileSystem}
|
|
118
|
+
* @see {@linkcode ModuleId}
|
|
119
|
+
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
120
|
+
*
|
|
121
|
+
* @param {string} specifier
|
|
122
|
+
* Module specifier to resolve
|
|
123
|
+
* @param {ModuleId} parent
|
|
124
|
+
* URL of parent module
|
|
125
|
+
* @param {Condition[] | Set<Condition> | null | undefined} [conditions]
|
|
126
|
+
* List of export/import conditions
|
|
127
|
+
* @param {MainField[] | Set<MainField> | null | undefined} [mainFields]
|
|
128
|
+
* List of legacy main fields
|
|
129
|
+
* @param {boolean | null | undefined} [preserveSymlinks]
|
|
130
|
+
* Keep symlinks instead of resolving them
|
|
131
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
132
|
+
* File system API
|
|
133
|
+
* @return {URL}
|
|
134
|
+
* Resolved URL
|
|
135
|
+
* @throws {ErrInvalidModuleSpecifier}
|
|
136
|
+
* @throws {ErrModuleNotFound}
|
|
137
|
+
* @throws {ErrUnsupportedDirImport}
|
|
138
|
+
*/
|
|
139
|
+
declare function moduleResolveSync(specifier: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, preserveSymlinks?: boolean | null | undefined, fs?: FileSystem | null | undefined): URL;
|
|
80
140
|
/**
|
|
81
141
|
* Resolve a package export.
|
|
82
142
|
*
|
|
@@ -112,6 +172,39 @@ declare function moduleResolve(specifier: string, parent: ModuleId, conditions?:
|
|
|
112
172
|
* @throws {ErrPackagePathNotExported}
|
|
113
173
|
*/
|
|
114
174
|
declare function packageExportsResolve(packageUrl: ModuleId, subpath: string, exports: Exports | undefined, conditions?: Condition[] | Set<Condition> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): Promise<URL>;
|
|
175
|
+
/**
|
|
176
|
+
* Resolve a package export.
|
|
177
|
+
*
|
|
178
|
+
* Implements the `PACKAGE_EXPORTS_RESOLVE` algorithm.
|
|
179
|
+
*
|
|
180
|
+
* @see {@linkcode Condition}
|
|
181
|
+
* @see {@linkcode ErrInvalidPackageConfig}
|
|
182
|
+
* @see {@linkcode ErrPackagePathNotExported}
|
|
183
|
+
* @see {@linkcode Exports}
|
|
184
|
+
* @see {@linkcode FileSystem}
|
|
185
|
+
* @see {@linkcode Imports}
|
|
186
|
+
* @see {@linkcode ModuleId}
|
|
187
|
+
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
188
|
+
*
|
|
189
|
+
* @param {ModuleId} packageUrl
|
|
190
|
+
* URL of package directory, `package.json` file, or module in the same
|
|
191
|
+
* directory as a `package.json` file
|
|
192
|
+
* @param {string} subpath
|
|
193
|
+
* Package subpath to resolve
|
|
194
|
+
* @param {Exports | undefined} exports
|
|
195
|
+
* Package exports
|
|
196
|
+
* @param {Condition[] | Set<Condition> | null | undefined} [conditions]
|
|
197
|
+
* List of export/import conditions
|
|
198
|
+
* @param {ModuleId | null | undefined} [parent]
|
|
199
|
+
* URL of parent module
|
|
200
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
201
|
+
* File system API
|
|
202
|
+
* @return {URL}
|
|
203
|
+
* Resolved URL
|
|
204
|
+
* @throws {ErrInvalidPackageConfig}
|
|
205
|
+
* @throws {ErrPackagePathNotExported}
|
|
206
|
+
*/
|
|
207
|
+
declare function packageExportsResolveSync(packageUrl: ModuleId, subpath: string, exports: Exports | undefined, conditions?: Condition[] | Set<Condition> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): URL;
|
|
115
208
|
/**
|
|
116
209
|
* Resolve a package export or import.
|
|
117
210
|
*
|
|
@@ -146,6 +239,38 @@ declare function packageExportsResolve(packageUrl: ModuleId, subpath: string, ex
|
|
|
146
239
|
* Resolved URL
|
|
147
240
|
*/
|
|
148
241
|
declare function packageImportsExportsResolve(matchKey: string, matchObject: ExportsObject | Imports | null | undefined, packageUrl: ModuleId, isImports?: boolean | null | undefined, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): Promise<URL | null | undefined>;
|
|
242
|
+
/**
|
|
243
|
+
* Resolve a package export or import.
|
|
244
|
+
*
|
|
245
|
+
* Implements the `PACKAGE_IMPORTS_EXPORTS_RESOLVE` algorithm.
|
|
246
|
+
*
|
|
247
|
+
* @see {@linkcode Condition}
|
|
248
|
+
* @see {@linkcode ExportsObject}
|
|
249
|
+
* @see {@linkcode FileSystem}
|
|
250
|
+
* @see {@linkcode Imports}
|
|
251
|
+
* @see {@linkcode ModuleId}
|
|
252
|
+
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
253
|
+
*
|
|
254
|
+
* @param {string} matchKey
|
|
255
|
+
* Package subpath from module specifier or dot character (`'.'`)
|
|
256
|
+
* @param {ExportsObject | Imports | null | undefined} matchObject
|
|
257
|
+
* Package exports object or imports
|
|
258
|
+
* @param {ModuleId} packageUrl
|
|
259
|
+
* URL of directory containing `package.json` file
|
|
260
|
+
* @param {boolean | null | undefined} [isImports]
|
|
261
|
+
* Whether `matchObject` is internal to the package
|
|
262
|
+
* @param {Condition[] | Set<Condition> | null | undefined} [conditions]
|
|
263
|
+
* List of export/import conditions
|
|
264
|
+
* @param {MainField[] | Set<MainField> | null | undefined} [mainFields]
|
|
265
|
+
* List of legacy main fields
|
|
266
|
+
* @param {ModuleId | null | undefined} [parent]
|
|
267
|
+
* URL of parent module
|
|
268
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
269
|
+
* File system API
|
|
270
|
+
* @return {URL | null | undefined}
|
|
271
|
+
* Resolved URL
|
|
272
|
+
*/
|
|
273
|
+
declare function packageImportsExportsResolveSync(matchKey: string, matchObject: ExportsObject | Imports | null | undefined, packageUrl: ModuleId, isImports?: boolean | null | undefined, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): URL | null | undefined;
|
|
149
274
|
/**
|
|
150
275
|
* Resolve a package import.
|
|
151
276
|
*
|
|
@@ -158,6 +283,8 @@ declare function packageImportsExportsResolve(matchKey: string, matchObject: Exp
|
|
|
158
283
|
* @see {@linkcode ModuleId}
|
|
159
284
|
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
160
285
|
*
|
|
286
|
+
* @async
|
|
287
|
+
*
|
|
161
288
|
* @param {string} specifier
|
|
162
289
|
* The import specifier to resolve
|
|
163
290
|
* @param {ModuleId} parent
|
|
@@ -174,6 +301,34 @@ declare function packageImportsExportsResolve(matchKey: string, matchObject: Exp
|
|
|
174
301
|
* @throws {ErrPackageImportNotDefined}
|
|
175
302
|
*/
|
|
176
303
|
declare function packageImportsResolve(specifier: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, fs?: FileSystem | null | undefined): Promise<URL>;
|
|
304
|
+
/**
|
|
305
|
+
* Resolve a package import.
|
|
306
|
+
*
|
|
307
|
+
* Implements the `PACKAGE_IMPORTS_RESOLVE` algorithm.
|
|
308
|
+
*
|
|
309
|
+
* @see {@linkcode Condition}
|
|
310
|
+
* @see {@linkcode ErrInvalidModuleSpecifier}
|
|
311
|
+
* @see {@linkcode ErrPackageImportNotDefined}
|
|
312
|
+
* @see {@linkcode FileSystem}
|
|
313
|
+
* @see {@linkcode ModuleId}
|
|
314
|
+
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
315
|
+
*
|
|
316
|
+
* @param {string} specifier
|
|
317
|
+
* The import specifier to resolve
|
|
318
|
+
* @param {ModuleId} parent
|
|
319
|
+
* URL of parent module
|
|
320
|
+
* @param {Condition[] | Set<Condition> | null | undefined} [conditions]
|
|
321
|
+
* List of export/import conditions
|
|
322
|
+
* @param {MainField[] | Set<MainField> | null | undefined} [mainFields]
|
|
323
|
+
* List of legacy main fields
|
|
324
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
325
|
+
* File system API
|
|
326
|
+
* @return {URL}
|
|
327
|
+
* Resolved URL
|
|
328
|
+
* @throws {ErrInvalidModuleSpecifier}
|
|
329
|
+
* @throws {ErrPackageImportNotDefined}
|
|
330
|
+
*/
|
|
331
|
+
declare function packageImportsResolveSync(specifier: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, fs?: FileSystem | null | undefined): URL;
|
|
177
332
|
/**
|
|
178
333
|
* Resolve a *bare specifier*.
|
|
179
334
|
*
|
|
@@ -213,6 +368,43 @@ declare function packageImportsResolve(specifier: string, parent: ModuleId, cond
|
|
|
213
368
|
* @throws {ErrModuleNotFound}
|
|
214
369
|
*/
|
|
215
370
|
declare function packageResolve(specifier: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, fs?: FileSystem | null | undefined): Promise<URL>;
|
|
371
|
+
/**
|
|
372
|
+
* Resolve a *bare specifier*.
|
|
373
|
+
*
|
|
374
|
+
* > *Bare specifiers* like `'some-package'` or `'some-package/shuffle'` refer
|
|
375
|
+
* > to the main entry point of a package by package name, or a specific feature
|
|
376
|
+
* > module within a package prefixed by the package name. Including the file
|
|
377
|
+
* > extension is only necessary for packages without an [`"exports"`][exports]
|
|
378
|
+
* > field.
|
|
379
|
+
*
|
|
380
|
+
* Implements the `PACKAGE_RESOLVE` algorithm.
|
|
381
|
+
*
|
|
382
|
+
* [exports]: https://nodejs.org/api/packages.html#exports
|
|
383
|
+
*
|
|
384
|
+
* @see {@linkcode Condition}
|
|
385
|
+
* @see {@linkcode ErrInvalidModuleSpecifier}
|
|
386
|
+
* @see {@linkcode ErrModuleNotFound}
|
|
387
|
+
* @see {@linkcode FileSystem}
|
|
388
|
+
* @see {@linkcode MainField}
|
|
389
|
+
* @see {@linkcode ModuleId}
|
|
390
|
+
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
391
|
+
*
|
|
392
|
+
* @param {string} specifier
|
|
393
|
+
* The package specifier to resolve
|
|
394
|
+
* @param {ModuleId} parent
|
|
395
|
+
* Id of module to resolve `packageSpecifier` against
|
|
396
|
+
* @param {Condition[] | Set<Condition> | null | undefined} [conditions]
|
|
397
|
+
* List of export/import conditions
|
|
398
|
+
* @param {MainField[] | Set<MainField> | null | undefined} [mainFields]
|
|
399
|
+
* List of legacy main fields
|
|
400
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
401
|
+
* File system API
|
|
402
|
+
* @return {URL}
|
|
403
|
+
* Resolved URL
|
|
404
|
+
* @throws {ErrInvalidModuleSpecifier}
|
|
405
|
+
* @throws {ErrModuleNotFound}
|
|
406
|
+
*/
|
|
407
|
+
declare function packageResolveSync(specifier: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, fs?: FileSystem | null | undefined): URL;
|
|
216
408
|
/**
|
|
217
409
|
* Resolve the self-import of a package.
|
|
218
410
|
*
|
|
@@ -239,6 +431,30 @@ declare function packageResolve(specifier: string, parent: ModuleId, conditions?
|
|
|
239
431
|
* Resolved URL
|
|
240
432
|
*/
|
|
241
433
|
declare function packageSelfResolve(name: string, subpath: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, fs?: FileSystem | null | undefined): Promise<URL | undefined>;
|
|
434
|
+
/**
|
|
435
|
+
* Resolve the self-import of a package.
|
|
436
|
+
*
|
|
437
|
+
* Implements the `PACKAGE_SELF_RESOLVE` algorithm.
|
|
438
|
+
*
|
|
439
|
+
* @see {@linkcode Condition}
|
|
440
|
+
* @see {@linkcode FileSystem}
|
|
441
|
+
* @see {@linkcode ModuleId}
|
|
442
|
+
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
443
|
+
*
|
|
444
|
+
* @param {string} name
|
|
445
|
+
* Package name
|
|
446
|
+
* @param {string} subpath
|
|
447
|
+
* Package subpath
|
|
448
|
+
* @param {ModuleId} parent
|
|
449
|
+
* URL of parent module
|
|
450
|
+
* @param {Condition[] | Set<Condition> | null | undefined} [conditions]
|
|
451
|
+
* List of export conditions
|
|
452
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
453
|
+
* File system API
|
|
454
|
+
* @return {URL | undefined}
|
|
455
|
+
* Resolved URL
|
|
456
|
+
*/
|
|
457
|
+
declare function packageSelfResolveSync(name: string, subpath: string, parent: ModuleId, conditions?: Condition[] | Set<Condition> | null | undefined, fs?: FileSystem | null | undefined): URL | undefined;
|
|
242
458
|
/**
|
|
243
459
|
* Resolve a package target.
|
|
244
460
|
*
|
|
@@ -278,3 +494,40 @@ declare function packageSelfResolve(name: string, subpath: string, parent: Modul
|
|
|
278
494
|
* @throws {ErrInvalidPackageTarget}
|
|
279
495
|
*/
|
|
280
496
|
declare function packageTargetResolve(packageUrl: ModuleId, target: unknown, subpath: string, patternMatch?: string | null | undefined, isImports?: boolean | null | undefined, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): Promise<URL | null | undefined>;
|
|
497
|
+
/**
|
|
498
|
+
* Resolve a package target.
|
|
499
|
+
*
|
|
500
|
+
* Implements the `PACKAGE_TARGET_RESOLVE` algorithm.
|
|
501
|
+
*
|
|
502
|
+
* @see {@linkcode Condition}
|
|
503
|
+
* @see {@linkcode ErrInvalidPackageConfig}
|
|
504
|
+
* @see {@linkcode ErrInvalidPackageTarget}
|
|
505
|
+
* @see {@linkcode FileSystem}
|
|
506
|
+
* @see {@linkcode ModuleId}
|
|
507
|
+
* @see {@linkcode Target}
|
|
508
|
+
* @see https://github.com/nodejs/node/blob/v22.9.0/doc/api/esm.md#resolution-algorithm
|
|
509
|
+
*
|
|
510
|
+
* @param {ModuleId} packageUrl
|
|
511
|
+
* URL of directory containing `package.json` file
|
|
512
|
+
* @param {unknown} target
|
|
513
|
+
* The package target to resolve
|
|
514
|
+
* @param {string} subpath
|
|
515
|
+
* Package subpath (key of `exports`/`imports`)
|
|
516
|
+
* @param {string | null | undefined} [patternMatch]
|
|
517
|
+
* Subpath pattern match
|
|
518
|
+
* @param {boolean | null | undefined} [isImports]
|
|
519
|
+
* Whether `target` is internal to the package
|
|
520
|
+
* @param {Condition[] | Set<Condition> | null | undefined} [conditions]
|
|
521
|
+
* List of export/import conditions
|
|
522
|
+
* @param {MainField[] | Set<MainField> | null | undefined} [mainFields]
|
|
523
|
+
* List of legacy main fields
|
|
524
|
+
* @param {ModuleId | null | undefined} [parent]
|
|
525
|
+
* URL of parent module
|
|
526
|
+
* @param {FileSystem | null | undefined} [fs]
|
|
527
|
+
* File system API
|
|
528
|
+
* @return {URL | null | undefined}
|
|
529
|
+
* Resolved URL
|
|
530
|
+
* @throws {ErrInvalidPackageConfig}
|
|
531
|
+
* @throws {ErrInvalidPackageTarget}
|
|
532
|
+
*/
|
|
533
|
+
declare function packageTargetResolveSync(packageUrl: ModuleId, target: unknown, subpath: string, patternMatch?: string | null | undefined, isImports?: boolean | null | undefined, conditions?: Condition[] | Set<Condition> | null | undefined, mainFields?: MainField[] | Set<MainField> | null | undefined, parent?: ModuleId | null | undefined, fs?: FileSystem | null | undefined): URL | null | undefined;
|
package/dist/lib/resolver.mjs
CHANGED
|
@@ -30,6 +30,17 @@ import { isBuiltin } from "@flex-development/is-builtin";
|
|
|
30
30
|
import pathe from "@flex-development/pathe";
|
|
31
31
|
import { ok } from "devlop";
|
|
32
32
|
async function legacyMainResolve(packageUrl, manifest, mainFields, parent, fs) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
return void resolve(legacyMainResolveSync(
|
|
35
|
+
packageUrl,
|
|
36
|
+
manifest,
|
|
37
|
+
mainFields,
|
|
38
|
+
parent,
|
|
39
|
+
fs
|
|
40
|
+
));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function legacyMainResolveSync(packageUrl, manifest, mainFields, parent, fs) {
|
|
33
44
|
if (manifest) {
|
|
34
45
|
for (const field of mainFields ?? defaultMainFields) {
|
|
35
46
|
const tries = [];
|
|
@@ -49,7 +60,7 @@ async function legacyMainResolve(packageUrl, manifest, mainFields, parent, fs) {
|
|
|
49
60
|
tries.push("./index.js", "./index.json", "./index.node");
|
|
50
61
|
for (const input of tries) {
|
|
51
62
|
resolved = new URL(input, packageUrl);
|
|
52
|
-
if (
|
|
63
|
+
if (isFile(resolved, fs)) return resolved;
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
}
|
|
@@ -59,6 +70,18 @@ async function legacyMainResolve(packageUrl, manifest, mainFields, parent, fs) {
|
|
|
59
70
|
);
|
|
60
71
|
}
|
|
61
72
|
async function moduleResolve(specifier, parent, conditions, mainFields, preserveSymlinks, fs) {
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
return void resolve(moduleResolveSync(
|
|
75
|
+
specifier,
|
|
76
|
+
parent,
|
|
77
|
+
conditions,
|
|
78
|
+
mainFields,
|
|
79
|
+
preserveSymlinks,
|
|
80
|
+
fs
|
|
81
|
+
));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function moduleResolveSync(specifier, parent, conditions, mainFields, preserveSymlinks, fs) {
|
|
62
85
|
const protocol = typeof parent === "string" ? parent.slice(0, parent.indexOf(":") + 1) : parent.protocol;
|
|
63
86
|
let resolved;
|
|
64
87
|
if (pathe.isAbsolute(specifier) || isRelativeSpecifier(specifier)) {
|
|
@@ -71,7 +94,7 @@ async function moduleResolve(specifier, parent, conditions, mainFields, preserve
|
|
|
71
94
|
throw error;
|
|
72
95
|
}
|
|
73
96
|
} else if (protocol === "file:" && isImportsSubpath(specifier)) {
|
|
74
|
-
resolved =
|
|
97
|
+
resolved = packageImportsResolveSync(
|
|
75
98
|
specifier,
|
|
76
99
|
parent,
|
|
77
100
|
conditions,
|
|
@@ -88,7 +111,7 @@ async function moduleResolve(specifier, parent, conditions, mainFields, preserve
|
|
|
88
111
|
error.cause = e;
|
|
89
112
|
throw error;
|
|
90
113
|
}
|
|
91
|
-
resolved =
|
|
114
|
+
resolved = packageResolveSync(
|
|
92
115
|
specifier,
|
|
93
116
|
parent,
|
|
94
117
|
conditions,
|
|
@@ -107,7 +130,7 @@ async function moduleResolve(specifier, parent, conditions, mainFields, preserve
|
|
|
107
130
|
pathe.fileURLToPath(parent)
|
|
108
131
|
);
|
|
109
132
|
}
|
|
110
|
-
if (
|
|
133
|
+
if (isDirectory(resolved, fs)) {
|
|
111
134
|
let error;
|
|
112
135
|
error = new ERR_UNSUPPORTED_DIR_IMPORT(
|
|
113
136
|
pathname,
|
|
@@ -116,7 +139,7 @@ async function moduleResolve(specifier, parent, conditions, mainFields, preserve
|
|
|
116
139
|
error.url = String(resolved);
|
|
117
140
|
throw error;
|
|
118
141
|
}
|
|
119
|
-
if (!
|
|
142
|
+
if (!isFile(resolved, fs)) {
|
|
120
143
|
throw new ERR_MODULE_NOT_FOUND(
|
|
121
144
|
pathname,
|
|
122
145
|
pathe.fileURLToPath(parent),
|
|
@@ -125,7 +148,7 @@ async function moduleResolve(specifier, parent, conditions, mainFields, preserve
|
|
|
125
148
|
}
|
|
126
149
|
if (!preserveSymlinks) {
|
|
127
150
|
fs ??= dfs;
|
|
128
|
-
resolved = new URL(pathe.pathToFileURL(
|
|
151
|
+
resolved = new URL(pathe.pathToFileURL(fs.realpathSync(resolved)));
|
|
129
152
|
resolved.hash = hash;
|
|
130
153
|
resolved.search = search;
|
|
131
154
|
}
|
|
@@ -133,6 +156,18 @@ async function moduleResolve(specifier, parent, conditions, mainFields, preserve
|
|
|
133
156
|
return resolved;
|
|
134
157
|
}
|
|
135
158
|
async function packageExportsResolve(packageUrl, subpath, exports, conditions, parent, fs) {
|
|
159
|
+
return new Promise((resolve) => {
|
|
160
|
+
return void resolve(packageExportsResolveSync(
|
|
161
|
+
packageUrl,
|
|
162
|
+
subpath,
|
|
163
|
+
exports,
|
|
164
|
+
conditions,
|
|
165
|
+
parent,
|
|
166
|
+
fs
|
|
167
|
+
));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function packageExportsResolveSync(packageUrl, subpath, exports, conditions, parent, fs) {
|
|
136
171
|
if (exports) {
|
|
137
172
|
let dot = false;
|
|
138
173
|
if (!Array.isArray(exports) && typeof exports === "object") {
|
|
@@ -160,7 +195,7 @@ async function packageExportsResolve(packageUrl, subpath, exports, conditions, p
|
|
|
160
195
|
mainExport = exports[pathe.dot];
|
|
161
196
|
}
|
|
162
197
|
if (mainExport !== void 0) {
|
|
163
|
-
resolved =
|
|
198
|
+
resolved = packageTargetResolveSync(
|
|
164
199
|
packageUrl,
|
|
165
200
|
mainExport,
|
|
166
201
|
subpath,
|
|
@@ -175,7 +210,7 @@ async function packageExportsResolve(packageUrl, subpath, exports, conditions, p
|
|
|
175
210
|
} else if (typeof exports === "object" && dot) {
|
|
176
211
|
ok(!Array.isArray(exports), "expected `exports` to not be an array");
|
|
177
212
|
ok(subpath.startsWith("./"), 'expected `subpath` to start with "./"');
|
|
178
|
-
resolved =
|
|
213
|
+
resolved = packageImportsExportsResolveSync(
|
|
179
214
|
subpath,
|
|
180
215
|
exports,
|
|
181
216
|
packageUrl,
|
|
@@ -195,10 +230,24 @@ async function packageExportsResolve(packageUrl, subpath, exports, conditions, p
|
|
|
195
230
|
);
|
|
196
231
|
}
|
|
197
232
|
async function packageImportsExportsResolve(matchKey, matchObject, packageUrl, isImports, conditions, mainFields, parent, fs) {
|
|
233
|
+
return new Promise((resolve) => {
|
|
234
|
+
return void resolve(packageImportsExportsResolveSync(
|
|
235
|
+
matchKey,
|
|
236
|
+
matchObject,
|
|
237
|
+
packageUrl,
|
|
238
|
+
isImports,
|
|
239
|
+
conditions,
|
|
240
|
+
mainFields,
|
|
241
|
+
parent,
|
|
242
|
+
fs
|
|
243
|
+
));
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function packageImportsExportsResolveSync(matchKey, matchObject, packageUrl, isImports, conditions, mainFields, parent, fs) {
|
|
198
247
|
if (typeof matchObject === "object" && matchObject) {
|
|
199
248
|
const match = patternMatch(matchKey, matchObject);
|
|
200
249
|
if (match) {
|
|
201
|
-
return
|
|
250
|
+
return packageTargetResolveSync(
|
|
202
251
|
packageUrl,
|
|
203
252
|
matchObject[match[0]],
|
|
204
253
|
...match,
|
|
@@ -213,6 +262,17 @@ async function packageImportsExportsResolve(matchKey, matchObject, packageUrl, i
|
|
|
213
262
|
return null;
|
|
214
263
|
}
|
|
215
264
|
async function packageImportsResolve(specifier, parent, conditions, mainFields, fs) {
|
|
265
|
+
return new Promise((resolve) => {
|
|
266
|
+
return void resolve(packageImportsResolveSync(
|
|
267
|
+
specifier,
|
|
268
|
+
parent,
|
|
269
|
+
conditions,
|
|
270
|
+
mainFields,
|
|
271
|
+
fs
|
|
272
|
+
));
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function packageImportsResolveSync(specifier, parent, conditions, mainFields, fs) {
|
|
216
276
|
if (!specifier.startsWith(chars.hash) || specifier === chars.hash || specifier.startsWith(chars.hash + pathe.sep)) {
|
|
217
277
|
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
218
278
|
specifier,
|
|
@@ -220,16 +280,16 @@ async function packageImportsResolve(specifier, parent, conditions, mainFields,
|
|
|
220
280
|
pathe.fileURLToPath(parent)
|
|
221
281
|
);
|
|
222
282
|
}
|
|
223
|
-
const packageUrl =
|
|
283
|
+
const packageUrl = lookupPackageScope(parent, null, fs);
|
|
224
284
|
if (packageUrl) {
|
|
225
|
-
const pjson =
|
|
285
|
+
const pjson = readPackageJson(
|
|
226
286
|
packageUrl,
|
|
227
287
|
specifier,
|
|
228
288
|
parent,
|
|
229
289
|
fs
|
|
230
290
|
);
|
|
231
291
|
if (pjson) {
|
|
232
|
-
const resolved =
|
|
292
|
+
const resolved = packageImportsExportsResolveSync(
|
|
233
293
|
specifier,
|
|
234
294
|
pjson.imports,
|
|
235
295
|
packageUrl,
|
|
@@ -249,6 +309,17 @@ async function packageImportsResolve(specifier, parent, conditions, mainFields,
|
|
|
249
309
|
);
|
|
250
310
|
}
|
|
251
311
|
async function packageResolve(specifier, parent, conditions, mainFields, fs) {
|
|
312
|
+
return new Promise((resolve) => {
|
|
313
|
+
return void resolve(packageResolveSync(
|
|
314
|
+
specifier,
|
|
315
|
+
parent,
|
|
316
|
+
conditions,
|
|
317
|
+
mainFields,
|
|
318
|
+
fs
|
|
319
|
+
));
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
function packageResolveSync(specifier, parent, conditions, mainFields, fs) {
|
|
252
323
|
if (isBuiltin(specifier)) return toUrl(specifier);
|
|
253
324
|
let separatorIndex = -1;
|
|
254
325
|
let valid = !!specifier;
|
|
@@ -272,7 +343,7 @@ async function packageResolve(specifier, parent, conditions, mainFields, fs) {
|
|
|
272
343
|
);
|
|
273
344
|
}
|
|
274
345
|
const packageSubpath = pathe.dot + (separatorIndex === -1 ? chars.empty : specifier.slice(separatorIndex));
|
|
275
|
-
const selfUrl =
|
|
346
|
+
const selfUrl = packageSelfResolveSync(
|
|
276
347
|
packageName,
|
|
277
348
|
packageSubpath,
|
|
278
349
|
parent,
|
|
@@ -284,15 +355,15 @@ async function packageResolve(specifier, parent, conditions, mainFields, fs) {
|
|
|
284
355
|
while (String(parentUrl) !== String(root)) {
|
|
285
356
|
let packageUrl = new URL(`node_modules/${packageName}/`, parentUrl);
|
|
286
357
|
parentUrl = new URL(pathe.dirname(parentUrl.href));
|
|
287
|
-
if (!
|
|
288
|
-
const pjson =
|
|
358
|
+
if (!isDirectory(packageUrl, fs)) continue;
|
|
359
|
+
const pjson = readPackageJson(
|
|
289
360
|
packageUrl,
|
|
290
361
|
null,
|
|
291
362
|
parent,
|
|
292
363
|
fs
|
|
293
364
|
);
|
|
294
365
|
if (pjson?.exports) {
|
|
295
|
-
return
|
|
366
|
+
return packageExportsResolveSync(
|
|
296
367
|
packageUrl,
|
|
297
368
|
packageSubpath,
|
|
298
369
|
pjson.exports,
|
|
@@ -302,23 +373,34 @@ async function packageResolve(specifier, parent, conditions, mainFields, fs) {
|
|
|
302
373
|
);
|
|
303
374
|
}
|
|
304
375
|
if (packageSubpath === pathe.dot) {
|
|
305
|
-
return
|
|
376
|
+
return legacyMainResolveSync(packageUrl, pjson, mainFields, parent, fs);
|
|
306
377
|
}
|
|
307
378
|
return new URL(packageSubpath, packageUrl);
|
|
308
379
|
}
|
|
309
380
|
throw new ERR_MODULE_NOT_FOUND(packageName, pathe.fileURLToPath(parent));
|
|
310
381
|
}
|
|
311
382
|
async function packageSelfResolve(name, subpath, parent, conditions, fs) {
|
|
312
|
-
|
|
383
|
+
return new Promise((resolve) => {
|
|
384
|
+
return void resolve(packageSelfResolveSync(
|
|
385
|
+
name,
|
|
386
|
+
subpath,
|
|
387
|
+
parent,
|
|
388
|
+
conditions,
|
|
389
|
+
fs
|
|
390
|
+
));
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function packageSelfResolveSync(name, subpath, parent, conditions, fs) {
|
|
394
|
+
const packageUrl = lookupPackageScope(parent, null, fs);
|
|
313
395
|
if (packageUrl) {
|
|
314
|
-
const pjson =
|
|
396
|
+
const pjson = readPackageJson(
|
|
315
397
|
packageUrl,
|
|
316
398
|
null,
|
|
317
399
|
parent,
|
|
318
400
|
fs
|
|
319
401
|
);
|
|
320
402
|
if (pjson?.exports && name === pjson.name) {
|
|
321
|
-
return
|
|
403
|
+
return packageExportsResolveSync(
|
|
322
404
|
packageUrl,
|
|
323
405
|
subpath,
|
|
324
406
|
pjson.exports,
|
|
@@ -331,6 +413,21 @@ async function packageSelfResolve(name, subpath, parent, conditions, fs) {
|
|
|
331
413
|
return void 0;
|
|
332
414
|
}
|
|
333
415
|
async function packageTargetResolve(packageUrl, target, subpath, patternMatch2, isImports, conditions, mainFields, parent, fs) {
|
|
416
|
+
return new Promise((resolve) => {
|
|
417
|
+
return void resolve(packageTargetResolveSync(
|
|
418
|
+
packageUrl,
|
|
419
|
+
target,
|
|
420
|
+
subpath,
|
|
421
|
+
patternMatch2,
|
|
422
|
+
isImports,
|
|
423
|
+
conditions,
|
|
424
|
+
mainFields,
|
|
425
|
+
parent,
|
|
426
|
+
fs
|
|
427
|
+
));
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
function packageTargetResolveSync(packageUrl, target, subpath, patternMatch2, isImports, conditions, mainFields, parent, fs) {
|
|
334
431
|
if (typeof target === "string") {
|
|
335
432
|
if (!target.startsWith(pathe.dot + pathe.sep)) {
|
|
336
433
|
if (!isImports || target.startsWith(pathe.dot + pathe.dot + pathe.sep) || target.startsWith(pathe.sep) || canParseUrl(target)) {
|
|
@@ -342,7 +439,7 @@ async function packageTargetResolve(packageUrl, target, subpath, patternMatch2,
|
|
|
342
439
|
parent
|
|
343
440
|
);
|
|
344
441
|
}
|
|
345
|
-
return
|
|
442
|
+
return packageResolveSync(
|
|
346
443
|
typeof patternMatch2 === "string" ? target.replace(chars.asterisk, patternMatch2) : target,
|
|
347
444
|
packageUrl,
|
|
348
445
|
conditions,
|
|
@@ -390,7 +487,7 @@ async function packageTargetResolve(packageUrl, target, subpath, patternMatch2,
|
|
|
390
487
|
for (const targetValue of target) {
|
|
391
488
|
let resolved;
|
|
392
489
|
try {
|
|
393
|
-
resolved =
|
|
490
|
+
resolved = packageTargetResolveSync(
|
|
394
491
|
packageUrl,
|
|
395
492
|
targetValue,
|
|
396
493
|
subpath,
|
|
@@ -425,7 +522,7 @@ async function packageTargetResolve(packageUrl, target, subpath, patternMatch2,
|
|
|
425
522
|
if (Array.isArray(conditions)) conditions = new Set(conditions);
|
|
426
523
|
for (const key of Object.getOwnPropertyNames(target)) {
|
|
427
524
|
if (conditions.has(key) || key === "default") {
|
|
428
|
-
const resolved =
|
|
525
|
+
const resolved = packageTargetResolveSync(
|
|
429
526
|
packageUrl,
|
|
430
527
|
target[key],
|
|
431
528
|
subpath,
|
|
@@ -452,11 +549,19 @@ async function packageTargetResolve(packageUrl, target, subpath, patternMatch2,
|
|
|
452
549
|
}
|
|
453
550
|
export {
|
|
454
551
|
legacyMainResolve,
|
|
552
|
+
legacyMainResolveSync,
|
|
455
553
|
moduleResolve,
|
|
554
|
+
moduleResolveSync,
|
|
456
555
|
packageExportsResolve,
|
|
556
|
+
packageExportsResolveSync,
|
|
457
557
|
packageImportsExportsResolve,
|
|
558
|
+
packageImportsExportsResolveSync,
|
|
458
559
|
packageImportsResolve,
|
|
560
|
+
packageImportsResolveSync,
|
|
459
561
|
packageResolve,
|
|
562
|
+
packageResolveSync,
|
|
460
563
|
packageSelfResolve,
|
|
461
|
-
|
|
564
|
+
packageSelfResolveSync,
|
|
565
|
+
packageTargetResolve,
|
|
566
|
+
packageTargetResolveSync
|
|
462
567
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flex-development/mlly",
|
|
3
3
|
"description": "ECMAScript module utilities",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.20",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecmascript",
|
|
7
7
|
"esm",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"mlly": "./src/internal/fs.browser.mts",
|
|
65
65
|
"default": "./dist/internal/fs.browser.mjs"
|
|
66
66
|
},
|
|
67
|
-
"node": "fs
|
|
68
|
-
"default": "fs
|
|
67
|
+
"node": "fs",
|
|
68
|
+
"default": "fs"
|
|
69
69
|
},
|
|
70
70
|
"#internal/process": {
|
|
71
71
|
"types": {
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"dependencies": {
|
|
137
137
|
"@flex-development/errnode": "3.1.1",
|
|
138
138
|
"@flex-development/is-builtin": "3.2.0",
|
|
139
|
-
"@flex-development/pathe": "4.0.
|
|
139
|
+
"@flex-development/pathe": "4.0.1",
|
|
140
140
|
"@flex-development/pkg-types": "4.1.0",
|
|
141
141
|
"devlop": "1.1.0"
|
|
142
142
|
},
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
"@flex-development/mkbuild": "1.0.0-alpha.23",
|
|
155
155
|
"@flex-development/tsconfig-utils": "2.0.2",
|
|
156
156
|
"@flex-development/tutils": "6.0.0-alpha.25",
|
|
157
|
-
"@stylistic/eslint-plugin": "2.
|
|
157
|
+
"@stylistic/eslint-plugin": "2.12.1",
|
|
158
158
|
"@tsconfig/strictest": "2.0.5",
|
|
159
159
|
"@types/chai": "5.0.0",
|
|
160
160
|
"@types/chai-string": "1.4.5",
|
|
@@ -164,18 +164,18 @@
|
|
|
164
164
|
"@types/node": "22.8.6",
|
|
165
165
|
"@types/node-notifier": "8.0.5",
|
|
166
166
|
"@types/rollup": "0.54.0",
|
|
167
|
-
"@typescript-eslint/eslint-plugin": "8.18.
|
|
168
|
-
"@typescript-eslint/parser": "8.18.
|
|
167
|
+
"@typescript-eslint/eslint-plugin": "8.18.3-alpha.5",
|
|
168
|
+
"@typescript-eslint/parser": "8.18.3-alpha.5",
|
|
169
169
|
"@vates/toggle-scripts": "1.0.0",
|
|
170
170
|
"@vitest/coverage-v8": "3.0.0-beta.3",
|
|
171
171
|
"@vitest/ui": "3.0.0-beta.3",
|
|
172
172
|
"chai": "5.1.2",
|
|
173
173
|
"chai-each": "0.0.1",
|
|
174
174
|
"chai-string": "1.5.0",
|
|
175
|
-
"consola": "3.
|
|
175
|
+
"consola": "3.3.3",
|
|
176
176
|
"cross-env": "7.0.3",
|
|
177
177
|
"cspell": "8.17.1",
|
|
178
|
-
"dprint": "0.
|
|
178
|
+
"dprint": "0.48.0",
|
|
179
179
|
"editorconfig": "2.0.0",
|
|
180
180
|
"esbuild": "0.24.2",
|
|
181
181
|
"eslint": "9.17.0",
|
|
@@ -274,7 +274,7 @@
|
|
|
274
274
|
"trash-cli": "6.0.0",
|
|
275
275
|
"ts-dedent": "2.2.0",
|
|
276
276
|
"typescript": "5.7.2",
|
|
277
|
-
"typescript-eslint": "8.18.
|
|
277
|
+
"typescript-eslint": "8.18.3-alpha.5",
|
|
278
278
|
"unified": "11.0.5",
|
|
279
279
|
"vfile": "6.0.3",
|
|
280
280
|
"vite": "5.4.11",
|