UNPKG

8.32 kBTypeScriptView Raw
1import type * as ts from "typescript";
2import type { NeverIfInternal } from "..";
3import type { Application } from "../../..";
4import type { Logger } from "../loggers";
5import { type DeclarationOption, type KeyToDeclaration, type TypeDocOptionMap, type TypeDocOptions, type TypeDocOptionValues } from "./declaration";
6import type { TranslationProxy } from "../../internationalization/internationalization";
7/**
8 * Describes an option reader that discovers user configuration and converts it to the
9 * TypeDoc format.
10 */
11export interface OptionsReader {
12 /**
13 * Readers will be processed according to their orders.
14 * A higher order indicates that the reader should be called *later*.
15 *
16 * Note that to preserve expected behavior, the argv reader must have both the lowest
17 * order so that it may set the location of config files used by other readers and
18 * the highest order so that it can override settings from lower order readers.
19 */
20 readonly order: number;
21 /**
22 * The name of this reader so that it may be removed by plugins without the plugin
23 * accessing the instance performing the read. Multiple readers may have the same
24 * name.
25 */
26 readonly name: string;
27 /**
28 * Flag to indicate that this reader should be included in sub-options objects created
29 * to read options for packages mode.
30 */
31 readonly supportsPackages: boolean;
32 /**
33 * Read options from the reader's source and place them in the options parameter.
34 * Options without a declared name may be treated as if they were declared with type
35 * {@link ParameterType.Mixed}. Options which have been declared must be converted to the
36 * correct type. As an alternative to doing this conversion in the reader,
37 * the reader may use {@link Options.setValue}, which will correctly convert values.
38 * @param container the options container that provides declarations
39 * @param logger logger to be used to report errors
40 * @param cwd the directory which should be treated as the current working directory for option file discovery
41 */
42 read(container: Options, logger: Logger, cwd: string): void | Promise<void>;
43}
44/**
45 * Maintains a collection of option declarations split into TypeDoc options
46 * and TypeScript options. Ensures options are of the correct type for calling
47 * code.
48 *
49 * ### Option Discovery
50 *
51 * Since plugins commonly add custom options, and TypeDoc does not permit options which have
52 * not been declared to be set, options must be read twice. The first time options are read,
53 * a noop logger is passed so that any errors are ignored. Then, after loading plugins, options
54 * are read again, this time with the logger specified by the application.
55 *
56 * Options are read in a specific order.
57 * 1. argv (0) - Must be read first since it should change the files read when
58 * passing --options or --tsconfig.
59 * 2. typedoc-json (100) - Read next so that it can specify the tsconfig.json file to read.
60 * 3. tsconfig-json (200) - Last config file reader, cannot specify the typedoc.json file to read.
61 * 4. argv (300) - Read argv again since any options set there should override those set in config
62 * files.
63 */
64export declare class Options {
65 private _readers;
66 private _declarations;
67 private _values;
68 private _setOptions;
69 private _compilerOptions;
70 private _fileNames;
71 private _projectReferences;
72 private _i18n;
73 /**
74 * In packages mode, the directory of the package being converted.
75 */
76 packageDir?: string;
77 constructor(i18n: TranslationProxy);
78 /**
79 * Clones the options, intended for use in packages mode.
80 */
81 copyForPackage(packageDir: string): Options;
82 /**
83 * Marks the options as readonly, enables caching when fetching options, which improves performance.
84 */
85 freeze(): void;
86 /**
87 * Checks if the options object has been frozen, preventing future changes to option values.
88 */
89 isFrozen(): boolean;
90 /**
91 * Take a snapshot of option values now, used in tests only.
92 * @internal
93 */
94 snapshot(): {
95 __optionSnapshot: never;
96 };
97 /**
98 * Take a snapshot of option values now, used in tests only.
99 * @internal
100 */
101 restore(snapshot: {
102 __optionSnapshot: never;
103 }): void;
104 /**
105 * Resets the option bag to all default values.
106 * If a name is provided, will only reset that name.
107 */
108 reset(name?: keyof TypeDocOptions): void;
109 reset(name?: NeverIfInternal<string>): void;
110 /**
111 * Adds an option reader that will be used to read configuration values
112 * from the command line, configuration files, or other locations.
113 * @param reader
114 */
115 addReader(reader: OptionsReader): void;
116 read(logger: Logger, cwd?: string): Promise<void>;
117 /**
118 * Adds an option declaration to the container with extra type checking to ensure that
119 * the runtime type is consistent with the declared type.
120 * @param declaration The option declaration that should be added.
121 */
122 addDeclaration<K extends keyof TypeDocOptions>(declaration: {
123 name: K;
124 } & KeyToDeclaration<K>): void;
125 /**
126 * Adds an option declaration to the container.
127 * @param declaration The option declaration that should be added.
128 */
129 addDeclaration(declaration: NeverIfInternal<Readonly<DeclarationOption>>): void;
130 /**
131 * Gets a declaration by one of its names.
132 * @param name
133 */
134 getDeclaration(name: string): Readonly<DeclarationOption> | undefined;
135 /**
136 * Gets all declared options.
137 */
138 getDeclarations(): Readonly<DeclarationOption>[];
139 /**
140 * Checks if the given option's value is deeply strict equal to the default.
141 * @param name
142 */
143 isSet(name: keyof TypeDocOptions): boolean;
144 isSet(name: NeverIfInternal<string>): boolean;
145 /**
146 * Gets all of the TypeDoc option values defined in this option container.
147 */
148 getRawValues(): Readonly<Partial<TypeDocOptions>>;
149 /**
150 * Gets a value for the given option key, throwing if the option has not been declared.
151 * @param name
152 */
153 getValue<K extends keyof TypeDocOptions>(name: K): TypeDocOptionValues[K];
154 getValue(name: NeverIfInternal<string>): unknown;
155 /**
156 * Sets the given declared option. Throws if setting the option fails.
157 * @param name
158 * @param value
159 * @param configPath the directory to resolve Path type values against
160 */
161 setValue<K extends keyof TypeDocOptions>(name: K, value: TypeDocOptions[K], configPath?: string): void;
162 setValue(name: NeverIfInternal<string>, value: NeverIfInternal<unknown>, configPath?: NeverIfInternal<string>): void;
163 /**
164 * Gets the set compiler options.
165 */
166 getCompilerOptions(): ts.CompilerOptions;
167 /** @internal */
168 fixCompilerOptions(options: Readonly<ts.CompilerOptions>): ts.CompilerOptions;
169 /**
170 * Gets the file names discovered through reading a tsconfig file.
171 */
172 getFileNames(): readonly string[];
173 /**
174 * Gets the project references - used in solution style tsconfig setups.
175 */
176 getProjectReferences(): readonly ts.ProjectReference[];
177 /**
178 * Sets the compiler options that will be used to get a TS program.
179 */
180 setCompilerOptions(fileNames: readonly string[], options: ts.CompilerOptions, projectReferences: readonly ts.ProjectReference[] | undefined): void;
181 /**
182 * Discover similar option names to the given name, for use in error reporting.
183 */
184 getSimilarOptions(missingName: string): string[];
185 /**
186 * Get the help message to be displayed to the user if `--help` is passed.
187 */
188 getHelp(i18n: TranslationProxy): string;
189}
190/**
191 * Binds an option to an accessor. Does not register the option.
192 *
193 * Note: This is a standard ES decorator. It will not work with pre-TS 5.0 experimental decorators enabled.
194 */
195export declare function Option<K extends keyof TypeDocOptionMap>(name: K): (_: unknown, _context: ClassAccessorDecoratorContext<{
196 application: Application;
197} | {
198 options: Options;
199}, TypeDocOptionValues[K]>) => {
200 get(this: {
201 application: Application;
202 } | {
203 options: Options;
204 }): TypeDocOptionValues[K];
205 set(_value: never): never;
206};