UNPKG

8.15 kBTypeScriptView Raw
1import type ts from "typescript";
2import type { NeverIfInternal } from "../index.js";
3import type { Application } from "../../../index.js";
4import type { Logger } from "../loggers.js";
5import { type DeclarationOption, type KeyToDeclaration, type TypeDocOptionMap, type TypeDocOptions, type TypeDocOptionValues } from "./declaration.js";
6import type { TranslationProxy } from "../../internationalization/internationalization.js";
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 *
64 * @group Common
65 * @summary Contains all of TypeDoc's option declarations & values
66 */
67export declare class Options {
68 private _readers;
69 private _declarations;
70 private _values;
71 private _setOptions;
72 private _compilerOptions;
73 private _fileNames;
74 private _projectReferences;
75 private _i18n;
76 /**
77 * In packages mode, the directory of the package being converted.
78 */
79 packageDir?: string;
80 constructor(i18n: TranslationProxy);
81 /**
82 * Clones the options, intended for use in packages mode.
83 */
84 copyForPackage(packageDir: string): Options;
85 /**
86 * Take a snapshot of option values now, used in tests only.
87 * @internal
88 */
89 snapshot(): {
90 __optionSnapshot: never;
91 };
92 /**
93 * Take a snapshot of option values now, used in tests only.
94 * @internal
95 */
96 restore(snapshot: {
97 __optionSnapshot: never;
98 }): void;
99 /**
100 * Resets the option bag to all default values.
101 * If a name is provided, will only reset that name.
102 */
103 reset(name?: keyof TypeDocOptions): void;
104 reset(name?: NeverIfInternal<string>): void;
105 /**
106 * Adds an option reader that will be used to read configuration values
107 * from the command line, configuration files, or other locations.
108 * @param reader
109 */
110 addReader(reader: OptionsReader): void;
111 read(logger: Logger, cwd?: string): Promise<void>;
112 /**
113 * Adds an option declaration to the container with extra type checking to ensure that
114 * the runtime type is consistent with the declared type.
115 * @param declaration The option declaration that should be added.
116 */
117 addDeclaration<K extends keyof TypeDocOptions>(declaration: {
118 name: K;
119 } & KeyToDeclaration<K>): void;
120 /**
121 * Adds an option declaration to the container.
122 * @param declaration The option declaration that should be added.
123 */
124 addDeclaration(declaration: NeverIfInternal<Readonly<DeclarationOption>>): void;
125 /**
126 * Gets a declaration by one of its names.
127 * @param name
128 */
129 getDeclaration(name: string): Readonly<DeclarationOption> | undefined;
130 /**
131 * Gets all declared options.
132 */
133 getDeclarations(): Readonly<DeclarationOption>[];
134 /**
135 * Checks if the given option's value is deeply strict equal to the default.
136 * @param name
137 */
138 isSet(name: keyof TypeDocOptions): boolean;
139 isSet(name: NeverIfInternal<string>): boolean;
140 /**
141 * Gets all of the TypeDoc option values defined in this option container.
142 */
143 getRawValues(): Readonly<Partial<TypeDocOptions>>;
144 /**
145 * Gets a value for the given option key, throwing if the option has not been declared.
146 * @param name
147 */
148 getValue<K extends keyof TypeDocOptions>(name: K): TypeDocOptionValues[K];
149 getValue(name: NeverIfInternal<string>): unknown;
150 /**
151 * Sets the given declared option. Throws if setting the option fails.
152 * @param name
153 * @param value
154 * @param configPath the directory to resolve Path type values against
155 */
156 setValue<K extends keyof TypeDocOptions>(name: K, value: TypeDocOptions[K], configPath?: string): void;
157 setValue(name: NeverIfInternal<string>, value: NeverIfInternal<unknown>, configPath?: NeverIfInternal<string>): void;
158 /**
159 * Gets the set compiler options.
160 */
161 getCompilerOptions(): ts.CompilerOptions;
162 /** @internal */
163 fixCompilerOptions(options: Readonly<ts.CompilerOptions>): ts.CompilerOptions;
164 /**
165 * Gets the file names discovered through reading a tsconfig file.
166 */
167 getFileNames(): readonly string[];
168 /**
169 * Gets the project references - used in solution style tsconfig setups.
170 */
171 getProjectReferences(): readonly ts.ProjectReference[];
172 /**
173 * Sets the compiler options that will be used to get a TS program.
174 */
175 setCompilerOptions(fileNames: readonly string[], options: ts.CompilerOptions, projectReferences: readonly ts.ProjectReference[] | undefined): void;
176 /**
177 * Discover similar option names to the given name, for use in error reporting.
178 */
179 getSimilarOptions(missingName: string): string[];
180 /**
181 * Get the help message to be displayed to the user if `--help` is passed.
182 */
183 getHelp(i18n: TranslationProxy): string;
184}
185/**
186 * Binds an option to an accessor. Does not register the option.
187 *
188 * Note: This is a standard ES decorator. It will not work with pre-TS 5.0 experimental decorators enabled.
189 */
190export declare function Option<K extends keyof TypeDocOptionMap>(name: K): (_: unknown, _context: ClassAccessorDecoratorContext<{
191 application: Application;
192} | {
193 options: Options;
194}, TypeDocOptionValues[K]>) => {
195 get(this: {
196 application: Application;
197 } | {
198 options: Options;
199 }): TypeDocOptionValues[K];
200 set(_value: never): never;
201};