UNPKG

48.8 kBTypeScriptView Raw
1/**
2 * API Extractor helps with validation, documentation, and reviewing of the exported API for a TypeScript library.
3 * The `@microsoft/api-extractor` package provides the command-line tool. It also exposes a developer API that you
4 * can use to invoke API Extractor programmatically.
5 *
6 * @packageDocumentation
7 */
8
9import { EnumMemberOrder } from '@microsoft/api-extractor-model';
10import { INodePackageJson } from '@rushstack/node-core-library';
11import { JsonSchema } from '@rushstack/node-core-library';
12import { NewlineKind } from '@rushstack/node-core-library';
13import { PackageJsonLookup } from '@rushstack/node-core-library';
14import { RigConfig } from '@rushstack/rig-package';
15import * as tsdoc from '@microsoft/tsdoc';
16import { TSDocConfigFile } from '@microsoft/tsdoc-config';
17import { TSDocConfiguration } from '@microsoft/tsdoc';
18
19/**
20 * This class represents the TypeScript compiler state. This allows an optimization where multiple invocations
21 * of API Extractor can reuse the same TypeScript compiler analysis.
22 *
23 * @public
24 */
25export declare class CompilerState {
26 /**
27 * The TypeScript compiler's `Program` object, which represents a complete scope of analysis.
28 */
29 readonly program: unknown;
30 private constructor();
31 /**
32 * Create a compiler state for use with the specified `IExtractorInvokeOptions`.
33 */
34 static create(extractorConfig: ExtractorConfig, options?: ICompilerStateCreateOptions): CompilerState;
35 /**
36 * Given a list of absolute file paths, return a list containing only the declaration
37 * files. Duplicates are also eliminated.
38 *
39 * @remarks
40 * The tsconfig.json settings specify the compiler's input (a set of *.ts source files,
41 * plus some *.d.ts declaration files used for legacy typings). However API Extractor
42 * analyzes the compiler's output (a set of *.d.ts entry point files, plus any legacy
43 * typings). This requires API Extractor to generate a special file list when it invokes
44 * the compiler.
45 *
46 * Duplicates are removed so that entry points can be appended without worrying whether they
47 * may already appear in the tsconfig.json file list.
48 */
49 private static _generateFilePathsForAnalysis;
50 private static _createCompilerHost;
51}
52
53/**
54 * Unique identifiers for console messages reported by API Extractor.
55 *
56 * @remarks
57 *
58 * These strings are possible values for the {@link ExtractorMessage.messageId} property
59 * when the `ExtractorMessage.category` is {@link ExtractorMessageCategory.Console}.
60 *
61 * @public
62 */
63export declare const enum ConsoleMessageId {
64 /**
65 * "Analysis will use the bundled TypeScript version ___"
66 */
67 Preamble = "console-preamble",
68 /**
69 * "The target project appears to use TypeScript ___ which is newer than the bundled compiler engine;
70 * consider upgrading API Extractor."
71 */
72 CompilerVersionNotice = "console-compiler-version-notice",
73 /**
74 * "Using custom TSDoc config from ___"
75 */
76 UsingCustomTSDocConfig = "console-using-custom-tsdoc-config",
77 /**
78 * "Found metadata in ___"
79 */
80 FoundTSDocMetadata = "console-found-tsdoc-metadata",
81 /**
82 * "Writing: ___"
83 */
84 WritingDocModelFile = "console-writing-doc-model-file",
85 /**
86 * "Writing package typings: ___"
87 */
88 WritingDtsRollup = "console-writing-dts-rollup",
89 /**
90 * "You have changed the public API signature for this project.
91 * Please copy the file ___ to ___, or perform a local build (which does this automatically).
92 * See the Git repo documentation for more info."
93 *
94 * OR
95 *
96 * "The API report file is missing.
97 * Please copy the file ___ to ___, or perform a local build (which does this automatically).
98 * See the Git repo documentation for more info."
99 */
100 ApiReportNotCopied = "console-api-report-not-copied",
101 /**
102 * "You have changed the public API signature for this project. Updating ___"
103 */
104 ApiReportCopied = "console-api-report-copied",
105 /**
106 * "The API report is up to date: ___"
107 */
108 ApiReportUnchanged = "console-api-report-unchanged",
109 /**
110 * "The API report file was missing, so a new file was created. Please add this file to Git: ___"
111 */
112 ApiReportCreated = "console-api-report-created",
113 /**
114 * "Unable to create the API report file. Please make sure the target folder exists: ___"
115 */
116 ApiReportFolderMissing = "console-api-report-folder-missing",
117 /**
118 * Used for the information printed when the "--diagnostics" flag is enabled.
119 */
120 Diagnostics = "console-diagnostics"
121}
122
123/**
124 * The starting point for invoking the API Extractor tool.
125 * @public
126 */
127export declare class Extractor {
128 /**
129 * Returns the version number of the API Extractor NPM package.
130 */
131 static get version(): string;
132 /**
133 * Returns the package name of the API Extractor NPM package.
134 */
135 static get packageName(): string;
136 private static _getPackageJson;
137 /**
138 * Load the api-extractor.json config file from the specified path, and then invoke API Extractor.
139 */
140 static loadConfigAndInvoke(configFilePath: string, options?: IExtractorInvokeOptions): ExtractorResult;
141 /**
142 * Invoke API Extractor using an already prepared `ExtractorConfig` object.
143 */
144 static invoke(extractorConfig: ExtractorConfig, options?: IExtractorInvokeOptions): ExtractorResult;
145 private static _checkCompilerCompatibility;
146 private static _generateRollupDtsFile;
147}
148
149/**
150 * The `ExtractorConfig` class loads, validates, interprets, and represents the api-extractor.json config file.
151 * @public
152 */
153export declare class ExtractorConfig {
154 /**
155 * The JSON Schema for API Extractor config file (api-extractor.schema.json).
156 */
157 static readonly jsonSchema: JsonSchema;
158 /**
159 * The config file name "api-extractor.json".
160 */
161 static readonly FILENAME: 'api-extractor.json';
162 /**
163 * The full path to `extends/tsdoc-base.json` which contains the standard TSDoc configuration
164 * for API Extractor.
165 * @internal
166 */
167 static readonly _tsdocBaseFilePath: string;
168 private static readonly _defaultConfig;
169 private static readonly _declarationFileExtensionRegExp;
170 /** {@inheritDoc IConfigFile.projectFolder} */
171 readonly projectFolder: string;
172 /**
173 * The parsed package.json file for the working package, or undefined if API Extractor was invoked without
174 * a package.json file.
175 */
176 readonly packageJson: INodePackageJson | undefined;
177 /**
178 * The absolute path of the folder containing the package.json file for the working package, or undefined
179 * if API Extractor was invoked without a package.json file.
180 */
181 readonly packageFolder: string | undefined;
182 /** {@inheritDoc IConfigFile.mainEntryPointFilePath} */
183 readonly mainEntryPointFilePath: string;
184 /** {@inheritDoc IConfigFile.bundledPackages} */
185 readonly bundledPackages: string[];
186 /** {@inheritDoc IConfigCompiler.tsconfigFilePath} */
187 readonly tsconfigFilePath: string;
188 /** {@inheritDoc IConfigCompiler.overrideTsconfig} */
189 readonly overrideTsconfig: {} | undefined;
190 /** {@inheritDoc IConfigCompiler.skipLibCheck} */
191 readonly skipLibCheck: boolean;
192 /** {@inheritDoc IConfigApiReport.enabled} */
193 readonly apiReportEnabled: boolean;
194 /** The `reportFolder` path combined with the `reportFileName`. */
195 readonly reportFilePath: string;
196 /** The `reportTempFolder` path combined with the `reportFileName`. */
197 readonly reportTempFilePath: string;
198 /** {@inheritDoc IConfigApiReport.includeForgottenExports} */
199 readonly apiReportIncludeForgottenExports: boolean;
200 /** {@inheritDoc IConfigDocModel.enabled} */
201 readonly docModelEnabled: boolean;
202 /** {@inheritDoc IConfigDocModel.apiJsonFilePath} */
203 readonly apiJsonFilePath: string;
204 /** {@inheritDoc IConfigDocModel.includeForgottenExports} */
205 readonly docModelIncludeForgottenExports: boolean;
206 /** {@inheritDoc IConfigDocModel.projectFolderUrl} */
207 readonly projectFolderUrl: string | undefined;
208 /** {@inheritDoc IConfigDtsRollup.enabled} */
209 readonly rollupEnabled: boolean;
210 /** {@inheritDoc IConfigDtsRollup.untrimmedFilePath} */
211 readonly untrimmedFilePath: string;
212 /** {@inheritDoc IConfigDtsRollup.alphaTrimmedFilePath} */
213 readonly alphaTrimmedFilePath: string;
214 /** {@inheritDoc IConfigDtsRollup.betaTrimmedFilePath} */
215 readonly betaTrimmedFilePath: string;
216 /** {@inheritDoc IConfigDtsRollup.publicTrimmedFilePath} */
217 readonly publicTrimmedFilePath: string;
218 /** {@inheritDoc IConfigDtsRollup.omitTrimmingComments} */
219 readonly omitTrimmingComments: boolean;
220 /** {@inheritDoc IConfigTsdocMetadata.enabled} */
221 readonly tsdocMetadataEnabled: boolean;
222 /** {@inheritDoc IConfigTsdocMetadata.tsdocMetadataFilePath} */
223 readonly tsdocMetadataFilePath: string;
224 /**
225 * The tsdoc.json configuration that will be used when parsing doc comments.
226 */
227 readonly tsdocConfigFile: TSDocConfigFile;
228 /**
229 * The `TSDocConfiguration` loaded from {@link ExtractorConfig.tsdocConfigFile}.
230 */
231 readonly tsdocConfiguration: TSDocConfiguration;
232 /**
233 * Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
234 * will be written with Windows-style newlines.
235 */
236 readonly newlineKind: NewlineKind;
237 /** {@inheritDoc IConfigFile.messages} */
238 readonly messages: IExtractorMessagesConfig;
239 /** {@inheritDoc IConfigFile.testMode} */
240 readonly testMode: boolean;
241 /** {@inheritDoc IConfigFile.enumMemberOrder} */
242 readonly enumMemberOrder: EnumMemberOrder;
243 private constructor();
244 /**
245 * Returns a JSON-like string representing the `ExtractorConfig` state, which can be printed to a console
246 * for diagnostic purposes.
247 *
248 * @remarks
249 * This is used by the "--diagnostics" command-line option. The string is not intended to be deserialized;
250 * its format may be changed at any time.
251 */
252 getDiagnosticDump(): string;
253 /**
254 * Returns a simplified file path for use in error messages.
255 * @internal
256 */
257 _getShortFilePath(absolutePath: string): string;
258 /**
259 * Searches for the api-extractor.json config file associated with the specified starting folder,
260 * and loads the file if found. This lookup supports
261 * {@link https://www.npmjs.com/package/@rushstack/rig-package | rig packages}.
262 *
263 * @remarks
264 * The search will first look for a package.json file in a parent folder of the starting folder;
265 * if found, that will be used as the base folder instead of the starting folder. If the config
266 * file is not found in `<baseFolder>/api-extractor.json` or `<baseFolder>/config/api-extractor.json`,
267 * then `<baseFolder/config/rig.json` will be checked to see whether a
268 * {@link https://www.npmjs.com/package/@rushstack/rig-package | rig package} is referenced; if so then
269 * the rig's api-extractor.json file will be used instead. If a config file is found, it will be loaded
270 * and returned with the `IExtractorConfigPrepareOptions` object. Otherwise, `undefined` is returned
271 * to indicate that API Extractor does not appear to be configured for the specified folder.
272 *
273 * @returns An options object that can be passed to {@link ExtractorConfig.prepare}, or `undefined`
274 * if not api-extractor.json file was found.
275 */
276 static tryLoadForFolder(options: IExtractorConfigLoadForFolderOptions): IExtractorConfigPrepareOptions | undefined;
277 /**
278 * Loads the api-extractor.json config file from the specified file path, and prepares an `ExtractorConfig` object.
279 *
280 * @remarks
281 * Loads the api-extractor.json config file from the specified file path. If the "extends" field is present,
282 * the referenced file(s) will be merged. For any omitted fields, the API Extractor default values are merged.
283 *
284 * The result is prepared using `ExtractorConfig.prepare()`.
285 */
286 static loadFileAndPrepare(configJsonFilePath: string): ExtractorConfig;
287 /**
288 * Performs only the first half of {@link ExtractorConfig.loadFileAndPrepare}, providing an opportunity to
289 * modify the object before it is passed to {@link ExtractorConfig.prepare}.
290 *
291 * @remarks
292 * Loads the api-extractor.json config file from the specified file path. If the "extends" field is present,
293 * the referenced file(s) will be merged. For any omitted fields, the API Extractor default values are merged.
294 */
295 static loadFile(jsonFilePath: string): IConfigFile;
296 private static _resolveConfigFileRelativePaths;
297 private static _resolveConfigFileRelativePath;
298 /**
299 * Prepares an `ExtractorConfig` object using a configuration that is provided as a runtime object,
300 * rather than reading it from disk. This allows configurations to be constructed programmatically,
301 * loaded from an alternate source, and/or customized after loading.
302 */
303 static prepare(options: IExtractorConfigPrepareOptions): ExtractorConfig;
304 private static _resolvePathWithTokens;
305 private static _expandStringWithTokens;
306 /**
307 * Returns true if the specified file path has the ".d.ts" file extension.
308 */
309 static hasDtsFileExtension(filePath: string): boolean;
310 /**
311 * Given a path string that may have originally contained expandable tokens such as `<projectFolder>"`
312 * this reports an error if any token-looking substrings remain after expansion (e.g. `c:\blah\<invalid>\blah`).
313 */
314 private static _rejectAnyTokensInPath;
315}
316
317/**
318 * Used with {@link IConfigMessageReportingRule.logLevel} and {@link IExtractorInvokeOptions.messageCallback}.
319 *
320 * @remarks
321 * This is part of the {@link IConfigFile} structure.
322 *
323 * @public
324 */
325export declare const enum ExtractorLogLevel {
326 /**
327 * The message will be displayed as an error.
328 *
329 * @remarks
330 * Errors typically cause the build to fail and return a nonzero exit code.
331 */
332 Error = "error",
333 /**
334 * The message will be displayed as an warning.
335 *
336 * @remarks
337 * Warnings typically cause a production build fail and return a nonzero exit code. For a non-production build
338 * (e.g. using the `--local` option with `api-extractor run`), the warning is displayed but the build will not fail.
339 */
340 Warning = "warning",
341 /**
342 * The message will be displayed as an informational message.
343 *
344 * @remarks
345 * Informational messages may contain newlines to ensure nice formatting of the output,
346 * however word-wrapping is the responsibility of the message handler.
347 */
348 Info = "info",
349 /**
350 * The message will be displayed only when "verbose" output is requested, e.g. using the `--verbose`
351 * command line option.
352 */
353 Verbose = "verbose",
354 /**
355 * The message will be discarded entirely.
356 */
357 None = "none"
358}
359
360/**
361 * This object is used to report an error or warning that occurred during API Extractor's analysis.
362 *
363 * @public
364 */
365export declare class ExtractorMessage {
366 private _handled;
367 private _logLevel;
368 /**
369 * The category of issue.
370 */
371 readonly category: ExtractorMessageCategory;
372 /**
373 * A text string that uniquely identifies the issue type. This identifier can be used to suppress
374 * or configure the reporting of issues, and also to search for help about an issue.
375 */
376 readonly messageId: tsdoc.TSDocMessageId | ExtractorMessageId | ConsoleMessageId | string;
377 /**
378 * The text description of this issue.
379 */
380 readonly text: string;
381 /**
382 * The absolute path to the affected input source file, if there is one.
383 */
384 readonly sourceFilePath: string | undefined;
385 /**
386 * The line number where the issue occurred in the input source file. This is not used if `sourceFilePath`
387 * is undefined. The first line number is 1.
388 */
389 readonly sourceFileLine: number | undefined;
390 /**
391 * The column number where the issue occurred in the input source file. This is not used if `sourceFilePath`
392 * is undefined. The first column number is 1.
393 */
394 readonly sourceFileColumn: number | undefined;
395 /**
396 * Additional contextual information about the message that may be useful when reporting errors.
397 * All properties are optional.
398 */
399 readonly properties: IExtractorMessageProperties;
400 /** @internal */
401 constructor(options: IExtractorMessageOptions);
402 /**
403 * If the {@link IExtractorInvokeOptions.messageCallback} sets this property to true, it will prevent the message
404 * from being displayed by API Extractor.
405 *
406 * @remarks
407 * If the `messageCallback` routes the message to a custom handler (e.g. a toolchain logger), it should
408 * assign `handled = true` to prevent API Extractor from displaying it. Assigning `handled = true` for all messages
409 * would effectively disable all console output from the `Extractor` API.
410 *
411 * If `handled` is set to true, the message will still be included in the count of errors/warnings;
412 * to discard a message entirely, instead assign `logLevel = none`.
413 */
414 get handled(): boolean;
415 set handled(value: boolean);
416 /**
417 * Specifies how the message should be reported.
418 *
419 * @remarks
420 * If the {@link IExtractorInvokeOptions.messageCallback} handles the message (i.e. sets `handled = true`),
421 * it can use the `logLevel` to determine how to display the message.
422 *
423 * Alternatively, if API Extractor is handling the message, the `messageCallback` could assign `logLevel` to change
424 * how it will be processed. However, in general the recommended practice is to configure message routing
425 * using the `messages` section in api-extractor.json.
426 *
427 * To discard a message entirely, assign `logLevel = none`.
428 */
429 get logLevel(): ExtractorLogLevel;
430 set logLevel(value: ExtractorLogLevel);
431 /**
432 * Returns the message formatted with its identifier and file position.
433 * @remarks
434 * Example:
435 * ```
436 * src/folder/File.ts:123:4 - (ae-extra-release-tag) The doc comment should not contain more than one release tag.
437 * ```
438 */
439 formatMessageWithLocation(workingPackageFolderPath: string | undefined): string;
440 formatMessageWithoutLocation(): string;
441}
442
443/**
444 * Specifies a category of messages for use with {@link ExtractorMessage}.
445 * @public
446 */
447export declare const enum ExtractorMessageCategory {
448 /**
449 * Messages originating from the TypeScript compiler.
450 *
451 * @remarks
452 * These strings begin with the prefix "TS" and have a numeric error code.
453 * Example: `TS2551`
454 */
455 Compiler = "Compiler",
456 /**
457 * Messages related to parsing of TSDoc comments.
458 *
459 * @remarks
460 * These strings begin with the prefix "tsdoc-".
461 * Example: `tsdoc-link-tag-unescaped-text`
462 */
463 TSDoc = "TSDoc",
464 /**
465 * Messages related to API Extractor's analysis.
466 *
467 * @remarks
468 * These strings begin with the prefix "ae-".
469 * Example: `ae-extra-release-tag`
470 */
471 Extractor = "Extractor",
472 /**
473 * Console messages communicate the progress of the overall operation. They may include newlines to ensure
474 * nice formatting. They are output in real time, and cannot be routed to the API Report file.
475 *
476 * @remarks
477 * These strings begin with the prefix "console-".
478 * Example: `console-writing-typings-file`
479 */
480 Console = "console"
481}
482
483/**
484 * Unique identifiers for messages reported by API Extractor during its analysis.
485 *
486 * @remarks
487 *
488 * These strings are possible values for the {@link ExtractorMessage.messageId} property
489 * when the `ExtractorMessage.category` is {@link ExtractorMessageCategory.Extractor}.
490 *
491 * @public
492 */
493export declare const enum ExtractorMessageId {
494 /**
495 * "The doc comment should not contain more than one release tag."
496 */
497 ExtraReleaseTag = "ae-extra-release-tag",
498 /**
499 * "This symbol has another declaration with a different release tag."
500 */
501 DifferentReleaseTags = "ae-different-release-tags",
502 /**
503 * "The symbol ___ is marked as ___, but its signature references ___ which is marked as ___."
504 */
505 IncompatibleReleaseTags = "ae-incompatible-release-tags",
506 /**
507 * "___ is part of the package's API, but it is missing a release tag (`@alpha`, `@beta`, `@public`, or `@internal`)."
508 */
509 MissingReleaseTag = "ae-missing-release-tag",
510 /**
511 * "The `@packageDocumentation` comment must appear at the top of entry point *.d.ts file."
512 */
513 MisplacedPackageTag = "ae-misplaced-package-tag",
514 /**
515 * "The symbol ___ needs to be exported by the entry point ___."
516 */
517 ForgottenExport = "ae-forgotten-export",
518 /**
519 * "The name ___ should be prefixed with an underscore because the declaration is marked as `@internal`."
520 */
521 InternalMissingUnderscore = "ae-internal-missing-underscore",
522 /**
523 * "Mixed release tags are not allowed for ___ because one of its declarations is marked as `@internal`."
524 */
525 InternalMixedReleaseTag = "ae-internal-mixed-release-tag",
526 /**
527 * "The `@preapproved` tag cannot be applied to ___ because it is not a supported declaration type."
528 */
529 PreapprovedUnsupportedType = "ae-preapproved-unsupported-type",
530 /**
531 * "The `@preapproved` tag cannot be applied to ___ without an `@internal` release tag."
532 */
533 PreapprovedBadReleaseTag = "ae-preapproved-bad-release-tag",
534 /**
535 * "The `@inheritDoc` reference could not be resolved."
536 */
537 UnresolvedInheritDocReference = "ae-unresolved-inheritdoc-reference",
538 /**
539 * "The `@inheritDoc` tag needs a TSDoc declaration reference; signature matching is not supported yet."
540 *
541 * @privateRemarks
542 * In the future, we will implement signature matching so that you can write `{@inheritDoc}` and API Extractor
543 * will find a corresponding member from a base class (or implemented interface). Until then, the tag
544 * always needs an explicit declaration reference such as `{@inhertDoc MyBaseClass.sameMethod}`.
545 */
546 UnresolvedInheritDocBase = "ae-unresolved-inheritdoc-base",
547 /**
548 * "The `@inheritDoc` tag for ___ refers to its own declaration."
549 */
550 CyclicInheritDoc = "ae-cyclic-inherit-doc",
551 /**
552 * "The `@link` reference could not be resolved."
553 */
554 UnresolvedLink = "ae-unresolved-link",
555 /**
556 * "The doc comment for the property ___ must appear on the getter, not the setter."
557 */
558 SetterWithDocs = "ae-setter-with-docs",
559 /**
560 * "The property ___ has a setter but no getter."
561 */
562 MissingGetter = "ae-missing-getter",
563 /**
564 * "Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension.
565 * Troubleshooting tips: `https://api-extractor.com/link/dts-error`"
566 */
567 WrongInputFileType = "ae-wrong-input-file-type"
568}
569
570/**
571 * This object represents the outcome of an invocation of API Extractor.
572 *
573 * @public
574 */
575export declare class ExtractorResult {
576 /**
577 * The TypeScript compiler state that was used.
578 */
579 readonly compilerState: CompilerState;
580 /**
581 * The API Extractor configuration that was used.
582 */
583 readonly extractorConfig: ExtractorConfig;
584 /**
585 * Whether the invocation of API Extractor was successful. For example, if `succeeded` is false, then the build task
586 * would normally return a nonzero process exit code, indicating that the operation failed.
587 *
588 * @remarks
589 *
590 * Normally the operation "succeeds" if `errorCount` and `warningCount` are both zero. However if
591 * {@link IExtractorInvokeOptions.localBuild} is `true`, then the operation "succeeds" if `errorCount` is zero
592 * (i.e. warnings are ignored).
593 */
594 readonly succeeded: boolean;
595 /**
596 * Returns true if the API report was found to have changed.
597 */
598 readonly apiReportChanged: boolean;
599 /**
600 * Reports the number of errors encountered during analysis.
601 *
602 * @remarks
603 * This does not count exceptions, where unexpected issues prematurely abort the operation.
604 */
605 readonly errorCount: number;
606 /**
607 * Reports the number of warnings encountered during analysis.
608 *
609 * @remarks
610 * This does not count warnings that are emitted in the API report file.
611 */
612 readonly warningCount: number;
613 /** @internal */
614 constructor(properties: ExtractorResult);
615}
616
617/**
618 * Options for {@link CompilerState.create}
619 * @public
620 */
621export declare interface ICompilerStateCreateOptions {
622 /** {@inheritDoc IExtractorInvokeOptions.typescriptCompilerFolder} */
623 typescriptCompilerFolder?: string;
624 /**
625 * Additional .d.ts files to include in the analysis.
626 */
627 additionalEntryPoints?: string[];
628}
629
630/**
631 * Configures how the API report files (*.api.md) will be generated.
632 *
633 * @remarks
634 * This is part of the {@link IConfigFile} structure.
635 *
636 * @public
637 */
638export declare interface IConfigApiReport {
639 /**
640 * Whether to generate an API report.
641 */
642 enabled: boolean;
643 /**
644 * The filename for the API report files. It will be combined with `reportFolder` or `reportTempFolder` to produce
645 * a full output filename.
646 *
647 * @remarks
648 * The file extension should be ".api.md", and the string should not contain a path separator such as `\` or `/`.
649 */
650 reportFileName?: string;
651 /**
652 * Specifies the folder where the API report file is written. The file name portion is determined by
653 * the `reportFileName` setting.
654 *
655 * @remarks
656 * The API report file is normally tracked by Git. Changes to it can be used to trigger a branch policy,
657 * e.g. for an API review.
658 *
659 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
660 * prepend a folder token such as `<projectFolder>`.
661 */
662 reportFolder?: string;
663 /**
664 * Specifies the folder where the temporary report file is written. The file name portion is determined by
665 * the `reportFileName` setting.
666 *
667 * @remarks
668 * After the temporary file is written to disk, it is compared with the file in the `reportFolder`.
669 * If they are different, a production build will fail.
670 *
671 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
672 * prepend a folder token such as `<projectFolder>`.
673 */
674 reportTempFolder?: string;
675 /**
676 * Whether "forgotten exports" should be included in the API report file.
677 *
678 * @remarks
679 * Forgotten exports are declarations flagged with `ae-forgotten-export` warnings. See
680 * https://api-extractor.com/pages/messages/ae-forgotten-export/ to learn more.
681 *
682 * @defaultValue `false`
683 */
684 includeForgottenExports?: boolean;
685}
686
687/**
688 * Determines how the TypeScript compiler engine will be invoked by API Extractor.
689 *
690 * @remarks
691 * This is part of the {@link IConfigFile} structure.
692 *
693 * @public
694 */
695export declare interface IConfigCompiler {
696 /**
697 * Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project.
698 *
699 * @remarks
700 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
701 * prepend a folder token such as `<projectFolder>`.
702 *
703 * Note: This setting will be ignored if `overrideTsconfig` is used.
704 */
705 tsconfigFilePath?: string;
706 /**
707 * Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk.
708 *
709 * @remarks
710 * The value must conform to the TypeScript tsconfig schema:
711 *
712 * http://json.schemastore.org/tsconfig
713 *
714 * If omitted, then the tsconfig.json file will instead be read from the projectFolder.
715 */
716 overrideTsconfig?: {};
717 /**
718 * This option causes the compiler to be invoked with the `--skipLibCheck` option.
719 *
720 * @remarks
721 * This option is not recommended and may cause API Extractor to produce incomplete or incorrect declarations,
722 * but it may be required when dependencies contain declarations that are incompatible with the TypeScript engine
723 * that API Extractor uses for its analysis. Where possible, the underlying issue should be fixed rather than
724 * relying on skipLibCheck.
725 */
726 skipLibCheck?: boolean;
727}
728
729/**
730 * Configures how the doc model file (*.api.json) will be generated.
731 *
732 * @remarks
733 * This is part of the {@link IConfigFile} structure.
734 *
735 * @public
736 */
737export declare interface IConfigDocModel {
738 /**
739 * Whether to generate a doc model file.
740 */
741 enabled: boolean;
742 /**
743 * The output path for the doc model file. The file extension should be ".api.json".
744 *
745 * @remarks
746 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
747 * prepend a folder token such as `<projectFolder>`.
748 */
749 apiJsonFilePath?: string;
750 /**
751 * Whether "forgotten exports" should be included in the doc model file.
752 *
753 * @remarks
754 * Forgotten exports are declarations flagged with `ae-forgotten-export` warnings. See
755 * https://api-extractor.com/pages/messages/ae-forgotten-export/ to learn more.
756 *
757 * @defaultValue `false`
758 */
759 includeForgottenExports?: boolean;
760 /**
761 * The base URL where the project's source code can be viewed on a website such as GitHub or
762 * Azure DevOps. This URL path corresponds to the `<projectFolder>` path on disk.
763 *
764 * @remarks
765 * This URL is concatenated with the file paths serialized to the doc model to produce URL file paths to individual API items.
766 * For example, if the `projectFolderUrl` is "https://github.com/microsoft/rushstack/tree/main/apps/api-extractor" and an API
767 * item's file path is "api/ExtractorConfig.ts", the full URL file path would be
768 * "https://github.com/microsoft/rushstack/tree/main/apps/api-extractor/api/ExtractorConfig.js".
769 *
770 * Can be omitted if you don't need source code links in your API documentation reference.
771 */
772 projectFolderUrl?: string;
773}
774
775/**
776 * Configures how the .d.ts rollup file will be generated.
777 *
778 * @remarks
779 * This is part of the {@link IConfigFile} structure.
780 *
781 * @public
782 */
783export declare interface IConfigDtsRollup {
784 /**
785 * Whether to generate the .d.ts rollup file.
786 */
787 enabled: boolean;
788 /**
789 * Specifies the output path for a .d.ts rollup file to be generated without any trimming.
790 *
791 * @remarks
792 * This file will include all declarations that are exported by the main entry point.
793 *
794 * If the path is an empty string, then this file will not be written.
795 *
796 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
797 * prepend a folder token such as `<projectFolder>`.
798 */
799 untrimmedFilePath?: string;
800 /**
801 * Specifies the output path for a .d.ts rollup file to be generated with trimming for an "alpha" release.
802 *
803 * @remarks
804 * This file will include only declarations that are marked as `@public`, `@beta`, or `@alpha`.
805 *
806 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
807 * prepend a folder token such as `<projectFolder>`.
808 */
809 alphaTrimmedFilePath?: string;
810 /**
811 * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
812 *
813 * @remarks
814 * This file will include only declarations that are marked as `@public` or `@beta`.
815 *
816 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
817 * prepend a folder token such as `<projectFolder>`.
818 */
819 betaTrimmedFilePath?: string;
820 /**
821 * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release.
822 *
823 * @remarks
824 * This file will include only declarations that are marked as `@public`.
825 *
826 * If the path is an empty string, then this file will not be written.
827 *
828 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
829 * prepend a folder token such as `<projectFolder>`.
830 */
831 publicTrimmedFilePath?: string;
832 /**
833 * When a declaration is trimmed, by default it will be replaced by a code comment such as
834 * "Excluded from this release type: exampleMember". Set "omitTrimmingComments" to true to remove the
835 * declaration completely.
836 */
837 omitTrimmingComments?: boolean;
838}
839
840/**
841 * Configuration options for the API Extractor tool. These options can be constructed programmatically
842 * or loaded from the api-extractor.json config file using the {@link ExtractorConfig} class.
843 *
844 * @public
845 */
846export declare interface IConfigFile {
847 /**
848 * Optionally specifies another JSON config file that this file extends from. This provides a way for
849 * standard settings to be shared across multiple projects.
850 *
851 * @remarks
852 * If the path starts with `./` or `../`, the path is resolved relative to the folder of the file that contains
853 * the `extends` field. Otherwise, the first path segment is interpreted as an NPM package name, and will be
854 * resolved using NodeJS `require()`.
855 */
856 extends?: string;
857 /**
858 * Determines the `<projectFolder>` token that can be used with other config file settings. The project folder
859 * typically contains the tsconfig.json and package.json config files, but the path is user-defined.
860 *
861 * @remarks
862 *
863 * The path is resolved relative to the folder of the config file that contains the setting.
864 *
865 * The default value for `projectFolder` is the token `<lookup>`, which means the folder is determined using
866 * the following heuristics:
867 *
868 * If the config/rig.json system is used (as defined by {@link https://www.npmjs.com/package/@rushstack/rig-package
869 * | @rushstack/rig-package}), then the `<lookup>` value will be the package folder that referenced the rig.
870 *
871 * Otherwise, the `<lookup>` value is determined by traversing parent folders, starting from the folder containing
872 * api-extractor.json, and stopping at the first folder that contains a tsconfig.json file. If a tsconfig.json file
873 * cannot be found in this way, then an error will be reported.
874 */
875 projectFolder?: string;
876 /**
877 * Specifies the .d.ts file to be used as the starting point for analysis. API Extractor
878 * analyzes the symbols exported by this module.
879 *
880 * @remarks
881 *
882 * The file extension must be ".d.ts" and not ".ts".
883 * The path is resolved relative to the "projectFolder" location.
884 */
885 mainEntryPointFilePath: string;
886 /**
887 * A list of NPM package names whose exports should be treated as part of this package.
888 *
889 * @remarks
890 *
891 * For example, suppose that Webpack is used to generate a distributed bundle for the project `library1`,
892 * and another NPM package `library2` is embedded in this bundle. Some types from `library2` may become part
893 * of the exported API for `library1`, but by default API Extractor would generate a .d.ts rollup that explicitly
894 * imports `library2`. To avoid this, we can specify:
895 *
896 * ```js
897 * "bundledPackages": [ "library2" ],
898 * ```
899 *
900 * This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
901 * local files for `library1`.
902 */
903 bundledPackages?: string[];
904 /**
905 * Specifies what type of newlines API Extractor should use when writing output files.
906 *
907 * @remarks
908 * By default, the output files will be written with Windows-style newlines.
909 * To use POSIX-style newlines, specify "lf" instead.
910 * To use the OS's default newline kind, specify "os".
911 */
912 newlineKind?: 'crlf' | 'lf' | 'os';
913 /**
914 * Set to true when invoking API Extractor's test harness.
915 * @remarks
916 * When `testMode` is true, the `toolVersion` field in the .api.json file is assigned an empty string
917 * to prevent spurious diffs in output files tracked for tests.
918 */
919 testMode?: boolean;
920 /**
921 * Specifies how API Extractor sorts members of an enum when generating the .api.json file.
922 *
923 * @remarks
924 * By default, the output files will be sorted alphabetically, which is "by-name".
925 * To keep the ordering in the source code, specify "preserve".
926 *
927 * @defaultValue `by-name`
928 */
929 enumMemberOrder?: EnumMemberOrder;
930 /**
931 * {@inheritDoc IConfigCompiler}
932 */
933 compiler?: IConfigCompiler;
934 /**
935 * {@inheritDoc IConfigApiReport}
936 */
937 apiReport?: IConfigApiReport;
938 /**
939 * {@inheritDoc IConfigDocModel}
940 */
941 docModel?: IConfigDocModel;
942 /**
943 * {@inheritDoc IConfigDtsRollup}
944 * @beta
945 */
946 dtsRollup?: IConfigDtsRollup;
947 /**
948 * {@inheritDoc IConfigTsdocMetadata}
949 * @beta
950 */
951 tsdocMetadata?: IConfigTsdocMetadata;
952 /**
953 * {@inheritDoc IExtractorMessagesConfig}
954 */
955 messages?: IExtractorMessagesConfig;
956}
957
958/**
959 * Configures reporting for a given message identifier.
960 *
961 * @remarks
962 * This is part of the {@link IConfigFile} structure.
963 *
964 * @public
965 */
966export declare interface IConfigMessageReportingRule {
967 /**
968 * Specifies whether the message should be written to the the tool's output log.
969 *
970 * @remarks
971 * Note that the `addToApiReportFile` property may supersede this option.
972 */
973 logLevel: ExtractorLogLevel;
974 /**
975 * When `addToApiReportFile` is true: If API Extractor is configured to write an API report file (.api.md),
976 * then the message will be written inside that file; otherwise, the message is instead logged according to
977 * the `logLevel` option.
978 */
979 addToApiReportFile?: boolean;
980}
981
982/**
983 * Specifies a table of reporting rules for different message identifiers, and also the default rule used for
984 * identifiers that do not appear in the table.
985 *
986 * @remarks
987 * This is part of the {@link IConfigFile} structure.
988 *
989 * @public
990 */
991export declare interface IConfigMessageReportingTable {
992 /**
993 * The key is a message identifier for the associated type of message, or "default" to specify the default policy.
994 * For example, the key might be `TS2551` (a compiler message), `tsdoc-link-tag-unescaped-text` (a TSDOc message),
995 * or `ae-extra-release-tag` (a message related to the API Extractor analysis).
996 */
997 [messageId: string]: IConfigMessageReportingRule;
998}
999
1000/**
1001 * Configures how the tsdoc-metadata.json file will be generated.
1002 *
1003 * @remarks
1004 * This is part of the {@link IConfigFile} structure.
1005 *
1006 * @public
1007 */
1008export declare interface IConfigTsdocMetadata {
1009 /**
1010 * Whether to generate the tsdoc-metadata.json file.
1011 */
1012 enabled: boolean;
1013 /**
1014 * Specifies where the TSDoc metadata file should be written.
1015 *
1016 * @remarks
1017 * The path is resolved relative to the folder of the config file that contains the setting; to change this,
1018 * prepend a folder token such as `<projectFolder>`.
1019 *
1020 * The default value is `<lookup>`, which causes the path to be automatically inferred from the `tsdocMetadata`,
1021 * `typings` or `main` fields of the project's package.json. If none of these fields are set, the lookup
1022 * falls back to `tsdoc-metadata.json` in the package folder.
1023 */
1024 tsdocMetadataFilePath?: string;
1025}
1026
1027/**
1028 * Options for {@link ExtractorConfig.tryLoadForFolder}.
1029 *
1030 * @public
1031 */
1032export declare interface IExtractorConfigLoadForFolderOptions {
1033 /**
1034 * The folder path to start from when searching for api-extractor.json.
1035 */
1036 startingFolder: string;
1037 /**
1038 * An already constructed `PackageJsonLookup` cache object to use. If omitted, a temporary one will
1039 * be constructed.
1040 */
1041 packageJsonLookup?: PackageJsonLookup;
1042 /**
1043 * An already constructed `RigConfig` object. If omitted, then a new `RigConfig` object will be constructed.
1044 */
1045 rigConfig?: RigConfig;
1046}
1047
1048/**
1049 * Options for {@link ExtractorConfig.prepare}.
1050 *
1051 * @public
1052 */
1053export declare interface IExtractorConfigPrepareOptions {
1054 /**
1055 * A configuration object as returned by {@link ExtractorConfig.loadFile}.
1056 */
1057 configObject: IConfigFile;
1058 /**
1059 * The absolute path of the file that the `configObject` object was loaded from. This is used for error messages
1060 * and when probing for `tsconfig.json`.
1061 *
1062 * @remarks
1063 *
1064 * If `configObjectFullPath` and `projectFolderLookupToken` are both unspecified, then the api-extractor.json
1065 * config file must explicitly specify a `projectFolder` setting rather than relying on the `<lookup>` token.
1066 */
1067 configObjectFullPath: string | undefined;
1068 /**
1069 * The parsed package.json file for the working package, or undefined if API Extractor was invoked without
1070 * a package.json file.
1071 *
1072 * @remarks
1073 *
1074 * If omitted, then the `<unscopedPackageName>` and `<packageName>` tokens will have default values.
1075 */
1076 packageJson?: INodePackageJson | undefined;
1077 /**
1078 * The absolute path of the file that the `packageJson` object was loaded from, or undefined if API Extractor
1079 * was invoked without a package.json file.
1080 *
1081 * @remarks
1082 *
1083 * This is used for error messages and when resolving paths found in package.json.
1084 *
1085 * If `packageJsonFullPath` is specified but `packageJson` is omitted, the file will be loaded automatically.
1086 */
1087 packageJsonFullPath: string | undefined;
1088 /**
1089 * The default value for the `projectFolder` setting is the `<lookup>` token, which uses a heuristic to guess
1090 * an appropriate project folder. Use `projectFolderLookupValue` to manually specify the `<lookup>` token value
1091 * instead.
1092 *
1093 * @remarks
1094 * If the `projectFolder` setting is explicitly specified in api-extractor.json file, it should take precedence
1095 * over a value specified via the API. Thus the `projectFolderLookupToken` option provides a way to override
1096 * the default value for `projectFolder` setting while still honoring a manually specified value.
1097 */
1098 projectFolderLookupToken?: string;
1099 /**
1100 * Allow customization of the tsdoc.json config file. If omitted, this file will be loaded from its default
1101 * location. If the file does not exist, then the standard definitions will be used from
1102 * `@microsoft/api-extractor/extends/tsdoc-base.json`.
1103 */
1104 tsdocConfigFile?: TSDocConfigFile;
1105 /**
1106 * When preparing the configuration object, folder and file paths referenced in the configuration are checked
1107 * for existence, and an error is reported if they are not found. This option can be used to disable this
1108 * check for the main entry point module. This may be useful when preparing a configuration file for an
1109 * un-built project.
1110 */
1111 ignoreMissingEntryPoint?: boolean;
1112}
1113
1114/**
1115 * Runtime options for Extractor.
1116 *
1117 * @public
1118 */
1119export declare interface IExtractorInvokeOptions {
1120 /**
1121 * An optional TypeScript compiler state. This allows an optimization where multiple invocations of API Extractor
1122 * can reuse the same TypeScript compiler analysis.
1123 */
1124 compilerState?: CompilerState;
1125 /**
1126 * Indicates that API Extractor is running as part of a local build, e.g. on developer's
1127 * machine.
1128 *
1129 * @remarks
1130 * This disables certain validation that would normally be performed for a ship/production build. For example,
1131 * the *.api.md report file is automatically updated in a local build.
1132 *
1133 * The default value is false.
1134 */
1135 localBuild?: boolean;
1136 /**
1137 * If true, API Extractor will include {@link ExtractorLogLevel.Verbose} messages in its output.
1138 */
1139 showVerboseMessages?: boolean;
1140 /**
1141 * If true, API Extractor will print diagnostic information used for troubleshooting problems.
1142 * These messages will be included as {@link ExtractorLogLevel.Verbose} output.
1143 *
1144 * @remarks
1145 * Setting `showDiagnostics=true` forces `showVerboseMessages=true`.
1146 */
1147 showDiagnostics?: boolean;
1148 /**
1149 * Specifies an alternate folder path to be used when loading the TypeScript system typings.
1150 *
1151 * @remarks
1152 * API Extractor uses its own TypeScript compiler engine to analyze your project. If your project
1153 * is built with a significantly different TypeScript version, sometimes API Extractor may report compilation
1154 * errors due to differences in the system typings (e.g. lib.dom.d.ts). You can use the "--typescriptCompilerFolder"
1155 * option to specify the folder path where you installed the TypeScript package, and API Extractor's compiler will
1156 * use those system typings instead.
1157 */
1158 typescriptCompilerFolder?: string;
1159 /**
1160 * An optional callback function that will be called for each `ExtractorMessage` before it is displayed by
1161 * API Extractor. The callback can customize the message, handle it, or discard it.
1162 *
1163 * @remarks
1164 * If a `messageCallback` is not provided, then by default API Extractor will print the messages to
1165 * the STDERR/STDOUT console.
1166 */
1167 messageCallback?: (message: ExtractorMessage) => void;
1168}
1169
1170/**
1171 * Constructor options for `ExtractorMessage`.
1172 */
1173declare interface IExtractorMessageOptions {
1174 category: ExtractorMessageCategory;
1175 messageId: tsdoc.TSDocMessageId | ExtractorMessageId | ConsoleMessageId | string;
1176 text: string;
1177 sourceFilePath?: string;
1178 sourceFileLine?: number;
1179 sourceFileColumn?: number;
1180 properties?: IExtractorMessageProperties;
1181 logLevel?: ExtractorLogLevel;
1182}
1183
1184/**
1185 * Used by {@link ExtractorMessage.properties}.
1186 *
1187 * @public
1188 */
1189export declare interface IExtractorMessageProperties {
1190 /**
1191 * A declaration can have multiple names if it is exported more than once.
1192 * If an `ExtractorMessage` applies to a specific export name, this property can indicate that.
1193 *
1194 * @remarks
1195 *
1196 * Used by {@link ExtractorMessageId.InternalMissingUnderscore}.
1197 */
1198 readonly exportName?: string;
1199}
1200
1201/**
1202 * Configures how API Extractor reports error and warning messages produced during analysis.
1203 *
1204 * @remarks
1205 * This is part of the {@link IConfigFile} structure.
1206 *
1207 * @public
1208 */
1209export declare interface IExtractorMessagesConfig {
1210 /**
1211 * Configures handling of diagnostic messages generating the TypeScript compiler while analyzing the
1212 * input .d.ts files.
1213 */
1214 compilerMessageReporting?: IConfigMessageReportingTable;
1215 /**
1216 * Configures handling of messages reported by API Extractor during its analysis.
1217 */
1218 extractorMessageReporting?: IConfigMessageReportingTable;
1219 /**
1220 * Configures handling of messages reported by the TSDoc parser when analyzing code comments.
1221 */
1222 tsdocMessageReporting?: IConfigMessageReportingTable;
1223}
1224
1225export { }