@docusaurus/types 2.0.0-beta.17 → 2.0.0-beta.18
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 +3 -4
- package/src/index.d.ts +91 -83
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/types",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.18",
|
|
4
4
|
"description": "Common types for Docusaurus packages.",
|
|
5
5
|
"types": "./src/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,10 +18,9 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"commander": "^5.1.0",
|
|
20
20
|
"joi": "^17.6.0",
|
|
21
|
-
"querystring": "0.2.1",
|
|
22
21
|
"utility-types": "^3.10.0",
|
|
23
|
-
"webpack": "^5.
|
|
22
|
+
"webpack": "^5.70.0",
|
|
24
23
|
"webpack-merge": "^5.8.0"
|
|
25
24
|
},
|
|
26
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
|
|
27
26
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {RuleSetRule, Configuration} from 'webpack';
|
|
8
|
+
import type {RuleSetRule, Configuration as WebpackConfiguration} from 'webpack';
|
|
9
9
|
import type {CustomizeRuleString} from 'webpack-merge/dist/types';
|
|
10
10
|
import type {CommanderStatic} from 'commander';
|
|
11
11
|
import type {ParsedUrlQueryInput} from 'querystring';
|
|
12
12
|
import type Joi from 'joi';
|
|
13
13
|
import type {Overwrite, DeepPartial} from 'utility-types';
|
|
14
14
|
import type {Location} from 'history';
|
|
15
|
+
import type Loadable from 'react-loadable';
|
|
15
16
|
|
|
16
17
|
export type ReportingSeverity = 'ignore' | 'log' | 'warn' | 'error' | 'throw';
|
|
17
18
|
|
|
@@ -40,24 +41,24 @@ export interface DocusaurusConfig {
|
|
|
40
41
|
deploymentBranch?: string;
|
|
41
42
|
githubHost?: string;
|
|
42
43
|
githubPort?: string;
|
|
43
|
-
plugins
|
|
44
|
-
themes
|
|
45
|
-
presets
|
|
44
|
+
plugins: PluginConfig[];
|
|
45
|
+
themes: PluginConfig[];
|
|
46
|
+
presets: PresetConfig[];
|
|
46
47
|
themeConfig: ThemeConfig;
|
|
47
48
|
customFields?: {
|
|
48
49
|
[key: string]: unknown;
|
|
49
50
|
};
|
|
50
|
-
scripts
|
|
51
|
+
scripts: (
|
|
51
52
|
| string
|
|
52
53
|
| {
|
|
53
54
|
src: string;
|
|
54
55
|
[key: string]: unknown;
|
|
55
56
|
}
|
|
56
57
|
)[];
|
|
57
|
-
clientModules
|
|
58
|
+
clientModules: string[];
|
|
58
59
|
ssrTemplate?: string;
|
|
59
60
|
staticDirectories: string[];
|
|
60
|
-
stylesheets
|
|
61
|
+
stylesheets: (
|
|
61
62
|
| string
|
|
62
63
|
| {
|
|
63
64
|
href: string;
|
|
@@ -90,7 +91,7 @@ export type Config = Overwrite<
|
|
|
90
91
|
* package.json.
|
|
91
92
|
* - `type: 'synthetic'`, docusaurus generated internal plugin.
|
|
92
93
|
*/
|
|
93
|
-
export type
|
|
94
|
+
export type PluginVersionInformation =
|
|
94
95
|
| {
|
|
95
96
|
readonly type: 'package';
|
|
96
97
|
readonly name?: string;
|
|
@@ -103,7 +104,7 @@ export type DocusaurusPluginVersionInformation =
|
|
|
103
104
|
export interface DocusaurusSiteMetadata {
|
|
104
105
|
readonly docusaurusVersion: string;
|
|
105
106
|
readonly siteVersion?: string;
|
|
106
|
-
readonly pluginVersions:
|
|
107
|
+
readonly pluginVersions: {[pluginName: string]: PluginVersionInformation};
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
// Inspired by Chrome JSON, because it's a widely supported i18n format
|
|
@@ -113,7 +114,7 @@ export interface DocusaurusSiteMetadata {
|
|
|
113
114
|
// https://docs.transifex.com/formats/chrome-json
|
|
114
115
|
// https://help.phrase.com/help/chrome-json-messages
|
|
115
116
|
export type TranslationMessage = {message: string; description?: string};
|
|
116
|
-
export type TranslationFileContent =
|
|
117
|
+
export type TranslationFileContent = {[key: string]: TranslationMessage};
|
|
117
118
|
export type TranslationFile = {path: string; content: TranslationFileContent};
|
|
118
119
|
export type TranslationFiles = TranslationFile[];
|
|
119
120
|
|
|
@@ -126,22 +127,24 @@ export type I18nLocaleConfig = {
|
|
|
126
127
|
export type I18nConfig = {
|
|
127
128
|
defaultLocale: string;
|
|
128
129
|
locales: [string, ...string[]];
|
|
129
|
-
localeConfigs:
|
|
130
|
+
localeConfigs: {[locale: string]: Partial<I18nLocaleConfig>};
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
export type I18n = {
|
|
133
134
|
defaultLocale: string;
|
|
134
135
|
locales: [string, ...string[]];
|
|
135
136
|
currentLocale: string;
|
|
136
|
-
localeConfigs:
|
|
137
|
+
localeConfigs: {[locale: string]: I18nLocaleConfig};
|
|
137
138
|
};
|
|
138
139
|
|
|
140
|
+
export type GlobalData = {[pluginName: string]: {[pluginId: string]: unknown}};
|
|
141
|
+
|
|
139
142
|
export interface DocusaurusContext {
|
|
140
143
|
siteConfig: DocusaurusConfig;
|
|
141
144
|
siteMetadata: DocusaurusSiteMetadata;
|
|
142
|
-
globalData:
|
|
145
|
+
globalData: GlobalData;
|
|
143
146
|
i18n: I18n;
|
|
144
|
-
codeTranslations:
|
|
147
|
+
codeTranslations: {[msgId: string]: string};
|
|
145
148
|
|
|
146
149
|
// Don't put mutable values here, to avoid triggering re-renders
|
|
147
150
|
// We could reconsider that choice if context selectors are implemented
|
|
@@ -161,10 +164,7 @@ export type ImportedPresetModule = PresetModule & {
|
|
|
161
164
|
default?: PresetModule;
|
|
162
165
|
};
|
|
163
166
|
|
|
164
|
-
export type PresetConfig =
|
|
165
|
-
| [string, Record<string, unknown>]
|
|
166
|
-
| [string]
|
|
167
|
-
| string;
|
|
167
|
+
export type PresetConfig = string | [string, {[key: string]: unknown}];
|
|
168
168
|
|
|
169
169
|
export type HostPortCLIOptions = {
|
|
170
170
|
host?: string;
|
|
@@ -209,7 +209,7 @@ export interface LoadContext {
|
|
|
209
209
|
baseUrl: string; // TODO to remove: useless, there's already siteConfig.baseUrl!
|
|
210
210
|
i18n: I18n;
|
|
211
211
|
ssrTemplate: string;
|
|
212
|
-
codeTranslations:
|
|
212
|
+
codeTranslations: {[msgId: string]: string};
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
export interface InjectedHtmlTags {
|
|
@@ -229,31 +229,27 @@ export interface Props extends LoadContext, InjectedHtmlTags {
|
|
|
229
229
|
|
|
230
230
|
export interface PluginContentLoadedActions {
|
|
231
231
|
addRoute: (config: RouteConfig) => void;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
setGlobalData: <T = unknown>(data: T) => void;
|
|
232
|
+
createData: (name: string, data: string) => Promise<string>;
|
|
233
|
+
setGlobalData: (data: unknown) => void;
|
|
235
234
|
}
|
|
236
235
|
|
|
237
|
-
export type AllContent =
|
|
238
|
-
string
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
>
|
|
243
|
-
>;
|
|
236
|
+
export type AllContent = {
|
|
237
|
+
[pluginName: string]: {
|
|
238
|
+
[pluginID: string]: unknown;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
244
241
|
|
|
245
242
|
// TODO improve type (not exposed by postcss-loader)
|
|
246
|
-
export type PostCssOptions =
|
|
243
|
+
export type PostCssOptions = {[key: string]: unknown} & {plugins: unknown[]};
|
|
247
244
|
|
|
248
245
|
export interface Plugin<Content = unknown> {
|
|
249
246
|
name: string;
|
|
250
247
|
loadContent?: () => Promise<Content>;
|
|
251
|
-
contentLoaded?: ({
|
|
252
|
-
content
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
allContent: AllContent; // content loaded by ALL the plugins
|
|
248
|
+
contentLoaded?: (args: {
|
|
249
|
+
/** the content loaded by this plugin instance */
|
|
250
|
+
content: Content; //
|
|
251
|
+
/** content loaded by ALL the plugins */
|
|
252
|
+
allContent: AllContent;
|
|
257
253
|
actions: PluginContentLoadedActions;
|
|
258
254
|
}) => Promise<void>;
|
|
259
255
|
routesLoaded?: (routes: RouteConfig[]) => void; // TODO remove soon, deprecated (alpha-60)
|
|
@@ -261,18 +257,20 @@ export interface Plugin<Content = unknown> {
|
|
|
261
257
|
// TODO refactor the configureWebpack API surface: use an object instead of
|
|
262
258
|
// multiple params (requires breaking change)
|
|
263
259
|
configureWebpack?: (
|
|
264
|
-
config:
|
|
260
|
+
config: WebpackConfiguration,
|
|
265
261
|
isServer: boolean,
|
|
266
262
|
utils: ConfigureWebpackUtils,
|
|
267
263
|
content: Content,
|
|
268
|
-
) =>
|
|
264
|
+
) => WebpackConfiguration & {
|
|
265
|
+
mergeStrategy?: ConfigureWebpackFnMergeStrategy;
|
|
266
|
+
};
|
|
269
267
|
configurePostCss?: (options: PostCssOptions) => PostCssOptions;
|
|
270
268
|
getThemePath?: () => string;
|
|
271
269
|
getTypeScriptThemePath?: () => string;
|
|
272
270
|
getPathsToWatch?: () => string[];
|
|
273
271
|
getClientModules?: () => string[];
|
|
274
272
|
extendCli?: (cli: CommanderStatic) => void;
|
|
275
|
-
injectHtmlTags?: (
|
|
273
|
+
injectHtmlTags?: (args: {content: Content}) => {
|
|
276
274
|
headTags?: HtmlTags;
|
|
277
275
|
preBodyTags?: HtmlTags;
|
|
278
276
|
postBodyTags?: HtmlTags;
|
|
@@ -280,36 +278,25 @@ export interface Plugin<Content = unknown> {
|
|
|
280
278
|
// TODO before/afterDevServer implementation
|
|
281
279
|
|
|
282
280
|
// translations
|
|
283
|
-
getTranslationFiles?: ({
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
content: Content;
|
|
287
|
-
}) => Promise<TranslationFiles>;
|
|
288
|
-
getDefaultCodeTranslationMessages?: () => Promise<
|
|
289
|
-
Record<
|
|
290
|
-
string, // id
|
|
291
|
-
string // message
|
|
292
|
-
>
|
|
293
|
-
>;
|
|
294
|
-
translateContent?: ({
|
|
295
|
-
content,
|
|
296
|
-
translationFiles,
|
|
297
|
-
}: {
|
|
281
|
+
getTranslationFiles?: (args: {content: Content}) => Promise<TranslationFiles>;
|
|
282
|
+
getDefaultCodeTranslationMessages?: () => Promise<{[id: string]: string}>;
|
|
283
|
+
translateContent?: (args: {
|
|
298
284
|
content: Content; // the content loaded by this plugin instance
|
|
299
285
|
translationFiles: TranslationFiles;
|
|
300
286
|
}) => Content;
|
|
301
|
-
translateThemeConfig?: ({
|
|
302
|
-
themeConfig,
|
|
303
|
-
translationFiles,
|
|
304
|
-
}: {
|
|
287
|
+
translateThemeConfig?: (args: {
|
|
305
288
|
themeConfig: ThemeConfig;
|
|
306
289
|
translationFiles: TranslationFiles;
|
|
307
290
|
}) => ThemeConfig;
|
|
308
291
|
}
|
|
309
292
|
|
|
310
293
|
export type InitializedPlugin<Content = unknown> = Plugin<Content> & {
|
|
311
|
-
readonly options: PluginOptions
|
|
312
|
-
readonly version:
|
|
294
|
+
readonly options: Required<PluginOptions>;
|
|
295
|
+
readonly version: PluginVersionInformation;
|
|
296
|
+
/**
|
|
297
|
+
* The absolute path to the folder containing the entry point file.
|
|
298
|
+
*/
|
|
299
|
+
readonly path: string;
|
|
313
300
|
};
|
|
314
301
|
|
|
315
302
|
export type LoadedPlugin<Content = unknown> = InitializedPlugin<Content> & {
|
|
@@ -320,12 +307,12 @@ export type SwizzleAction = 'eject' | 'wrap';
|
|
|
320
307
|
export type SwizzleActionStatus = 'safe' | 'unsafe' | 'forbidden';
|
|
321
308
|
|
|
322
309
|
export type SwizzleComponentConfig = {
|
|
323
|
-
actions:
|
|
310
|
+
actions: {[action in SwizzleAction]: SwizzleActionStatus};
|
|
324
311
|
description?: string;
|
|
325
312
|
};
|
|
326
313
|
|
|
327
314
|
export type SwizzleConfig = {
|
|
328
|
-
components:
|
|
315
|
+
components: {[componentName: string]: SwizzleComponentConfig};
|
|
329
316
|
// Other settings could be added here,
|
|
330
317
|
// For example: the ability to declare the config as exhaustive
|
|
331
318
|
// so that we can emit errors
|
|
@@ -335,7 +322,7 @@ export type PluginModule = {
|
|
|
335
322
|
<Options, Content>(context: LoadContext, options: Options):
|
|
336
323
|
| Plugin<Content>
|
|
337
324
|
| Promise<Plugin<Content>>;
|
|
338
|
-
validateOptions?: <T>(data: OptionValidationContext<T>) =>
|
|
325
|
+
validateOptions?: <T, U>(data: OptionValidationContext<T, U>) => U;
|
|
339
326
|
validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;
|
|
340
327
|
|
|
341
328
|
getSwizzleComponentList?: () => string[] | undefined; // TODO deprecate this one later
|
|
@@ -347,18 +334,16 @@ export type ImportedPluginModule = PluginModule & {
|
|
|
347
334
|
};
|
|
348
335
|
|
|
349
336
|
export type ConfigureWebpackFn = Plugin<unknown>['configureWebpack'];
|
|
350
|
-
export type ConfigureWebpackFnMergeStrategy =
|
|
351
|
-
string
|
|
352
|
-
|
|
353
|
-
>;
|
|
337
|
+
export type ConfigureWebpackFnMergeStrategy = {
|
|
338
|
+
[key: string]: CustomizeRuleString;
|
|
339
|
+
};
|
|
354
340
|
export type ConfigurePostCssFn = Plugin<unknown>['configurePostCss'];
|
|
355
341
|
|
|
356
|
-
export type PluginOptions = {id?: string} &
|
|
342
|
+
export type PluginOptions = {id?: string} & {[key: string]: unknown};
|
|
357
343
|
|
|
358
344
|
export type PluginConfig =
|
|
359
|
-
| [string, PluginOptions]
|
|
360
|
-
| [string]
|
|
361
345
|
| string
|
|
346
|
+
| [string, PluginOptions]
|
|
362
347
|
| [PluginModule, PluginOptions]
|
|
363
348
|
| PluginModule;
|
|
364
349
|
|
|
@@ -393,6 +378,31 @@ export interface RouteConfig {
|
|
|
393
378
|
[propName: string]: unknown;
|
|
394
379
|
}
|
|
395
380
|
|
|
381
|
+
export interface RouteContext {
|
|
382
|
+
/**
|
|
383
|
+
* Plugin-specific context data.
|
|
384
|
+
*/
|
|
385
|
+
data?: object | undefined;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Top-level plugin routes automatically add some context data to the route.
|
|
390
|
+
* This permits us to know which plugin is handling the current route.
|
|
391
|
+
*/
|
|
392
|
+
export interface PluginRouteContext extends RouteContext {
|
|
393
|
+
plugin: {
|
|
394
|
+
id: string;
|
|
395
|
+
name: string;
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export type Route = {
|
|
400
|
+
readonly path: string;
|
|
401
|
+
readonly component: ReturnType<typeof Loadable>;
|
|
402
|
+
readonly exact?: boolean;
|
|
403
|
+
readonly routes?: Route[];
|
|
404
|
+
};
|
|
405
|
+
|
|
396
406
|
// Aliases used for Webpack resolution (when using docusaurus swizzle)
|
|
397
407
|
export interface ThemeAliases {
|
|
398
408
|
[alias: string]: string;
|
|
@@ -407,7 +417,7 @@ export interface ConfigureWebpackUtils {
|
|
|
407
417
|
) => RuleSetRule[];
|
|
408
418
|
getJSLoader: (options: {
|
|
409
419
|
isServer: boolean;
|
|
410
|
-
babelOptions?:
|
|
420
|
+
babelOptions?: {[key: string]: unknown};
|
|
411
421
|
}) => RuleSetRule;
|
|
412
422
|
}
|
|
413
423
|
|
|
@@ -416,7 +426,7 @@ interface HtmlTagObject {
|
|
|
416
426
|
* Attributes of the html tag
|
|
417
427
|
* E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
|
|
418
428
|
*/
|
|
419
|
-
attributes?: Partial<
|
|
429
|
+
attributes?: Partial<{[key: string]: string | boolean}>;
|
|
420
430
|
/**
|
|
421
431
|
* The tag name e.g. `div`, `script`, `link`, `meta`
|
|
422
432
|
*/
|
|
@@ -427,22 +437,20 @@ interface HtmlTagObject {
|
|
|
427
437
|
innerHTML?: string;
|
|
428
438
|
}
|
|
429
439
|
|
|
430
|
-
export type ValidationResult<T> = T;
|
|
431
|
-
|
|
432
440
|
export type ValidationSchema<T> = Joi.ObjectSchema<T>;
|
|
433
441
|
|
|
434
|
-
export type Validate<T> = (
|
|
435
|
-
validationSchema: ValidationSchema<
|
|
436
|
-
options:
|
|
437
|
-
) =>
|
|
442
|
+
export type Validate<T, U> = (
|
|
443
|
+
validationSchema: ValidationSchema<U>,
|
|
444
|
+
options: T,
|
|
445
|
+
) => U;
|
|
438
446
|
|
|
439
|
-
export
|
|
440
|
-
validate: Validate<T>;
|
|
441
|
-
options:
|
|
442
|
-
}
|
|
447
|
+
export type OptionValidationContext<T, U> = {
|
|
448
|
+
validate: Validate<T, U>;
|
|
449
|
+
options: T;
|
|
450
|
+
};
|
|
443
451
|
|
|
444
452
|
export interface ThemeConfigValidationContext<T> {
|
|
445
|
-
validate: Validate<T>;
|
|
453
|
+
validate: Validate<T, T>;
|
|
446
454
|
themeConfig: Partial<T>;
|
|
447
455
|
}
|
|
448
456
|
|