Skip to content

Commit 20a1523

Browse files
committed
fix types
1 parent 5b660e9 commit 20a1523

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

bin/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4449,6 +4449,9 @@ async function main(input, output) {
44494449
async function getPackageName() {
44504450
try {
44514451
const pkgPath = await findUp("package.json");
4452+
if (!pkgPath) {
4453+
throw new Error("Could not find package.json");
4454+
}
44524455
const pkgStr = await import_promises.default.readFile(pkgPath, "utf-8");
44534456
const pkg = JSON.parse(pkgStr);
44544457
return pkg.name;
@@ -4461,7 +4464,7 @@ function newParser() {
44614464
const errors = [];
44624465
function parse([line1, line2]) {
44634466
const match = UGLY_REGEX.exec(line1);
4464-
if (match) {
4467+
if (match?.groups) {
44654468
errors.push({
44664469
filename: import_node_path3.default.resolve(match.groups.file),
44674470
line: Number(match.groups.line),

src/main.mjs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ async function main(input, output) {
4747
}
4848

4949
/**
50-
* @returns {string}
50+
* @returns {Promise<string>}
5151
*/
5252
async function getPackageName() {
5353
try {
5454
const pkgPath = await findUp('package.json')
55+
if (!pkgPath) {
56+
throw new Error('Could not find package.json')
57+
}
5558
const pkgStr = await fs.readFile(pkgPath, 'utf-8')
5659
const pkg = JSON.parse(pkgStr)
5760
return pkg.name
@@ -72,7 +75,7 @@ async function getPackageName() {
7275
* @property {string} code
7376
* @property {string} message
7477
* @property {string} specificMessage
75-
* @property {string} [source]
78+
* @property {[string, string]} source
7679
*/
7780

7881
// We only handle the format without --pretty right now
@@ -82,11 +85,18 @@ const UGLY_REGEX = /^(?<file>.+?)\((?<line>\d+),(?<col>\d+)\): error (?<code>\S+
8285
* @returns {Parser}
8386
*/
8487
function newParser() {
88+
/**
89+
* @type {CompilerError[]}
90+
*/
8591
const errors = []
92+
93+
/**
94+
* @type {(lines: string[]) => void}
95+
*/
8696
function parse([line1, line2]) {
8797
const match = UGLY_REGEX.exec(line1)
8898

89-
if (match) {
99+
if (match?.groups) {
90100
errors.push({
91101
filename: path.resolve(match.groups.file),
92102
line: Number(match.groups.line),
@@ -102,6 +112,9 @@ function newParser() {
102112
return { errors, parse }
103113
}
104114

115+
/**
116+
* @param {CompilerError}
117+
*/
105118
function getFailureText({ filename, line, col, code, message, specificMessage }) {
106119
return `error ${code}: ${message}
107120
${specificMessage}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"outDir": "dist",
44
"allowJs": true,
5+
"checkJs": true,
56
"allowSyntheticDefaultImports": true,
67
"allowUnreachableCode": true,
78
"allowUnusedLabels": false,

0 commit comments

Comments
 (0)