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