Skip to content

Commit 1838446

Browse files
authored
Merge pull request #1 from octogonz/octogonz/better-ts-file-error
Provide a way to suppress the error
2 parents 933b463 + f4d5519 commit 1838446

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

apps/api-extractor/src/api/ExtractorMessageId.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ export const enum ExtractorMessageId {
9595
/**
9696
* "The property ___ has a setter but no getter."
9797
*/
98-
MissingGetter = 'ae-missing-getter'
98+
MissingGetter = 'ae-missing-getter',
99+
100+
/**
101+
* "Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension.
102+
* Troubleshooting tips: `https://api-extractor.com/link/dts-error`"
103+
*/
104+
NotDtsFileExtension = 'ae-wrong-input-file-type'
99105
}
100106

101107
export const allExtractorMessageIds: Set<string> = new Set<string>([
@@ -114,5 +120,6 @@ export const allExtractorMessageIds: Set<string> = new Set<string>([
114120
'ae-cyclic-inherit-doc',
115121
'ae-unresolved-link',
116122
'ae-setter-with-docs',
117-
'ae-missing-getter'
123+
'ae-missing-getter',
124+
'ae-wrong-input-file-type'
118125
]);

apps/api-extractor/src/collector/Collector.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,17 @@ export class Collector {
206206

207207
// We can throw this error earlier in CompilerState.ts, but intentionally wait until after we've logged the
208208
// associated diagnostic message above to make debugging easier for developers.
209-
const badSourceFile: boolean = sourceFiles.some(
209+
// Typically there will be many such files -- to avoid too much noise, only report the first one.
210+
const badSourceFile: ts.SourceFile | undefined = sourceFiles.find(
210211
({ fileName }) => !ExtractorConfig.hasDtsFileExtension(fileName)
211212
);
212213
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).'
214+
this.messageRouter.addAnalyzerIssueForPosition(
215+
ExtractorMessageId.NotDtsFileExtension,
216+
'Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension. ' +
217+
'Troubleshooting tips: https://api-extractor.com/link/dts-error',
218+
badSourceFile,
219+
0
217220
);
218221
}
219222

apps/api-extractor/src/schemas/api-extractor-defaults.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
"ae-unresolved-inheritdoc-base": {
7272
"logLevel": "warning",
7373
"addToApiReportFile": true
74+
},
75+
"ae-wrong-input-file-type": {
76+
"logLevel": "error"
7477
}
7578
},
7679
"tsdocMessageReporting": {

common/reviews/api/api-extractor.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const enum ExtractorMessageId {
135135
MisplacedPackageTag = "ae-misplaced-package-tag",
136136
MissingGetter = "ae-missing-getter",
137137
MissingReleaseTag = "ae-missing-release-tag",
138+
NotDtsFileExtension = "ae-wrong-input-file-type",
138139
PreapprovedBadReleaseTag = "ae-preapproved-bad-release-tag",
139140
PreapprovedUnsupportedType = "ae-preapproved-unsupported-type",
140141
SetterWithDocs = "ae-setter-with-docs",
@@ -265,5 +266,4 @@ export interface IExtractorMessagesConfig {
265266
tsdocMessageReporting?: IConfigMessageReportingTable;
266267
}
267268

268-
269269
```

0 commit comments

Comments
 (0)