@docusaurus/types 2.0.0-beta.1 → 2.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -6
- package/src/index.d.ts +82 -42
- package/tsconfig.json +7 -0
- package/src/index.js +0 -10
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/types",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.12",
|
|
4
4
|
"description": "Common types for Docusaurus packages.",
|
|
5
|
-
"main": "./src/index.js",
|
|
6
5
|
"types": "./src/index.d.ts",
|
|
7
6
|
"publishConfig": {
|
|
8
7
|
"access": "public"
|
|
@@ -13,12 +12,16 @@
|
|
|
13
12
|
"directory": "packages/docusaurus-types"
|
|
14
13
|
},
|
|
15
14
|
"license": "MIT",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "tsc -p ."
|
|
17
|
+
},
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"commander": "^5.1.0",
|
|
18
|
-
"joi": "^17.4.
|
|
20
|
+
"joi": "^17.4.2",
|
|
19
21
|
"querystring": "0.2.0",
|
|
20
|
-
"
|
|
21
|
-
"webpack
|
|
22
|
+
"utility-types": "^3.10.0",
|
|
23
|
+
"webpack": "^5.61.0",
|
|
24
|
+
"webpack-merge": "^5.8.0"
|
|
22
25
|
},
|
|
23
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "891fd1f397c1f0aaf840906bd7f4e537d1e8816e"
|
|
24
27
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// ESLint doesn't understand types dependencies in d.ts
|
|
9
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
10
8
|
import type {RuleSetRule, Configuration} from 'webpack';
|
|
11
9
|
import type {Command} from 'commander';
|
|
12
10
|
import type {ParsedUrlQueryInput} from 'querystring';
|
|
13
11
|
import type Joi from 'joi';
|
|
12
|
+
import type {Overwrite, DeepPartial} from 'utility-types';
|
|
14
13
|
|
|
15
14
|
// Convert webpack-merge webpack-merge enum to union type
|
|
16
15
|
// For type retro-compatible webpack-merge upgrade: we used string literals before)
|
|
@@ -23,10 +22,11 @@ export type ThemeConfig = {
|
|
|
23
22
|
[key: string]: unknown;
|
|
24
23
|
};
|
|
25
24
|
|
|
25
|
+
// Docusaurus config, after validation/normalization
|
|
26
26
|
export interface DocusaurusConfig {
|
|
27
27
|
baseUrl: string;
|
|
28
28
|
baseUrlIssueBanner: boolean;
|
|
29
|
-
favicon
|
|
29
|
+
favicon?: string;
|
|
30
30
|
tagline?: string;
|
|
31
31
|
title: string;
|
|
32
32
|
url: string;
|
|
@@ -39,6 +39,7 @@ export interface DocusaurusConfig {
|
|
|
39
39
|
noIndex: boolean;
|
|
40
40
|
organizationName?: string;
|
|
41
41
|
projectName?: string;
|
|
42
|
+
deploymentBranch?: string;
|
|
42
43
|
githubHost?: string;
|
|
43
44
|
githubPort?: string;
|
|
44
45
|
plugins?: PluginConfig[];
|
|
@@ -57,6 +58,7 @@ export interface DocusaurusConfig {
|
|
|
57
58
|
)[];
|
|
58
59
|
clientModules?: string[];
|
|
59
60
|
ssrTemplate?: string;
|
|
61
|
+
staticDirectories: string[];
|
|
60
62
|
stylesheets?: (
|
|
61
63
|
| string
|
|
62
64
|
| {
|
|
@@ -70,6 +72,19 @@ export interface DocusaurusConfig {
|
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
// Docusaurus config, as provided by the user (partial/unnormalized)
|
|
76
|
+
// This type is used to provide type-safety / IDE auto-complete on the config file
|
|
77
|
+
// See https://docusaurus.io/docs/typescript-support
|
|
78
|
+
export type Config = Overwrite<
|
|
79
|
+
Partial<DocusaurusConfig>,
|
|
80
|
+
{
|
|
81
|
+
title: Required<DocusaurusConfig['title']>;
|
|
82
|
+
url: Required<DocusaurusConfig['url']>;
|
|
83
|
+
baseUrl: Required<DocusaurusConfig['baseUrl']>;
|
|
84
|
+
i18n?: DeepPartial<DocusaurusConfig['i18n']>;
|
|
85
|
+
}
|
|
86
|
+
>;
|
|
87
|
+
|
|
73
88
|
/**
|
|
74
89
|
* - `type: 'package'`, plugin is in a different package.
|
|
75
90
|
* - `type: 'project'`, plugin is in the same docusaurus project.
|
|
@@ -127,7 +142,10 @@ export interface DocusaurusContext {
|
|
|
127
142
|
globalData: Record<string, unknown>;
|
|
128
143
|
i18n: I18n;
|
|
129
144
|
codeTranslations: Record<string, string>;
|
|
130
|
-
|
|
145
|
+
|
|
146
|
+
// Don't put mutable values here, to avoid triggering re-renders
|
|
147
|
+
// We could reconsider that choice if context selectors are implemented
|
|
148
|
+
// isBrowser: boolean; // Not here on purpose!
|
|
131
149
|
}
|
|
132
150
|
|
|
133
151
|
export interface Preset {
|
|
@@ -135,6 +153,14 @@ export interface Preset {
|
|
|
135
153
|
themes?: PluginConfig[];
|
|
136
154
|
}
|
|
137
155
|
|
|
156
|
+
export type PresetModule = {
|
|
157
|
+
<T>(context: LoadContext, presetOptions: T): Preset;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type ImportedPresetModule = PresetModule & {
|
|
161
|
+
default?: PresetModule;
|
|
162
|
+
};
|
|
163
|
+
|
|
138
164
|
export type PresetConfig =
|
|
139
165
|
| [string, Record<string, unknown>]
|
|
140
166
|
| [string]
|
|
@@ -180,7 +206,7 @@ export interface LoadContext {
|
|
|
180
206
|
siteConfig: DocusaurusConfig;
|
|
181
207
|
siteConfigPath: string;
|
|
182
208
|
outDir: string;
|
|
183
|
-
baseUrl: string;
|
|
209
|
+
baseUrl: string; // TODO to remove: useless, there's already siteConfig.baseUrl!
|
|
184
210
|
i18n: I18n;
|
|
185
211
|
ssrTemplate?: string;
|
|
186
212
|
codeTranslations: Record<string, string>;
|
|
@@ -195,17 +221,17 @@ export interface InjectedHtmlTags {
|
|
|
195
221
|
export type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[];
|
|
196
222
|
|
|
197
223
|
export interface Props extends LoadContext, InjectedHtmlTags {
|
|
198
|
-
siteMetadata: DocusaurusSiteMetadata;
|
|
199
|
-
routes: RouteConfig[];
|
|
200
|
-
routesPaths: string[];
|
|
201
|
-
plugins:
|
|
224
|
+
readonly siteMetadata: DocusaurusSiteMetadata;
|
|
225
|
+
readonly routes: RouteConfig[];
|
|
226
|
+
readonly routesPaths: string[];
|
|
227
|
+
readonly plugins: LoadedPlugin[];
|
|
202
228
|
}
|
|
203
229
|
|
|
204
230
|
export interface PluginContentLoadedActions {
|
|
205
|
-
addRoute(config: RouteConfig)
|
|
231
|
+
addRoute: (config: RouteConfig) => void;
|
|
206
232
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
207
|
-
createData(name: string, data: any)
|
|
208
|
-
setGlobalData<T = unknown>(data: T)
|
|
233
|
+
createData: (name: string, data: any) => Promise<string>;
|
|
234
|
+
setGlobalData: <T = unknown>(data: T) => void;
|
|
209
235
|
}
|
|
210
236
|
|
|
211
237
|
export type AllContent = Record<
|
|
@@ -219,32 +245,34 @@ export type AllContent = Record<
|
|
|
219
245
|
// TODO improve type (not exposed by postcss-loader)
|
|
220
246
|
export type PostCssOptions = Record<string, unknown> & {plugins: unknown[]};
|
|
221
247
|
|
|
222
|
-
export interface Plugin<Content> {
|
|
248
|
+
export interface Plugin<Content = unknown> {
|
|
223
249
|
name: string;
|
|
224
|
-
loadContent
|
|
225
|
-
contentLoaded
|
|
250
|
+
loadContent?: () => Promise<Content>;
|
|
251
|
+
contentLoaded?: ({
|
|
226
252
|
content,
|
|
227
253
|
actions,
|
|
228
254
|
}: {
|
|
229
255
|
content: Content; // the content loaded by this plugin instance
|
|
230
256
|
allContent: AllContent; // content loaded by ALL the plugins
|
|
231
257
|
actions: PluginContentLoadedActions;
|
|
232
|
-
})
|
|
233
|
-
routesLoaded
|
|
234
|
-
postBuild
|
|
235
|
-
postStart
|
|
236
|
-
configureWebpack
|
|
258
|
+
}) => Promise<void>;
|
|
259
|
+
routesLoaded?: (routes: RouteConfig[]) => void; // TODO remove soon, deprecated (alpha-60)
|
|
260
|
+
postBuild?: (props: Props) => void;
|
|
261
|
+
postStart?: (props: Props) => void;
|
|
262
|
+
// TODO refactor the configureWebpack API surface: use an object instead of multiple params (requires breaking change)
|
|
263
|
+
configureWebpack?: (
|
|
237
264
|
config: Configuration,
|
|
238
265
|
isServer: boolean,
|
|
239
266
|
utils: ConfigureWebpackUtils,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
267
|
+
content: Content,
|
|
268
|
+
) => Configuration & {mergeStrategy?: ConfigureWebpackFnMergeStrategy};
|
|
269
|
+
configurePostCss?: (options: PostCssOptions) => PostCssOptions;
|
|
270
|
+
getThemePath?: () => string;
|
|
271
|
+
getTypeScriptThemePath?: () => string;
|
|
272
|
+
getPathsToWatch?: () => string[];
|
|
273
|
+
getClientModules?: () => string[];
|
|
274
|
+
extendCli?: (cli: Command) => void;
|
|
275
|
+
injectHtmlTags?: ({content}: {content: Content}) => {
|
|
248
276
|
headTags?: HtmlTags;
|
|
249
277
|
preBodyTags?: HtmlTags;
|
|
250
278
|
postBodyTags?: HtmlTags;
|
|
@@ -252,38 +280,47 @@ export interface Plugin<Content> {
|
|
|
252
280
|
// TODO before/afterDevServer implementation
|
|
253
281
|
|
|
254
282
|
// translations
|
|
255
|
-
getTranslationFiles
|
|
283
|
+
getTranslationFiles?: ({
|
|
256
284
|
content,
|
|
257
285
|
}: {
|
|
258
286
|
content: Content;
|
|
259
|
-
})
|
|
260
|
-
getDefaultCodeTranslationMessages
|
|
287
|
+
}) => Promise<TranslationFiles>;
|
|
288
|
+
getDefaultCodeTranslationMessages?: () => Promise<
|
|
261
289
|
Record<
|
|
262
290
|
string, // id
|
|
263
291
|
string // message
|
|
264
292
|
>
|
|
265
293
|
>;
|
|
266
|
-
translateContent
|
|
294
|
+
translateContent?: ({
|
|
267
295
|
content,
|
|
268
296
|
translationFiles,
|
|
269
297
|
}: {
|
|
270
298
|
content: Content; // the content loaded by this plugin instance
|
|
271
299
|
translationFiles: TranslationFiles;
|
|
272
|
-
})
|
|
273
|
-
translateThemeConfig
|
|
300
|
+
}) => Content;
|
|
301
|
+
translateThemeConfig?: ({
|
|
274
302
|
themeConfig,
|
|
275
303
|
translationFiles,
|
|
276
304
|
}: {
|
|
277
305
|
themeConfig: ThemeConfig;
|
|
278
306
|
translationFiles: TranslationFiles;
|
|
279
|
-
})
|
|
307
|
+
}) => ThemeConfig;
|
|
280
308
|
}
|
|
281
309
|
|
|
310
|
+
export type InitializedPlugin<Content = unknown> = Plugin<Content> & {
|
|
311
|
+
readonly options: PluginOptions;
|
|
312
|
+
readonly version: DocusaurusPluginVersionInformation;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export type LoadedPlugin<Content = unknown> = InitializedPlugin<Content> & {
|
|
316
|
+
readonly content: Content;
|
|
317
|
+
};
|
|
318
|
+
|
|
282
319
|
export type PluginModule = {
|
|
283
320
|
<T, X>(context: LoadContext, options: T): Plugin<X>;
|
|
284
|
-
validateOptions
|
|
285
|
-
validateThemeConfig
|
|
286
|
-
getSwizzleComponentList
|
|
321
|
+
validateOptions?: <T>(data: OptionValidationContext<T>) => T;
|
|
322
|
+
validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;
|
|
323
|
+
getSwizzleComponentList?: () => string[];
|
|
287
324
|
};
|
|
288
325
|
|
|
289
326
|
export type ImportedPluginModule = PluginModule & {
|
|
@@ -331,9 +368,11 @@ export interface RouteConfig {
|
|
|
331
368
|
routes?: RouteConfig[];
|
|
332
369
|
exact?: boolean;
|
|
333
370
|
priority?: number;
|
|
371
|
+
[propName: string]: unknown;
|
|
334
372
|
}
|
|
335
373
|
|
|
336
|
-
|
|
374
|
+
// Aliases used for Webpack resolution (when using docusaurus swizzle)
|
|
375
|
+
export interface ThemeAliases {
|
|
337
376
|
[alias: string]: string;
|
|
338
377
|
}
|
|
339
378
|
|
|
@@ -367,9 +406,7 @@ interface HtmlTagObject {
|
|
|
367
406
|
* Attributes of the html tag
|
|
368
407
|
* E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
|
|
369
408
|
*/
|
|
370
|
-
attributes?:
|
|
371
|
-
[attributeName: string]: string | boolean;
|
|
372
|
-
};
|
|
409
|
+
attributes?: Partial<Record<string, string | boolean>>;
|
|
373
410
|
/**
|
|
374
411
|
* The tag name e.g. `div`, `script`, `link`, `meta`
|
|
375
412
|
*/
|
|
@@ -403,4 +440,7 @@ export interface TOCItem {
|
|
|
403
440
|
readonly value: string;
|
|
404
441
|
readonly id: string;
|
|
405
442
|
readonly children: TOCItem[];
|
|
443
|
+
readonly level: number;
|
|
406
444
|
}
|
|
445
|
+
|
|
446
|
+
export type RouteChunksTree = {[x: string | number]: string | RouteChunksTree};
|
package/tsconfig.json
ADDED
package/src/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/* eslint-disable */
|
|
9
|
-
'use strict';
|
|
10
|
-
Object.defineProperty(exports, '__esModule', {value: true});
|