@docusaurus/types 2.0.0-beta.15d451942 → 2.0.0-beta.16

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.
Files changed (3) hide show
  1. package/package.json +10 -7
  2. package/src/index.d.ts +127 -68
  3. 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.15d451942",
3
+ "version": "2.0.0-beta.16",
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.0",
19
- "querystring": "0.2.0",
20
- "webpack": "^5.37.0",
21
- "webpack-merge": "^5.7.3"
20
+ "joi": "^17.6.0",
21
+ "querystring": "0.2.1",
22
+ "utility-types": "^3.10.0",
23
+ "webpack": "^5.69.1",
24
+ "webpack-merge": "^5.8.0"
22
25
  },
23
- "gitHead": "dfceae8bd3e8b42ba8fc14f1449d861046c26143"
26
+ "gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
24
27
  }
package/src/index.d.ts CHANGED
@@ -5,17 +5,13 @@
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
- import type {Command} from 'commander';
9
+ import type {CustomizeRuleString} from 'webpack-merge/dist/types';
10
+ import type {CommanderStatic} from 'commander';
12
11
  import type {ParsedUrlQueryInput} from 'querystring';
13
12
  import type Joi from 'joi';
14
-
15
- // Convert webpack-merge webpack-merge enum to union type
16
- // For type retro-compatible webpack-merge upgrade: we used string literals before)
17
- // see https://github.com/survivejs/webpack-merge/issues/179
18
- type MergeStrategy = 'match' | 'merge' | 'append' | 'prepend' | 'replace';
13
+ import type {Overwrite, DeepPartial} from 'utility-types';
14
+ import type {Location} from 'history';
19
15
 
20
16
  export type ReportingSeverity = 'ignore' | 'log' | 'warn' | 'error' | 'throw';
21
17
 
@@ -23,13 +19,17 @@ export type ThemeConfig = {
23
19
  [key: string]: unknown;
24
20
  };
25
21
 
22
+ // Docusaurus config, after validation/normalization
26
23
  export interface DocusaurusConfig {
27
24
  baseUrl: string;
28
25
  baseUrlIssueBanner: boolean;
29
- favicon: string;
30
- tagline?: string;
26
+ favicon?: string;
27
+ tagline: string;
31
28
  title: string;
32
29
  url: string;
30
+ // trailingSlash undefined = legacy retrocompatible behavior
31
+ // /file => /file/index.html
32
+ trailingSlash: boolean | undefined;
33
33
  i18n: I18nConfig;
34
34
  onBrokenLinks: ReportingSeverity;
35
35
  onBrokenMarkdownLinks: ReportingSeverity;
@@ -37,6 +37,7 @@ export interface DocusaurusConfig {
37
37
  noIndex: boolean;
38
38
  organizationName?: string;
39
39
  projectName?: string;
40
+ deploymentBranch?: string;
40
41
  githubHost?: string;
41
42
  githubPort?: string;
42
43
  plugins?: PluginConfig[];
@@ -55,6 +56,7 @@ export interface DocusaurusConfig {
55
56
  )[];
56
57
  clientModules?: string[];
57
58
  ssrTemplate?: string;
59
+ staticDirectories: string[];
58
60
  stylesheets?: (
59
61
  | string
60
62
  | {
@@ -68,10 +70,24 @@ export interface DocusaurusConfig {
68
70
  };
69
71
  }
70
72
 
73
+ // Docusaurus config, as provided by the user (partial/unnormalized)
74
+ // This type is used to provide type-safety / IDE auto-complete on the config
75
+ // file. See https://docusaurus.io/docs/typescript-support
76
+ export type Config = Overwrite<
77
+ Partial<DocusaurusConfig>,
78
+ {
79
+ title: Required<DocusaurusConfig['title']>;
80
+ url: Required<DocusaurusConfig['url']>;
81
+ baseUrl: Required<DocusaurusConfig['baseUrl']>;
82
+ i18n?: DeepPartial<DocusaurusConfig['i18n']>;
83
+ }
84
+ >;
85
+
71
86
  /**
72
87
  * - `type: 'package'`, plugin is in a different package.
73
88
  * - `type: 'project'`, plugin is in the same docusaurus project.
74
- * - `type: 'local'`, none of plugin's ancestor directory contains any package.json.
89
+ * - `type: 'local'`, none of the plugin's ancestor directories contains a
90
+ * package.json.
75
91
  * - `type: 'synthetic'`, docusaurus generated internal plugin.
76
92
  */
77
93
  export type DocusaurusPluginVersionInformation =
@@ -103,6 +119,7 @@ export type TranslationFiles = TranslationFile[];
103
119
 
104
120
  export type I18nLocaleConfig = {
105
121
  label: string;
122
+ htmlLang: string;
106
123
  direction: string;
107
124
  };
108
125
 
@@ -125,7 +142,10 @@ export interface DocusaurusContext {
125
142
  globalData: Record<string, unknown>;
126
143
  i18n: I18n;
127
144
  codeTranslations: Record<string, string>;
128
- isClient: boolean;
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!
129
149
  }
130
150
 
131
151
  export interface Preset {
@@ -133,6 +153,14 @@ export interface Preset {
133
153
  themes?: PluginConfig[];
134
154
  }
135
155
 
156
+ export type PresetModule = {
157
+ <T>(context: LoadContext, presetOptions: T): Preset;
158
+ };
159
+
160
+ export type ImportedPresetModule = PresetModule & {
161
+ default?: PresetModule;
162
+ };
163
+
136
164
  export type PresetConfig =
137
165
  | [string, Record<string, unknown>]
138
166
  | [string]
@@ -178,9 +206,9 @@ export interface LoadContext {
178
206
  siteConfig: DocusaurusConfig;
179
207
  siteConfigPath: string;
180
208
  outDir: string;
181
- baseUrl: string;
209
+ baseUrl: string; // TODO to remove: useless, there's already siteConfig.baseUrl!
182
210
  i18n: I18n;
183
- ssrTemplate?: string;
211
+ ssrTemplate: string;
184
212
  codeTranslations: Record<string, string>;
185
213
  }
186
214
 
@@ -193,17 +221,17 @@ export interface InjectedHtmlTags {
193
221
  export type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[];
194
222
 
195
223
  export interface Props extends LoadContext, InjectedHtmlTags {
196
- siteMetadata: DocusaurusSiteMetadata;
197
- routes: RouteConfig[];
198
- routesPaths: string[];
199
- plugins: Plugin<unknown>[];
224
+ readonly siteMetadata: DocusaurusSiteMetadata;
225
+ readonly routes: RouteConfig[];
226
+ readonly routesPaths: string[];
227
+ readonly plugins: LoadedPlugin[];
200
228
  }
201
229
 
202
230
  export interface PluginContentLoadedActions {
203
- addRoute(config: RouteConfig): void;
231
+ addRoute: (config: RouteConfig) => void;
204
232
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
205
- createData(name: string, data: any): Promise<string>;
206
- setGlobalData<T = unknown>(data: T): void;
233
+ createData: (name: string, data: any) => Promise<string>;
234
+ setGlobalData: <T = unknown>(data: T) => void;
207
235
  }
208
236
 
209
237
  export type AllContent = Record<
@@ -217,32 +245,34 @@ export type AllContent = Record<
217
245
  // TODO improve type (not exposed by postcss-loader)
218
246
  export type PostCssOptions = Record<string, unknown> & {plugins: unknown[]};
219
247
 
220
- export interface Plugin<Content> {
248
+ export interface Plugin<Content = unknown> {
221
249
  name: string;
222
- loadContent?(): Promise<Content>;
223
- contentLoaded?({
250
+ loadContent?: () => Promise<Content>;
251
+ contentLoaded?: ({
224
252
  content,
225
253
  actions,
226
254
  }: {
227
255
  content: Content; // the content loaded by this plugin instance
228
256
  allContent: AllContent; // content loaded by ALL the plugins
229
257
  actions: PluginContentLoadedActions;
230
- }): void;
231
- routesLoaded?(routes: RouteConfig[]): void; // TODO remove soon, deprecated (alpha-60)
232
- postBuild?(props: Props): void;
233
- postStart?(props: Props): void;
234
- configureWebpack?(
258
+ }) => Promise<void>;
259
+ routesLoaded?: (routes: RouteConfig[]) => void; // TODO remove soon, deprecated (alpha-60)
260
+ postBuild?: (props: Props & {content: Content}) => Promise<void>;
261
+ // TODO refactor the configureWebpack API surface: use an object instead of
262
+ // multiple params (requires breaking change)
263
+ configureWebpack?: (
235
264
  config: Configuration,
236
265
  isServer: boolean,
237
266
  utils: ConfigureWebpackUtils,
238
- ): Configuration & {mergeStrategy?: ConfigureWebpackFnMergeStrategy};
239
- configurePostCss?(options: PostCssOptions): PostCssOptions;
240
- getThemePath?(): string;
241
- getTypeScriptThemePath?(): string;
242
- getPathsToWatch?(): string[];
243
- getClientModules?(): string[];
244
- extendCli?(cli: Command): void;
245
- injectHtmlTags?(): {
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: CommanderStatic) => void;
275
+ injectHtmlTags?: ({content}: {content: Content}) => {
246
276
  headTags?: HtmlTags;
247
277
  preBodyTags?: HtmlTags;
248
278
  postBodyTags?: HtmlTags;
@@ -250,38 +280,66 @@ export interface Plugin<Content> {
250
280
  // TODO before/afterDevServer implementation
251
281
 
252
282
  // translations
253
- getTranslationFiles?({
283
+ getTranslationFiles?: ({
254
284
  content,
255
285
  }: {
256
286
  content: Content;
257
- }): Promise<TranslationFiles>;
258
- getDefaultCodeTranslationMessages?(): Promise<
287
+ }) => Promise<TranslationFiles>;
288
+ getDefaultCodeTranslationMessages?: () => Promise<
259
289
  Record<
260
290
  string, // id
261
291
  string // message
262
292
  >
263
293
  >;
264
- translateContent?({
294
+ translateContent?: ({
265
295
  content,
266
296
  translationFiles,
267
297
  }: {
268
298
  content: Content; // the content loaded by this plugin instance
269
299
  translationFiles: TranslationFiles;
270
- }): Content;
271
- translateThemeConfig?({
300
+ }) => Content;
301
+ translateThemeConfig?: ({
272
302
  themeConfig,
273
303
  translationFiles,
274
304
  }: {
275
305
  themeConfig: ThemeConfig;
276
306
  translationFiles: TranslationFiles;
277
- }): ThemeConfig;
307
+ }) => ThemeConfig;
278
308
  }
279
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
+
319
+ export type SwizzleAction = 'eject' | 'wrap';
320
+ export type SwizzleActionStatus = 'safe' | 'unsafe' | 'forbidden';
321
+
322
+ export type SwizzleComponentConfig = {
323
+ actions: Record<SwizzleAction, SwizzleActionStatus>;
324
+ description?: string;
325
+ };
326
+
327
+ export type SwizzleConfig = {
328
+ components: Record<string, SwizzleComponentConfig>;
329
+ // Other settings could be added here,
330
+ // For example: the ability to declare the config as exhaustive
331
+ // so that we can emit errors
332
+ };
333
+
280
334
  export type PluginModule = {
281
- <T, X>(context: LoadContext, options: T): Plugin<X>;
282
- validateOptions?<T>(data: OptionValidationContext<T>): T;
283
- validateThemeConfig?<T>(data: ThemeConfigValidationContext<T>): T;
284
- getSwizzleComponentList?(): string[];
335
+ <Options, Content>(context: LoadContext, options: Options):
336
+ | Plugin<Content>
337
+ | Promise<Plugin<Content>>;
338
+ validateOptions?: <T>(data: OptionValidationContext<T>) => T;
339
+ validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;
340
+
341
+ getSwizzleComponentList?: () => string[] | undefined; // TODO deprecate this one later
342
+ getSwizzleConfig?: () => SwizzleConfig | undefined;
285
343
  };
286
344
 
287
345
  export type ImportedPluginModule = PluginModule & {
@@ -289,7 +347,10 @@ export type ImportedPluginModule = PluginModule & {
289
347
  };
290
348
 
291
349
  export type ConfigureWebpackFn = Plugin<unknown>['configureWebpack'];
292
- export type ConfigureWebpackFnMergeStrategy = Record<string, MergeStrategy>;
350
+ export type ConfigureWebpackFnMergeStrategy = Record<
351
+ string,
352
+ CustomizeRuleString
353
+ >;
293
354
  export type ConfigurePostCssFn = Plugin<unknown>['configurePostCss'];
294
355
 
295
356
  export type PluginOptions = {id?: string} & Record<string, unknown>;
@@ -329,9 +390,11 @@ export interface RouteConfig {
329
390
  routes?: RouteConfig[];
330
391
  exact?: boolean;
331
392
  priority?: number;
393
+ [propName: string]: unknown;
332
394
  }
333
395
 
334
- export interface ThemeAlias {
396
+ // Aliases used for Webpack resolution (when using docusaurus swizzle)
397
+ export interface ThemeAliases {
335
398
  [alias: string]: string;
336
399
  }
337
400
 
@@ -346,18 +409,6 @@ export interface ConfigureWebpackUtils {
346
409
  isServer: boolean;
347
410
  babelOptions?: Record<string, unknown>;
348
411
  }) => RuleSetRule;
349
-
350
- // TODO deprecated: remove before end of 2021?
351
- getCacheLoader: (
352
- isServer: boolean,
353
- cacheOptions?: Record<string, unknown>,
354
- ) => RuleSetRule | null;
355
-
356
- // TODO deprecated: remove before end of 2021?
357
- getBabelLoader: (
358
- isServer: boolean,
359
- options?: Record<string, unknown>,
360
- ) => RuleSetRule;
361
412
  }
362
413
 
363
414
  interface HtmlTagObject {
@@ -365,9 +416,7 @@ interface HtmlTagObject {
365
416
  * Attributes of the html tag
366
417
  * E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
367
418
  */
368
- attributes?: {
369
- [attributeName: string]: string | boolean;
370
- };
419
+ attributes?: Partial<Record<string, string | boolean>>;
371
420
  /**
372
421
  * The tag name e.g. `div`, `script`, `link`, `meta`
373
422
  */
@@ -397,8 +446,18 @@ export interface ThemeConfigValidationContext<T> {
397
446
  themeConfig: Partial<T>;
398
447
  }
399
448
 
400
- export interface TOCItem {
449
+ export type TOCItem = {
401
450
  readonly value: string;
402
451
  readonly id: string;
403
- readonly children: TOCItem[];
404
- }
452
+ readonly level: number;
453
+ };
454
+
455
+ export type RouteChunksTree = {[x: string | number]: string | RouteChunksTree};
456
+
457
+ export type ClientModule = {
458
+ onRouteUpdate?: (args: {
459
+ previousLocation: Location | null;
460
+ location: Location;
461
+ }) => void;
462
+ onRouteUpdateDelayed?: (args: {location: Location}) => void;
463
+ };
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});