Skip to content

Commit b244176

Browse files
fix: types
1 parent 775f2fb commit b244176

File tree

8 files changed

+673
-931
lines changed

8 files changed

+673
-931
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ resolve.sync("/some/path/to/folder", "../../dir");
4242

4343
const myResolve = resolve.create({
4444
// or resolve.create.sync
45-
extensions: [".ts", ".js"]
45+
extensions: [".ts", ".js"],
4646
// see more options below
4747
});
4848

@@ -63,7 +63,7 @@ const { CachedInputFileSystem, ResolverFactory } = require("enhanced-resolve");
6363
const myResolver = ResolverFactory.createResolver({
6464
// Typical usage will consume the `fs` + `CachedInputFileSystem`, which wraps Node.js `fs` to add caching.
6565
fileSystem: new CachedInputFileSystem(fs, 4000),
66-
extensions: [".js", ".json"]
66+
extensions: [".js", ".json"],
6767
/* any other resolver options here. Options/defaults can be seen below */
6868
});
6969

@@ -79,7 +79,7 @@ myResolver.resolve(
7979
resolveContext,
8080
(err /* Error */, filepath /* string */) => {
8181
// Do something with the path
82-
}
82+
},
8383
);
8484
```
8585

generate-types-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
module.exports = {
4+
typeMapping: {
5+
"^signal in Abortable events Interface": "AbortSignal",
6+
},
7+
};

lib/Resolver.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ const {
4646

4747
/**
4848
* @typedef {object} ObjectEncodingOptions
49-
* @property {(BufferEncoding | null | undefined)=} encoding encoding
49+
* @property {BufferEncoding | null | undefined=} encoding encoding
50+
*/
51+
52+
/**
53+
* @typedef {ObjectEncodingOptions | BufferEncoding | undefined | null} EncodingOption
5054
*/
5155

5256
/** @typedef {(err: NodeJS.ErrnoException | null, result?: string) => void} StringCallback */
@@ -56,10 +60,6 @@ const {
5660
/** @typedef {(err: NodeJS.ErrnoException | null, result?: IBigIntStats) => void} BigIntStatsCallback */
5761
/** @typedef {(err: NodeJS.ErrnoException | null, result?: (IStats | IBigIntStats)) => void} StatsOrBigIntStatsCallback */
5862
/** @typedef {(err: NodeJS.ErrnoException | Error | null, result?: JsonObject) => void} ReadJsonCallback */
59-
/** @typedef {(err: NodeJS.ErrnoException | null, result?: string[]) => void} ReaddirStringCallback */
60-
/** @typedef {(err: NodeJS.ErrnoException | null, result?: Buffer[]) => void} ReaddirBufferCallback */
61-
/** @typedef {(err: NodeJS.ErrnoException | null, result?: (string[] | Buffer[])) => void} ReaddirStringOrBufferCallback */
62-
/** @typedef {(err: NodeJS.ErrnoException | null, result?: Dirent[]) => void} ReaddirDirentCallback */
6363

6464
/**
6565
* @template T
@@ -96,10 +96,12 @@ const {
9696
*/
9797

9898
/**
99-
* @typedef {IStatsBase<bigint> & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint }} IBigIntStats
99+
* @typedef {IStatsBase<bigint> & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint }} IBigIntStats
100100
*/
101101

102+
/* eslint-disable jsdoc/require-template */
102103
/**
104+
* @template {string | Buffer} [T=string]
103105
* @typedef {object} Dirent
104106
* @property {() => boolean} isFile true when is file, otherwise false
105107
* @property {() => boolean} isDirectory true when is directory, otherwise false
@@ -108,9 +110,11 @@ const {
108110
* @property {() => boolean} isSymbolicLink true when is symbolic link, otherwise false
109111
* @property {() => boolean} isFIFO true when is FIFO, otherwise false
110112
* @property {() => boolean} isSocket true when is socket, otherwise false
111-
* @property {string} name name
112-
* @property {string} path path
113+
* @property {T} name name
114+
* @property {string} parentPath path
115+
* @property {string=} path path
113116
*/
117+
/* eslint-enable jsdoc/require-template */
114118

115119
/**
116120
* @typedef {object} StatOptions
@@ -132,10 +136,6 @@ const {
132136
* }} ReadFile
133137
*/
134138

135-
/**
136-
* @typedef {ObjectEncodingOptions | BufferEncoding | undefined | null} EncodingOption
137-
*/
138-
139139
/**
140140
* @typedef {'buffer'| { encoding: 'buffer' }} BufferEncodingOption
141141
*/
@@ -150,23 +150,26 @@ const {
150150

151151
/**
152152
* @typedef {{
153-
* (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: ReaddirStringCallback): void;
154-
* (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer', callback: ReaddirBufferCallback): void;
155-
* (path: PathLike, callback: ReaddirStringCallback): void;
156-
* (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: ReaddirStringOrBufferCallback): void;
157-
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: ReaddirDirentCallback): void;
153+
* (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void;
154+
* (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer', callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void;
155+
* (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void;
156+
* (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void;
157+
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent<string>[]) => void): void;
158+
* (path: PathLike, options: { encoding: 'buffer', withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files: Dirent<Buffer>[]) => void): void;
158159
* }} Readdir
159160
*/
160161

161162
/**
162163
* @typedef {{
163-
* (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | null): string[];
164+
* (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined; } | BufferEncoding | null): string[];
164165
* (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer'): Buffer[];
165166
* (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[];
166167
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[];
168+
* (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }): Dirent<Buffer>[];
167169
* }} ReaddirSync
168-
*
169-
* /**
170+
*/
171+
172+
/**
170173
* @typedef {(pathOrFileDescription: PathOrFileDescriptor, callback: ReadJsonCallback) => void} ReadJson
171174
*/
172175

lib/SyncAsyncFileSystemDecorator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"use strict";
77

88
/** @typedef {import("./Resolver").FileSystem} FileSystem */
9-
/** @typedef {import("./Resolver").ReaddirStringCallback} ReaddirStringCallback */
109
/** @typedef {import("./Resolver").StringCallback} StringCallback */
1110
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
1211

@@ -90,14 +89,15 @@ function SyncAsyncFileSystemDecorator(fs) {
9089
result = /** @type {SyncOrAsyncFunction | undefined} */ (callback)
9190
? fs.readdirSync(
9291
arg,
93-
/** @type {Exclude<Parameters<FileSystem["readdir"]>[1], ReaddirStringCallback>} */
92+
/** @type {Exclude<Parameters<FileSystem["readdir"]>[1], (err: NodeJS.ErrnoException | null, files: string[]) => void>} */
9493
(options),
9594
)
9695
: fs.readdirSync(arg);
9796
} catch (err) {
9897
return (callback || options)(
9998
/** @type {NodeJS.ErrnoException | null} */
10099
(err),
100+
[],
101101
);
102102
}
103103

lib/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ const fs = require("graceful-fs");
99
const CachedInputFileSystem = require("./CachedInputFileSystem");
1010
const ResolverFactory = require("./ResolverFactory");
1111

12+
/** @typedef {import("./CachedInputFileSystem").BaseFileSystem} BaseFileSystem */
1213
/** @typedef {import("./PnpPlugin").PnpApiImpl} PnpApi */
1314
/** @typedef {import("./Resolver")} Resolver */
1415
/** @typedef {import("./Resolver").FileSystem} FileSystem */
15-
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
16-
/** @typedef {import("./CachedInputFileSystem").BaseFileSystem} BaseFileSystem */
1716
/** @typedef {import("./Resolver").ResolveCallback} ResolveCallback */
1817
/** @typedef {import("./Resolver").ResolveContext} ResolveContext */
1918
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
19+
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
2020
/** @typedef {import("./ResolverFactory").Plugin} Plugin */
2121
/** @typedef {import("./ResolverFactory").UserResolveOptions} ResolveOptions */
22+
2223
/**
2324
* @typedef {{
2425
* (context: object, path: string, request: string, resolveContext: ResolveContext, callback: ResolveCallback): void;
@@ -27,10 +28,11 @@ const ResolverFactory = require("./ResolverFactory");
2728
* (path: string, request: string, callback: ResolveCallback): void;
2829
* }} ResolveFunctionAsync
2930
*/
31+
3032
/**
3133
* @typedef {{
32-
* (context: object, path: string, request: string): string|false;
33-
* (path: string, request: string): string|false;
34+
* (context: object, path: string, request: string): string | false;
35+
* (path: string, request: string): string | false;
3436
* }} ResolveFunction
3537
*/
3638

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
"@eslint/markdown": ">= 6.5.0",
2323
"@types/graceful-fs": "^4.1.6",
2424
"@types/jest": "^27.5.1",
25-
"@types/node": "20.9.5",
25+
"@types/node": "^24.0.3",
2626
"@stylistic/eslint-plugin": ">= 4.4.1",
2727
"cspell": "4.2.8",
2828
"eslint": "^9.28.0",
2929
"eslint-config-prettier": "^10.1.5",
30-
"eslint-config-webpack": "^4.0.2",
30+
"eslint-config-webpack": "^4.1.2",
3131
"eslint-plugin-import": "^2.31.0",
32-
"eslint-plugin-jest": "^28.13.0",
33-
"eslint-plugin-jsdoc": "^50.7.1",
32+
"eslint-plugin-jest": "^29.0.1",
33+
"eslint-plugin-jsdoc": "^51.2.2",
3434
"eslint-plugin-n": "^17.19.0",
3535
"eslint-plugin-prettier": "^5.4.1",
3636
"eslint-plugin-unicorn": "^59.0.1",
@@ -41,8 +41,8 @@
4141
"memfs": "^3.2.0",
4242
"prettier": "^3.5.3",
4343
"prettier-2": "npm:prettier@^2",
44-
"tooling": "webpack/tooling#v1.23.10",
45-
"typescript": "^5.3.3"
44+
"tooling": "webpack/tooling#v1.24.0",
45+
"typescript": "^5.8.3"
4646
},
4747
"engines": {
4848
"node": ">=10.13.0"

types.d.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ declare class CloneBasenamePlugin {
160160
>;
161161
apply(resolver: Resolver): void;
162162
}
163-
declare interface Dirent {
163+
declare interface Dirent<T extends string | Buffer = string> {
164164
/**
165165
* true when is file, otherwise false
166166
*/
@@ -199,12 +199,17 @@ declare interface Dirent {
199199
/**
200200
* name
201201
*/
202-
name: string;
202+
name: T;
203203

204204
/**
205205
* path
206206
*/
207-
path: string;
207+
parentPath: string;
208+
209+
/**
210+
* path
211+
*/
212+
path?: string;
208213
}
209214
type EncodingOption =
210215
| undefined
@@ -852,18 +857,14 @@ declare interface Readdir {
852857
withFileTypes?: false;
853858
recursive?: boolean;
854859
},
855-
callback: (err: null | NodeJS.ErrnoException, result?: string[]) => void,
860+
callback: (err: null | NodeJS.ErrnoException, files?: string[]) => void,
856861
): void;
857862
(
858863
path: PathLike,
859864
options:
860865
| { encoding: "buffer"; withFileTypes?: false; recursive?: boolean }
861866
| "buffer",
862-
callback: (err: null | NodeJS.ErrnoException, result?: Buffer[]) => void,
863-
): void;
864-
(
865-
path: PathLike,
866-
callback: (err: null | NodeJS.ErrnoException, result?: string[]) => void,
867+
callback: (err: null | NodeJS.ErrnoException, files?: Buffer[]) => void,
867868
): void;
868869
(
869870
path: PathLike,
@@ -888,16 +889,31 @@ declare interface Readdir {
888889
}),
889890
callback: (
890891
err: null | NodeJS.ErrnoException,
891-
result?: string[] | Buffer[],
892+
files?: string[] | Buffer[],
892893
) => void,
893894
): void;
895+
(
896+
path: PathLike,
897+
callback: (err: null | NodeJS.ErrnoException, files?: string[]) => void,
898+
): void;
894899
(
895900
path: PathLike,
896901
options: ObjectEncodingOptions & {
897902
withFileTypes: true;
898903
recursive?: boolean;
899904
},
900-
callback: (err: null | NodeJS.ErrnoException, result?: Dirent[]) => void,
905+
callback: (
906+
err: null | NodeJS.ErrnoException,
907+
files?: Dirent<string>[],
908+
) => void,
909+
): void;
910+
(
911+
path: PathLike,
912+
options: { encoding: "buffer"; withFileTypes: true; recursive?: boolean },
913+
callback: (
914+
err: null | NodeJS.ErrnoException,
915+
files: Dirent<Buffer>[],
916+
) => void,
901917
): void;
902918
}
903919
declare interface ReaddirSync {
@@ -969,7 +985,11 @@ declare interface ReaddirSync {
969985
withFileTypes: true;
970986
recursive?: boolean;
971987
},
972-
): Dirent[];
988+
): Dirent<string>[];
989+
(
990+
path: PathLike,
991+
options: { encoding: "buffer"; withFileTypes: true; recursive?: boolean },
992+
): Dirent<Buffer>[];
973993
}
974994
declare interface Readlink {
975995
(
@@ -1549,11 +1569,6 @@ declare interface SyncFileSystem {
15491569
*/
15501570
realpathSync?: RealPathSync;
15511571
}
1552-
1553-
/**
1554-
* `URL` class is a global reference for `require('url').URL`
1555-
* https://nodejs.org/api/url.html#the-whatwg-url-api
1556-
*/
15571572
declare interface URL_url extends URL_Import {}
15581573
declare interface WriteOnlySet<T> {
15591574
add: (item: T) => void;
@@ -1626,13 +1641,13 @@ declare namespace exports {
16261641
CloneBasenamePlugin,
16271642
LogInfoPlugin,
16281643
ResolveOptionsOptionalFS,
1644+
BaseFileSystem,
16291645
PnpApi,
16301646
Resolver,
16311647
FileSystem,
1632-
SyncFileSystem,
1633-
BaseFileSystem,
16341648
ResolveContext,
16351649
ResolveRequest,
1650+
SyncFileSystem,
16361651
Plugin,
16371652
ResolveOptionsResolverFactoryObject_2 as ResolveOptions,
16381653
ResolveFunctionAsync,

0 commit comments

Comments
 (0)