@docusaurus/types 2.0.0-beta.fbdeefcac → 2.0.0-rc.1

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 CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/types",
3
- "version": "2.0.0-beta.fbdeefcac",
3
+ "version": "2.0.0-rc.1",
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,15 +12,19 @@
13
12
  "directory": "packages/docusaurus-types"
14
13
  },
15
14
  "license": "MIT",
16
- "scripts": {
17
- "test": "tsc -p ."
18
- },
19
15
  "dependencies": {
16
+ "@types/history": "^4.7.11",
17
+ "@types/react": "*",
20
18
  "commander": "^5.1.0",
21
- "joi": "^17.4.0",
22
- "querystring": "0.2.0",
23
- "webpack": "^5.40.0",
19
+ "joi": "^17.6.0",
20
+ "react-helmet-async": "^1.3.0",
21
+ "utility-types": "^3.10.0",
22
+ "webpack": "^5.73.0",
24
23
  "webpack-merge": "^5.8.0"
25
24
  },
26
- "gitHead": "636c490f68d16a7452499ab722deb5ed51ef49fc"
25
+ "peerDependencies": {
26
+ "react": "^16.8.4 || ^17.0.0",
27
+ "react-dom": "^16.8.4 || ^17.0.0"
28
+ },
29
+ "gitHead": "c8ddd02a8e68dfaf515c20465a049a83153bd205"
27
30
  }
@@ -0,0 +1,19 @@
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
+ import type {Location} from 'history';
9
+
10
+ export type ClientModule = {
11
+ onRouteDidUpdate?: (args: {
12
+ previousLocation: Location | null;
13
+ location: Location;
14
+ }) => (() => void) | void;
15
+ onRouteUpdate?: (args: {
16
+ previousLocation: Location | null;
17
+ location: Location;
18
+ }) => (() => void) | void;
19
+ };
@@ -0,0 +1,283 @@
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
+ import type {RuleSetRule} from 'webpack';
9
+ import type {Required as RequireKeys, DeepPartial} from 'utility-types';
10
+ import type {I18nConfig} from './i18n';
11
+ import type {PluginConfig, PresetConfig} from './plugin';
12
+
13
+ export type ReportingSeverity = 'ignore' | 'log' | 'warn' | 'throw';
14
+
15
+ export type ThemeConfig = {
16
+ [key: string]: unknown;
17
+ };
18
+
19
+ /**
20
+ * Docusaurus config, after validation/normalization.
21
+ */
22
+ export type DocusaurusConfig = {
23
+ /**
24
+ * Title for your website. Will be used in metadata and as browser tab title.
25
+ *
26
+ * @see https://docusaurus.io/docs/api/docusaurus-config#title
27
+ */
28
+ title: string;
29
+ /**
30
+ * URL for your website. This can also be considered the top-level hostname.
31
+ * For example, `https://facebook.github.io` is the URL of
32
+ * https://facebook.github.io/metro/, and `https://docusaurus.io` is the URL
33
+ * for https://docusaurus.io.
34
+ *
35
+ * @see https://docusaurus.io/docs/api/docusaurus-config#url
36
+ */
37
+ url: string;
38
+ /**
39
+ * Can be considered as the path after the host. For example, `/metro/` is the
40
+ * base URL of https://facebook.github.io/metro/. For URLs that have no path,
41
+ * it should be set to `/`. Always has both leading and trailing slash.
42
+ *
43
+ * @see https://docusaurus.io/docs/api/docusaurus-config#baseUrl
44
+ */
45
+ baseUrl: string;
46
+ /**
47
+ * Path to your site favicon; must be a URL that can be used in link's href.
48
+ *
49
+ * @see https://docusaurus.io/docs/api/docusaurus-config#favicon
50
+ */
51
+ favicon?: string;
52
+ /**
53
+ * Allow to customize the presence/absence of a trailing slash at the end of
54
+ * URLs/links, and how static HTML files are generated:
55
+ *
56
+ * - `undefined` (default): keeps URLs untouched, and emit
57
+ * `/docs/myDoc/index.html` for `/docs/myDoc.md`
58
+ * - `true`: add trailing slashes to URLs/links, and emit
59
+ * `/docs/myDoc/index.html` for `/docs/myDoc.md`
60
+ * - `false`: remove trailing slashes from URLs/links, and emit
61
+ * `/docs/myDoc.html` for `/docs/myDoc.md`
62
+ *
63
+ * @see https://github.com/slorber/trailing-slash-guide
64
+ * @see https://docusaurus.io/docs/api/docusaurus-config#trailingSlash
65
+ * @default undefined
66
+ */
67
+ trailingSlash: boolean | undefined;
68
+ /**
69
+ * The i18n configuration object to [localize your
70
+ * site](https://docusaurus.io/docs/i18n/introduction).
71
+ *
72
+ * @see https://docusaurus.io/docs/api/docusaurus-config#i18n
73
+ */
74
+ i18n: I18nConfig;
75
+ /**
76
+ * This option adds `<meta name="robots" content="noindex, nofollow">` to
77
+ * every page to tell search engines to avoid indexing your site.
78
+ *
79
+ * @see https://moz.com/learn/seo/robots-meta-directives
80
+ * @see https://docusaurus.io/docs/api/docusaurus-config#noIndex
81
+ * @default false
82
+ */
83
+ noIndex: boolean;
84
+ /**
85
+ * The behavior of Docusaurus when it detects any broken link.
86
+ *
87
+ * @see https://docusaurus.io/docs/api/docusaurus-config#onBrokenLinks
88
+ * @default "throw"
89
+ */
90
+ onBrokenLinks: ReportingSeverity;
91
+ /**
92
+ * The behavior of Docusaurus when it detects any broken markdown link.
93
+ *
94
+ * @see https://docusaurus.io/docs/api/docusaurus-config#onBrokenMarkdownLinks
95
+ * @default "warn"
96
+ */
97
+ onBrokenMarkdownLinks: ReportingSeverity;
98
+ /**
99
+ * The behavior of Docusaurus when it detects any [duplicate
100
+ * routes](https://docusaurus.io/docs/creating-pages#duplicate-routes).
101
+ *
102
+ * @see https://docusaurus.io/docs/api/docusaurus-config#onDuplicateRoutes
103
+ * @default "warn"
104
+ */
105
+ onDuplicateRoutes: ReportingSeverity;
106
+ /**
107
+ * The tagline for your website.
108
+ *
109
+ * @see https://docusaurus.io/docs/api/docusaurus-config#tagline
110
+ * @default ""
111
+ */
112
+ tagline: string;
113
+ /**
114
+ * The GitHub user or organization that owns the repository. You don't need
115
+ * this if you are not using the `docusaurus deploy` command.
116
+ *
117
+ * @see https://docusaurus.io/docs/api/docusaurus-config#organizationName
118
+ */
119
+ organizationName?: string;
120
+ /**
121
+ * The name of the GitHub repository. You don't need this if you are not using
122
+ * the `docusaurus deploy` command.
123
+ *
124
+ * @see https://docusaurus.io/docs/api/docusaurus-config#projectName
125
+ */
126
+ projectName?: string;
127
+ /**
128
+ * The name of the branch to deploy the static files to. You don't need this
129
+ * if you are not using the `docusaurus deploy` command.
130
+ *
131
+ * @see https://docusaurus.io/docs/api/docusaurus-config#deploymentBranch
132
+ */
133
+ deploymentBranch?: string;
134
+ /**
135
+ * The hostname of your server. Useful if you are using GitHub Enterprise. You
136
+ * don't need this if you are not using the `docusaurus deploy` command.
137
+ *
138
+ * @see https://docusaurus.io/docs/api/docusaurus-config#githubHost
139
+ */
140
+ githubHost?: string;
141
+ /**
142
+ * The port of your server. Useful if you are using GitHub Enterprise. You
143
+ * don't need this if you are not using the `docusaurus deploy` command.
144
+ *
145
+ * @see https://docusaurus.io/docs/api/docusaurus-config#githubPort
146
+ */
147
+ githubPort?: string;
148
+ /**
149
+ * The [theme configuration](https://docusaurus.io/docs/api/themes/configuration)
150
+ * object to customize your site UI like navbar and footer.
151
+ *
152
+ * @see https://docusaurus.io/docs/api/docusaurus-config#themeConfig
153
+ * @default {}
154
+ */
155
+ themeConfig: ThemeConfig;
156
+ /**
157
+ * List of plugins.
158
+ *
159
+ * @see https://docusaurus.io/docs/api/docusaurus-config#plugins
160
+ * @default []
161
+ */
162
+ plugins: PluginConfig[];
163
+ /**
164
+ * List of themes.
165
+ *
166
+ * @see https://docusaurus.io/docs/api/docusaurus-config#themes
167
+ * @default []
168
+ */
169
+ themes: PluginConfig[];
170
+ /**
171
+ * List of presets.
172
+ *
173
+ * @see https://docusaurus.io/docs/api/docusaurus-config#presets
174
+ * @default []
175
+ */
176
+ presets: PresetConfig[];
177
+ /**
178
+ * Docusaurus guards `docusaurus.config.js` from unknown fields. To add a
179
+ * custom field, define it on `customFields`.
180
+ *
181
+ * @see https://docusaurus.io/docs/api/docusaurus-config#customFields
182
+ * @default {}
183
+ */
184
+ customFields?: {
185
+ [key: string]: unknown;
186
+ };
187
+ /**
188
+ * An array of paths, relative to the site's directory or absolute. Files
189
+ * under these paths will be copied to the build output as-is.
190
+ *
191
+ * @see https://docusaurus.io/docs/api/docusaurus-config#staticDirectories
192
+ * @default ["static"]
193
+ */
194
+ staticDirectories: string[];
195
+ /**
196
+ * An array of scripts to load. The values can be either strings or plain
197
+ * objects of attribute-value maps. The `<script>` tags will be inserted in
198
+ * the HTML `<head>`.
199
+ *
200
+ * Note that `<script>` added here are render-blocking, so you might want to
201
+ * add `async: true`/`defer: true` to the objects.
202
+ *
203
+ * @see https://docusaurus.io/docs/api/docusaurus-config#scripts
204
+ * @default []
205
+ */
206
+ scripts: (
207
+ | string
208
+ | {
209
+ src: string;
210
+ [key: string]: string | boolean | undefined;
211
+ }
212
+ )[];
213
+ /**
214
+ * An array of CSS sources to load. The values can be either strings or plain
215
+ * objects of attribute-value maps. The `<link>` tags will be inserted in the
216
+ * HTML `<head>`.
217
+ *
218
+ * @see https://docusaurus.io/docs/api/docusaurus-config#stylesheets
219
+ * @default []
220
+ */
221
+ stylesheets: (
222
+ | string
223
+ | {
224
+ href: string;
225
+ [key: string]: string | boolean | undefined;
226
+ }
227
+ )[];
228
+ /**
229
+ * An array of [client modules](https://docusaurus.io/docs/advanced/client#client-modules)
230
+ * to load globally on your site.
231
+ *
232
+ * @see https://docusaurus.io/docs/api/docusaurus-config#clientModules
233
+ * @default []
234
+ */
235
+ clientModules: string[];
236
+ /**
237
+ * An HTML template written in [Eta's syntax](https://eta.js.org/docs/syntax#syntax-overview)
238
+ * that will be used to render your application. This can be used to set
239
+ * custom attributes on the `body` tags, additional `meta` tags, customize the
240
+ * `viewport`, etc. Please note that Docusaurus will rely on the template to
241
+ * be correctly structured in order to function properly, once you do
242
+ * customize it, you will have to make sure that your template is compliant
243
+ * with the requirements from upstream.
244
+ *
245
+ * @see https://docusaurus.io/docs/api/docusaurus-config#ssrTemplate
246
+ */
247
+ ssrTemplate?: string;
248
+ /**
249
+ * Will be used as title delimiter in the generated `<title>` tag.
250
+ *
251
+ * @see https://docusaurus.io/docs/api/docusaurus-config#titleDelimiter
252
+ * @default "|"
253
+ */
254
+ titleDelimiter: string;
255
+ /**
256
+ * When enabled, will show a banner in case your site can't load its CSS or
257
+ * JavaScript files, which is a very common issue, often related to a wrong
258
+ * `baseUrl` in site config.
259
+ *
260
+ * @see https://docusaurus.io/docs/api/docusaurus-config#baseUrlIssueBanner
261
+ * @default true
262
+ */
263
+ baseUrlIssueBanner: boolean;
264
+ /** Webpack-related options. */
265
+ webpack?: {
266
+ /**
267
+ * Configuration for alternative JS loaders. "babel" will use the built-in
268
+ * Babel loader and preset; otherwise, you can provide your custom Webpack
269
+ * rule set.
270
+ */
271
+ jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule);
272
+ };
273
+ };
274
+
275
+ /**
276
+ * Docusaurus config, as provided by the user (partial/unnormalized). This type
277
+ * is used to provide type-safety / IDE auto-complete on the config file.
278
+ * @see https://docusaurus.io/docs/typescript-support
279
+ */
280
+ export type Config = RequireKeys<
281
+ DeepPartial<DocusaurusConfig>,
282
+ 'title' | 'url' | 'baseUrl'
283
+ >;
@@ -0,0 +1,62 @@
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
+ import type {DocusaurusConfig} from './config';
8
+ import type {CodeTranslations, I18n} from './i18n';
9
+ import type {LoadedPlugin, PluginVersionInformation} from './plugin';
10
+ import type {RouteConfig} from './routing';
11
+
12
+ export type DocusaurusContext = {
13
+ siteConfig: DocusaurusConfig;
14
+ siteMetadata: SiteMetadata;
15
+ globalData: GlobalData;
16
+ i18n: I18n;
17
+ codeTranslations: CodeTranslations;
18
+
19
+ // Don't put mutable values here, to avoid triggering re-renders
20
+ // We could reconsider that choice if context selectors are implemented
21
+ // isBrowser: boolean; // Not here on purpose!
22
+ };
23
+
24
+ export type SiteMetadata = {
25
+ readonly docusaurusVersion: string;
26
+ readonly siteVersion?: string;
27
+ readonly pluginVersions: {[pluginName: string]: PluginVersionInformation};
28
+ };
29
+
30
+ export type GlobalData = {[pluginName: string]: {[pluginId: string]: unknown}};
31
+
32
+ export type LoadContext = {
33
+ siteDir: string;
34
+ generatedFilesDir: string;
35
+ siteConfig: DocusaurusConfig;
36
+ siteConfigPath: string;
37
+ outDir: string;
38
+ /**
39
+ * Directory where all source translations for the current locale can be found
40
+ * in. Constructed with `i18n.path` + `i18n.currentLocale.path` (e.g.
41
+ * `<siteDir>/i18n/en`)
42
+ */
43
+ localizationDir: string;
44
+ /**
45
+ * Duplicated from `siteConfig.baseUrl`, but probably worth keeping. We mutate
46
+ * `siteConfig` to make `baseUrl` there localized as well, but that's mostly
47
+ * for client-side. `context.baseUrl` is still more convenient for plugins.
48
+ */
49
+ baseUrl: string;
50
+ i18n: I18n;
51
+ codeTranslations: CodeTranslations;
52
+ };
53
+
54
+ export type Props = LoadContext & {
55
+ headTags: string;
56
+ preBodyTags: string;
57
+ postBodyTags: string;
58
+ siteMetadata: SiteMetadata;
59
+ routes: RouteConfig[];
60
+ routesPaths: string[];
61
+ plugins: LoadedPlugin[];
62
+ };
package/src/i18n.d.ts ADDED
@@ -0,0 +1,82 @@
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
+ import type {DeepRequired} from 'utility-types';
9
+
10
+ export type I18nLocaleConfig = {
11
+ /** The label displayed for this locale in the locales dropdown. */
12
+ label: string;
13
+ /**
14
+ * BCP 47 language tag to use in `<html lang="...">` and in
15
+ * `<link ... hreflang="...">`
16
+ */
17
+ htmlLang: string;
18
+ /** Used to select the locale's CSS and html meta attribute. */
19
+ direction: 'ltr' | 'rtl';
20
+ /**
21
+ * The [calendar](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
22
+ * used to calculate the date era. Note that it doesn't control the actual
23
+ * string displayed: `MM/DD/YYYY` and `DD/MM/YYYY` are both gregory. To choose
24
+ * the format (`DD/MM/YYYY` or `MM/DD/YYYY`), set your locale name to `en-GB`
25
+ * or `en-US` (`en` means `en-US`).
26
+ */
27
+ calendar: string;
28
+ /**
29
+ * Root folder that all plugin localization folders of this locale are
30
+ * relative to. Will be resolved against `i18n.path`. Defaults to the locale's
31
+ * name.
32
+ */
33
+ path: string;
34
+ };
35
+
36
+ export type I18nConfig = {
37
+ /**
38
+ * The locale that:
39
+ * 1. Does not have its name in the base URL
40
+ * 2. Gets started with `docusaurus start` without `--locale` option
41
+ * 3. Will be used for the `<link hrefLang="x-default">` tag
42
+ */
43
+ defaultLocale: string;
44
+ /**
45
+ * Root folder which all locale folders are relative to. Can be absolute or
46
+ * relative to the config file. e.g. `i18n`
47
+ */
48
+ path: string;
49
+ /** List of locales deployed on your site. Must contain `defaultLocale`. */
50
+ locales: [string, ...string[]];
51
+ /** Individual options for each locale. */
52
+ localeConfigs: {[locale: string]: Partial<I18nLocaleConfig>};
53
+ };
54
+
55
+ export type I18n = DeepRequired<I18nConfig> & {currentLocale: string};
56
+
57
+ /**
58
+ * Inspired by Chrome JSON, because it's a widely supported i18n format
59
+ * @see https://developer.chrome.com/apps/i18n-messages
60
+ * @see https://support.crowdin.com/file-formats/chrome-json/
61
+ * @see https://www.applanga.com/docs/formats/chrome_i18n_json
62
+ * @see https://docs.transifex.com/formats/chrome-json
63
+ * @see https://help.phrase.com/help/chrome-json-messages
64
+ */
65
+ export type TranslationMessage = {message: string; description?: string};
66
+ export type TranslationFileContent = {[msgId: string]: TranslationMessage};
67
+ /**
68
+ * An abstract representation of how a translation file exists on disk. The core
69
+ * would handle the file reading/writing; plugins just need to deal with
70
+ * translations in-memory.
71
+ */
72
+ export type TranslationFile = {
73
+ /**
74
+ * Relative to the directory where it's expected to be found. For plugin
75
+ * files, it's relative to `i18n/<locale>/<pluginName>/<pluginId>`. Should NOT
76
+ * have any extension.
77
+ */
78
+ path: string;
79
+ content: TranslationFileContent;
80
+ };
81
+
82
+ export type CodeTranslations = {[msgId: string]: string};
package/src/index.d.ts CHANGED
@@ -5,416 +5,73 @@
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
- import type {RuleSetRule, Configuration} from 'webpack';
11
- import type {Command} from 'commander';
12
- import type {ParsedUrlQueryInput} from 'querystring';
13
- 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';
19
-
20
- export type ReportingSeverity = 'ignore' | 'log' | 'warn' | 'error' | 'throw';
21
-
22
- export type ThemeConfig = {
23
- [key: string]: unknown;
24
- };
25
-
26
- export interface DocusaurusConfig {
27
- baseUrl: string;
28
- baseUrlIssueBanner: boolean;
29
- favicon?: string;
30
- tagline?: string;
31
- title: string;
32
- url: string;
33
- // trailingSlash undefined = legacy retrocompatible behavior => /file => /file/index.html
34
- trailingSlash: boolean | undefined;
35
- i18n: I18nConfig;
36
- onBrokenLinks: ReportingSeverity;
37
- onBrokenMarkdownLinks: ReportingSeverity;
38
- onDuplicateRoutes: ReportingSeverity;
39
- noIndex: boolean;
40
- organizationName?: string;
41
- projectName?: string;
42
- githubHost?: string;
43
- githubPort?: string;
44
- plugins?: PluginConfig[];
45
- themes?: PluginConfig[];
46
- presets?: PresetConfig[];
47
- themeConfig: ThemeConfig;
48
- customFields?: {
49
- [key: string]: unknown;
50
- };
51
- scripts?: (
52
- | string
53
- | {
54
- src: string;
55
- [key: string]: unknown;
56
- }
57
- )[];
58
- clientModules?: string[];
59
- ssrTemplate?: string;
60
- stylesheets?: (
61
- | string
62
- | {
63
- href: string;
64
- [key: string]: unknown;
65
- }
66
- )[];
67
- titleDelimiter?: string;
68
- webpack?: {
69
- jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule);
70
- };
71
- }
72
-
73
- /**
74
- * - `type: 'package'`, plugin is in a different package.
75
- * - `type: 'project'`, plugin is in the same docusaurus project.
76
- * - `type: 'local'`, none of plugin's ancestor directory contains any package.json.
77
- * - `type: 'synthetic'`, docusaurus generated internal plugin.
78
- */
79
- export type DocusaurusPluginVersionInformation =
80
- | {
81
- readonly type: 'package';
82
- readonly name?: string;
83
- readonly version?: string;
84
- }
85
- | {readonly type: 'project'}
86
- | {readonly type: 'local'}
87
- | {readonly type: 'synthetic'};
88
-
89
- export interface DocusaurusSiteMetadata {
90
- readonly docusaurusVersion: string;
91
- readonly siteVersion?: string;
92
- readonly pluginVersions: Record<string, DocusaurusPluginVersionInformation>;
93
- }
94
-
95
- // Inspired by Chrome JSON, because it's a widely supported i18n format
96
- // https://developer.chrome.com/apps/i18n-messages
97
- // https://support.crowdin.com/file-formats/chrome-json/
98
- // https://www.applanga.com/docs/formats/chrome_i18n_json
99
- // https://docs.transifex.com/formats/chrome-json
100
- // https://help.phrase.com/help/chrome-json-messages
101
- export type TranslationMessage = {message: string; description?: string};
102
- export type TranslationFileContent = Record<string, TranslationMessage>;
103
- export type TranslationFile = {path: string; content: TranslationFileContent};
104
- export type TranslationFiles = TranslationFile[];
105
-
106
- export type I18nLocaleConfig = {
107
- label: string;
108
- direction: string;
109
- };
110
-
111
- export type I18nConfig = {
112
- defaultLocale: string;
113
- locales: [string, ...string[]];
114
- localeConfigs: Record<string, Partial<I18nLocaleConfig>>;
115
- };
116
-
117
- export type I18n = {
118
- defaultLocale: string;
119
- locales: [string, ...string[]];
120
- currentLocale: string;
121
- localeConfigs: Record<string, I18nLocaleConfig>;
122
- };
123
-
124
- export interface DocusaurusContext {
125
- siteConfig: DocusaurusConfig;
126
- siteMetadata: DocusaurusSiteMetadata;
127
- globalData: Record<string, unknown>;
128
- i18n: I18n;
129
- codeTranslations: Record<string, string>;
130
- isClient: boolean;
131
- }
132
-
133
- export interface Preset {
134
- plugins?: PluginConfig[];
135
- themes?: PluginConfig[];
136
- }
137
-
138
- export type PresetConfig =
139
- | [string, Record<string, unknown>]
140
- | [string]
141
- | string;
142
-
143
- export type HostPortCLIOptions = {
144
- host?: string;
145
- port?: string;
146
- };
147
-
148
- export type ConfigOptions = {
149
- config: string;
150
- };
151
-
152
- export type StartCLIOptions = HostPortCLIOptions &
153
- ConfigOptions & {
154
- hotOnly: boolean;
155
- open: boolean;
156
- poll: boolean | number;
157
- locale?: string;
158
- };
159
-
160
- export type ServeCLIOptions = HostPortCLIOptions &
161
- ConfigOptions & {
162
- dir: string;
163
- build: boolean;
164
- };
165
-
166
- export type BuildOptions = ConfigOptions & {
167
- bundleAnalyzer: boolean;
168
- outDir: string;
169
- minify: boolean;
170
- skipBuild: boolean;
171
- };
172
-
173
- export type BuildCLIOptions = BuildOptions & {
174
- locale?: string;
175
- };
176
-
177
- export interface LoadContext {
178
- siteDir: string;
179
- generatedFilesDir: string;
180
- siteConfig: DocusaurusConfig;
181
- siteConfigPath: string;
182
- outDir: string;
183
- baseUrl: string; // TODO to remove: useless, there's already siteConfig.baseUrl!
184
- i18n: I18n;
185
- ssrTemplate?: string;
186
- codeTranslations: Record<string, string>;
187
- }
188
-
189
- export interface InjectedHtmlTags {
190
- headTags: string;
191
- preBodyTags: string;
192
- postBodyTags: string;
193
- }
194
-
195
- export type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[];
196
-
197
- export interface Props extends LoadContext, InjectedHtmlTags {
198
- siteMetadata: DocusaurusSiteMetadata;
199
- routes: RouteConfig[];
200
- routesPaths: string[];
201
- plugins: LoadedPlugin[];
202
- }
203
-
204
- export interface PluginContentLoadedActions {
205
- addRoute(config: RouteConfig): void;
206
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
207
- createData(name: string, data: any): Promise<string>;
208
- setGlobalData<T = unknown>(data: T): void;
209
- }
210
-
211
- export type AllContent = Record<
212
- string, // plugin name
213
- Record<
214
- string, // plugin id
215
- unknown // plugin data
216
- >
217
- >;
218
-
219
- // TODO improve type (not exposed by postcss-loader)
220
- export type PostCssOptions = Record<string, unknown> & {plugins: unknown[]};
221
-
222
- export interface Plugin<Content = unknown> {
223
- name: string;
224
- loadContent?(): Promise<Content>;
225
- contentLoaded?({
226
- content,
227
- actions,
228
- }: {
229
- content: Content; // the content loaded by this plugin instance
230
- allContent: AllContent; // content loaded by ALL the plugins
231
- actions: PluginContentLoadedActions;
232
- }): void;
233
- routesLoaded?(routes: RouteConfig[]): void; // TODO remove soon, deprecated (alpha-60)
234
- postBuild?(props: Props): void;
235
- postStart?(props: Props): void;
236
- // TODO refactor the configureWebpack API surface: use an object instead of multiple params (requires breaking change)
237
- configureWebpack?(
238
- config: Configuration,
239
- isServer: boolean,
240
- utils: ConfigureWebpackUtils,
241
- content: Content,
242
- ): Configuration & {mergeStrategy?: ConfigureWebpackFnMergeStrategy};
243
- configurePostCss?(options: PostCssOptions): PostCssOptions;
244
- getThemePath?(): string;
245
- getTypeScriptThemePath?(): string;
246
- getPathsToWatch?(): string[];
247
- getClientModules?(): string[];
248
- extendCli?(cli: Command): void;
249
- injectHtmlTags?({
250
- content: Content,
251
- }): {
252
- headTags?: HtmlTags;
253
- preBodyTags?: HtmlTags;
254
- postBodyTags?: HtmlTags;
255
- };
256
- // TODO before/afterDevServer implementation
257
-
258
- // translations
259
- getTranslationFiles?({
260
- content,
261
- }: {
262
- content: Content;
263
- }): Promise<TranslationFiles>;
264
- getDefaultCodeTranslationMessages?(): Promise<
265
- Record<
266
- string, // id
267
- string // message
268
- >
269
- >;
270
- translateContent?({
271
- content,
272
- translationFiles,
273
- }: {
274
- content: Content; // the content loaded by this plugin instance
275
- translationFiles: TranslationFiles;
276
- }): Content;
277
- translateThemeConfig?({
278
- themeConfig,
279
- translationFiles,
280
- }: {
281
- themeConfig: ThemeConfig;
282
- translationFiles: TranslationFiles;
283
- }): ThemeConfig;
284
- }
285
-
286
- export type InitializedPlugin<Content = unknown> = Plugin<Content> & {
287
- readonly options: PluginOptions;
288
- readonly version: DocusaurusPluginVersionInformation;
289
- };
290
-
291
- export type LoadedPlugin<Content = unknown> = InitializedPlugin<Content> & {
292
- readonly content: Content;
293
- };
294
-
295
- export type PluginModule = {
296
- <T, X>(context: LoadContext, options: T): Plugin<X>;
297
- validateOptions?<T>(data: OptionValidationContext<T>): T;
298
- validateThemeConfig?<T>(data: ThemeConfigValidationContext<T>): T;
299
- getSwizzleComponentList?(): string[];
300
- };
301
-
302
- export type ImportedPluginModule = PluginModule & {
303
- default?: PluginModule;
304
- };
305
-
306
- export type ConfigureWebpackFn = Plugin<unknown>['configureWebpack'];
307
- export type ConfigureWebpackFnMergeStrategy = Record<string, MergeStrategy>;
308
- export type ConfigurePostCssFn = Plugin<unknown>['configurePostCss'];
309
-
310
- export type PluginOptions = {id?: string} & Record<string, unknown>;
311
-
312
- export type PluginConfig =
313
- | [string, PluginOptions]
314
- | [string]
315
- | string
316
- | [PluginModule, PluginOptions]
317
- | PluginModule;
318
-
319
- export interface ChunkRegistry {
320
- loader: string;
321
- modulePath: string;
322
- }
323
-
324
- export type Module =
325
- | {
326
- path: string;
327
- __import?: boolean;
328
- query?: ParsedUrlQueryInput;
329
- }
330
- | string;
331
-
332
- export interface RouteModule {
333
- [module: string]: Module | RouteModule | RouteModule[];
334
- }
335
-
336
- export interface ChunkNames {
337
- [name: string]: string | null | ChunkNames | ChunkNames[];
338
- }
339
-
340
- export interface RouteConfig {
341
- path: string;
342
- component: string;
343
- modules?: RouteModule;
344
- routes?: RouteConfig[];
345
- exact?: boolean;
346
- priority?: number;
347
- }
348
-
349
- // Aliases used for Webpack resolution (when using docusaurus swizzle)
350
- export interface ThemeAliases {
351
- [alias: string]: string;
352
- }
353
-
354
- export interface ConfigureWebpackUtils {
355
- getStyleLoaders: (
356
- isServer: boolean,
357
- cssOptions: {
358
- [key: string]: unknown;
359
- },
360
- ) => RuleSetRule[];
361
- getJSLoader: (options: {
362
- isServer: boolean;
363
- babelOptions?: Record<string, unknown>;
364
- }) => RuleSetRule;
365
-
366
- // TODO deprecated: remove before end of 2021?
367
- getCacheLoader: (
368
- isServer: boolean,
369
- cacheOptions?: Record<string, unknown>,
370
- ) => RuleSetRule | null;
371
-
372
- // TODO deprecated: remove before end of 2021?
373
- getBabelLoader: (
374
- isServer: boolean,
375
- options?: Record<string, unknown>,
376
- ) => RuleSetRule;
377
- }
378
-
379
- interface HtmlTagObject {
380
- /**
381
- * Attributes of the html tag
382
- * E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
383
- */
384
- attributes?: {
385
- [attributeName: string]: string | boolean;
386
- };
387
- /**
388
- * The tag name e.g. `div`, `script`, `link`, `meta`
389
- */
390
- tagName: string;
391
- /**
392
- * The inner HTML
393
- */
394
- innerHTML?: string;
395
- }
396
-
397
- export type ValidationResult<T> = T;
398
-
399
- export type ValidationSchema<T> = Joi.ObjectSchema<T>;
400
-
401
- export type Validate<T> = (
402
- validationSchema: ValidationSchema<T>,
403
- options: Partial<T>,
404
- ) => ValidationResult<T>;
405
-
406
- export interface OptionValidationContext<T> {
407
- validate: Validate<T>;
408
- options: Partial<T>;
409
- }
410
-
411
- export interface ThemeConfigValidationContext<T> {
412
- validate: Validate<T>;
413
- themeConfig: Partial<T>;
414
- }
415
-
416
- export interface TOCItem {
417
- readonly value: string;
418
- readonly id: string;
419
- readonly children: TOCItem[];
420
- }
8
+ export {
9
+ ReportingSeverity,
10
+ ThemeConfig,
11
+ DocusaurusConfig,
12
+ Config,
13
+ } from './config';
14
+
15
+ export {
16
+ SiteMetadata,
17
+ DocusaurusContext,
18
+ GlobalData,
19
+ LoadContext,
20
+ Props,
21
+ } from './context';
22
+
23
+ export {ClientModule} from './clientModule';
24
+
25
+ export {
26
+ SwizzleAction,
27
+ SwizzleActionStatus,
28
+ SwizzleConfig,
29
+ SwizzleComponentConfig,
30
+ WrapperProps,
31
+ } from './swizzle';
32
+
33
+ export {
34
+ I18nConfig,
35
+ I18nLocaleConfig,
36
+ I18n,
37
+ CodeTranslations,
38
+ TranslationFileContent,
39
+ TranslationMessage,
40
+ TranslationFile,
41
+ } from './i18n';
42
+
43
+ export {
44
+ Plugin,
45
+ InitializedPlugin,
46
+ LoadedPlugin,
47
+ PluginModule,
48
+ PluginOptions,
49
+ PluginConfig,
50
+ PluginContentLoadedActions,
51
+ PluginVersionInformation,
52
+ Preset,
53
+ PresetConfig,
54
+ PresetModule,
55
+ OptionValidationContext,
56
+ ThemeConfigValidationContext,
57
+ Validate,
58
+ ValidationSchema,
59
+ AllContent,
60
+ ConfigureWebpackUtils,
61
+ PostCssOptions,
62
+ HtmlTagObject,
63
+ HtmlTags,
64
+ } from './plugin';
65
+
66
+ export {
67
+ RouteConfig,
68
+ RouteContext,
69
+ PluginRouteContext,
70
+ Registry,
71
+ RouteChunkNames,
72
+ RouteModules,
73
+ Module,
74
+ ChunkNames,
75
+ } from './routing';
76
+
77
+ export {UseDataOptions} from './utils';
@@ -0,0 +1,195 @@
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
+ import type {TranslationFile} from './i18n';
9
+ import type {RuleSetRule, Configuration as WebpackConfiguration} from 'webpack';
10
+ import type {CustomizeRuleString} from 'webpack-merge/dist/types';
11
+ import type {CommanderStatic} from 'commander';
12
+ import type Joi from 'joi';
13
+ import type {HelmetServerState} from 'react-helmet-async';
14
+ import type {ThemeConfig} from './config';
15
+ import type {LoadContext, Props} from './context';
16
+ import type {SwizzleConfig} from './swizzle';
17
+ import type {RouteConfig} from './routing';
18
+
19
+ export type PluginOptions = {id?: string} & {[key: string]: unknown};
20
+
21
+ export type PluginConfig =
22
+ | string
23
+ | [string, PluginOptions]
24
+ | [PluginModule, PluginOptions]
25
+ | PluginModule
26
+ | false
27
+ | null;
28
+
29
+ export type PresetConfig =
30
+ | string
31
+ | [string, {[key: string]: unknown}]
32
+ | false
33
+ | null;
34
+
35
+ /**
36
+ * - `type: 'package'`, plugin is in a different package.
37
+ * - `type: 'project'`, plugin is in the same docusaurus project.
38
+ * - `type: 'local'`, none of the plugin's ancestor directories contains a
39
+ * package.json.
40
+ * - `type: 'synthetic'`, docusaurus generated internal plugin.
41
+ */
42
+ export type PluginVersionInformation =
43
+ | {
44
+ readonly type: 'package';
45
+ readonly name?: string;
46
+ readonly version?: string;
47
+ }
48
+ | {readonly type: 'project'}
49
+ | {readonly type: 'local'}
50
+ | {readonly type: 'synthetic'};
51
+
52
+ export type PluginContentLoadedActions = {
53
+ addRoute: (config: RouteConfig) => void;
54
+ createData: (name: string, data: string) => Promise<string>;
55
+ setGlobalData: (data: unknown) => void;
56
+ };
57
+
58
+ export type ConfigureWebpackUtils = {
59
+ getStyleLoaders: (
60
+ isServer: boolean,
61
+ cssOptions: {[key: string]: unknown},
62
+ ) => RuleSetRule[];
63
+ getJSLoader: (options: {
64
+ isServer: boolean;
65
+ babelOptions?: {[key: string]: unknown};
66
+ }) => RuleSetRule;
67
+ };
68
+
69
+ export type AllContent = {
70
+ [pluginName: string]: {
71
+ [pluginID: string]: unknown;
72
+ };
73
+ };
74
+
75
+ // TODO improve type (not exposed by postcss-loader)
76
+ export type PostCssOptions = {plugins: unknown[]; [key: string]: unknown};
77
+
78
+ export type ValidationSchema<T> = Joi.ObjectSchema<T>;
79
+
80
+ export type Validate<In, Out> = (
81
+ validationSchema: ValidationSchema<Out>,
82
+ options: In,
83
+ ) => Out;
84
+
85
+ export type OptionValidationContext<In, Out> = {
86
+ validate: Validate<In, Out>;
87
+ options: In;
88
+ };
89
+
90
+ export type ThemeConfigValidationContext<In, Out = In> = {
91
+ validate: Validate<In, Out>;
92
+ themeConfig: In;
93
+ };
94
+
95
+ export type HtmlTagObject = {
96
+ /**
97
+ * Attributes of the html tag.
98
+ * E.g. `{ disabled: true, value: "demo", rel: "preconnect" }`
99
+ */
100
+ attributes?: Partial<{[key: string]: string | boolean}>;
101
+ /** The tag name, e.g. `div`, `script`, `link`, `meta` */
102
+ tagName: string;
103
+ /** The inner HTML */
104
+ innerHTML?: string;
105
+ };
106
+
107
+ export type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[];
108
+
109
+ export type Plugin<Content = unknown> = {
110
+ name: string;
111
+ loadContent?: () => Promise<Content> | Content;
112
+ contentLoaded?: (args: {
113
+ /** The content loaded by this plugin instance */
114
+ content: Content; //
115
+ /** Content loaded by ALL the plugins */
116
+ allContent: AllContent;
117
+ actions: PluginContentLoadedActions;
118
+ }) => Promise<void> | void;
119
+ postBuild?: (
120
+ props: Props & {
121
+ content: Content;
122
+ head: {[location: string]: HelmetServerState};
123
+ },
124
+ ) => Promise<void> | void;
125
+ // TODO refactor the configureWebpack API surface: use an object instead of
126
+ // multiple params (requires breaking change)
127
+ configureWebpack?: (
128
+ config: WebpackConfiguration,
129
+ isServer: boolean,
130
+ utils: ConfigureWebpackUtils,
131
+ content: Content,
132
+ ) => WebpackConfiguration & {
133
+ mergeStrategy?: {
134
+ [key: string]: CustomizeRuleString;
135
+ };
136
+ };
137
+ configurePostCss?: (options: PostCssOptions) => PostCssOptions;
138
+ getThemePath?: () => string;
139
+ getTypeScriptThemePath?: () => string;
140
+ getPathsToWatch?: () => string[];
141
+ getClientModules?: () => string[];
142
+ extendCli?: (cli: CommanderStatic) => void;
143
+ injectHtmlTags?: (args: {content: Content}) => {
144
+ headTags?: HtmlTags;
145
+ preBodyTags?: HtmlTags;
146
+ postBodyTags?: HtmlTags;
147
+ };
148
+ // TODO before/afterDevServer implementation
149
+
150
+ // translations
151
+ getTranslationFiles?: (args: {
152
+ content: Content;
153
+ }) => Promise<TranslationFile[]> | TranslationFile[];
154
+ getDefaultCodeTranslationMessages?: () =>
155
+ | Promise<{[id: string]: string}>
156
+ | {[id: string]: string};
157
+ translateContent?: (args: {
158
+ /** The content loaded by this plugin instance. */
159
+ content: Content;
160
+ translationFiles: TranslationFile[];
161
+ }) => Content;
162
+ translateThemeConfig?: (args: {
163
+ themeConfig: ThemeConfig;
164
+ translationFiles: TranslationFile[];
165
+ }) => ThemeConfig;
166
+ };
167
+
168
+ export type InitializedPlugin = Plugin & {
169
+ readonly options: Required<PluginOptions>;
170
+ readonly version: PluginVersionInformation;
171
+ /** The absolute path to the folder containing the entry point file. */
172
+ readonly path: string;
173
+ };
174
+
175
+ export type LoadedPlugin = InitializedPlugin & {
176
+ readonly content: unknown;
177
+ };
178
+
179
+ export type PluginModule = {
180
+ (context: LoadContext, options: unknown): Plugin | Promise<Plugin>;
181
+ validateOptions?: <T, U>(data: OptionValidationContext<T, U>) => U;
182
+ validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;
183
+
184
+ getSwizzleComponentList?: () => string[] | undefined; // TODO deprecate this one later
185
+ getSwizzleConfig?: () => SwizzleConfig | undefined;
186
+ };
187
+
188
+ export type Preset = {
189
+ plugins?: PluginConfig[];
190
+ themes?: PluginConfig[];
191
+ };
192
+
193
+ export type PresetModule = {
194
+ (context: LoadContext, presetOptions: unknown): Preset;
195
+ };
@@ -0,0 +1,138 @@
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
+ import type {ParsedUrlQueryInput} from 'querystring';
9
+
10
+ /**
11
+ * A "module" represents a unit of serialized data emitted from the plugin. It
12
+ * will be imported on client-side and passed as props, context, etc.
13
+ *
14
+ * If it's a string, it's a file path that Webpack can `require`; if it's
15
+ * an object, it can also contain `query` or other metadata.
16
+ */
17
+ export type Module =
18
+ | {
19
+ /**
20
+ * A marker that tells the route generator this is an import and not a
21
+ * nested object to recurse.
22
+ */
23
+ __import?: boolean;
24
+ path: string;
25
+ query?: ParsedUrlQueryInput;
26
+ }
27
+ | string;
28
+
29
+ /**
30
+ * Represents the data attached to each route. Since the routes.js is a
31
+ * monolithic data file, any data (like props) should be serialized separately
32
+ * and registered here as file paths (a {@link Module}), so that we could
33
+ * code-split.
34
+ */
35
+ export type RouteModules = {
36
+ [propName: string]: Module | RouteModules | RouteModules[];
37
+ };
38
+
39
+ /**
40
+ * Represents a "slice" of the final route structure returned from the plugin
41
+ * `addRoute` action.
42
+ */
43
+ export type RouteConfig = {
44
+ /** With leading slash. Trailing slash will be normalized by config. */
45
+ path: string;
46
+ /** Component used to render this route, a path that Webpack can `require`. */
47
+ component: string;
48
+ /**
49
+ * Props. Each entry should be `[propName]: pathToPropModule` (created with
50
+ * `createData`)
51
+ */
52
+ modules?: RouteModules;
53
+ /**
54
+ * The route context will wrap the `component`. Use `useRouteContext` to
55
+ * retrieve what's declared here. Note that all custom route context declared
56
+ * here will be namespaced under {@link RouteContext.data}.
57
+ */
58
+ context?: RouteModules;
59
+ /** Nested routes config. */
60
+ routes?: RouteConfig[];
61
+ /** React router config option: `exact` routes would not match subroutes. */
62
+ exact?: boolean;
63
+ /** Used to sort routes. Higher-priority routes will be placed first. */
64
+ priority?: number;
65
+ /** Extra props; will be copied to routes.js. */
66
+ [propName: string]: unknown;
67
+ };
68
+
69
+ export type RouteContext = {
70
+ /**
71
+ * Plugin-specific context data.
72
+ */
73
+ data?: object | undefined;
74
+ };
75
+
76
+ /**
77
+ * Top-level plugin routes automatically add some context data to the route.
78
+ * This permits us to know which plugin is handling the current route.
79
+ */
80
+ export type PluginRouteContext = RouteContext & {
81
+ plugin: {
82
+ id: string;
83
+ name: string;
84
+ };
85
+ };
86
+
87
+ /**
88
+ * The shape would be isomorphic to {@link RouteModules}:
89
+ * {@link Module} -> `string`, `RouteModules[]` -> `ChunkNames[]`.
90
+ *
91
+ * Each `string` chunk name will correlate with one key in the {@link Registry}.
92
+ */
93
+ export type ChunkNames = {
94
+ [propName: string]: string | ChunkNames | ChunkNames[];
95
+ };
96
+
97
+ /**
98
+ * A map from route paths (with a hash) to the chunk names of each module, which
99
+ * the bundler will collect.
100
+ *
101
+ * Chunk keys are routes with a hash, because 2 routes can conflict with each
102
+ * other if they have the same path, e.g.: parent=/docs, child=/docs
103
+ *
104
+ * @see https://github.com/facebook/docusaurus/issues/2917
105
+ */
106
+ export type RouteChunkNames = {
107
+ [routePathHashed: string]: ChunkNames;
108
+ };
109
+
110
+ /**
111
+ * Each key is the chunk name, which you can get from `routeChunkNames` (see
112
+ * {@link RouteChunkNames}). The values are the opts data that react-loadable
113
+ * needs. For example:
114
+ *
115
+ * ```js
116
+ * const options = {
117
+ * optsLoader: {
118
+ * component: () => import('./Pages.js'),
119
+ * content.foo: () => import('./doc1.md'),
120
+ * },
121
+ * optsModules: ['./Pages.js', './doc1.md'],
122
+ * optsWebpack: [
123
+ * require.resolveWeak('./Pages.js'),
124
+ * require.resolveWeak('./doc1.md'),
125
+ * ],
126
+ * }
127
+ * ```
128
+ *
129
+ * @see https://github.com/jamiebuilds/react-loadable#declaring-which-modules-are-being-loaded
130
+ */
131
+ export type Registry = {
132
+ readonly [chunkName: string]: [
133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
+ Loader: () => Promise<any>,
135
+ ModuleName: string,
136
+ ResolvedModuleName: string,
137
+ ];
138
+ };
@@ -0,0 +1,43 @@
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
+ import type {JSXElementConstructor} from 'react';
9
+
10
+ export type SwizzleAction = 'eject' | 'wrap';
11
+ export type SwizzleActionStatus = 'safe' | 'unsafe' | 'forbidden';
12
+
13
+ export type SwizzleComponentConfig = {
14
+ actions: {[action in SwizzleAction]: SwizzleActionStatus};
15
+ description?: string;
16
+ };
17
+
18
+ export type SwizzleConfig = {
19
+ components: {[componentName: string]: SwizzleComponentConfig};
20
+ // Other settings could be added here, like the ability to declare the config
21
+ // as exhaustive so that we can emit errors
22
+ };
23
+
24
+ /**
25
+ * This type is almost the same as `React.ComponentProps`, but with one minor
26
+ * fix: when the component is a function with no parameters, it produces `{}`
27
+ * instead of `unknown`, allowing us to spread the props derived from another
28
+ * component. This is useful for wrap swizzling.
29
+ *
30
+ * @see https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/60766
31
+ */
32
+ export type WrapperProps<
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>,
35
+ > = T extends JSXElementConstructor<infer P>
36
+ ? unknown extends P
37
+ ? // eslint-disable-next-line @typescript-eslint/ban-types
38
+ {}
39
+ : P
40
+ : T extends keyof JSX.IntrinsicElements
41
+ ? JSX.IntrinsicElements[T]
42
+ : // eslint-disable-next-line @typescript-eslint/ban-types
43
+ {};
package/src/utils.d.ts ADDED
@@ -0,0 +1,14 @@
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
+ export type UseDataOptions = {
9
+ /**
10
+ * Throw an error, or simply return undefined if the data cannot be found. Use
11
+ * `true` if you are sure the data must exist.
12
+ */
13
+ failfast?: boolean;
14
+ };
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});
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "http://json.schemastore.org/tsconfig",
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "noEmit": true
6
- }
7
- }