File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,8 @@ export class Collector {
188188 this . messageRouter . addCompilerDiagnostic ( diagnostic ) ;
189189 }
190190
191+ const sourceFiles : readonly ts . SourceFile [ ] = this . program . getSourceFiles ( ) ;
192+
191193 if ( this . messageRouter . showDiagnostics ) {
192194 this . messageRouter . logDiagnosticHeader ( 'Root filenames' ) ;
193195 for ( const fileName of this . program . getRootFileNames ( ) ) {
@@ -196,12 +198,25 @@ export class Collector {
196198 this . messageRouter . logDiagnosticFooter ( ) ;
197199
198200 this . messageRouter . logDiagnosticHeader ( 'Files analyzed by compiler' ) ;
199- for ( const sourceFile of this . program . getSourceFiles ( ) ) {
201+ for ( const sourceFile of sourceFiles ) {
200202 this . messageRouter . logDiagnostic ( sourceFile . fileName ) ;
201203 }
202204 this . messageRouter . logDiagnosticFooter ( ) ;
203205 }
204206
207+ // We can throw this error earlier in CompilerState.ts, but intentionally wait until after we've logged the
208+ // associated diagnostic message above to make debugging easier for developers.
209+ const badSourceFile : boolean = sourceFiles . some (
210+ ( { fileName } ) => ! ExtractorConfig . hasDtsFileExtension ( fileName )
211+ ) ;
212+ if ( badSourceFile ) {
213+ throw new Error (
214+ 'API Extractor expects to only process .d.ts files, but encountered non-.d.ts file(s).\n' +
215+ 'Run with the "--diagnostics" flag and inspect the "Files analyzed by compiler" to find the unexpected ' +
216+ 'file(s).'
217+ ) ;
218+ }
219+
205220 // Build the entry point
206221 const entryPointSourceFile : ts . SourceFile = this . workingPackage . entryPointSourceFile ;
207222
Original file line number Diff line number Diff line change 1+ {
2+ "changes" : [
3+ {
4+ "packageName" : " @microsoft/api-extractor" ,
5+ "comment" : " Throw an error early if API Extractor will attempt to process non-.d.ts files" ,
6+ "type" : " patch"
7+ }
8+ ],
9+ "packageName" : " @microsoft/api-extractor"
10+ }
You can’t perform that action at this time.
0 commit comments