Skip to content

Commit bf89031

Browse files
fix: types
1 parent 1780817 commit bf89031

File tree

4 files changed

+143
-50
lines changed

4 files changed

+143
-50
lines changed

lib/Resolver.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ const {
4949
* @property {BufferEncoding | null | undefined} [encoding]
5050
*/
5151

52-
/** @typedef {function(NodeJS.ErrnoException | null, string | undefined): void} StringCallback */
53-
/** @typedef {function(NodeJS.ErrnoException | null, Buffer | undefined): void} BufferCallback */
54-
/** @typedef {function(NodeJS.ErrnoException | null, string | Buffer | undefined): void} StringOrBufferCallback */
55-
/** @typedef {function(NodeJS.ErrnoException | null, IStats | undefined): void} StatsCallback */
56-
/** @typedef {function(NodeJS.ErrnoException | null, IBigIntStats | undefined): void} BigIntStatsCallback */
57-
/** @typedef {function(NodeJS.ErrnoException | null, IStats | IBigIntStats | undefined): void} StatsOrBigIntStatsCallback */
58-
/** @typedef {function(NodeJS.ErrnoException | Error | null, JsonObject | undefined): void} ReadJsonCallback */
59-
/** @typedef {function(NodeJS.ErrnoException | null, string[] | undefined): void} ReaddirStringCallback */
60-
/** @typedef {function(NodeJS.ErrnoException | null, Buffer[] | undefined): void} ReaddirBufferCallback */
61-
/** @typedef {function(NodeJS.ErrnoException | null, string[] | Buffer[] | undefined): void} ReaddirStringOrBufferCallback */
62-
/** @typedef {function(NodeJS.ErrnoException | null, Dirent[] | undefined): void} ReaddirDirentCallback */
52+
/** @typedef {function(NodeJS.ErrnoException | null, string=): void} StringCallback */
53+
/** @typedef {function(NodeJS.ErrnoException | null, Buffer=): void} BufferCallback */
54+
/** @typedef {function(NodeJS.ErrnoException | null, (string | Buffer)=): void} StringOrBufferCallback */
55+
/** @typedef {function(NodeJS.ErrnoException | null, IStats=): void} StatsCallback */
56+
/** @typedef {function(NodeJS.ErrnoException | null, IBigIntStats=): void} BigIntStatsCallback */
57+
/** @typedef {function(NodeJS.ErrnoException | null, (IStats | IBigIntStats)=): void} StatsOrBigIntStatsCallback */
58+
/** @typedef {function(NodeJS.ErrnoException | Error | null, JsonObject=): void} ReadJsonCallback */
59+
/** @typedef {function(NodeJS.ErrnoException | null, string[]=): void} ReaddirStringCallback */
60+
/** @typedef {function(NodeJS.ErrnoException | null, Buffer[]=): void} ReaddirBufferCallback */
61+
/** @typedef {function(NodeJS.ErrnoException | null, (string[] | Buffer[])=): void} ReaddirStringOrBufferCallback */
62+
/** @typedef {function(NodeJS.ErrnoException | null, Dirent[]=): void} ReaddirDirentCallback */
6363

6464
/**
6565
* @template T

lib/SyncAsyncFileSystemDecorator.js

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

88
/** @typedef {import("./Resolver").FileSystem} FileSystem */
9-
/** @typedef {import("./Resolver").Dirent} Dirent */
9+
/** @typedef {import("./Resolver").ReaddirStringCallback} ReaddirStringCallback */
10+
/** @typedef {import("./Resolver").StringCallback} StringCallback */
1011
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
1112

1213
/**
@@ -26,12 +27,16 @@ function SyncAsyncFileSystemDecorator(fs) {
2627
(arg, options, callback) => {
2728
let result;
2829
try {
29-
result = lstatSync.call(fs, arg);
30+
result = /** @type {Function | undefined} */ (callback)
31+
? lstatSync.call(fs, arg, options)
32+
: lstatSync.call(fs, arg);
3033
} catch (e) {
31-
return (callback || options)(e);
34+
return (callback || options)(
35+
/** @type {NodeJS.ErrnoException | null} */ (e)
36+
);
3237
}
3338

34-
(callback || options)(null, result);
39+
(callback || options)(null, /** @type {any} */ (result));
3540
}
3641
);
3742
this.lstatSync =
@@ -45,11 +50,16 @@ function SyncAsyncFileSystemDecorator(fs) {
4550
(arg, options, callback) => {
4651
let result;
4752
try {
48-
result = callback ? fs.statSync(arg, options) : fs.statSync(arg);
53+
result = /** @type {Function | undefined} */ (callback)
54+
? fs.statSync(arg, options)
55+
: fs.statSync(arg);
4956
} catch (e) {
50-
return (callback || options)(e);
57+
return (callback || options)(
58+
/** @type {NodeJS.ErrnoException | null} */ (e)
59+
);
5160
}
52-
(callback || options)(null, result);
61+
62+
(callback || options)(null, /** @type {any} */ (result));
5363
}
5464
);
5565
this.statSync =
@@ -62,31 +72,48 @@ function SyncAsyncFileSystemDecorator(fs) {
6272
(arg, options, callback) => {
6373
let result;
6474
try {
65-
result = callback
66-
? fs.readdirSync(arg, options)
75+
result = /** @type {Function | undefined} */ (callback)
76+
? fs.readdirSync(
77+
arg,
78+
/** @type {Exclude<Parameters<FileSystem["readdir"]>[1], ReaddirStringCallback>} */
79+
(options)
80+
)
6781
: fs.readdirSync(arg);
6882
} catch (e) {
69-
return (callback || options)(e);
83+
return (callback || options)(
84+
/** @type {NodeJS.ErrnoException | null} */ (e)
85+
);
7086
}
7187

72-
(callback || options)(null, result);
88+
(callback || options)(null, /** @type {any} */ (result));
7389
}
7490
);
7591
this.readdirSync =
7692
/** @type {SyncFileSystem["readdirSync"]} */
77-
((arg, options) => fs.readdirSync(arg, options));
93+
(
94+
(arg, options) =>
95+
fs.readdirSync(
96+
arg,
97+
/** @type {Parameters<SyncFileSystem["readdirSync"]>[1]} */ (options)
98+
)
99+
);
78100

79101
this.readFile =
80102
/** @type {FileSystem["readFile"]} */
81103
(
82104
(arg, options, callback) => {
83105
let result;
84106
try {
85-
result = fs.readFileSync(arg);
107+
result = /** @type {Function | undefined} */ (callback)
108+
? fs.readFileSync(arg, options)
109+
: fs.readFileSync(arg);
86110
} catch (e) {
87-
return (callback || options)(e);
111+
return (callback || options)(
112+
/** @type {NodeJS.ErrnoException | null} */ (e)
113+
);
88114
}
89-
(callback || options)(null, result);
115+
116+
(callback || options)(null, /** @type {any} */ (result));
90117
}
91118
);
92119
this.readFileSync =
@@ -99,37 +126,55 @@ function SyncAsyncFileSystemDecorator(fs) {
99126
(arg, options, callback) => {
100127
let result;
101128
try {
102-
result = fs.readlinkSync(arg);
129+
result = /** @type {Function | undefined} */ (callback)
130+
? fs.readlinkSync(
131+
arg,
132+
/** @type {Exclude<Parameters<FileSystem["readlink"]>[1], StringCallback>} */
133+
(options)
134+
)
135+
: fs.readlinkSync(arg);
103136
} catch (e) {
104-
return (callback || options)(e);
137+
return (callback || options)(
138+
/** @type {NodeJS.ErrnoException | null} */ (e)
139+
);
105140
}
106-
(callback || options)(null, result);
141+
142+
(callback || options)(null, /** @type {any} */ (result));
107143
}
108144
);
109145
this.readlinkSync =
110146
/** @type {SyncFileSystem["readlinkSync"]} */
111-
((arg, options) => fs.readlinkSync(arg, options));
147+
(
148+
(arg, options) =>
149+
fs.readlinkSync(
150+
arg,
151+
/** @type {Parameters<SyncFileSystem["readlinkSync"]>[1]} */ (options)
152+
)
153+
);
112154

113155
this.readJson = undefined;
114156
this.readJsonSync = undefined;
115157
const readJsonSync = fs.readJsonSync;
116158
if (readJsonSync) {
117159
this.readJson =
118-
/** @type {NonNullable<FileSystem["readJson"]>} */
160+
/** @type {FileSystem["readJson"]} */
119161
(
120-
(arg, options, callback) => {
162+
(arg, callback) => {
121163
let result;
122164
try {
123165
result = readJsonSync.call(fs, arg);
124166
} catch (e) {
125-
return (callback || options)(e);
167+
return callback(
168+
/** @type {NodeJS.ErrnoException | Error | null} */ (e)
169+
);
126170
}
127-
(callback || options)(null, result);
171+
172+
callback(null, result);
128173
}
129174
);
130175
this.readJsonSync =
131176
/** @type {SyncFileSystem["readJsonSync"]} */
132-
((arg, options) => readJsonSync.call(fs, arg, options));
177+
(arg => readJsonSync.call(fs, arg));
133178
}
134179

135180
this.realpath = undefined;
@@ -142,16 +187,34 @@ function SyncAsyncFileSystemDecorator(fs) {
142187
(arg, options, callback) => {
143188
let result;
144189
try {
145-
result = realpathSync.call(fs, arg);
190+
result = /** @type {Function | undefined} */ (callback)
191+
? realpathSync.call(
192+
fs,
193+
arg,
194+
/** @type {Exclude<Parameters<NonNullable<FileSystem["realpath"]>>[1], StringCallback>} */
195+
(options)
196+
)
197+
: realpathSync.call(fs, arg);
146198
} catch (e) {
147-
return (callback || options)(e);
199+
return (callback || options)(
200+
/** @type {NodeJS.ErrnoException | null} */ (e)
201+
);
148202
}
149-
(callback || options)(null, result);
203+
204+
(callback || options)(null, /** @type {any} */ (result));
150205
}
151206
);
152207
this.realpathSync =
153208
/** @type {SyncFileSystem["realpathSync"]} */
154-
((arg, options) => realpathSync.call(fs, arg, options));
209+
(
210+
(arg, options) =>
211+
realpathSync.call(
212+
fs,
213+
arg,
214+
/** @type {Parameters<NonNullable<SyncFileSystem["realpathSync"]>>[1]} */
215+
(options)
216+
)
217+
);
155218
}
156219
}
157220
module.exports = SyncAsyncFileSystemDecorator;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"lint-staged": "^10.4.0",
3333
"memfs": "^3.2.0",
3434
"prettier": "^2.1.2",
35-
"tooling": "webpack/tooling#v1.14.0",
36-
"typescript": "^5.0.4"
35+
"tooling": "webpack/tooling#v1.23.1",
36+
"typescript": "^5.3.3"
3737
},
3838
"engines": {
3939
"node": ">=10.13.0"

yarn.lock

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,14 @@
779779
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
780780
integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==
781781

782+
"@jridgewell/source-map@^0.3.3":
783+
version "0.3.5"
784+
resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.5.tgz#a3bb4d5c6825aab0d281268f47f6ad5853431e91"
785+
integrity sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==
786+
dependencies:
787+
"@jridgewell/gen-mapping" "^0.3.0"
788+
"@jridgewell/trace-mapping" "^0.3.9"
789+
782790
"@jridgewell/[email protected]":
783791
version "1.4.14"
784792
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24"
@@ -970,6 +978,11 @@ acorn@^8.2.4:
970978
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a"
971979
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==
972980

981+
acorn@^8.8.2:
982+
version "8.11.3"
983+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a"
984+
integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==
985+
973986
agent-base@6:
974987
version "6.0.2"
975988
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
@@ -995,7 +1008,7 @@ ajv@^6.10.0, ajv@^6.12.4:
9951008
json-schema-traverse "^0.4.1"
9961009
uri-js "^4.2.2"
9971010

998-
ajv@^8.0.1:
1011+
ajv@^8.0.1, ajv@^8.1.0:
9991012
version "8.12.0"
10001013
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1"
10011014
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
@@ -1337,6 +1350,11 @@ combined-stream@^1.0.8:
13371350
dependencies:
13381351
delayed-stream "~1.0.0"
13391352

1353+
commander@^2.20.0:
1354+
version "2.20.3"
1355+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
1356+
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
1357+
13401358
commander@^6.2.0:
13411359
version "6.2.1"
13421360
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c"
@@ -3585,7 +3603,7 @@ slice-ansi@^4.0.0:
35853603
astral-regex "^2.0.0"
35863604
is-fullwidth-code-point "^3.0.0"
35873605

3588-
source-map-support@^0.5.6:
3606+
source-map-support@^0.5.6, source-map-support@~0.5.20:
35893607
version "0.5.21"
35903608
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
35913609
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
@@ -3754,6 +3772,16 @@ terminal-link@^2.0.0:
37543772
ansi-escapes "^4.2.1"
37553773
supports-hyperlinks "^2.0.0"
37563774

3775+
terser@^5.6.1:
3776+
version "5.29.1"
3777+
resolved "https://registry.yarnpkg.com/terser/-/terser-5.29.1.tgz#44e58045b70c09792ba14bfb7b4e14ca8755b9fa"
3778+
integrity sha512-lZQ/fyaIGxsbGxApKmoPTODIzELy3++mXhS5hOqaAWZjQtpq/hFHAc+rm29NND1rYRxRWKcjuARNwULNXa5RtQ==
3779+
dependencies:
3780+
"@jridgewell/source-map" "^0.3.3"
3781+
acorn "^8.8.2"
3782+
commander "^2.20.0"
3783+
source-map-support "~0.5.20"
3784+
37573785
test-exclude@^6.0.0:
37583786
version "6.0.0"
37593787
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"
@@ -3817,14 +3845,16 @@ to-regex-range@^5.0.1:
38173845
dependencies:
38183846
is-number "^7.0.0"
38193847

3820-
tooling@webpack/tooling#v1.14.0:
3821-
version "1.14.0"
3822-
resolved "https://codeload.github.com/webpack/tooling/tar.gz/f8500c02cf2a04b3a0c0c2ca38ad9df959b9d02a"
3848+
tooling@webpack/tooling#v1.23.1:
3849+
version "1.23.1"
3850+
resolved "https://codeload.github.com/webpack/tooling/tar.gz/017c076821912f5e9f5c0d04508ed6fb7f0319ad"
38233851
dependencies:
38243852
"@yarnpkg/lockfile" "^1.1.0"
3853+
ajv "^8.1.0"
38253854
commondir "^1.0.1"
38263855
glob "^7.1.6"
38273856
json-schema-to-typescript "^9.1.1"
3857+
terser "^5.6.1"
38283858
yargs "^16.1.1"
38293859

38303860
tough-cookie@^4.0.0:
@@ -3895,10 +3925,10 @@ typedarray-to-buffer@^3.1.5:
38953925
dependencies:
38963926
is-typedarray "^1.0.0"
38973927

3898-
typescript@^5.0.4:
3899-
version "5.0.4"
3900-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
3901-
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
3928+
typescript@^5.3.3:
3929+
version "5.3.3"
3930+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
3931+
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==
39023932

39033933
undici-types@~5.26.4:
39043934
version "5.26.5"

0 commit comments

Comments
 (0)