Skip to content

Commit 5c38d42

Browse files
renovate[bot]renovate-botJoshuaKGoldberg
authored
fix(deps): update dependency typescript to v4.4.2 (#1192)
* fix(deps): update dependency typescript to v4.4.2 * Introduce asError and fs.promises * Fixed tests I think Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Josh Goldberg <me@joshuakgoldberg.com>
1 parent ed0781b commit 5c38d42

File tree

9 files changed

+9310
-19
lines changed

9 files changed

+9310
-19
lines changed

package-lock.json

Lines changed: 9259 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"lodash": "4.17.21",
2020
"minimatch": "3.0.4",
2121
"tslint": "6.1.3",
22-
"typescript": "4.3.5"
22+
"typescript": "4.4.2"
2323
},
2424
"devDependencies": {
2525
"@babel/core": "7.15.0",

src/adapters/exec.stubs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export const createStubExec = ({ stderr = "", stdout = "" } = {}) =>
77
jest.fn().mockReturnValue(Promise.resolve({ stderr, stdout }));
88

99
export const createStubThrowingExec = ({ stderr = "" } = {}) =>
10-
jest.fn().mockRejectedValue(Promise.resolve(new Error(stderr)));
10+
jest.fn().mockRejectedValue(new Error(stderr));

src/adapters/fsFileSystem.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
import * as fs from "fs";
2-
import { promisify } from "util";
32

3+
import { asError } from "../utils";
44
import { FileSystem } from "./fileSystem";
55

6-
const readFile = promisify(fs.readFile);
7-
const writeFile = promisify(fs.writeFile);
8-
96
export const fsFileSystem: FileSystem = {
107
fileExists: async (filePath: string) => {
118
try {
129
return fs.existsSync(filePath);
13-
} catch (error) {
10+
} catch {
1411
return false;
1512
}
1613
},
1714
readFile: async (filePath: string) => {
1815
try {
19-
return (await readFile(filePath)).toString();
16+
return (await fs.promises.readFile(filePath)).toString();
2017
} catch (error) {
21-
return error;
18+
return asError(error);
2219
}
2320
},
2421
writeFile: async (filePath: string, contents: string) => {
2522
try {
26-
return writeFile(filePath, contents);
23+
await fs.promises.writeFile(filePath, contents);
24+
return undefined;
2725
} catch (error) {
28-
return error;
26+
return asError(error);
2927
}
3028
},
3129
};

src/cli/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EOL } from "os";
33
import { processLogger } from "../adapters/processLogger";
44
import { runCliDependencies } from "../api/dependencies";
55
import { runCli } from "../cli/runCli";
6+
import { asError } from "../utils";
67

78
export const main = async (argv: string[]) => {
89
try {
@@ -14,7 +15,9 @@ export const main = async (argv: string[]) => {
1415
}
1516
} catch (error) {
1617
processLogger.info.close();
17-
processLogger.stdout.write(`Error in tslint-to-eslint-config: ${error.stack}${EOL}`);
18+
processLogger.stdout.write(
19+
`Error in tslint-to-eslint-config: ${asError(error).stack}${EOL}`,
20+
);
1821
process.exitCode = 1;
1922
}
2023
};

src/input/findRawConfiguration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SansDependencies } from "../binding";
2+
import { asError } from "../utils";
23
import { importer } from "./importer";
34

45
export const findRawConfiguration = async <Configuration>(
@@ -11,7 +12,7 @@ export const findRawConfiguration = async <Configuration>(
1112
try {
1213
results = (await fileImporter(filePath)) as Configuration;
1314
} catch (error) {
14-
return error;
15+
return asError(error);
1516
}
1617

1718
return {

src/input/findReportedConfiguration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Exec } from "../adapters/exec";
2+
import { asError } from "../utils";
23

34
export type DeepPartial<T> = {
45
[P in keyof T]?: T[P] extends Record<string, unknown> ? DeepPartial<T[P]> : T[P];
@@ -37,6 +38,6 @@ const execAndCatch = async (exec: Exec, fullCommand: string): Promise<string | E
3738

3839
return stdout;
3940
} catch (error) {
40-
return error;
41+
return asError(error);
4142
}
4243
};

src/utils.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
import { isDefined, isError, removeEmptyMembers, separateErrors, uniqueFromSources } from "./utils";
1+
import {
2+
asError,
3+
isDefined,
4+
isError,
5+
removeEmptyMembers,
6+
separateErrors,
7+
uniqueFromSources,
8+
} from "./utils";
9+
10+
describe("asError", () => {
11+
it("returns the input when the input is an error", () => {
12+
// Arrange
13+
const input = new Error("Oh no!");
14+
15+
// Act
16+
const result = asError(input);
17+
18+
// Assert
19+
expect(result).toBe(input);
20+
});
21+
22+
it("returns an equivalent error when the input is not an error", () => {
23+
// Arrange
24+
const input = "Oh no!";
25+
26+
// Act
27+
const result = asError(input);
28+
29+
// Assert
30+
expect(result).toEqual(new Error(input));
31+
});
32+
});
233

334
describe("isDefined", () => {
435
it("returns true when the item is defined", () => {

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export type Entries<T> = {
44
[K in keyof T]: [K, T[K]];
55
}[keyof T][];
66

7+
export const asError = (error: unknown) => (error instanceof Error ? error : new Error(`${error}`));
8+
79
export const isDefined = <Item>(item: Item | undefined): item is Item => item !== undefined;
810

911
export const isError = <Item>(item: Item | Error): item is Error => item instanceof Error;

0 commit comments

Comments
 (0)