Skip to content

Commit d2d9f45

Browse files
committed
update typescript
1 parent 3ca91de commit d2d9f45

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

lib/ResolverFactory.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const UseFilePlugin = require("./UseFilePlugin");
4040
/** @typedef {import("./PnpPlugin").PnpApiImpl} PnpApi */
4141
/** @typedef {import("./Resolver").FileSystem} FileSystem */
4242
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
43+
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
4344

4445
/** @typedef {string|string[]|false} AliasOptionNewRequest */
4546
/** @typedef {{[k: string]: AliasOptionNewRequest}} AliasOptions */
@@ -187,7 +188,11 @@ function createOptions(options) {
187188
enforceExtension: options.enforceExtension || false,
188189
extensions: new Set(options.extensions || [".js", ".json", ".node"]),
189190
fileSystem: options.useSyncFileSystemCalls
190-
? new SyncAsyncFileSystemDecorator(options.fileSystem)
191+
? new SyncAsyncFileSystemDecorator(
192+
/** @type {SyncFileSystem} */ (
193+
/** @type {unknown} */ (options.fileSystem)
194+
)
195+
)
191196
: options.fileSystem,
192197
unsafeCache:
193198
options.unsafeCache && typeof options.unsafeCache !== "object"

lib/SyncAsyncFileSystemDecorator.js

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,74 @@
55

66
"use strict";
77

8+
/** @typedef {import("./Resolver").FileSystem} FileSystem */
9+
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
10+
811
/**
9-
* @param {Object} fs file system implementation
12+
* @param {SyncFileSystem} fs file system implementation
1013
* @constructor
1114
*/
1215
function SyncAsyncFileSystemDecorator(fs) {
13-
/**
14-
* @type {Object}
15-
*/
1616
this.fs = fs;
17-
if (fs.statSync) {
18-
this.stat = (arg, callback) => {
19-
let result;
20-
try {
21-
result = fs.statSync(arg);
22-
} catch (e) {
23-
return callback(e);
24-
}
25-
callback(null, result);
26-
};
17+
this.stat = (arg, callback) => {
18+
let result;
19+
try {
20+
result = fs.statSync(arg);
21+
} catch (e) {
22+
return callback(e);
23+
}
24+
callback(null, result);
25+
};
26+
this.statSync = arg => fs.statSync(arg);
2727

28-
this.statSync = arg => fs.statSync(arg);
29-
}
30-
if (fs.readdirSync) {
31-
this.readdir = (arg, callback) => {
32-
let result;
33-
try {
34-
result = fs.readdirSync(arg);
35-
} catch (e) {
36-
return callback(e);
37-
}
38-
callback(null, result);
39-
};
28+
this.readdir = (arg, callback) => {
29+
let result;
30+
try {
31+
result = fs.readdirSync(arg);
32+
} catch (e) {
33+
return callback(e);
34+
}
35+
callback(null, result);
36+
};
37+
this.readdirSync = arg => fs.readdirSync(arg);
4038

41-
this.readdirSync = arg => fs.readdirSync(arg);
42-
}
43-
if (fs.readFileSync) {
44-
this.readFile = (arg, callback) => {
45-
let result;
46-
try {
47-
result = fs.readFileSync(arg);
48-
} catch (e) {
49-
return callback(e);
50-
}
51-
callback(null, result);
52-
};
39+
this.readFile = (arg, callback) => {
40+
let result;
41+
try {
42+
result = fs.readFileSync(arg);
43+
} catch (e) {
44+
return callback(e);
45+
}
46+
callback(null, result);
47+
};
48+
this.readFileSync = arg => fs.readFileSync(arg);
5349

54-
this.readFileSync = arg => fs.readFileSync(arg);
55-
}
56-
if (fs.readlinkSync) {
57-
this.readlink = (arg, callback) => {
58-
let result;
59-
try {
60-
result = fs.readlinkSync(arg);
61-
} catch (e) {
62-
return callback(e);
63-
}
64-
callback(null, result);
65-
};
50+
this.readlink = (arg, callback) => {
51+
let result;
52+
try {
53+
result = fs.readlinkSync(arg);
54+
} catch (e) {
55+
return callback(e);
56+
}
57+
callback(null, result);
58+
};
59+
this.readlinkSync = arg => fs.readlinkSync(arg);
6660

67-
this.readlinkSync = arg => fs.readlinkSync(arg);
68-
}
69-
if (fs.readJsonSync) {
61+
this.readJson = undefined;
62+
this.readJsonSync = undefined;
63+
const readJsonSync = fs.readJsonSync;
64+
if (readJsonSync) {
7065
this.readJson = (arg, callback) => {
7166
let result;
7267
try {
73-
result = fs.readJsonSync(arg);
68+
result = readJsonSync.call(fs, arg);
7469
} catch (e) {
7570
return callback(e);
7671
}
7772
callback(null, result);
7873
};
7974

80-
this.readJsonSync = arg => fs.readJsonSync(arg);
75+
this.readJsonSync = arg => readJsonSync.call(fs, arg);
8176
}
8277
}
8378
module.exports = SyncAsyncFileSystemDecorator;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"prettier": "^2.1.2",
3030
"should": "^13.2.3",
3131
"tooling": "webpack/tooling#v1.8.0",
32-
"typescript": "3.8.3"
32+
"typescript": "^4.0.2"
3333
},
3434
"engines": {
3535
"node": ">=10.13.0"

types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ declare namespace exports {
463463
Resolver,
464464
FileSystem,
465465
ResolveContext,
466-
UserResolveOptions as ResolveOptions,
466+
UserResolveOptions as ResolveOptions
467467
};
468468
}
469469

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,10 +2758,10 @@ typedarray-to-buffer@^3.1.5:
27582758
dependencies:
27592759
is-typedarray "^1.0.0"
27602760

2761-
typescript@3.8.3:
2762-
version "3.8.3"
2763-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
2764-
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
2761+
typescript@^4.0.2:
2762+
version "4.0.2"
2763+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2"
2764+
integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==
27652765

27662766
uri-js@^4.2.2:
27672767
version "4.2.2"

0 commit comments

Comments
 (0)