@docusaurus/core 0.0.0-5858 → 0.0.0-5860

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 (44) hide show
  1. package/lib/commands/build.d.ts +2 -2
  2. package/lib/commands/build.js +6 -6
  3. package/lib/commands/deploy.d.ts +2 -2
  4. package/lib/commands/deploy.js +2 -2
  5. package/lib/commands/external.js +2 -2
  6. package/lib/commands/serve.d.ts +2 -2
  7. package/lib/commands/{start.d.ts → start/start.d.ts} +3 -3
  8. package/lib/commands/start/start.js +47 -0
  9. package/lib/commands/start/utils.d.ts +31 -0
  10. package/lib/commands/start/utils.js +88 -0
  11. package/lib/commands/start/watcher.d.ts +42 -0
  12. package/lib/commands/start/watcher.js +78 -0
  13. package/lib/commands/start/webpack.d.ts +15 -0
  14. package/lib/commands/start/webpack.js +133 -0
  15. package/lib/commands/swizzle/context.js +2 -2
  16. package/lib/commands/writeHeadingIds.js +2 -2
  17. package/lib/commands/writeTranslations.d.ts +2 -2
  18. package/lib/commands/writeTranslations.js +2 -2
  19. package/lib/index.d.ts +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/server/brokenLinks.js +2 -2
  22. package/lib/server/codegen/codegen.d.ts +20 -0
  23. package/lib/server/codegen/codegen.js +65 -0
  24. package/lib/server/codegen/codegenRoutes.d.ts +49 -0
  25. package/lib/server/codegen/codegenRoutes.js +190 -0
  26. package/lib/server/i18n.d.ts +2 -2
  27. package/lib/server/plugins/{index.d.ts → plugins.d.ts} +15 -4
  28. package/lib/server/plugins/plugins.js +176 -0
  29. package/lib/server/plugins/routeConfig.d.ts +1 -1
  30. package/lib/server/plugins/routeConfig.js +4 -4
  31. package/lib/server/routes.d.ts +4 -45
  32. package/lib/server/routes.js +15 -166
  33. package/lib/server/{index.d.ts → site.d.ts} +12 -4
  34. package/lib/server/site.js +167 -0
  35. package/lib/server/translations/translations.d.ts +3 -0
  36. package/lib/server/translations/translations.js +7 -1
  37. package/lib/server/utils.d.ts +0 -2
  38. package/lib/server/utils.js +1 -9
  39. package/lib/utils.d.ts +1 -0
  40. package/lib/utils.js +14 -3
  41. package/package.json +10 -10
  42. package/lib/commands/start.js +0 -242
  43. package/lib/server/index.js +0 -154
  44. package/lib/server/plugins/index.js +0 -106
@@ -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 { type LoadContextOptions } from '../server';
8
- export type BuildCLIOptions = Pick<LoadContextOptions, 'config' | 'locale' | 'outDir'> & {
7
+ import { type LoadContextParams } from '../server/site';
8
+ export type BuildCLIOptions = Pick<LoadContextParams, 'config' | 'locale' | 'outDir'> & {
9
9
  bundleAnalyzer?: boolean;
10
10
  minify?: boolean;
11
11
  dev?: boolean;
@@ -13,10 +13,10 @@ const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const utils_1 = require("@docusaurus/utils");
16
- const server_1 = require("../server");
16
+ const site_1 = require("../server/site");
17
17
  const brokenLinks_1 = require("../server/brokenLinks");
18
18
  const client_1 = require("../webpack/client");
19
- const server_2 = tslib_1.__importDefault(require("../webpack/server"));
19
+ const server_1 = tslib_1.__importDefault(require("../webpack/server"));
20
20
  const utils_2 = require("../webpack/utils");
21
21
  const utils_3 = require("../utils");
22
22
  const i18n_1 = require("../server/i18n");
@@ -77,7 +77,7 @@ async function getLocalesToBuild({ siteDir, cliOptions, }) {
77
77
  if (cliOptions.locale) {
78
78
  return [cliOptions.locale];
79
79
  }
80
- const context = await (0, server_1.loadContext)({
80
+ const context = await (0, site_1.loadContext)({
81
81
  siteDir,
82
82
  outDir: cliOptions.outDir,
83
83
  config: cliOptions.config,
@@ -104,7 +104,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
104
104
  process.env.DOCUSAURUS_CURRENT_LOCALE = locale;
105
105
  logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
106
106
  utils_3.PerfLogger.start('Loading site');
107
- const props = await (0, server_1.load)({
107
+ const site = await (0, site_1.loadSite)({
108
108
  siteDir,
109
109
  outDir: cliOptions.outDir,
110
110
  config: cliOptions.config,
@@ -112,7 +112,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
112
112
  localizePath: cliOptions.locale ? false : undefined,
113
113
  });
114
114
  utils_3.PerfLogger.end('Loading site');
115
- // Apply user webpack config.
115
+ const { props } = site;
116
116
  const { outDir, plugins } = props;
117
117
  // We can build the 2 configs in parallel
118
118
  utils_3.PerfLogger.start('Creating webpack configs');
@@ -239,7 +239,7 @@ async function getBuildClientConfig({ props, cliOptions, }) {
239
239
  }
240
240
  async function getBuildServerConfig({ props }) {
241
241
  const { plugins } = props;
242
- const result = await (0, server_2.default)({
242
+ const result = await (0, server_1.default)({
243
243
  props,
244
244
  });
245
245
  let { config } = result;
@@ -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 { type LoadContextOptions } from '../server';
8
- export type DeployCLIOptions = Pick<LoadContextOptions, 'config' | 'locale' | 'outDir'> & {
7
+ import { type LoadContextParams } from '../server/site';
8
+ export type DeployCLIOptions = Pick<LoadContextParams, 'config' | 'locale' | 'outDir'> & {
9
9
  skipBuild?: boolean;
10
10
  };
11
11
  export declare function deploy(siteDirParam?: string, cliOptions?: Partial<DeployCLIOptions>): Promise<void>;
@@ -14,7 +14,7 @@ const os_1 = tslib_1.__importDefault(require("os"));
14
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
16
16
  const utils_1 = require("@docusaurus/utils");
17
- const server_1 = require("../server");
17
+ const site_1 = require("../server/site");
18
18
  const build_1 = require("./build");
19
19
  // GIT_PASS env variable should not appear in logs
20
20
  function obfuscateGitPass(str) {
@@ -36,7 +36,7 @@ function shellExecLog(cmd) {
36
36
  }
37
37
  async function deploy(siteDirParam = '.', cliOptions = {}) {
38
38
  const siteDir = await fs_extra_1.default.realpath(siteDirParam);
39
- const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)({
39
+ const { outDir, siteConfig, siteConfigPath } = await (0, site_1.loadContext)({
40
40
  siteDir,
41
41
  config: cliOptions.config,
42
42
  outDir: cliOptions.outDir,
@@ -9,11 +9,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.externalCommand = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const server_1 = require("../server");
12
+ const site_1 = require("../server/site");
13
13
  const init_1 = require("../server/plugins/init");
14
14
  async function externalCommand(cli) {
15
15
  const siteDir = await fs_extra_1.default.realpath('.');
16
- const context = await (0, server_1.loadContext)({ siteDir });
16
+ const context = await (0, site_1.loadContext)({ siteDir });
17
17
  const plugins = await (0, init_1.initPlugins)(context);
18
18
  // Plugin Lifecycle - extendCli.
19
19
  plugins.forEach((plugin) => {
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type HostPortOptions } from '../server/getHostPort';
8
- import type { LoadContextOptions } from '../server';
9
- export type ServeCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'config'> & {
8
+ import type { LoadContextParams } from '../server/site';
9
+ export type ServeCLIOptions = HostPortOptions & Pick<LoadContextParams, 'config'> & {
10
10
  dir?: string;
11
11
  build?: boolean;
12
12
  open?: boolean;
@@ -4,9 +4,9 @@
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
- import { type HostPortOptions } from '../server/getHostPort';
9
- export type StartCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'locale' | 'config'> & {
7
+ import type { LoadContextParams } from '../../server/site';
8
+ import type { HostPortOptions } from '../../server/getHostPort';
9
+ export type StartCLIOptions = HostPortOptions & Pick<LoadContextParams, 'locale' | 'config'> & {
10
10
  hotOnly?: boolean;
11
11
  open?: boolean;
12
12
  poll?: boolean | number;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.start = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
+ const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
13
+ const watcher_1 = require("./watcher");
14
+ const webpack_1 = require("./webpack");
15
+ const utils_1 = require("./utils");
16
+ async function start(siteDirParam = '.', cliOptions = {}) {
17
+ logger_1.default.info('Starting the development server...');
18
+ // Temporary workaround to unlock the ability to translate the site config
19
+ // We'll remove it if a better official API can be designed
20
+ // See https://github.com/facebook/docusaurus/issues/4542
21
+ process.env.DOCUSAURUS_CURRENT_LOCALE = cliOptions.locale;
22
+ const reloadableSite = await (0, utils_1.createReloadableSite)({ siteDirParam, cliOptions });
23
+ (0, watcher_1.setupSiteFileWatchers)({ props: reloadableSite.get().props, cliOptions }, ({ plugin }) => {
24
+ if (plugin) {
25
+ reloadableSite.reloadPlugin(plugin);
26
+ }
27
+ else {
28
+ reloadableSite.reload();
29
+ }
30
+ });
31
+ const devServer = await (0, webpack_1.createWebpackDevServer)({
32
+ props: reloadableSite.get().props,
33
+ cliOptions,
34
+ openUrlContext: reloadableSite.openUrlContext,
35
+ });
36
+ ['SIGINT', 'SIGTERM'].forEach((sig) => {
37
+ process.on(sig, () => {
38
+ devServer.stop();
39
+ process.exit();
40
+ });
41
+ });
42
+ await devServer.start();
43
+ if (cliOptions.open) {
44
+ (0, openBrowser_1.default)(reloadableSite.getOpenUrl());
45
+ }
46
+ }
47
+ exports.start = start;
@@ -0,0 +1,31 @@
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 _ from 'lodash';
8
+ import type { StartCLIOptions } from './start';
9
+ import type { LoadedPlugin } from '@docusaurus/types';
10
+ export type OpenUrlContext = {
11
+ host: string;
12
+ port: number;
13
+ getOpenUrl: ({ baseUrl }: {
14
+ baseUrl: string;
15
+ }) => string;
16
+ };
17
+ export declare function createOpenUrlContext({ cliOptions, }: {
18
+ cliOptions: StartCLIOptions;
19
+ }): Promise<OpenUrlContext>;
20
+ type StartParams = {
21
+ siteDirParam: string;
22
+ cliOptions: Partial<StartCLIOptions>;
23
+ };
24
+ export declare function createReloadableSite(startParams: StartParams): Promise<{
25
+ get: () => import("../../server/site").Site;
26
+ getOpenUrl: () => string;
27
+ reload: _.DebouncedFunc<() => Promise<void>>;
28
+ reloadPlugin: (plugin: LoadedPlugin) => Promise<void>;
29
+ openUrlContext: OpenUrlContext;
30
+ }>;
31
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createReloadableSite = exports.createOpenUrlContext = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
+ const getHostPort_1 = require("../../server/getHostPort");
17
+ const utils_2 = require("../../utils");
18
+ const site_1 = require("../../server/site");
19
+ async function createOpenUrlContext({ cliOptions, }) {
20
+ const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
21
+ const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
22
+ if (port === null) {
23
+ return process.exit();
24
+ }
25
+ const getOpenUrl = ({ baseUrl }) => {
26
+ const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
27
+ return (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
28
+ };
29
+ return { host, port, getOpenUrl };
30
+ }
31
+ exports.createOpenUrlContext = createOpenUrlContext;
32
+ async function createLoadSiteParams({ siteDirParam, cliOptions, }) {
33
+ const siteDir = await fs_extra_1.default.realpath(siteDirParam);
34
+ return {
35
+ siteDir,
36
+ config: cliOptions.config,
37
+ locale: cliOptions.locale,
38
+ localizePath: undefined, // Should this be configurable?
39
+ };
40
+ }
41
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
42
+ async function createReloadableSite(startParams) {
43
+ const openUrlContext = await createOpenUrlContext(startParams);
44
+ let site = await utils_2.PerfLogger.async('Loading site', async () => {
45
+ const params = await createLoadSiteParams(startParams);
46
+ return (0, site_1.loadSite)(params);
47
+ });
48
+ const get = () => site;
49
+ const getOpenUrl = () => openUrlContext.getOpenUrl({
50
+ baseUrl: site.props.baseUrl,
51
+ });
52
+ const printOpenUrlMessage = () => {
53
+ logger_1.default.success `Docusaurus website is running at: url=${getOpenUrl()}`;
54
+ };
55
+ printOpenUrlMessage();
56
+ const reloadBase = async () => {
57
+ try {
58
+ const oldSite = site;
59
+ site = await utils_2.PerfLogger.async('Reloading site', () => (0, site_1.reloadSite)(site));
60
+ if (oldSite.props.baseUrl !== site.props.baseUrl) {
61
+ printOpenUrlMessage();
62
+ }
63
+ }
64
+ catch (e) {
65
+ logger_1.default.error('Site reload failure');
66
+ console.error(e);
67
+ }
68
+ };
69
+ // TODO instead of debouncing we should rather add AbortController support?
70
+ const reload = lodash_1.default.debounce(reloadBase, 500);
71
+ // TODO this could be subject to plugin reloads race conditions
72
+ // In practice, it is not likely the user will hot reload 2 plugins at once
73
+ // but we should still support it and probably use a task queuing system
74
+ const reloadPlugin = async (plugin) => {
75
+ try {
76
+ site = await utils_2.PerfLogger.async(`Reloading site plugin ${plugin.name}@${plugin.options.id}`, () => {
77
+ const pluginIdentifier = { name: plugin.name, id: plugin.options.id };
78
+ return (0, site_1.reloadSitePlugin)(site, pluginIdentifier);
79
+ });
80
+ }
81
+ catch (e) {
82
+ logger_1.default.error(`Site plugin reload failure - Plugin ${plugin.name}@${plugin.options.id}`);
83
+ console.error(e);
84
+ }
85
+ };
86
+ return { get, getOpenUrl, reload, reloadPlugin, openUrlContext };
87
+ }
88
+ exports.createReloadableSite = createReloadableSite;
@@ -0,0 +1,42 @@
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 { StartCLIOptions } from './start';
8
+ import type { LoadedPlugin, Props } from '@docusaurus/types';
9
+ type PollingOptions = {
10
+ usePolling: boolean;
11
+ interval: number | undefined;
12
+ };
13
+ export declare function createPollingOptions(cliOptions: StartCLIOptions): PollingOptions;
14
+ export type FileWatchEventName = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
15
+ export type FileWatchEvent = {
16
+ name: FileWatchEventName;
17
+ path: string;
18
+ };
19
+ type WatchParams = {
20
+ pathsToWatch: string[];
21
+ siteDir: string;
22
+ } & PollingOptions;
23
+ /**
24
+ * Watch file system paths for changes and emit events
25
+ * Returns an async handle to stop watching
26
+ */
27
+ export declare function watch(params: WatchParams, callback: (event: FileWatchEvent) => void): () => Promise<void>;
28
+ export declare function getSitePathsToWatch({ props }: {
29
+ props: Props;
30
+ }): string[];
31
+ export declare function getPluginPathsToWatch({ siteDir, plugin, }: {
32
+ siteDir: string;
33
+ plugin: LoadedPlugin;
34
+ }): string[];
35
+ export declare function setupSiteFileWatchers({ props, cliOptions, }: {
36
+ props: Props;
37
+ cliOptions: StartCLIOptions;
38
+ }, callback: (params: {
39
+ plugin: LoadedPlugin | null;
40
+ event: FileWatchEvent;
41
+ }) => void): void;
42
+ export {};
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.setupSiteFileWatchers = exports.getPluginPathsToWatch = exports.getSitePathsToWatch = exports.watch = exports.createPollingOptions = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
13
+ const utils_1 = require("@docusaurus/utils");
14
+ function createPollingOptions(cliOptions) {
15
+ return {
16
+ usePolling: !!cliOptions.poll,
17
+ interval: Number.isInteger(cliOptions.poll)
18
+ ? cliOptions.poll
19
+ : undefined,
20
+ };
21
+ }
22
+ exports.createPollingOptions = createPollingOptions;
23
+ /**
24
+ * Watch file system paths for changes and emit events
25
+ * Returns an async handle to stop watching
26
+ */
27
+ function watch(params, callback) {
28
+ const { pathsToWatch, siteDir, ...options } = params;
29
+ const fsWatcher = chokidar_1.default.watch(pathsToWatch, {
30
+ cwd: siteDir,
31
+ ignoreInitial: true,
32
+ ...options,
33
+ });
34
+ fsWatcher.on('all', (name, eventPath) => callback({ name, path: eventPath }));
35
+ return () => fsWatcher.close();
36
+ }
37
+ exports.watch = watch;
38
+ function getSitePathsToWatch({ props }) {
39
+ return [
40
+ // TODO we should also watch all imported modules!
41
+ // Use https://github.com/vercel/nft ?
42
+ props.siteConfigPath,
43
+ props.localizationDir,
44
+ ];
45
+ }
46
+ exports.getSitePathsToWatch = getSitePathsToWatch;
47
+ function getPluginPathsToWatch({ siteDir, plugin, }) {
48
+ const normalizeToSiteDir = (filepath) => {
49
+ if (filepath && path_1.default.isAbsolute(filepath)) {
50
+ return (0, utils_1.posixPath)(path_1.default.relative(siteDir, filepath));
51
+ }
52
+ return (0, utils_1.posixPath)(filepath);
53
+ };
54
+ return (plugin.getPathsToWatch?.() ?? [])
55
+ .filter(Boolean)
56
+ .map(normalizeToSiteDir);
57
+ }
58
+ exports.getPluginPathsToWatch = getPluginPathsToWatch;
59
+ function setupSiteFileWatchers({ props, cliOptions, }, callback) {
60
+ const { siteDir } = props;
61
+ const pollingOptions = createPollingOptions(cliOptions);
62
+ // TODO on config / or local plugin updates,
63
+ // the getFilePathsToWatch lifecycle code might get updated
64
+ // so we should probably reset the watchers?
65
+ watch({
66
+ pathsToWatch: getSitePathsToWatch({ props }),
67
+ siteDir: props.siteDir,
68
+ ...pollingOptions,
69
+ }, (event) => callback({ plugin: null, event }));
70
+ props.plugins.forEach((plugin) => {
71
+ watch({
72
+ pathsToWatch: getPluginPathsToWatch({ plugin, siteDir }),
73
+ siteDir,
74
+ ...pollingOptions,
75
+ }, (event) => callback({ plugin, event }));
76
+ });
77
+ }
78
+ exports.setupSiteFileWatchers = setupSiteFileWatchers;
@@ -0,0 +1,15 @@
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 WebpackDevServer from 'webpack-dev-server';
8
+ import type { StartCLIOptions } from './start';
9
+ import type { Props } from '@docusaurus/types';
10
+ import type { OpenUrlContext } from './utils';
11
+ export declare function createWebpackDevServer({ props, cliOptions, openUrlContext, }: {
12
+ props: Props;
13
+ cliOptions: StartCLIOptions;
14
+ openUrlContext: OpenUrlContext;
15
+ }): Promise<WebpackDevServer>;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createWebpackDevServer = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
13
+ const webpack_1 = tslib_1.__importDefault(require("webpack"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
16
+ const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
17
+ const watcher_1 = require("./watcher");
18
+ const utils_1 = require("../../webpack/utils");
19
+ const client_1 = require("../../webpack/client");
20
+ // E2E_TEST=true docusaurus start
21
+ // Makes "docusaurus start" exit immediately on success/error, for E2E test
22
+ function registerWebpackE2ETestHook(compiler) {
23
+ compiler.hooks.done.tap('done', (stats) => {
24
+ const errorsWarnings = stats.toJson('errors-warnings');
25
+ const statsErrorMessage = (0, utils_1.formatStatsErrorMessage)(errorsWarnings);
26
+ if (statsErrorMessage) {
27
+ console.error(statsErrorMessage);
28
+ }
29
+ (0, utils_1.printStatsWarnings)(errorsWarnings);
30
+ if (process.env.E2E_TEST) {
31
+ if (stats.hasErrors()) {
32
+ logger_1.default.error('E2E_TEST: Project has compiler errors.');
33
+ process.exit(1);
34
+ }
35
+ logger_1.default.success('E2E_TEST: Project can compile.');
36
+ process.exit(0);
37
+ }
38
+ });
39
+ }
40
+ async function createDevServerConfig({ cliOptions, props, host, port, }) {
41
+ const { baseUrl, siteDir, siteConfig } = props;
42
+ const pollingOptions = (0, watcher_1.createPollingOptions)(cliOptions);
43
+ const httpsConfig = await (0, utils_1.getHttpsConfig)();
44
+ // https://webpack.js.org/configuration/dev-server
45
+ return {
46
+ hot: cliOptions.hotOnly ? 'only' : true,
47
+ liveReload: false,
48
+ client: {
49
+ progress: true,
50
+ overlay: {
51
+ warnings: false,
52
+ errors: true,
53
+ },
54
+ webSocketURL: {
55
+ hostname: '0.0.0.0',
56
+ port: 0,
57
+ },
58
+ },
59
+ headers: {
60
+ 'access-control-allow-origin': '*',
61
+ },
62
+ devMiddleware: {
63
+ publicPath: baseUrl,
64
+ // Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
65
+ stats: 'summary',
66
+ },
67
+ static: siteConfig.staticDirectories.map((dir) => ({
68
+ publicPath: baseUrl,
69
+ directory: path_1.default.resolve(siteDir, dir),
70
+ watch: {
71
+ // Useful options for our own monorepo using symlinks!
72
+ // See https://github.com/webpack/webpack/issues/11612#issuecomment-879259806
73
+ followSymlinks: true,
74
+ ignored: /node_modules\/(?!@docusaurus)/,
75
+ ...{ pollingOptions },
76
+ },
77
+ })),
78
+ ...(httpsConfig && {
79
+ server: typeof httpsConfig === 'object'
80
+ ? {
81
+ type: 'https',
82
+ options: httpsConfig,
83
+ }
84
+ : 'https',
85
+ }),
86
+ historyApiFallback: {
87
+ rewrites: [{ from: /\/*/, to: baseUrl }],
88
+ },
89
+ allowedHosts: 'all',
90
+ host,
91
+ port,
92
+ setupMiddlewares: (middlewares, devServer) => {
93
+ // This lets us fetch source contents from webpack for the error overlay.
94
+ middlewares.unshift((0, evalSourceMapMiddleware_1.default)(devServer));
95
+ return middlewares;
96
+ },
97
+ };
98
+ }
99
+ async function getStartClientConfig({ props, minify, poll, }) {
100
+ const { plugins, siteConfig } = props;
101
+ let { clientConfig: config } = await (0, client_1.createStartClientConfig)({
102
+ props,
103
+ minify,
104
+ poll,
105
+ });
106
+ config = (0, utils_1.executePluginsConfigurePostCss)({ plugins, config });
107
+ config = (0, utils_1.executePluginsConfigureWebpack)({
108
+ plugins,
109
+ config,
110
+ isServer: false,
111
+ jsLoader: siteConfig.webpack?.jsLoader,
112
+ });
113
+ return config;
114
+ }
115
+ async function createWebpackDevServer({ props, cliOptions, openUrlContext, }) {
116
+ const config = await getStartClientConfig({
117
+ props,
118
+ minify: cliOptions.minify ?? true,
119
+ poll: cliOptions.poll,
120
+ });
121
+ const compiler = (0, webpack_1.default)(config);
122
+ registerWebpackE2ETestHook(compiler);
123
+ const defaultDevServerConfig = await createDevServerConfig({
124
+ cliOptions,
125
+ props,
126
+ host: openUrlContext.host,
127
+ port: openUrlContext.port,
128
+ });
129
+ // Allow plugin authors to customize/override devServer config
130
+ const devServerConfig = (0, webpack_merge_1.default)([defaultDevServerConfig, config.devServer].filter(Boolean));
131
+ return new webpack_dev_server_1.default(devServerConfig, compiler);
132
+ }
133
+ exports.createWebpackDevServer = createWebpackDevServer;
@@ -7,11 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.initSwizzleContext = void 0;
10
- const server_1 = require("../../server");
10
+ const site_1 = require("../../server/site");
11
11
  const init_1 = require("../../server/plugins/init");
12
12
  const configs_1 = require("../../server/plugins/configs");
13
13
  async function initSwizzleContext(siteDir, options) {
14
- const context = await (0, server_1.loadContext)({ siteDir, config: options.config });
14
+ const context = await (0, site_1.loadContext)({ siteDir, config: options.config });
15
15
  const plugins = await (0, init_1.initPlugins)(context);
16
16
  const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
17
17
  return {
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
- const server_1 = require("../server");
14
+ const site_1 = require("../server/site");
15
15
  const init_1 = require("../server/plugins/init");
16
16
  const utils_2 = require("../server/utils");
17
17
  async function transformMarkdownFile(filepath, options) {
@@ -30,7 +30,7 @@ async function transformMarkdownFile(filepath, options) {
30
30
  * transformed
31
31
  */
32
32
  async function getPathsToWatch(siteDir) {
33
- const context = await (0, server_1.loadContext)({ siteDir });
33
+ const context = await (0, site_1.loadContext)({ siteDir });
34
34
  const plugins = await (0, init_1.initPlugins)(context);
35
35
  return plugins.flatMap((plugin) => plugin.getPathsToWatch?.() ?? []);
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 { type LoadContextOptions } from '../server';
7
+ import { type LoadContextParams } from '../server/site';
8
8
  import { type WriteTranslationsOptions } from '../server/translations/translations';
9
- export type WriteTranslationsCLIOptions = Pick<LoadContextOptions, 'config' | 'locale'> & WriteTranslationsOptions;
9
+ export type WriteTranslationsCLIOptions = Pick<LoadContextParams, 'config' | 'locale'> & WriteTranslationsOptions;
10
10
  export declare function writeTranslations(siteDirParam?: string, options?: Partial<WriteTranslationsCLIOptions>): Promise<void>;
@@ -10,7 +10,7 @@ exports.writeTranslations = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
- const server_1 = require("../server");
13
+ const site_1 = require("../server/site");
14
14
  const init_1 = require("../server/plugins/init");
15
15
  const translations_1 = require("../server/translations/translations");
16
16
  const translationsExtractor_1 = require("../server/translations/translationsExtractor");
@@ -55,7 +55,7 @@ async function writePluginTranslationFiles({ localizationDir, plugin, options, }
55
55
  }
56
56
  async function writeTranslations(siteDirParam = '.', options = {}) {
57
57
  const siteDir = await fs_extra_1.default.realpath(siteDirParam);
58
- const context = await (0, server_1.loadContext)({
58
+ const context = await (0, site_1.loadContext)({
59
59
  siteDir,
60
60
  config: options.config,
61
61
  locale: options.locale,
package/lib/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { clear } from './commands/clear';
9
9
  export { deploy } from './commands/deploy';
10
10
  export { externalCommand } from './commands/external';
11
11
  export { serve } from './commands/serve';
12
- export { start } from './commands/start';
12
+ export { start } from './commands/start/start';
13
13
  export { swizzle } from './commands/swizzle';
14
14
  export { writeHeadingIds } from './commands/writeHeadingIds';
15
15
  export { writeTranslations } from './commands/writeTranslations';
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ var external_1 = require("./commands/external");
17
17
  Object.defineProperty(exports, "externalCommand", { enumerable: true, get: function () { return external_1.externalCommand; } });
18
18
  var serve_1 = require("./commands/serve");
19
19
  Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return serve_1.serve; } });
20
- var start_1 = require("./commands/start");
20
+ var start_1 = require("./commands/start/start");
21
21
  Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_1.start; } });
22
22
  var swizzle_1 = require("./commands/swizzle");
23
23
  Object.defineProperty(exports, "swizzle", { enumerable: true, get: function () { return swizzle_1.swizzle; } });