@docusaurus/core 2.0.0-beta.20 → 2.0.0-beta.21

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 (66) hide show
  1. package/bin/beforeCli.mjs +6 -4
  2. package/bin/docusaurus.mjs +9 -1
  3. package/lib/babel/preset.js +2 -1
  4. package/lib/client/App.js +5 -5
  5. package/lib/client/ClientLifecyclesDispatcher.js +1 -1
  6. package/lib/client/PendingNavigation.js +3 -1
  7. package/lib/client/SiteMetadataDefaults.js +4 -2
  8. package/lib/client/docusaurus.d.ts +1 -1
  9. package/lib/client/docusaurus.js +1 -1
  10. package/lib/client/exports/ComponentCreator.d.ts +5 -0
  11. package/lib/client/exports/ComponentCreator.js +14 -7
  12. package/lib/client/exports/ErrorBoundary.js +8 -7
  13. package/lib/client/exports/Link.d.ts +1 -1
  14. package/lib/client/exports/Link.js +1 -1
  15. package/lib/client/exports/isInternalUrl.js +1 -1
  16. package/lib/client/exports/useGlobalData.js +0 -3
  17. package/lib/client/prefetch.js +2 -2
  18. package/lib/client/preload.js +1 -3
  19. package/lib/client/serverEntry.js +23 -12
  20. package/lib/client/theme-fallback/Error/index.js +2 -2
  21. package/lib/client/theme-fallback/Loading/index.js +1 -1
  22. package/lib/client/theme-fallback/NotFound/index.js +1 -1
  23. package/lib/commands/build.js +9 -9
  24. package/lib/commands/deploy.js +13 -13
  25. package/lib/commands/serve.d.ts +2 -1
  26. package/lib/commands/serve.js +10 -5
  27. package/lib/commands/start.d.ts +1 -0
  28. package/lib/commands/start.js +6 -6
  29. package/lib/commands/swizzle/actions.js +6 -8
  30. package/lib/commands/swizzle/common.js +1 -1
  31. package/lib/commands/swizzle/components.js +1 -1
  32. package/lib/commands/swizzle/config.js +9 -8
  33. package/lib/commands/swizzle/prompts.js +8 -8
  34. package/lib/commands/swizzle/tables.js +1 -1
  35. package/lib/commands/swizzle/themes.js +3 -3
  36. package/lib/commands/writeHeadingIds.d.ts +1 -1
  37. package/lib/commands/writeHeadingIds.js +1 -1
  38. package/lib/server/brokenLinks.js +4 -4
  39. package/lib/server/config.js +17 -2
  40. package/lib/server/configValidation.d.ts +3 -3
  41. package/lib/server/configValidation.js +6 -5
  42. package/lib/server/getHostPort.js +3 -3
  43. package/lib/server/htmlTags.js +1 -1
  44. package/lib/server/i18n.js +1 -1
  45. package/lib/server/index.js +3 -3
  46. package/lib/server/plugins/configs.js +2 -2
  47. package/lib/server/plugins/index.js +3 -3
  48. package/lib/server/plugins/init.js +4 -4
  49. package/lib/server/plugins/routeConfig.d.ts +1 -1
  50. package/lib/server/plugins/routeConfig.js +2 -2
  51. package/lib/server/plugins/synthetic.js +1 -1
  52. package/lib/server/routes.js +2 -2
  53. package/lib/server/siteMetadata.js +1 -1
  54. package/lib/server/translations/translations.js +1 -1
  55. package/lib/server/translations/translationsExtractor.js +9 -11
  56. package/lib/server/utils.d.ts +1 -1
  57. package/lib/webpack/aliases/index.js +1 -1
  58. package/lib/webpack/base.js +11 -11
  59. package/lib/webpack/client.d.ts +1 -1
  60. package/lib/webpack/client.js +1 -1
  61. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +0 -19
  62. package/lib/webpack/plugins/CleanWebpackPlugin.js +26 -4
  63. package/lib/webpack/server.d.ts +2 -2
  64. package/lib/webpack/server.js +3 -3
  65. package/lib/webpack/utils.js +15 -17
  66. package/package.json +39 -36
package/bin/beforeCli.mjs CHANGED
@@ -7,16 +7,18 @@
7
7
 
8
8
  // @ts-check
9
9
 
10
- import logger from '@docusaurus/logger';
11
10
  import fs from 'fs-extra';
12
- import semver from 'semver';
13
11
  import path from 'path';
12
+ import {createRequire} from 'module';
13
+ import logger from '@docusaurus/logger';
14
+ import semver from 'semver';
14
15
  import updateNotifier from 'update-notifier';
15
16
  import boxen from 'boxen';
16
- import {createRequire} from 'module';
17
17
  import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
18
18
 
19
- const packageJson = createRequire(import.meta.url)('../package.json');
19
+ const packageJson = /** @type {import("../package.json")} */ (
20
+ createRequire(import.meta.url)('../package.json')
21
+ );
20
22
  /** @type {Record<string, any>} */
21
23
  let sitePkg;
22
24
  try {
@@ -8,8 +8,8 @@
8
8
 
9
9
  // @ts-check
10
10
 
11
- import logger from '@docusaurus/logger';
12
11
  import fs from 'fs-extra';
12
+ import logger from '@docusaurus/logger';
13
13
  import cli from 'commander';
14
14
  import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
15
15
  import {
@@ -126,6 +126,10 @@ cli
126
126
  '--poll [interval]',
127
127
  'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
128
128
  )
129
+ .option(
130
+ '--no-minify',
131
+ 'build website without minimizing JS bundles (default: false)',
132
+ )
129
133
  .action(async (siteDir, options) =>
130
134
  start(await resolveDir(siteDir), options),
131
135
  );
@@ -144,6 +148,10 @@ cli
144
148
  .option('-p, --port <port>', 'use specified port (default: 3000)')
145
149
  .option('--build', 'build website before serving (default: false)')
146
150
  .option('-h, --host <host>', 'use specified host (default: localhost)')
151
+ .option(
152
+ '--no-open',
153
+ 'do not open page in the browser (default: false, or true in CI)',
154
+ )
147
155
  .action(async (siteDir, options) =>
148
156
  serve(await resolveDir(siteDir), options),
149
157
  );
@@ -51,7 +51,8 @@ function getTransformOptions(isServer) {
51
51
  // better to explicitly specify the version so that it can reuse the
52
52
  // helper better. See https://github.com/babel/babel/issues/10261
53
53
  // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
54
- version: require('@babel/runtime/package.json').version,
54
+ version: require('@babel/runtime/package.json')
55
+ .version,
55
56
  regenerator: true,
56
57
  useESModules: true,
57
58
  // Undocumented option that lets us encapsulate our runtime, ensuring
package/lib/client/App.js CHANGED
@@ -8,22 +8,22 @@ import React from 'react';
8
8
  import '@generated/client-modules';
9
9
  import routes from '@generated/routes';
10
10
  import { useLocation } from '@docusaurus/router';
11
- import normalizeLocation from './normalizeLocation';
12
11
  import renderRoutes from '@docusaurus/renderRoutes';
12
+ import Root from '@theme/Root';
13
+ import SiteMetadata from '@theme/SiteMetadata';
14
+ import normalizeLocation from './normalizeLocation';
13
15
  import { BrowserContextProvider } from './browserContext';
14
16
  import { DocusaurusContextProvider } from './docusaurusContext';
15
17
  import PendingNavigation from './PendingNavigation';
16
18
  import BaseUrlIssueBanner from './BaseUrlIssueBanner';
17
19
  import SiteMetadataDefaults from './SiteMetadataDefaults';
18
- import Root from '@theme/Root';
19
- import SiteMetadata from '@theme/SiteMetadata';
20
20
  // TODO, quick fix for CSS insertion order
21
+ // eslint-disable-next-line import/order
21
22
  import ErrorBoundary from '@docusaurus/ErrorBoundary';
22
- import Error from '@theme/Error';
23
23
  export default function App() {
24
24
  const routeElement = renderRoutes(routes);
25
25
  const location = useLocation();
26
- return (<ErrorBoundary fallback={Error}>
26
+ return (<ErrorBoundary>
27
27
  <DocusaurusContextProvider>
28
28
  <BrowserContextProvider>
29
29
  <Root>
@@ -8,7 +8,7 @@ import { useLayoutEffect } from 'react';
8
8
  import clientModules from '@generated/client-modules';
9
9
  export function dispatchLifecycleAction(lifecycleAction, ...args) {
10
10
  const callbacks = clientModules.map((clientModule) => {
11
- const lifecycleFunction = (clientModule?.default?.[lifecycleAction] ??
11
+ const lifecycleFunction = (clientModule.default?.[lifecycleAction] ??
12
12
  clientModule[lifecycleAction]);
13
13
  return lifecycleFunction?.(...args);
14
14
  });
@@ -10,6 +10,8 @@ import ClientLifecyclesDispatcher, { dispatchLifecycleAction, } from './ClientLi
10
10
  import ExecutionEnvironment from './exports/ExecutionEnvironment';
11
11
  import preload from './preload';
12
12
  class PendingNavigation extends React.Component {
13
+ previousLocation;
14
+ routeUpdateCleanupCb;
13
15
  constructor(props) {
14
16
  super(props);
15
17
  // previousLocation doesn't affect rendering, hence not stored in state.
@@ -47,7 +49,7 @@ class PendingNavigation extends React.Component {
47
49
  // user is on saveData
48
50
  preload(nextLocation.pathname)
49
51
  .then(() => {
50
- this.routeUpdateCleanupCb?.();
52
+ this.routeUpdateCleanupCb();
51
53
  this.setState({ nextRouteHasLoaded: true });
52
54
  })
53
55
  .catch((e) => console.warn(e));
@@ -9,11 +9,13 @@ import Head from '@docusaurus/Head';
9
9
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
10
  import useBaseUrl from '@docusaurus/useBaseUrl';
11
11
  export default function SiteMetadataDefaults() {
12
- const { siteConfig: { favicon, tagline, title }, i18n: { currentLocale, localeConfigs }, } = useDocusaurusContext();
12
+ const { siteConfig: { favicon, title }, i18n: { currentLocale, localeConfigs }, } = useDocusaurusContext();
13
13
  const faviconUrl = useBaseUrl(favicon);
14
14
  const { htmlLang, direction: htmlDir } = localeConfigs[currentLocale];
15
- return (<Head defaultTitle={`${title}${tagline ? ` · ${tagline}` : ''}`}>
15
+ return (<Head>
16
16
  <html lang={htmlLang} dir={htmlDir}/>
17
+ <title>{title}</title>
18
+ <meta property="og:title" content={title}/>
17
19
  {favicon && <link rel="icon" href={faviconUrl}/>}
18
20
  </Head>);
19
21
  }
@@ -9,7 +9,7 @@ declare global {
9
9
  gca: (name: string) => string;
10
10
  };
11
11
  interface Navigator {
12
- connection: {
12
+ connection?: {
13
13
  effectiveType: string;
14
14
  saveData: boolean;
15
15
  };
@@ -42,7 +42,7 @@ const docusaurus = {
42
42
  // In some cases, webpack might decide to optimize further, leading to
43
43
  // the chunk assets being merged to another chunk. In this case, we can
44
44
  // safely filter it out and don't need to load it.
45
- if (chunkAsset && !/undefined/.test(chunkAsset)) {
45
+ if (chunkAsset && !chunkAsset.includes('undefined')) {
46
46
  return prefetchHelper(chunkAsset);
47
47
  }
48
48
  return Promise.resolve();
@@ -5,4 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import Loadable from 'react-loadable';
8
+ declare global {
9
+ interface NodeRequire {
10
+ resolveWeak: (name: string) => number;
11
+ }
12
+ }
8
13
  export default function ComponentCreator(path: string, hash: string): ReturnType<typeof Loadable>;
@@ -6,9 +6,9 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import Loadable from 'react-loadable';
9
- import Loading from '@theme/Loading';
10
9
  import routesChunkNames from '@generated/routesChunkNames';
11
10
  import registry from '@generated/registry';
11
+ import Loading from '@theme/Loading';
12
12
  import flat from '../flat';
13
13
  import { RouteContextProvider } from '../routeContext';
14
14
  export default function ComponentCreator(path, hash) {
@@ -16,11 +16,17 @@ export default function ComponentCreator(path, hash) {
16
16
  if (path === '*') {
17
17
  return Loadable({
18
18
  loading: Loading,
19
- loader: () => import('@theme/NotFound').then(({ default: NotFound }) => (props) => (<RouteContextProvider
20
- // Do we want a better name than native-default?
21
- value={{ plugin: { name: 'native', id: 'default' } }}>
19
+ loader: () => import('@theme/NotFound'),
20
+ modules: ['@theme/NotFound'],
21
+ webpack: () => [require.resolveWeak('@theme/NotFound')],
22
+ render(loaded, props) {
23
+ const NotFound = loaded.default;
24
+ return (<RouteContextProvider
25
+ // Do we want a better name than native-default?
26
+ value={{ plugin: { name: 'native', id: 'default' } }}>
22
27
  <NotFound {...props}/>
23
- </RouteContextProvider>)),
28
+ </RouteContextProvider>);
29
+ },
24
30
  });
25
31
  }
26
32
  const chunkNames = routesChunkNames[`${path}-${hash}`];
@@ -49,7 +55,7 @@ export default function ComponentCreator(path, hash) {
49
55
  loader,
50
56
  modules,
51
57
  webpack: () => optsWebpack,
52
- render: (loaded, props) => {
58
+ render(loaded, props) {
53
59
  // `loaded` will be a map from key path (as returned from the flattened
54
60
  // chunk names) to the modules loaded from the loaders. We now have to
55
61
  // restore the chunk names' previous shape from this flat record.
@@ -76,7 +82,8 @@ export default function ComponentCreator(path, hash) {
76
82
  Object.keys(loadedModule)
77
83
  .filter((k) => k !== 'default')
78
84
  .forEach((nonDefaultKey) => {
79
- chunk[nonDefaultKey] = loadedModule[nonDefaultKey];
85
+ chunk[nonDefaultKey] =
86
+ loadedModule[nonDefaultKey];
80
87
  });
81
88
  }
82
89
  // We now have this chunk prepared. Go down the key path and replace the
@@ -6,7 +6,8 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
- import DefaultFallback from '@theme/Error';
9
+ import ThemeError from '@theme/Error';
10
+ const DefaultFallback = (params) => (<ThemeError {...params}/>);
10
11
  export default class ErrorBoundary extends React.Component {
11
12
  constructor(props) {
12
13
  super(props);
@@ -22,14 +23,14 @@ export default class ErrorBoundary extends React.Component {
22
23
  const { children } = this.props;
23
24
  const { error } = this.state;
24
25
  if (error) {
25
- const fallback = this.props.fallback ?? DefaultFallback;
26
- return fallback({
26
+ const fallbackParams = {
27
27
  error,
28
28
  tryAgain: () => this.setState({ error: null }),
29
- });
29
+ };
30
+ const fallback = this.props.fallback ?? DefaultFallback;
31
+ return fallback(fallbackParams);
30
32
  }
31
- return (children ??
32
- // See https://github.com/facebook/docusaurus/issues/6337#issuecomment-1012913647
33
- null);
33
+ // See https://github.com/facebook/docusaurus/issues/6337#issuecomment-1012913647
34
+ return children ?? null;
34
35
  }
35
36
  }
@@ -7,5 +7,5 @@
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
8
  import React from 'react';
9
9
  import type { Props } from '@docusaurus/Link';
10
- declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "replace" | "slot" | "style" | "title" | "location" | "component" | "exact" | "sensitive" | "strict" | "type" | "key" | "id" | "lang" | "dir" | "rel" | "href" | "isNavLink" | "className" | "to" | "innerRef" | "download" | "hrefLang" | "media" | "ping" | "target" | "referrerPolicy" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "activeClassName" | "activeStyle" | "isActive" | "data-noBrokenLinkCheck" | "autoAddBaseUrl"> & React.RefAttributes<HTMLAnchorElement>>;
10
+ declare const _default: React.ForwardRefExoticComponent<Pick<Props, "location" | "children" | "replace" | "slot" | "style" | "title" | "component" | "exact" | "sensitive" | "strict" | "type" | "key" | "id" | "lang" | "dir" | "property" | "rel" | "href" | "isNavLink" | "className" | "to" | "innerRef" | "download" | "hrefLang" | "media" | "ping" | "target" | "referrerPolicy" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "activeClassName" | "activeStyle" | "isActive" | "data-noBrokenLinkCheck" | "autoAddBaseUrl"> & React.RefAttributes<HTMLAnchorElement>>;
11
11
  export default _default;
@@ -6,12 +6,12 @@
6
6
  */
7
7
  import React, { useEffect, useImperativeHandle, useRef, } from 'react';
8
8
  import { NavLink, Link as RRLink } from 'react-router-dom';
9
+ import { applyTrailingSlash } from '@docusaurus/utils-common';
9
10
  import useDocusaurusContext from './useDocusaurusContext';
10
11
  import isInternalUrl from './isInternalUrl';
11
12
  import ExecutionEnvironment from './ExecutionEnvironment';
12
13
  import { useLinksCollector } from '../LinksCollector';
13
14
  import { useBaseUrlUtils } from './useBaseUrl';
14
- import { applyTrailingSlash } from '@docusaurus/utils-common';
15
15
  // TODO all this wouldn't be necessary if we used ReactRouter basename feature
16
16
  // We don't automatically add base urls to all links,
17
17
  // only the "safe" ones, starting with / (like /docs/introduction)
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export function hasProtocol(url) {
8
- return /^(?:\w*:|\/\/)/.test(url) === true;
8
+ return /^(?:\w*:|\/\/)/.test(url);
9
9
  }
10
10
  export default function isInternalUrl(url) {
11
11
  return typeof url !== 'undefined' && !hasProtocol(url);
@@ -8,9 +8,6 @@ import useDocusaurusContext from './useDocusaurusContext';
8
8
  import { DEFAULT_PLUGIN_ID } from './constants';
9
9
  export default function useGlobalData() {
10
10
  const { globalData } = useDocusaurusContext();
11
- if (!globalData) {
12
- throw new Error('Docusaurus global data not found.');
13
- }
14
11
  return globalData;
15
12
  }
16
13
  export function useAllPluginInstancesData(pluginName, options = {}) {
@@ -7,9 +7,9 @@
7
7
  function supports(feature) {
8
8
  try {
9
9
  const fakeLink = document.createElement('link');
10
- return fakeLink.relList?.supports?.(feature);
10
+ return fakeLink.relList.supports(feature);
11
11
  }
12
- catch (err) {
12
+ catch {
13
13
  return false;
14
14
  }
15
15
  }
@@ -16,7 +16,5 @@ import { matchRoutes } from 'react-router-config';
16
16
  */
17
17
  export default function preload(pathname) {
18
18
  const matches = matchRoutes(routes, pathname);
19
- return Promise.all(
20
- // @ts-expect-error: ComponentCreator injected this method.
21
- matches.map((match) => match.route.component?.preload?.()));
19
+ return Promise.all(matches.map((match) => match.route.component.preload?.()));
22
20
  }
@@ -4,22 +4,22 @@
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 * as eta from 'eta';
8
7
  import React from 'react';
8
+ import path from 'path';
9
+ import fs from 'fs-extra';
10
+ // eslint-disable-next-line no-restricted-imports
11
+ import _ from 'lodash';
12
+ import chalk from 'chalk';
13
+ import * as eta from 'eta';
9
14
  import { StaticRouter } from 'react-router-dom';
10
15
  import ReactDOMServer from 'react-dom/server';
11
16
  import { HelmetProvider } from 'react-helmet-async';
12
17
  import { getBundles } from 'react-loadable-ssr-addon-v5-slorber';
13
18
  import Loadable from 'react-loadable';
14
19
  import { minify } from 'html-minifier-terser';
15
- import path from 'path';
16
- import fs from 'fs-extra';
17
20
  import preload from './preload';
18
21
  import App from './App';
19
22
  import { createStatefulLinksCollector, LinksCollectorProvider, } from './LinksCollector';
20
- import logger from '@docusaurus/logger';
21
- // eslint-disable-next-line no-restricted-imports
22
- import _ from 'lodash';
23
23
  const getCompiledSSRTemplate = _.memoize((template) => eta.compile(template.trim(), {
24
24
  rmWhitespace: true,
25
25
  }));
@@ -32,12 +32,17 @@ export default async function render(locals) {
32
32
  return await doRender(locals);
33
33
  }
34
34
  catch (err) {
35
- logger.error `Docusaurus server-side rendering could not render static page with path path=${locals.path}.`;
35
+ // We are not using logger in this file, because it seems to fail with some
36
+ // compilers / some polyfill methods. This is very likely a bug, but in the
37
+ // long term, when we output native ES modules in SSR, the bug will be gone.
38
+ // prettier-ignore
39
+ console.error(chalk.red(`${chalk.bold('[ERROR]')} Docusaurus server-side rendering could not render static page with path ${chalk.cyan.underline(locals.path)}.`));
36
40
  const isNotDefinedErrorRegex = /(?:window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
37
41
  if (isNotDefinedErrorRegex.test(err.message)) {
38
- logger.info `It looks like you are using code that should run on the client-side only.
39
- To get around it, try using code=${'<BrowserOnly>'} (url=${'https://docusaurus.io/docs/docusaurus-core/#browseronly'}) or code=${'ExecutionEnvironment'} (url=${'https://docusaurus.io/docs/docusaurus-core/#executionenvironment'}).
40
- It might also require to wrap your client code in code=${'useEffect'} hook and/or import a third-party library dynamically (if any).`;
42
+ // prettier-ignore
43
+ console.info(`${chalk.cyan.bold('[INFO]')} It looks like you are using code that should run on the client-side only.
44
+ To get around it, try using ${chalk.cyan('`<BrowserOnly>`')} (${chalk.cyan.underline('https://docusaurus.io/docs/docusaurus-core/#browseronly')}) or ${chalk.cyan('`ExecutionEnvironment`')} (${chalk.cyan.underline('https://docusaurus.io/docs/docusaurus-core/#executionenvironment')}).
45
+ It might also require to wrap your client code in ${chalk.cyan('`useEffect`')} hook and/or import a third-party library dynamically (if any).`);
41
46
  }
42
47
  throw err;
43
48
  }
@@ -76,7 +81,12 @@ async function doRender(locals) {
76
81
  const metaAttributes = metaStrings.filter(Boolean);
77
82
  const { generatedFilesDir } = locals;
78
83
  const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
79
- const manifest = await fs.readJSON(manifestPath);
84
+ // Using readJSON seems to fail for users of some plugins, possibly because of
85
+ // the eval sandbox having a different `Buffer` instance (native one instead
86
+ // of polyfilled one)
87
+ const manifest = (await fs
88
+ .readFile(manifestPath, 'utf-8')
89
+ .then(JSON.parse));
80
90
  // Get all required assets for this particular page based on client
81
91
  // manifest information.
82
92
  const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
@@ -110,7 +120,8 @@ async function doRender(locals) {
110
120
  });
111
121
  }
112
122
  catch (err) {
113
- logger.error `Minification of page path=${locals.path} failed.`;
123
+ // prettier-ignore
124
+ console.error(chalk.red(`${chalk.bold('[ERROR]')} Minification of page ${chalk.cyan.underline(locals.path)} failed.`));
114
125
  throw err;
115
126
  }
116
127
  }
@@ -7,9 +7,9 @@
7
7
  // Should we translate theme-fallback?
8
8
  /* eslint-disable @docusaurus/no-untranslated-text */
9
9
  import React from 'react';
10
- import Layout from '@theme/Layout';
11
- import ErrorBoundary from '@docusaurus/ErrorBoundary';
12
10
  import Head from '@docusaurus/Head';
11
+ import ErrorBoundary from '@docusaurus/ErrorBoundary';
12
+ import Layout from '@theme/Layout';
13
13
  function ErrorDisplay({ error, tryAgain }) {
14
14
  return (<div style={{
15
15
  display: 'flex',
@@ -27,7 +27,7 @@ export default function Loading({ error, retry, pastDelay, }) {
27
27
  maxWidth: '50%',
28
28
  width: '100%',
29
29
  }}>
30
- <p>{error.message}</p>
30
+ <p>{String(error)}</p>
31
31
  <div>
32
32
  <button type="button" onClick={retry}>
33
33
  Retry
@@ -7,8 +7,8 @@
7
7
  // Should we translate theme-fallback?
8
8
  /* eslint-disable @docusaurus/no-untranslated-text */
9
9
  import React from 'react';
10
- import Layout from '@theme/Layout';
11
10
  import Head from '@docusaurus/Head';
11
+ import Layout from '@theme/Layout';
12
12
  export default function NotFound() {
13
13
  return (<>
14
14
  <Head>
@@ -8,10 +8,11 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.build = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
- const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
13
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
14
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
15
16
  const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
16
17
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
17
18
  const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
@@ -19,10 +20,9 @@ const server_1 = require("../server");
19
20
  const brokenLinks_1 = require("../server/brokenLinks");
20
21
  const client_1 = tslib_1.__importDefault(require("../webpack/client"));
21
22
  const server_2 = tslib_1.__importDefault(require("../webpack/server"));
22
- const utils_1 = require("../webpack/utils");
23
+ const utils_2 = require("../webpack/utils");
23
24
  const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("../webpack/plugins/CleanWebpackPlugin"));
24
25
  const i18n_1 = require("../server/i18n");
25
- const utils_2 = require("@docusaurus/utils");
26
26
  async function build(siteDir, cliOptions,
27
27
  // When running build, we force terminate the process to prevent async
28
28
  // operations from never returning. However, if run as part of docusaurus
@@ -69,7 +69,7 @@ forceTerminate = true) {
69
69
  i18n.defaultLocale,
70
70
  ...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
71
71
  ];
72
- const results = await (0, utils_2.mapAsyncSequential)(orderedLocales, (locale) => {
72
+ const results = await (0, utils_1.mapAsyncSequential)(orderedLocales, (locale) => {
73
73
  const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
74
74
  return tryToBuildLocale({ locale, isLastLocale });
75
75
  });
@@ -139,12 +139,12 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
139
139
  plugins.forEach((plugin) => {
140
140
  const { configureWebpack, configurePostCss } = plugin;
141
141
  if (configurePostCss) {
142
- clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss.bind(plugin), clientConfig);
142
+ clientConfig = (0, utils_2.applyConfigurePostCss)(configurePostCss.bind(plugin), clientConfig);
143
143
  }
144
144
  if (configureWebpack) {
145
- clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
145
+ clientConfig = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
146
146
  clientConfig, false, props.siteConfig.webpack?.jsLoader, plugin.content);
147
- serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
147
+ serverConfig = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
148
148
  serverConfig, true, props.siteConfig.webpack?.jsLoader, plugin.content);
149
149
  }
150
150
  });
@@ -154,7 +154,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
154
154
  await fs_extra_1.default.unlink(clientManifestPath);
155
155
  }
156
156
  // Run webpack to build JS bundle (client) and static html files (server).
157
- await (0, utils_1.compile)([clientConfig, serverConfig]);
157
+ await (0, utils_2.compile)([clientConfig, serverConfig]);
158
158
  // Remove server.bundle.js because it is not needed.
159
159
  if (typeof serverConfig.output?.filename === 'string') {
160
160
  const serverBundle = path_1.default.join(outDir, serverConfig.output.filename);
@@ -9,13 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.deploy = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const os_1 = tslib_1.__importDefault(require("os"));
13
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
14
16
  const utils_1 = require("@docusaurus/utils");
15
17
  const server_1 = require("../server");
16
18
  const build_1 = require("./build");
17
- const path_1 = tslib_1.__importDefault(require("path"));
18
- const os_1 = tslib_1.__importDefault(require("os"));
19
19
  // GIT_PASS env variable should not appear in logs
20
20
  function obfuscateGitPass(str) {
21
21
  const gitPass = process.env.GIT_PASS;
@@ -55,7 +55,7 @@ This behavior can have SEO impacts and create relative link issues.
55
55
  .exec('git config --get remote.origin.url', { silent: true })
56
56
  .stdout.trim();
57
57
  // The source branch; defaults to the currently checked out branch
58
- const sourceBranch = process.env.CURRENT_BRANCH ||
58
+ const sourceBranch = process.env.CURRENT_BRANCH ??
59
59
  shelljs_1.default.exec('git rev-parse --abbrev-ref HEAD', { silent: true }).stdout.trim();
60
60
  const gitUser = process.env.GIT_USER;
61
61
  let useSSH = process.env.USE_SSH !== undefined &&
@@ -69,22 +69,22 @@ This behavior can have SEO impacts and create relative link issues.
69
69
  throw new Error('Please set the GIT_USER environment variable, or explicitly specify USE_SSH instead!');
70
70
  }
71
71
  }
72
- const organizationName = process.env.ORGANIZATION_NAME ||
73
- process.env.CIRCLE_PROJECT_USERNAME ||
72
+ const organizationName = process.env.ORGANIZATION_NAME ??
73
+ process.env.CIRCLE_PROJECT_USERNAME ??
74
74
  siteConfig.organizationName;
75
75
  if (!organizationName) {
76
76
  throw new Error(`Missing project organization name. Did you forget to define "organizationName" in ${siteConfigPath}? You may also export it via the ORGANIZATION_NAME environment variable.`);
77
77
  }
78
78
  logger_1.default.info `organizationName: name=${organizationName}`;
79
- const projectName = process.env.PROJECT_NAME ||
80
- process.env.CIRCLE_PROJECT_REPONAME ||
79
+ const projectName = process.env.PROJECT_NAME ??
80
+ process.env.CIRCLE_PROJECT_REPONAME ??
81
81
  siteConfig.projectName;
82
82
  if (!projectName) {
83
83
  throw new Error(`Missing project name. Did you forget to define "projectName" in ${siteConfigPath}? You may also export it via the PROJECT_NAME environment variable.`);
84
84
  }
85
85
  logger_1.default.info `projectName: name=${projectName}`;
86
86
  // We never deploy on pull request.
87
- const isPullRequest = process.env.CI_PULL_REQUEST || process.env.CIRCLE_PULL_REQUEST;
87
+ const isPullRequest = process.env.CI_PULL_REQUEST ?? process.env.CIRCLE_PULL_REQUEST;
88
88
  if (isPullRequest) {
89
89
  shelljs_1.default.echo('Skipping deploy on a pull request.');
90
90
  shelljs_1.default.exit(0);
@@ -102,10 +102,10 @@ This behavior can have SEO impacts and create relative link issues.
102
102
  Please provide the branch name to deploy to as an environment variable, for example DEPLOYMENT_BRANCH=main or DEPLOYMENT_BRANCH=master .
103
103
  You can also set the deploymentBranch property in docusaurus.config.js .`);
104
104
  }
105
- const deploymentBranch = process.env.DEPLOYMENT_BRANCH || siteConfig.deploymentBranch || 'gh-pages';
105
+ const deploymentBranch = process.env.DEPLOYMENT_BRANCH ?? siteConfig.deploymentBranch ?? 'gh-pages';
106
106
  logger_1.default.info `deploymentBranch: name=${deploymentBranch}`;
107
- const githubHost = process.env.GITHUB_HOST || siteConfig.githubHost || 'github.com';
108
- const githubPort = process.env.GITHUB_PORT || siteConfig.githubPort;
107
+ const githubHost = process.env.GITHUB_HOST ?? siteConfig.githubHost ?? 'github.com';
108
+ const githubPort = process.env.GITHUB_PORT ?? siteConfig.githubPort;
109
109
  let deploymentRepoURL;
110
110
  if (useSSH) {
111
111
  deploymentRepoURL = (0, utils_1.buildSshUrl)(githubHost, organizationName, projectName, githubPort);
@@ -150,7 +150,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
150
150
  throw err;
151
151
  }
152
152
  shellExecLog('git add --all');
153
- const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ||
153
+ const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ??
154
154
  `Deploy website - based on ${currentCommit}`;
155
155
  const commitResults = shellExecLog(`git commit -m "${commitMessage}"`);
156
156
  if (shellExecLog(`git push --force origin ${deploymentBranch}`).code !== 0) {
@@ -4,10 +4,11 @@
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 type { LoadContextOptions } from '../server';
8
7
  import { type HostPortOptions } from '../server/getHostPort';
8
+ import type { LoadContextOptions } from '../server';
9
9
  export declare type ServeCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'config'> & {
10
10
  dir?: string;
11
11
  build?: boolean;
12
+ open?: boolean;
12
13
  };
13
14
  export declare function serve(siteDir: string, cliOptions: Partial<ServeCLIOptions>): Promise<void>;