@docusaurus/core 2.0.0-beta.14 → 2.0.0-beta.15

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 (81) hide show
  1. package/bin/docusaurus.js +1 -1
  2. package/lib/babel/preset.d.ts +1 -1
  3. package/lib/client/LinksCollector.d.ts +1 -1
  4. package/lib/client/PendingNavigation.d.ts +2 -2
  5. package/lib/client/exports/BrowserOnly.d.ts +1 -1
  6. package/lib/client/exports/BrowserOnly.js +7 -2
  7. package/lib/client/exports/ErrorBoundary.d.ts +1 -1
  8. package/lib/client/exports/ErrorBoundary.js +3 -1
  9. package/lib/client/exports/Interpolate.d.ts +1 -1
  10. package/lib/client/exports/Translate.d.ts +2 -2
  11. package/lib/client/exports/browserContext.d.ts +1 -1
  12. package/lib/client/exports/docusaurusContext.d.ts +2 -2
  13. package/lib/client/exports/useBaseUrl.js +2 -2
  14. package/lib/client/exports/useDocusaurusContext.d.ts +1 -1
  15. package/lib/client/nprogress.css +2 -2
  16. package/lib/client/preload.d.ts +1 -1
  17. package/lib/client/serverEntry.d.ts +10 -0
  18. package/lib/client/serverEntry.js +81 -115
  19. package/lib/commands/build.d.ts +1 -1
  20. package/lib/commands/build.js +11 -7
  21. package/lib/commands/commandUtils.d.ts +1 -1
  22. package/lib/commands/deploy.d.ts +1 -1
  23. package/lib/commands/deploy.js +1 -1
  24. package/lib/commands/external.d.ts +1 -1
  25. package/lib/commands/external.js +1 -1
  26. package/lib/commands/serve.d.ts +1 -1
  27. package/lib/commands/start.d.ts +1 -1
  28. package/lib/commands/start.js +4 -5
  29. package/lib/commands/swizzle.d.ts +1 -1
  30. package/lib/commands/swizzle.js +2 -2
  31. package/lib/commands/writeHeadingIds.d.ts +1 -1
  32. package/lib/commands/writeHeadingIds.js +1 -1
  33. package/lib/commands/writeTranslations.d.ts +2 -2
  34. package/lib/commands/writeTranslations.js +1 -1
  35. package/lib/server/brokenLinks.d.ts +1 -1
  36. package/lib/server/brokenLinks.js +1 -2
  37. package/lib/server/client-modules/index.d.ts +1 -1
  38. package/lib/server/config.d.ts +2 -2
  39. package/lib/server/config.js +5 -2
  40. package/lib/server/configValidation.d.ts +1 -1
  41. package/lib/server/configValidation.js +2 -3
  42. package/lib/server/duplicateRoutes.d.ts +1 -1
  43. package/lib/server/html-tags/index.d.ts +1 -1
  44. package/lib/server/i18n.d.ts +1 -1
  45. package/lib/server/i18n.js +3 -8
  46. package/lib/server/index.d.ts +1 -1
  47. package/lib/server/index.js +18 -10
  48. package/lib/server/loadSetup.d.ts +1 -1
  49. package/lib/server/moduleShorthand.js +11 -7
  50. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
  51. package/lib/server/plugins/index.d.ts +1 -1
  52. package/lib/server/plugins/index.js +1 -1
  53. package/lib/server/plugins/init.d.ts +2 -2
  54. package/lib/server/plugins/init.js +10 -9
  55. package/lib/server/plugins/pluginIds.d.ts +1 -1
  56. package/lib/server/presets/index.d.ts +1 -1
  57. package/lib/server/presets/index.js +1 -1
  58. package/lib/server/routes.d.ts +1 -1
  59. package/lib/server/routes.js +1 -2
  60. package/lib/server/themes/alias.d.ts +1 -1
  61. package/lib/server/themes/index.d.ts +1 -1
  62. package/lib/server/translations/translations.d.ts +1 -1
  63. package/lib/server/translations/translations.js +1 -1
  64. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  65. package/lib/server/translations/translationsExtractor.js +121 -88
  66. package/lib/server/utils.d.ts +1 -1
  67. package/lib/server/versions/__tests/index.test.js +6 -5
  68. package/lib/server/versions/index.d.ts +1 -1
  69. package/lib/webpack/base.d.ts +2 -2
  70. package/lib/webpack/client.d.ts +2 -2
  71. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +1 -1
  72. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +1 -1
  73. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  74. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  75. package/lib/webpack/server.d.ts +2 -2
  76. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  77. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  78. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  79. package/lib/webpack/utils.d.ts +4 -4
  80. package/lib/webpack/utils.js +8 -5
  81. package/package.json +22 -22
package/bin/docusaurus.js CHANGED
@@ -34,7 +34,7 @@ cli
34
34
  .description('Build website.')
35
35
  .option(
36
36
  '--bundle-analyzer',
37
- 'visualize size of webpack output files with an interactive zoomable treemap (default: false)',
37
+ 'visualize size of webpack output files with an interactive zoomable tree map (default: false)',
38
38
  )
39
39
  .option(
40
40
  '--out-dir <dir>',
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { ConfigAPI, TransformOptions } from '@babel/core';
7
+ import type { ConfigAPI, TransformOptions } from '@babel/core';
8
8
  declare function babelPresets(api: ConfigAPI): TransformOptions;
9
9
  export default babelPresets;
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { ReactNode } from 'react';
7
+ import { type ReactNode } from 'react';
8
8
  declare type LinksCollector = {
9
9
  collectLink: (link: string) => void;
10
10
  };
@@ -6,8 +6,8 @@
6
6
  */
7
7
  /// <reference types="node" />
8
8
  import React from 'react';
9
- import { RouteComponentProps } from 'react-router-dom';
10
- import { RouteConfig } from 'react-router-config';
9
+ import { type RouteComponentProps } from 'react-router-dom';
10
+ import type { RouteConfig } from 'react-router-config';
11
11
  import type { Location } from '@docusaurus/history';
12
12
  import './nprogress.css';
13
13
  interface Props extends RouteComponentProps {
@@ -6,7 +6,7 @@
6
6
  */
7
7
  /// <reference types="react" />
8
8
  declare function BrowserOnly({ children, fallback, }: {
9
- children?: () => JSX.Element;
9
+ children: () => JSX.Element;
10
10
  fallback?: JSX.Element;
11
11
  }): JSX.Element | null;
12
12
  export default BrowserOnly;
@@ -4,13 +4,18 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React from 'react';
7
+ import React, { isValidElement } from 'react';
8
8
  import useIsBrowser from '@docusaurus/useIsBrowser';
9
9
  // Similar comp to the one described here:
10
10
  // https://www.joshwcomeau.com/react/the-perils-of-rehydration/#abstractions
11
11
  function BrowserOnly({ children, fallback, }) {
12
12
  const isBrowser = useIsBrowser();
13
- if (isBrowser && children != null) {
13
+ if (isBrowser) {
14
+ if (typeof children !== 'function' &&
15
+ process.env.NODE_ENV === 'development') {
16
+ throw new Error(`Docusaurus error: The children of <BrowserOnly> must be a "render function", e.g. <BrowserOnly>{() => <span>{window.location.href}</span>}</BrowserOnly>.
17
+ Current type: ${isValidElement(children) ? 'React element' : typeof children}`);
18
+ }
14
19
  return React.createElement(React.Fragment, null, children());
15
20
  }
16
21
  return fallback || null;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
- import React, { ReactNode } from 'react';
8
+ import React, { type ReactNode } from 'react';
9
9
  import type { Props } from '@docusaurus/ErrorBoundary';
10
10
  interface State {
11
11
  error: Error | null;
@@ -29,7 +29,9 @@ class ErrorBoundary extends React.Component {
29
29
  tryAgain: () => this.setState({ error: null }),
30
30
  });
31
31
  }
32
- return children;
32
+ return (children !== null && children !== void 0 ? children :
33
+ // See https://github.com/facebook/docusaurus/issues/6337#issuecomment-1012913647
34
+ null);
33
35
  }
34
36
  }
35
37
  export default ErrorBoundary;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
- import { ReactNode } from 'react';
8
+ import { type ReactNode } from 'react';
9
9
  import type { InterpolateProps, InterpolateValues } from '@docusaurus/Interpolate';
10
10
  export declare function interpolate<Str extends string>(text: Str, values?: InterpolateValues<Str, string | number>): string;
11
11
  export declare function interpolate<Str extends string, Value extends ReactNode>(text: Str, values?: InterpolateValues<Str, Value>): ReactNode;
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
- import { ReactNode } from 'react';
9
- import { InterpolateValues } from '@docusaurus/Interpolate';
8
+ import type { ReactNode } from 'react';
9
+ import { type InterpolateValues } from '@docusaurus/Interpolate';
10
10
  import type { TranslateParam, TranslateProps } from '@docusaurus/Translate';
11
11
  export declare function translate<Str extends string>({ message, id }: TranslateParam<Str>, values?: InterpolateValues<Str, string | number>): string;
12
12
  export default function Translate<Str extends string>({ children, id, values, }: TranslateProps<Str>): ReactNode;
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { ReactNode } from 'react';
7
+ import React, { type ReactNode } from 'react';
8
8
  export declare const Context: React.Context<boolean>;
9
9
  export declare function BrowserContextProvider({ children, }: {
10
10
  children: ReactNode;
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { ReactNode } from 'react';
8
- import { DocusaurusContext } from '@docusaurus/types';
7
+ import React, { type ReactNode } from 'react';
8
+ import type { DocusaurusContext } from '@docusaurus/types';
9
9
  export declare const Context: React.Context<DocusaurusContext>;
10
10
  export declare function DocusaurusContextProvider({ children, }: {
11
11
  children: ReactNode;
@@ -19,7 +19,7 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
19
19
  return url;
20
20
  }
21
21
  if (forcePrependBaseUrl) {
22
- return baseUrl + url;
22
+ return baseUrl + url.replace(/^\//, '');
23
23
  }
24
24
  // We should avoid adding the baseurl twice if it's already there
25
25
  const shouldAddBaseUrl = !url.startsWith(baseUrl);
@@ -27,7 +27,7 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
27
27
  return absolute ? siteUrl + basePath : basePath;
28
28
  }
29
29
  export function useBaseUrlUtils() {
30
- const { siteConfig: { baseUrl = '/', url: siteUrl } = {} } = useDocusaurusContext();
30
+ const { siteConfig: { baseUrl, url: siteUrl }, } = useDocusaurusContext();
31
31
  return {
32
32
  withBaseUrl: (url, options) => addBaseUrl(siteUrl, baseUrl, url, options),
33
33
  };
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { DocusaurusContext } from '@docusaurus/types';
7
+ import type { DocusaurusContext } from '@docusaurus/types';
8
8
  declare function useDocusaurusContext(): DocusaurusContext;
9
9
  export default useDocusaurusContext;
@@ -27,10 +27,10 @@
27
27
 
28
28
  #nprogress .peg {
29
29
  position: absolute;
30
- right: 0px;
30
+ right: 0;
31
31
  width: 100px;
32
32
  height: 100%;
33
33
  box-shadow: 0 0 10px #29d, 0 0 5px #29d;
34
34
  opacity: 1;
35
- transform: rotate(3deg) translate(0px, -4px);
35
+ transform: rotate(3deg) translate(0, -4px);
36
36
  }
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { RouteConfig } from 'react-router-config';
7
+ import { type RouteConfig } from 'react-router-config';
8
8
  /**
9
9
  * Helper function to make sure all async components for that particular route
10
10
  * is preloaded before rendering. This is especially useful to avoid loading screens.
@@ -0,0 +1,10 @@
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 { Locals } from '@slorber/static-site-generator-webpack-plugin';
8
+ export default function render(locals: Locals & {
9
+ path: string;
10
+ }): Promise<string>;
@@ -4,143 +4,109 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
-
8
- // @ts-check
9
-
10
7
  import * as eta from 'eta';
11
8
  import React from 'react';
12
- import {StaticRouter} from 'react-router-dom';
9
+ import { StaticRouter } from 'react-router-dom';
13
10
  import ReactDOMServer from 'react-dom/server';
14
- import {Helmet} from 'react-helmet';
15
- import {getBundles} from 'react-loadable-ssr-addon-v5-slorber';
11
+ import { Helmet } from 'react-helmet';
12
+ import { getBundles } from 'react-loadable-ssr-addon-v5-slorber';
16
13
  import Loadable from 'react-loadable';
17
-
18
- import {minify} from 'html-minifier-terser';
14
+ import { minify } from 'html-minifier-terser';
19
15
  import path from 'path';
20
16
  import fs from 'fs-extra';
21
17
  import routes from '@generated/routes';
22
- import packageJson from '../../package.json';
23
18
  import preload from './preload';
24
19
  import App from './App';
25
- import {
26
- createStatefulLinksCollector,
27
- ProvideLinksCollector,
28
- } from './LinksCollector';
20
+ import { createStatefulLinksCollector, ProvideLinksCollector, } from './LinksCollector';
29
21
  import logger from '@docusaurus/logger';
30
22
  // eslint-disable-next-line no-restricted-imports
31
- import {memoize} from 'lodash';
32
-
33
- const getCompiledSSRTemplate = memoize((template) =>
34
- eta.compile(template.trim(), {
23
+ import { memoize } from 'lodash';
24
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
25
+ const packageJson = require('../../package.json');
26
+ const getCompiledSSRTemplate = memoize((template) => eta.compile(template.trim(), {
35
27
  rmWhitespace: true,
36
- }),
37
- );
38
-
28
+ }));
39
29
  function renderSSRTemplate(ssrTemplate, data) {
40
- const compiled = getCompiledSSRTemplate(ssrTemplate);
41
- return compiled(data, eta.defaultConfig);
30
+ const compiled = getCompiledSSRTemplate(ssrTemplate);
31
+ return compiled(data, eta.defaultConfig);
42
32
  }
43
-
44
33
  export default async function render(locals) {
45
- try {
46
- return await doRender(locals);
47
- } catch (e) {
48
- logger.error`Docusaurus Node/SSR could not render static page with path path=${locals.path} because of following error:
34
+ try {
35
+ return await doRender(locals);
36
+ }
37
+ catch (e) {
38
+ logger.error `Docusaurus Node/SSR could not render static page with path path=${locals.path} because of following error:
49
39
  ${e.stack}`;
50
-
51
- const isNotDefinedErrorRegex =
52
- /(window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
53
-
54
- if (isNotDefinedErrorRegex.test(e.message)) {
55
- logger.info`It looks like you are using code that should run on the client-side only.
40
+ const isNotDefinedErrorRegex = /(window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
41
+ if (isNotDefinedErrorRegex.test(e.message)) {
42
+ logger.info `It looks like you are using code that should run on the client-side only.
56
43
  To get around it, try using code=${'<BrowserOnly>'} (path=${'https://docusaurus.io/docs/docusaurus-core/#browseronly'}) or code=${'ExecutionEnvironment'} (path=${'https://docusaurus.io/docs/docusaurus-core/#executionenvironment'}).
57
44
  It might also require to wrap your client code in code=${'useEffect'} hook and/or import a third-party library dynamically (if any).`;
45
+ }
46
+ throw new Error('Server-side rendering fails due to the error above.');
58
47
  }
59
-
60
- throw new Error('Server-side rendering fails due to the error above.');
61
- }
62
48
  }
63
-
64
49
  // Renderer for static-site-generator-webpack-plugin (async rendering via promises).
65
50
  async function doRender(locals) {
66
- const {
67
- routesLocation,
68
- headTags,
69
- preBodyTags,
70
- postBodyTags,
71
- onLinksCollected,
72
- baseUrl,
73
- ssrTemplate,
74
- noIndex,
75
- } = locals;
76
- const location = routesLocation[locals.path];
77
- await preload(routes, location);
78
- const modules = new Set();
79
- const context = {};
80
-
81
- const linksCollector = createStatefulLinksCollector();
82
- const appHtml = ReactDOMServer.renderToString(
83
- <Loadable.Capture report={(moduleName) => modules.add(moduleName)}>
84
- <StaticRouter location={location} context={context}>
85
- <ProvideLinksCollector linksCollector={linksCollector}>
86
- <App />
87
- </ProvideLinksCollector>
88
- </StaticRouter>
89
- </Loadable.Capture>,
90
- );
91
- onLinksCollected(location, linksCollector.getCollectedLinks());
92
-
93
- const helmet = Helmet.renderStatic();
94
- const htmlAttributes = helmet.htmlAttributes.toString();
95
- const bodyAttributes = helmet.bodyAttributes.toString();
96
- const metaStrings = [
97
- helmet.title.toString(),
98
- helmet.meta.toString(),
99
- helmet.link.toString(),
100
- helmet.script.toString(),
101
- ];
102
- const metaAttributes = metaStrings.filter(Boolean);
103
-
104
- const {generatedFilesDir} = locals;
105
- const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
106
- const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
107
-
108
- // Get all required assets for this particular page based on client
109
- // manifest information.
110
- const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
111
- const bundles = getBundles(manifest, modulesToBeLoaded);
112
- const stylesheets = (bundles.css || []).map((b) => b.file);
113
- const scripts = (bundles.js || []).map((b) => b.file);
114
-
115
- const renderedHtml = renderSSRTemplate(ssrTemplate, {
116
- appHtml,
117
- baseUrl,
118
- htmlAttributes: htmlAttributes || '',
119
- bodyAttributes: bodyAttributes || '',
120
- headTags,
121
- preBodyTags,
122
- postBodyTags,
123
- metaAttributes,
124
- scripts,
125
- stylesheets,
126
- noIndex,
127
- version: packageJson.version,
128
- });
129
-
130
- try {
131
- // Minify html with https://github.com/DanielRuf/html-minifier-terser
132
- return await minify(renderedHtml, {
133
- removeComments: false,
134
- removeRedundantAttributes: true,
135
- removeEmptyAttributes: true,
136
- removeScriptTypeAttributes: true,
137
- removeStyleLinkTypeAttributes: true,
138
- useShortDoctype: true,
139
- minifyJS: true,
51
+ const { routesLocation, headTags, preBodyTags, postBodyTags, onLinksCollected, baseUrl, ssrTemplate, noIndex, } = locals;
52
+ const location = routesLocation[locals.path];
53
+ await preload(routes, location);
54
+ const modules = new Set();
55
+ const context = {};
56
+ const linksCollector = createStatefulLinksCollector();
57
+ const appHtml = ReactDOMServer.renderToString(React.createElement(Loadable.Capture, { report: (moduleName) => modules.add(moduleName) },
58
+ React.createElement(StaticRouter, { location: location, context: context },
59
+ React.createElement(ProvideLinksCollector, { linksCollector: linksCollector },
60
+ React.createElement(App, null)))));
61
+ onLinksCollected(location, linksCollector.getCollectedLinks());
62
+ const helmet = Helmet.renderStatic();
63
+ const htmlAttributes = helmet.htmlAttributes.toString();
64
+ const bodyAttributes = helmet.bodyAttributes.toString();
65
+ const metaStrings = [
66
+ helmet.title.toString(),
67
+ helmet.meta.toString(),
68
+ helmet.link.toString(),
69
+ helmet.script.toString(),
70
+ ];
71
+ const metaAttributes = metaStrings.filter(Boolean);
72
+ const { generatedFilesDir } = locals;
73
+ const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
74
+ const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
75
+ // Get all required assets for this particular page based on client
76
+ // manifest information.
77
+ const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
78
+ const bundles = getBundles(manifest, modulesToBeLoaded);
79
+ const stylesheets = (bundles.css || []).map((b) => b.file);
80
+ const scripts = (bundles.js || []).map((b) => b.file);
81
+ const renderedHtml = renderSSRTemplate(ssrTemplate, {
82
+ appHtml,
83
+ baseUrl,
84
+ htmlAttributes: htmlAttributes || '',
85
+ bodyAttributes: bodyAttributes || '',
86
+ headTags,
87
+ preBodyTags,
88
+ postBodyTags,
89
+ metaAttributes,
90
+ scripts,
91
+ stylesheets,
92
+ noIndex,
93
+ version: packageJson.version,
140
94
  });
141
- } catch (e) {
142
- logger.error`Minification of page path=${locals.path} failed because of following error:
95
+ try {
96
+ // Minify html with https://github.com/DanielRuf/html-minifier-terser
97
+ return await minify(renderedHtml, {
98
+ removeComments: false,
99
+ removeRedundantAttributes: true,
100
+ removeEmptyAttributes: true,
101
+ removeScriptTypeAttributes: true,
102
+ removeStyleLinkTypeAttributes: true,
103
+ useShortDoctype: true,
104
+ minifyJS: true,
105
+ });
106
+ }
107
+ catch (e) {
108
+ logger.error `Minification of page path=${locals.path} failed because of following error:
143
109
  ${e.stack}`;
144
- throw e;
145
- }
110
+ throw e;
111
+ }
146
112
  }
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { BuildCLIOptions } from '@docusaurus/types';
7
+ import type { BuildCLIOptions } from '@docusaurus/types';
8
8
  export default function build(siteDir: string, cliOptions?: Partial<BuildCLIOptions>, forceTerminate?: boolean): Promise<string>;
@@ -23,7 +23,10 @@ const CleanWebpackPlugin_1 = (0, tslib_1.__importDefault)(require("../webpack/pl
23
23
  const i18n_1 = require("../server/i18n");
24
24
  const utils_2 = require("@docusaurus/utils");
25
25
  async function build(siteDir, cliOptions = {},
26
- // TODO what's the purpose of this arg ?
26
+ // When running build, we force terminate the process to prevent async
27
+ // operations from never returning. However, if run as part of docusaurus
28
+ // deploy, we have to let deploy finish.
29
+ // See https://github.com/facebook/docusaurus/pull/2496
27
30
  forceTerminate = true) {
28
31
  ['SIGINT', 'SIGTERM'].forEach((sig) => {
29
32
  process.on(sig, () => process.exit());
@@ -60,12 +63,12 @@ forceTerminate = true) {
60
63
  logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
61
64
  }
62
65
  // We need the default locale to always be the 1st in the list
63
- // If we build it last, it would "erase" the localized sites built in subfolders
66
+ // If we build it last, it would "erase" the localized sites built in sub-folders
64
67
  const orderedLocales = [
65
68
  i18n.defaultLocale,
66
69
  ...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
67
70
  ];
68
- const results = await (0, utils_2.mapAsyncSequencial)(orderedLocales, (locale) => {
71
+ const results = await (0, utils_2.mapAsyncSequential)(orderedLocales, (locale) => {
69
72
  const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
70
73
  return tryToBuildLocale({ locale, isLastLocale });
71
74
  });
@@ -90,7 +93,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
90
93
  plugins: [
91
94
  // Remove/clean build folders before building bundles.
92
95
  new CleanWebpackPlugin_1.default({ verbose: false }),
93
- // Visualize size of webpack output files with an interactive zoomable treemap.
96
+ // Visualize size of webpack output files with an interactive zoomable tree map.
94
97
  cliOptions.bundleAnalyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
95
98
  // Generate client manifests file that will be used for server bundle.
96
99
  new react_loadable_ssr_addon_v5_slorber_1.default({
@@ -123,9 +126,9 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
123
126
  clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss, clientConfig);
124
127
  }
125
128
  if (configureWebpack) {
126
- clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
129
+ clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
127
130
  clientConfig, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
128
- serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
131
+ serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
129
132
  serverConfig, true, (_b = props.siteConfig.webpack) === null || _b === void 0 ? void 0 : _b.jsLoader, plugin.content);
130
133
  }
131
134
  });
@@ -150,7 +153,8 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
150
153
  if (!plugin.postBuild) {
151
154
  return;
152
155
  }
153
- await plugin.postBuild(props);
156
+ // The plugin may reference `this`. We manually bind it again to prevent any bugs.
157
+ await plugin.postBuild({ ...props, content: plugin.content });
154
158
  }));
155
159
  await (0, brokenLinks_1.handleBrokenLinks)({
156
160
  allCollectedLinks,
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { HostPortCLIOptions } from '@docusaurus/types';
7
+ import type { HostPortCLIOptions } from '@docusaurus/types';
8
8
  export declare function getCLIOptionHost(hostOption: HostPortCLIOptions['host']): string;
9
9
  export declare function getCLIOptionPort(portOption: HostPortCLIOptions['port'], host: string): Promise<number | null>;
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { BuildCLIOptions } from '@docusaurus/types';
7
+ import type { BuildCLIOptions } from '@docusaurus/types';
8
8
  export declare function buildSshUrl(githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
9
9
  export declare function buildHttpsUrl(gitCredentials: string, githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
10
10
  export declare function hasSSHProtocol(sourceRepoUrl: string): boolean;
@@ -158,7 +158,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
158
158
  // the files in the directory. If the 'clone' command fails, assume that
159
159
  // the deployment branch doesn't exist, and initialize git in an empty
160
160
  // directory, check out a clean deployment branch and add remote.
161
- if (shellExecLog(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} ${toPath}`).code === 0) {
161
+ if (shellExecLog(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} "${toPath}"`).code === 0) {
162
162
  shellExecLog('git rm -rf .');
163
163
  }
164
164
  else {
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Command } from 'commander';
7
+ import type { Command } from 'commander';
8
8
  export default function externalCommand(cli: Command, siteDir: string): Promise<void>;
@@ -12,7 +12,7 @@ const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
12
12
  async function externalCommand(cli, siteDir) {
13
13
  const context = await (0, server_1.loadContext)(siteDir);
14
14
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
15
- const plugins = (0, init_1.default)({ pluginConfigs, context });
15
+ const plugins = await (0, init_1.default)({ pluginConfigs, context });
16
16
  // Plugin Lifecycle - extendCli.
17
17
  plugins.forEach((plugin) => {
18
18
  const { extendCli } = plugin;
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { ServeCLIOptions } from '@docusaurus/types';
7
+ import type { ServeCLIOptions } from '@docusaurus/types';
8
8
  export default function serve(siteDir: string, cliOptions: ServeCLIOptions): Promise<void>;
@@ -4,5 +4,5 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { StartCLIOptions } from '@docusaurus/types';
7
+ import type { StartCLIOptions } from '@docusaurus/types';
8
8
  export default function start(siteDir: string, cliOptions: Partial<StartCLIOptions>): Promise<void>;
@@ -101,7 +101,7 @@ async function start(siteDir, cliOptions) {
101
101
  plugins: [
102
102
  // Generates an `index.html` file with the <script> injected.
103
103
  new html_webpack_plugin_1.default({
104
- template: path_1.default.resolve(__dirname, '../client/templates/index.html.template.ejs'),
104
+ template: path_1.default.resolve(__dirname, '../webpack/templates/index.html.template.ejs'),
105
105
  // So we can define the position where the scripts are injected.
106
106
  inject: false,
107
107
  filename: 'index.html',
@@ -179,11 +179,10 @@ async function start(siteDir, cliOptions) {
179
179
  allowedHosts: 'all',
180
180
  host,
181
181
  port,
182
- onBeforeSetupMiddleware: (devServer) => {
182
+ setupMiddlewares: (middlewares, devServer) => {
183
183
  // This lets us fetch source contents from webpack for the error overlay.
184
- devServer.app.use((0, evalSourceMapMiddleware_1.default)(
185
- // @ts-expect-error: bad types
186
- devServer));
184
+ middlewares.unshift((0, evalSourceMapMiddleware_1.default)(devServer));
185
+ return middlewares;
187
186
  },
188
187
  };
189
188
  // Allow plugin authors to customize/override devServer config
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { PluginConfig } from '@docusaurus/types';
7
+ import type { PluginConfig } from '@docusaurus/types';
8
8
  export declare function getPluginNames(plugins: PluginConfig[]): string[];
9
9
  export default function swizzle(siteDir: string, themeName?: string, componentName?: string, typescript?: boolean, danger?: boolean): Promise<void>;
@@ -111,7 +111,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
111
111
  const context = await (0, server_1.loadContext)(siteDir);
112
112
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
113
113
  const pluginNames = getPluginNames(pluginConfigs);
114
- const plugins = (0, init_1.default)({
114
+ const plugins = await (0, init_1.default)({
115
115
  pluginConfigs,
116
116
  context,
117
117
  });
@@ -162,7 +162,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
162
162
  }
163
163
  // support both commonjs and ES style exports
164
164
  const plugin = (_c = pluginModule.default) !== null && _c !== void 0 ? _c : pluginModule;
165
- const pluginInstance = plugin(context, pluginOptions);
165
+ const pluginInstance = await plugin(context, pluginOptions);
166
166
  const themePath = typescript
167
167
  ? (_d = pluginInstance.getTypeScriptThemePath) === null || _d === void 0 ? void 0 : _d.call(pluginInstance)
168
168
  : (_e = pluginInstance.getThemePath) === null || _e === void 0 ? void 0 : _e.call(pluginInstance);
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Slugger } from '@docusaurus/utils';
7
+ import { type Slugger } from '@docusaurus/utils';
8
8
  declare type Options = {
9
9
  maintainCase?: boolean;
10
10
  overwrite?: boolean;
@@ -87,7 +87,7 @@ async function transformMarkdownFile(filepath, options) {
87
87
  async function getPathsToWatch(siteDir) {
88
88
  const context = await (0, server_1.loadContext)(siteDir);
89
89
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
90
- const plugins = (0, init_1.default)({
90
+ const plugins = await (0, init_1.default)({
91
91
  pluginConfigs,
92
92
  context,
93
93
  });