@@ -47,11 +47,14 @@ async function main(input, output) {
47
47
}
48
48
49
49
/**
50
- * @returns {string }
50
+ * @returns {Promise< string> }
51
51
*/
52
52
async function getPackageName ( ) {
53
53
try {
54
54
const pkgPath = await findUp ( 'package.json' )
55
+ if ( ! pkgPath ) {
56
+ throw new Error ( 'Could not find package.json' )
57
+ }
55
58
const pkgStr = await fs . readFile ( pkgPath , 'utf-8' )
56
59
const pkg = JSON . parse ( pkgStr )
57
60
return pkg . name
@@ -72,7 +75,7 @@ async function getPackageName() {
72
75
* @property {string } code
73
76
* @property {string } message
74
77
* @property {string } specificMessage
75
- * @property {string } [ source]
78
+ * @property {[ string, string] } source
76
79
*/
77
80
78
81
// We only handle the format without --pretty right now
@@ -82,11 +85,18 @@ const UGLY_REGEX = /^(?<file>.+?)\((?<line>\d+),(?<col>\d+)\): error (?<code>\S+
82
85
* @returns {Parser }
83
86
*/
84
87
function newParser ( ) {
88
+ /**
89
+ * @type {CompilerError[] }
90
+ */
85
91
const errors = [ ]
92
+
93
+ /**
94
+ * @type {(lines: string[]) => void }
95
+ */
86
96
function parse ( [ line1 , line2 ] ) {
87
97
const match = UGLY_REGEX . exec ( line1 )
88
98
89
- if ( match ) {
99
+ if ( match ?. groups ) {
90
100
errors . push ( {
91
101
filename : path . resolve ( match . groups . file ) ,
92
102
line : Number ( match . groups . line ) ,
@@ -102,6 +112,9 @@ function newParser() {
102
112
return { errors, parse }
103
113
}
104
114
115
+ /**
116
+ * @param {CompilerError }
117
+ */
105
118
function getFailureText ( { filename, line, col, code, message, specificMessage } ) {
106
119
return `error ${ code } : ${ message }
107
120
${ specificMessage }
0 commit comments