Skip to content

Commit 1a92f17

Browse files
authored
[api-extractor] Clarify "reportFileName" semantics (#4846)
* Update api-extractor-template.json to document reportVariants; clarify associated docs * Fix an edge case where indexOf() would incorrectly match the middle of a string * rush change
1 parent 0e14ced commit 1a92f17

File tree

5 files changed

+71
-48
lines changed

5 files changed

+71
-48
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,7 @@ export class ExtractorConfig {
931931
);
932932
}
933933

934-
const suffixIndex: number = apiReportConfig.reportFileName.indexOf(reportFileNameSuffix);
935-
if (suffixIndex < 0) {
934+
if (!apiReportConfig.reportFileName.endsWith(reportFileNameSuffix)) {
936935
// `.api.md` extension was not specified. Use provided file name base as is.
937936
reportFileNameBase = apiReportConfig.reportFileName;
938937
} else {
@@ -941,7 +940,7 @@ export class ExtractorConfig {
941940
// that ends with the `.api.md` extension specially, by stripping it out.
942941
// This should be removed in version 8, possibly replaced with an explicit error to help users
943942
// migrate their configs.
944-
reportFileNameBase = apiReportConfig.reportFileName.slice(0, suffixIndex);
943+
reportFileNameBase = apiReportConfig.reportFileName.slice(0, -reportFileNameSuffix.length);
945944
}
946945
} else {
947946
// Default value

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,36 @@ export interface IConfigApiReport {
7070
enabled: boolean;
7171

7272
/**
73-
* The base component of API report filenames.
73+
* The base filename for the API report files, to be combined with {@link IConfigApiReport.reportFolder} or
74+
* {@link IConfigApiReport.reportTempFolder} to produce the full file path.
7475
*
7576
* @remarks
76-
* It will be combined with the specified {@link IConfigApiReport.reportVariants}, and {@link IConfigApiReport.reportFolder} and {@link IConfigApiReport.reportTempFolder} to
77-
* produce a full output filenames in the form `<folder><reportFileName>.<variant>.api.md`.
77+
* The `reportFileName` should not include any path separators such as `\` or `/`. The `reportFileName` should
78+
* not include a file extension, since API Extractor will automatically append an appropriate file extension such
79+
* as `.api.md`. If the {@link IConfigApiReport.reportVariants} setting is used, then the file extension includes
80+
* the variant name, for example `my-report.public.api.md` or `my-report.beta.api.md`. The `complete` variant always
81+
* uses the simple extension `my-report.api.md`.
7882
*
79-
* The string should not contain a file extension.
80-
* Note: previous guidance noted that this should be specified in a form including the `.api.md` extension.
81-
* This is no longer recommended, and support for this will be removed in a future release.
82-
* For example, if you were previously specifying `Foo.api.md`, you should now specify `Foo`.
83-
* The `.api.md` extension will be added automatically to the resulting filename.
83+
* Previous versions of API Extractor required `reportFileName` to include the `.api.md` extension explicitly;
84+
* for backwards compatibility, that is still accepted but will be discarded before applying the above rules.
8485
*
85-
* The string must not contain a path separator such as `\` or `/`.
86-
*
87-
* @defaultValue `<unscopedPackageName>.api.md` will be used if this argument is not specified or if it is empty.
86+
* @defaultValue `<unscopedPackageName>`
8887
*/
8988
reportFileName?: string;
9089

9190
/**
9291
* The set of report variants to generate.
9392
*
9493
* @remarks
95-
* Each variant corresponds to a minimal release level, denoted by release tag in the TSDoc comment for each API item.
96-
* E.g., the `beta` report variant will include all API items tagged `@beta` or higher (i.e. `@beta` and `@public`).
94+
* To support different approval requirements for different API levels, multiple "variants" of the API report can
95+
* be generated. The `reportVariants` setting specifies a list of variants to be generated. If omitted,
96+
* by default only the `complete` variant will be generated, which includes all `@internal`, `@alpha`, `@beta`,
97+
* and `@public` items. Other possible variants are `alpha` (`@alpha` + `@beta` + `@public`),
98+
* `beta` (`@beta` + `@public`), and `public` (`@public only`).
9799
*
98100
* The resulting API report file names will be derived from the {@link IConfigApiReport.reportFileName}.
99-
* E.g., `foo.beta.api.md`.
100-
* The only exception to this is the `complete` variant.
101-
* This variant name will not be contained in the corresponding file name.
102-
* I.e., `foo.api.md`.
103101
*
104-
* @defaultValue `['complete']`
102+
* @defaultValue `[ "complete" ]`
105103
*/
106104
reportVariants?: ApiReportVariant[];
107105

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@
7878
*/
7979
// "newlineKind": "crlf",
8080

81-
/**
82-
* Set to true when invoking API Extractor's test harness. When `testMode` is true, the `toolVersion` field in the
83-
* .api.json file is assigned an empty string to prevent spurious diffs in output files tracked for tests.
84-
*
85-
* DEFAULT VALUE: "false"
86-
*/
87-
// "testMode": false,
88-
8981
/**
9082
* Specifies how API Extractor sorts members of an enum when generating the .api.json file. By default, the output
9183
* files will be sorted alphabetically, which is "by-name". To keep the ordering in the source code, specify
@@ -95,6 +87,14 @@
9587
*/
9688
// "enumMemberOrder": "by-name",
9789

90+
/**
91+
* Set to true when invoking API Extractor's test harness. When `testMode` is true, the `toolVersion` field in the
92+
* .api.json file is assigned an empty string to prevent spurious diffs in output files tracked for tests.
93+
*
94+
* DEFAULT VALUE: "false"
95+
*/
96+
// "testMode": false,
97+
9898
/**
9999
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
100100
*/
@@ -145,15 +145,31 @@
145145
"enabled": true
146146

147147
/**
148-
* The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce
149-
* a full file path.
148+
* The base filename for the API report files, to be combined with "reportFolder" or "reportTempFolder"
149+
* to produce the full file path. The "reportFileName" should not include any path separators such as
150+
* "\" or "/". The "reportFileName" should not include a file extension, since API Extractor will automatically
151+
* append an appropriate file extension such as ".api.md". If the "reportVariants" setting is used, then the
152+
* file extension includes the variant name, for example "my-report.public.api.md" or "my-report.beta.api.md".
153+
* The "complete" variant always uses the simple extension "my-report.api.md".
150154
*
151-
* The file extension should be ".api.md", and the string should not contain a path separator such as "\" or "/".
155+
* Previous versions of API Extractor required "reportFileName" to include the ".api.md" extension explicitly;
156+
* for backwards compatibility, that is still accepted but will be discarded before applying the above rules.
152157
*
153158
* SUPPORTED TOKENS: <packageName>, <unscopedPackageName>
154-
* DEFAULT VALUE: "<unscopedPackageName>.api.md"
159+
* DEFAULT VALUE: "<unscopedPackageName>"
160+
*/
161+
// "reportFileName": "<unscopedPackageName>",
162+
163+
/**
164+
* To support different approval requirements for different API levels, multiple "variants" of the API report can
165+
* be generated. The "reportVariants" setting specifies a list of variants to be generated. If omitted,
166+
* by default only the "complete" variant will be generated, which includes all @internal, @alpha, @beta,
167+
* and @public items. Other possible variants are "alpha" (@alpha + @beta + @public), "beta" (@beta + @public),
168+
* and "public" (@public only).
169+
*
170+
* DEFAULT VALUE: [ "complete" ]
155171
*/
156-
// "reportFileName": "<unscopedPackageName>.api.md",
172+
// "reportVariants": ["public", "beta"],
157173

158174
/**
159175
* Specifies the folder where the API report file is written. The file name portion is determined by

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,25 @@
3131
}
3232
},
3333

34+
"newlineKind": {
35+
"description": "Specifies what type of newlines API Extractor should use when writing output files. By default, the output files will be written with Windows-style newlines. To use POSIX-style newlines, specify \"lf\" instead. To use the OS's default newline kind, specify \"os\".",
36+
"type": "string",
37+
"enum": ["crlf", "lf", "os"],
38+
"default": "crlf"
39+
},
40+
3441
"enumMemberOrder": {
3542
"description": "Specifies how API Extractor sorts the members of an enum when generating the .api.json doc model. \n 'by-name': sort the items according to the enum member name \n 'preserve': keep the original order that items appear in the source code",
3643
"type": "string",
3744
"enum": ["by-name", "preserve"],
3845
"default": "by-name"
3946
},
4047

48+
"testMode": {
49+
"description": "Set to true invoking API Extractor's test harness. When \"testMode\" is true, the \"toolVersion\" field in the .api.json file is assigned an empty string to prevent spurious diffs in output files tracked for tests.",
50+
"type": "boolean"
51+
},
52+
4153
"compiler": {
4254
"description": "Determines how the TypeScript compiler engine will be invoked by API Extractor.",
4355
"type": "object",
@@ -68,12 +80,12 @@
6880
},
6981

7082
"reportFileName": {
71-
"description": "The base filename for the API report files. It will be combined with \"reportFolder\" or \"reportTempFolder\" to produce a full file path. It should not contain a file extension, nor a path separator such as \"\\\" or \"/\". The resulting file with have the extension \"api.md\". The \"complete\" report variant uses this base filename directly; other variants insert a name such as \"my-report.alpha.api.md\" or \"my-report.beta.api.md\" for alpha and beta variants.",
83+
"description": "The base filename for the API report files, to be combined with \"reportFolder\" or \"reportTempFolder\" to produce the full file path. The \"reportFileName\" should not include any path separators such as \"\\\" or \"/\". The \"reportFileName\" should not include a file extension, since API Extractor will automatically append an appropriate file extension such as \".api.md\". If the \"reportVariants\" setting is used, then the file extension includes the variant name, for example \"my-report.public.api.md\" or \"my-report.beta.api.md\". The \"complete\" variant always uses the simple extension \"my-report.api.md\".\n\nPrevious versions of API Extractor required \"reportFileName\" to include the \".api.md\" extension explicitly; for backwards compatibility, that is still accepted but will be discarded before applying the above rules.",
7284
"type": ["string"]
7385
},
7486

7587
"reportVariants": {
76-
"description": "To support different approval requirements for different API levels, multiple variants of the API report can be generated. The \"reportVariants\" setting specifies a list of variants to be generated. If omitted, by default only the \"complete\" variant will be generated, which includes all @alpha, @beta, and @public items. Other possible variants are \"alpha\" (@alpha + @beta + @public), \"beta\" (@beta + @public), and \"public\" (@public only). If you are leveraging API-Extractor's trimmed roll-ups feature, these reports will match the contents of each corresponding roll-up.",
88+
"description": "To support different approval requirements for different API levels, multiple \"variants\" of the API report can be generated. The \"reportVariants\" setting specifies a list of variants to be generated. If omitted, by default only the \"complete\" variant will be generated, which includes all @internal, @alpha, @beta, and @public items. Other possible variants are \"alpha\" (@alpha + @beta + @public), \"beta\" (@beta + @public), and \"public\" (@public only).",
7789
"type": "array",
7890
"items": {
7991
"type": "string",
@@ -174,13 +186,6 @@
174186
"additionalProperties": false
175187
},
176188

177-
"newlineKind": {
178-
"description": "Specifies what type of newlines API Extractor should use when writing output files. By default, the output files will be written with Windows-style newlines. To use POSIX-style newlines, specify \"lf\" instead. To use the OS's default newline kind, specify \"os\".",
179-
"type": "string",
180-
"enum": ["crlf", "lf", "os"],
181-
"default": "crlf"
182-
},
183-
184189
"messages": {
185190
"description": "Configures how API Extractor reports error and warning messages produced during analysis.",
186191
"type": "object",
@@ -199,11 +204,6 @@
199204
}
200205
},
201206
"additionalProperties": false
202-
},
203-
204-
"testMode": {
205-
"description": "Set to true invoking API Extractor's test harness. When \"testMode\" is true, the \"toolVersion\" field in the .api.json file is assigned an empty string to prevent spurious diffs in output files tracked for tests.",
206-
"type": "boolean"
207207
}
208208
},
209209
"required": ["mainEntryPointFilePath"],
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Fix an edge case when discarding the file extension from the \"reportFileName\" setting and improve its documentation",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor"
10+
}

0 commit comments

Comments
 (0)