Skip to content

Commit 861b1c3

Browse files
committed
Add filepath to extract-meta errors
1 parent 6b21ec9 commit 861b1c3

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

dash/extract-meta.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function getTsConfigCompilerOptions() {
4747

4848
let failedBuild = false;
4949
const excludedDocProps = ['setProps', 'id', 'className', 'style'];
50+
const errorFiles = [];
5051

5152
const isOptional = prop => (prop.getFlags() & ts.SymbolFlags.Optional) !== 0;
5253

@@ -91,14 +92,18 @@ function logError(error, filePath) {
9192
if (error instanceof Error) {
9293
process.stderr.write(error.stack + '\n');
9394
}
95+
if (filePath && !errorFiles.includes(filePath)) {
96+
errorFiles.push(filePath);
97+
}
9498
}
9599

96-
function isReservedPropName(propName) {
100+
function isReservedPropName(propName, filepath) {
97101
reservedPatterns.forEach(reservedPattern => {
98102
if (reservedPattern.test(propName)) {
99-
process.stderr.write(
100-
`\nERROR: "${propName}" matches reserved word ` +
101-
`pattern: ${reservedPattern.toString()}\n`
103+
logError(
104+
`\nERROR:${filepath}: "${propName}" matches reserved word ` +
105+
`pattern: ${reservedPattern.toString()}\n`,
106+
filepath
102107
);
103108
failedBuild = true;
104109
}
@@ -140,7 +145,7 @@ function parseJSX(filepath) {
140145
const src = fs.readFileSync(filepath);
141146
const doc = reactDocs.parse(src);
142147
Object.keys(doc.props).forEach(propName =>
143-
isReservedPropName(propName)
148+
isReservedPropName(propName, filepath)
144149
);
145150
docstringWarning(doc);
146151
return doc;
@@ -152,6 +157,7 @@ function parseJSX(filepath) {
152157
function gatherComponents(sources, components = {}) {
153158
const names = [];
154159
const filepaths = [];
160+
let currentFilepath = ""; // For debugging purposes.
155161

156162
const gather = filepath => {
157163
if (ignorePattern && ignorePattern.test(filepath)) {
@@ -166,8 +172,9 @@ function gatherComponents(sources, components = {}) {
166172
filepaths.push(filepath);
167173
names.push(name);
168174
} catch (err) {
169-
process.stderr.write(
170-
`ERROR: Invalid component file ${filepath}: ${err}`
175+
logError(
176+
`ERROR: Invalid component file ${filepath}: ${err}`,
177+
filepath,
171178
);
172179
}
173180
}
@@ -594,7 +601,7 @@ function gatherComponents(sources, components = {}) {
594601

595602
properties.forEach(prop => {
596603
const name = prop.getName();
597-
if (isReservedPropName(name)) {
604+
if (isReservedPropName(name, currentFilepath)) {
598605
return;
599606
}
600607
const propType = checker.getTypeOfSymbolAtLocation(
@@ -660,6 +667,7 @@ function gatherComponents(sources, components = {}) {
660667
};
661668

662669
zipArrays(filepaths, names).forEach(([filepath, name]) => {
670+
currentFilepath = filepath;
663671
const source = program.getSourceFile(filepath);
664672
const moduleSymbol = checker.getSymbolAtLocation(source);
665673
const exports = checker.getExportsOfModule(moduleSymbol);
@@ -791,5 +799,9 @@ if (!failedBuild) {
791799
process.stdout.write(JSON.stringify(metadata, null, 2));
792800
} else {
793801
logError('extract-meta failed');
802+
logError('Check these files for errors:')
803+
errorFiles.forEach((errorFile) => {
804+
logError(`Error in: ${errorFile}`)
805+
})
794806
process.exit(1);
795807
}

0 commit comments

Comments
 (0)