UNPKG

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