-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
index.d.ts
436 lines (382 loc) · 11.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {RuleSetRule, Configuration} from 'webpack';
import type {Command} from 'commander';
import type {ParsedUrlQueryInput} from 'querystring';
import type Joi from 'joi';
import type {Overwrite, DeepPartial} from 'utility-types';
// Convert webpack-merge webpack-merge enum to union type
// For type retro-compatible webpack-merge upgrade: we used string literals before)
// see https://github.com/survivejs/webpack-merge/issues/179
type MergeStrategy = 'match' | 'merge' | 'append' | 'prepend' | 'replace';
export type ReportingSeverity = 'ignore' | 'log' | 'warn' | 'error' | 'throw';
export type ThemeConfig = {
[key: string]: unknown;
};
// Docusaurus config, after validation/normalization
export interface DocusaurusConfig {
baseUrl: string;
baseUrlIssueBanner: boolean;
favicon?: string;
tagline?: string;
title: string;
url: string;
// trailingSlash undefined = legacy retrocompatible behavior => /file => /file/index.html
trailingSlash: boolean | undefined;
i18n: I18nConfig;
onBrokenLinks: ReportingSeverity;
onBrokenMarkdownLinks: ReportingSeverity;
onDuplicateRoutes: ReportingSeverity;
noIndex: boolean;
organizationName?: string;
projectName?: string;
deploymentBranch?: string;
githubHost?: string;
githubPort?: string;
plugins?: PluginConfig[];
themes?: PluginConfig[];
presets?: PresetConfig[];
themeConfig: ThemeConfig;
customFields?: {
[key: string]: unknown;
};
scripts?: (
| string
| {
src: string;
[key: string]: unknown;
}
)[];
clientModules?: string[];
ssrTemplate?: string;
staticDirectories: string[];
stylesheets?: (
| string
| {
href: string;
[key: string]: unknown;
}
)[];
titleDelimiter?: string;
webpack?: {
jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule);
};
}
// Docusaurus config, as provided by the user (partial/unnormalized)
// This type is used to provide type-safety / IDE auto-complete on the config file
// See https://docusaurus.io/docs/typescript-support
export type Config = Overwrite<
Partial<DocusaurusConfig>,
{
title: Required<DocusaurusConfig['title']>;
url: Required<DocusaurusConfig['url']>;
baseUrl: Required<DocusaurusConfig['baseUrl']>;
i18n?: DeepPartial<DocusaurusConfig['i18n']>;
}
>;
/**
* - `type: 'package'`, plugin is in a different package.
* - `type: 'project'`, plugin is in the same docusaurus project.
* - `type: 'local'`, none of plugin's ancestor directory contains any package.json.
* - `type: 'synthetic'`, docusaurus generated internal plugin.
*/
export type DocusaurusPluginVersionInformation =
| {
readonly type: 'package';
readonly name?: string;
readonly version?: string;
}
| {readonly type: 'project'}
| {readonly type: 'local'}
| {readonly type: 'synthetic'};
export interface DocusaurusSiteMetadata {
readonly docusaurusVersion: string;
readonly siteVersion?: string;
readonly pluginVersions: Record<string, DocusaurusPluginVersionInformation>;
}
// Inspired by Chrome JSON, because it's a widely supported i18n format
// https://developer.chrome.com/apps/i18n-messages
// https://support.crowdin.com/file-formats/chrome-json/
// https://www.applanga.com/docs/formats/chrome_i18n_json
// https://docs.transifex.com/formats/chrome-json
// https://help.phrase.com/help/chrome-json-messages
export type TranslationMessage = {message: string; description?: string};
export type TranslationFileContent = Record<string, TranslationMessage>;
export type TranslationFile = {path: string; content: TranslationFileContent};
export type TranslationFiles = TranslationFile[];
export type I18nLocaleConfig = {
label: string;
direction: string;
};
export type I18nConfig = {
defaultLocale: string;
locales: [string, ...string[]];
localeConfigs: Record<string, Partial<I18nLocaleConfig>>;
};
export type I18n = {
defaultLocale: string;
locales: [string, ...string[]];
currentLocale: string;
localeConfigs: Record<string, I18nLocaleConfig>;
};
export interface DocusaurusContext {
siteConfig: DocusaurusConfig;
siteMetadata: DocusaurusSiteMetadata;
globalData: Record<string, unknown>;
i18n: I18n;
codeTranslations: Record<string, string>;
// Don't put mutable values here, to avoid triggering re-renders
// We could reconsider that choice if context selectors are implemented
// isBrowser: boolean; // Not here on purpose!
}
export interface Preset {
plugins?: PluginConfig[];
themes?: PluginConfig[];
}
export type PresetConfig =
| [string, Record<string, unknown>]
| [string]
| string;
export type HostPortCLIOptions = {
host?: string;
port?: string;
};
export type ConfigOptions = {
config: string;
};
export type StartCLIOptions = HostPortCLIOptions &
ConfigOptions & {
hotOnly: boolean;
open: boolean;
poll: boolean | number;
locale?: string;
};
export type ServeCLIOptions = HostPortCLIOptions &
ConfigOptions & {
dir: string;
build: boolean;
};
export type BuildOptions = ConfigOptions & {
bundleAnalyzer: boolean;
outDir: string;
minify: boolean;
skipBuild: boolean;
};
export type BuildCLIOptions = BuildOptions & {
locale?: string;
};
export interface LoadContext {
siteDir: string;
generatedFilesDir: string;
siteConfig: DocusaurusConfig;
siteConfigPath: string;
outDir: string;
baseUrl: string; // TODO to remove: useless, there's already siteConfig.baseUrl!
i18n: I18n;
ssrTemplate?: string;
codeTranslations: Record<string, string>;
}
export interface InjectedHtmlTags {
headTags: string;
preBodyTags: string;
postBodyTags: string;
}
export type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[];
export interface Props extends LoadContext, InjectedHtmlTags {
readonly siteMetadata: DocusaurusSiteMetadata;
readonly routes: RouteConfig[];
readonly routesPaths: string[];
readonly plugins: LoadedPlugin[];
}
export interface PluginContentLoadedActions {
addRoute(config: RouteConfig): void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
createData(name: string, data: any): Promise<string>;
setGlobalData<T = unknown>(data: T): void;
}
export type AllContent = Record<
string, // plugin name
Record<
string, // plugin id
unknown // plugin data
>
>;
// TODO improve type (not exposed by postcss-loader)
export type PostCssOptions = Record<string, unknown> & {plugins: unknown[]};
export interface Plugin<Content = unknown> {
name: string;
loadContent?(): Promise<Content>;
contentLoaded?({
content,
actions,
}: {
content: Content; // the content loaded by this plugin instance
allContent: AllContent; // content loaded by ALL the plugins
actions: PluginContentLoadedActions;
}): Promise<void>;
routesLoaded?(routes: RouteConfig[]): void; // TODO remove soon, deprecated (alpha-60)
postBuild?(props: Props): void;
postStart?(props: Props): void;
// TODO refactor the configureWebpack API surface: use an object instead of multiple params (requires breaking change)
configureWebpack?(
config: Configuration,
isServer: boolean,
utils: ConfigureWebpackUtils,
content: Content,
): Configuration & {mergeStrategy?: ConfigureWebpackFnMergeStrategy};
configurePostCss?(options: PostCssOptions): PostCssOptions;
getThemePath?(): string;
getTypeScriptThemePath?(): string;
getPathsToWatch?(): string[];
getClientModules?(): string[];
extendCli?(cli: Command): void;
injectHtmlTags?({content}: {content: Content}): {
headTags?: HtmlTags;
preBodyTags?: HtmlTags;
postBodyTags?: HtmlTags;
};
// TODO before/afterDevServer implementation
// translations
getTranslationFiles?({
content,
}: {
content: Content;
}): Promise<TranslationFiles>;
getDefaultCodeTranslationMessages?(): Promise<
Record<
string, // id
string // message
>
>;
translateContent?({
content,
translationFiles,
}: {
content: Content; // the content loaded by this plugin instance
translationFiles: TranslationFiles;
}): Content;
translateThemeConfig?({
themeConfig,
translationFiles,
}: {
themeConfig: ThemeConfig;
translationFiles: TranslationFiles;
}): ThemeConfig;
}
export type InitializedPlugin<Content = unknown> = Plugin<Content> & {
readonly options: PluginOptions;
readonly version: DocusaurusPluginVersionInformation;
};
export type LoadedPlugin<Content = unknown> = InitializedPlugin<Content> & {
readonly content: Content;
};
export type PluginModule = {
<T, X>(context: LoadContext, options: T): Plugin<X>;
validateOptions?<T>(data: OptionValidationContext<T>): T;
validateThemeConfig?<T>(data: ThemeConfigValidationContext<T>): T;
getSwizzleComponentList?(): string[];
};
export type ImportedPluginModule = PluginModule & {
default?: PluginModule;
};
export type ConfigureWebpackFn = Plugin<unknown>['configureWebpack'];
export type ConfigureWebpackFnMergeStrategy = Record<string, MergeStrategy>;
export type ConfigurePostCssFn = Plugin<unknown>['configurePostCss'];
export type PluginOptions = {id?: string} & Record<string, unknown>;
export type PluginConfig =
| [string, PluginOptions]
| [string]
| string
| [PluginModule, PluginOptions]
| PluginModule;
export interface ChunkRegistry {
loader: string;
modulePath: string;
}
export type Module =
| {
path: string;
__import?: boolean;
query?: ParsedUrlQueryInput;
}
| string;
export interface RouteModule {
[module: string]: Module | RouteModule | RouteModule[];
}
export interface ChunkNames {
[name: string]: string | null | ChunkNames | ChunkNames[];
}
export interface RouteConfig {
path: string;
component: string;
modules?: RouteModule;
routes?: RouteConfig[];
exact?: boolean;
priority?: number;
[propName: string]: unknown;
}
// Aliases used for Webpack resolution (when using docusaurus swizzle)
export interface ThemeAliases {
[alias: string]: string;
}
export interface ConfigureWebpackUtils {
getStyleLoaders: (
isServer: boolean,
cssOptions: {
[key: string]: unknown;
},
) => RuleSetRule[];
getJSLoader: (options: {
isServer: boolean;
babelOptions?: Record<string, unknown>;
}) => RuleSetRule;
// TODO deprecated: remove before end of 2021?
getCacheLoader: (
isServer: boolean,
cacheOptions?: Record<string, unknown>,
) => RuleSetRule | null;
// TODO deprecated: remove before end of 2021?
getBabelLoader: (
isServer: boolean,
options?: Record<string, unknown>,
) => RuleSetRule;
}
interface HtmlTagObject {
/**
* Attributes of the html tag
* E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
*/
attributes?: Partial<Record<string, string | boolean>>;
/**
* The tag name e.g. `div`, `script`, `link`, `meta`
*/
tagName: string;
/**
* The inner HTML
*/
innerHTML?: string;
}
export type ValidationResult<T> = T;
export type ValidationSchema<T> = Joi.ObjectSchema<T>;
export type Validate<T> = (
validationSchema: ValidationSchema<T>,
options: Partial<T>,
) => ValidationResult<T>;
export interface OptionValidationContext<T> {
validate: Validate<T>;
options: Partial<T>;
}
export interface ThemeConfigValidationContext<T> {
validate: Validate<T>;
themeConfig: Partial<T>;
}
export interface TOCItem {
readonly value: string;
readonly id: string;
readonly children: TOCItem[];
readonly level: number;
}