@docusaurus/core 4.0.0-canary-7029 → 4.0.0-canary-7039

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.
@@ -12,7 +12,7 @@ const node_path_1 = tslib_1.__importDefault(require("node:path"));
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
14
  const fs_1 = require("@docusaurus/fs");
15
- const clearPath_1 = tslib_1.__importDefault(require("./utils/clearPath"));
15
+ const clearPath_1 = tslib_1.__importDefault(require("../utils/clearPath"));
16
16
  async function removePath(entry) {
17
17
  if (!(await (0, fs_1.pathExists)(entry.path))) {
18
18
  return;
@@ -12,14 +12,14 @@ const logger_1 = require("@docusaurus/logger");
12
12
  const commander_1 = require("commander");
13
13
  const utils_1 = require("@docusaurus/utils");
14
14
  const build_1 = require("./build/build");
15
- const clear_1 = require("./clear");
16
- const deploy_1 = require("./deploy");
17
- const external_1 = require("./external");
18
- const serve_1 = require("./serve");
15
+ const clear_1 = require("./clear/clear");
16
+ const deploy_1 = require("./deploy/deploy");
17
+ const external_1 = require("./external/external");
18
+ const serve_1 = require("./serve/serve");
19
19
  const start_1 = require("./start/start");
20
- const swizzle_1 = require("./swizzle");
21
- const writeHeadingIds_1 = require("./writeHeadingIds");
22
- const writeTranslations_1 = require("./writeTranslations");
20
+ const swizzle_1 = require("./swizzle/swizzle");
21
+ const writeHeadingIds_1 = require("./writeHeadingIds/writeHeadingIds");
22
+ const writeTranslations_1 = require("./writeTranslations/writeTranslations");
23
23
  function concatLocaleOptions(locale, locales = []) {
24
24
  return locales.concat(locale);
25
25
  }
@@ -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 LoadContextParams } from '../server/site';
7
+ import { type LoadContextParams } from '../../server/site';
8
8
  export type DeployCLIOptions = Pick<LoadContextParams, 'config' | 'outDir'> & {
9
9
  locale?: [string, ...string[]];
10
10
  skipBuild?: boolean;
@@ -14,8 +14,8 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
14
  const execa_1 = require("execa");
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  const fs_1 = require("@docusaurus/fs");
17
- const site_1 = require("../server/site");
18
- const build_1 = require("./build/build");
17
+ const site_1 = require("../../server/site");
18
+ const build_1 = require("../build/build");
19
19
  // GIT_PASS env variable should not appear in logs
20
20
  function obfuscateGitPass(str) {
21
21
  const gitPass = process.env.GIT_PASS;
@@ -8,8 +8,8 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.externalCommand = externalCommand;
10
10
  const fs_1 = require("@docusaurus/fs");
11
- const site_1 = require("../server/site");
12
- const init_1 = require("../server/plugins/init");
11
+ const site_1 = require("../../server/site");
12
+ const init_1 = require("../../server/plugins/init");
13
13
  async function externalCommand({ cli, siteDir: siteDirInput, config, }) {
14
14
  const siteDir = await (0, fs_1.realpath)(siteDirInput);
15
15
  const context = await (0, site_1.loadContext)({ siteDir, config });
@@ -0,0 +1,13 @@
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 http from 'node:http';
8
+ import type { DocusaurusConfig } from '@docusaurus/types';
9
+ type ServeRequestHandler = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
10
+ export declare function createServeRequestHandler({ outDir, baseUrl, trailingSlash, }: {
11
+ outDir: string;
12
+ } & Pick<DocusaurusConfig, 'baseUrl' | 'trailingSlash'>): ServeRequestHandler;
13
+ export {};
@@ -0,0 +1,68 @@
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.createServeRequestHandler = createServeRequestHandler;
10
+ const tslib_1 = require("tslib");
11
+ const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
12
+ const utils_common_1 = require("@docusaurus/utils-common");
13
+ function createServeRequestHandler({ outDir, baseUrl, trailingSlash, }) {
14
+ return async (req, res) => {
15
+ const redirectLocation = getRedirectLocation(req.url, {
16
+ baseUrl,
17
+ trailingSlash,
18
+ });
19
+ if (redirectLocation !== undefined) {
20
+ redirect(res, redirectLocation);
21
+ return;
22
+ }
23
+ // Remove baseUrl before calling serveHandler, because /baseUrl/ should
24
+ // serve /build/index.html, not /build/baseUrl/index.html (does not exist)
25
+ // Note server-handler is really annoying here:
26
+ // - no easy way to do rewrites such as "/baseUrl/:path" => "/:path"
27
+ // - no easy way to "reapply" the baseUrl to the redirect "Location" header
28
+ // See also https://github.com/meta/docusaurus/pull/10090
29
+ // Requests without url were redirected to the baseUrl
30
+ req.url = req.url.replace(baseUrl, '/');
31
+ await (0, serve_handler_1.default)(req, res, {
32
+ cleanUrls: true,
33
+ public: outDir,
34
+ trailingSlash,
35
+ directoryListing: false,
36
+ });
37
+ };
38
+ }
39
+ function getRedirectLocation(url, { baseUrl, trailingSlash }) {
40
+ // Automatically redirect requests to /baseUrl/
41
+ if (!url?.startsWith(baseUrl)) {
42
+ return baseUrl;
43
+ }
44
+ // We do the redirect ourselves for a good reason
45
+ // server-handler is annoying and won't include /baseUrl/ in redirects
46
+ // See https://github.com/meta/docusaurus/issues/10078#issuecomment-2084932934
47
+ if (baseUrl !== '/') {
48
+ // Not super robust, but should be good enough for our use case
49
+ // See https://github.com/meta/docusaurus/pull/10090
50
+ const looksLikeAsset = !!url.match(/\.[a-z\d]{1,4}$/i);
51
+ if (!looksLikeAsset) {
52
+ const normalizedUrl = (0, utils_common_1.applyTrailingSlash)(url, {
53
+ trailingSlash,
54
+ baseUrl,
55
+ });
56
+ if (url !== normalizedUrl) {
57
+ return normalizedUrl;
58
+ }
59
+ }
60
+ }
61
+ return undefined;
62
+ }
63
+ function redirect(res, location) {
64
+ res.writeHead(302, {
65
+ Location: location,
66
+ });
67
+ res.end();
68
+ }
@@ -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 HostPortOptions } from '../server/getHostPort';
8
- import type { LoadContextParams } from '../server/site';
7
+ import { type HostPortOptions } from '../../server/getHostPort';
8
+ import type { LoadContextParams } from '../../server/site';
9
9
  export type ServeCLIOptions = HostPortOptions & Pick<LoadContextParams, 'config'> & {
10
10
  dir?: string;
11
11
  build?: boolean;
@@ -0,0 +1,48 @@
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.serve = serve;
10
+ const tslib_1 = require("tslib");
11
+ const node_http_1 = tslib_1.__importDefault(require("node:http"));
12
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const fs_1 = require("@docusaurus/fs");
16
+ const openBrowser_1 = tslib_1.__importDefault(require("../utils/openBrowser/openBrowser"));
17
+ const config_1 = require("../../server/config");
18
+ const build_1 = require("../build/build");
19
+ const getHostPort_1 = require("../../server/getHostPort");
20
+ const listenToServer_1 = require("./listenToServer");
21
+ const requestHandler_1 = require("./requestHandler");
22
+ async function serve(siteDirParam = '.', cliOptions = {}) {
23
+ const siteDir = await (0, fs_1.realpath)(siteDirParam);
24
+ const buildDir = cliOptions.dir ?? utils_1.DEFAULT_BUILD_DIR_NAME;
25
+ const outDir = node_path_1.default.resolve(siteDir, buildDir);
26
+ if (cliOptions.build) {
27
+ await (0, build_1.build)(siteDir, {
28
+ config: cliOptions.config,
29
+ outDir,
30
+ });
31
+ }
32
+ const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
33
+ if (port === null) {
34
+ process.exit();
35
+ }
36
+ const { siteConfig: { baseUrl, trailingSlash }, } = await (0, config_1.loadSiteConfig)({
37
+ siteDir,
38
+ customConfigFilePath: cliOptions.config,
39
+ });
40
+ const servingUrl = `http://${host}:${port}`;
41
+ const server = node_http_1.default.createServer((0, requestHandler_1.createServeRequestHandler)({ outDir, baseUrl, trailingSlash }));
42
+ const url = servingUrl + baseUrl;
43
+ logger_1.default.success `Serving path=${buildDir} directory at: url=${url}`;
44
+ await (0, listenToServer_1.listenToServer)({ server, host, port });
45
+ if (cliOptions.open && !process.env.CI) {
46
+ await (0, openBrowser_1.default)(url);
47
+ }
48
+ }
@@ -14,8 +14,8 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const glob_1 = require("@docusaurus/glob");
16
16
  const fs_1 = require("@docusaurus/fs");
17
- const site_1 = require("../server/site");
18
- const init_1 = require("../server/plugins/init");
17
+ const site_1 = require("../../server/site");
18
+ const init_1 = require("../../server/plugins/init");
19
19
  exports.HeadingIdSyntaxes = [
20
20
  'classic',
21
21
  'mdx-comment',
@@ -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 LoadContextParams } from '../server/site';
8
- import { type WriteTranslationsOptions } from '../server/translations/translations';
7
+ import { type LoadContextParams } from '../../server/site';
8
+ import { type WriteTranslationsOptions } from '../../server/translations/translations';
9
9
  export type WriteTranslationsCLIOptions = Pick<LoadContextParams, 'config' | 'locale'> & WriteTranslationsOptions;
10
10
  export declare function writeTranslations(siteDirParam?: string, options?: Partial<WriteTranslationsCLIOptions>): Promise<void>;
@@ -11,10 +11,10 @@ const tslib_1 = require("tslib");
11
11
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
12
12
  const glob_1 = require("@docusaurus/glob");
13
13
  const fs_1 = require("@docusaurus/fs");
14
- const site_1 = require("../server/site");
15
- const init_1 = require("../server/plugins/init");
16
- const translations_1 = require("../server/translations/translations");
17
- const translationsExtractor_1 = require("../server/translations/translationsExtractor");
14
+ const site_1 = require("../../server/site");
15
+ const init_1 = require("../../server/plugins/init");
16
+ const translations_1 = require("../../server/translations/translations");
17
+ const translationsExtractor_1 = require("../../server/translations/translationsExtractor");
18
18
  function resolveThemeCommonLibDir() {
19
19
  try {
20
20
  return node_path_1.default.dirname(require.resolve('@docusaurus/theme-common'));
package/lib/index.d.ts CHANGED
@@ -6,11 +6,11 @@
6
6
  */
7
7
  export { runCLI } from './commands/cli';
8
8
  export { build } from './commands/build/build';
9
- export { clear } from './commands/clear';
10
- export { deploy } from './commands/deploy';
11
- export { externalCommand } from './commands/external';
12
- export { serve } from './commands/serve';
9
+ export { clear } from './commands/clear/clear';
10
+ export { deploy } from './commands/deploy/deploy';
11
+ export { externalCommand } from './commands/external/external';
12
+ export { serve } from './commands/serve/serve';
13
13
  export { start } from './commands/start/start';
14
- export { swizzle } from './commands/swizzle';
15
- export { writeHeadingIds } from './commands/writeHeadingIds';
16
- export { writeTranslations } from './commands/writeTranslations';
14
+ export { swizzle } from './commands/swizzle/swizzle';
15
+ export { writeHeadingIds } from './commands/writeHeadingIds/writeHeadingIds';
16
+ export { writeTranslations } from './commands/writeTranslations/writeTranslations';
package/lib/index.js CHANGED
@@ -11,19 +11,19 @@ var cli_1 = require("./commands/cli");
11
11
  Object.defineProperty(exports, "runCLI", { enumerable: true, get: function () { return cli_1.runCLI; } });
12
12
  var build_1 = require("./commands/build/build");
13
13
  Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
14
- var clear_1 = require("./commands/clear");
14
+ var clear_1 = require("./commands/clear/clear");
15
15
  Object.defineProperty(exports, "clear", { enumerable: true, get: function () { return clear_1.clear; } });
16
- var deploy_1 = require("./commands/deploy");
16
+ var deploy_1 = require("./commands/deploy/deploy");
17
17
  Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return deploy_1.deploy; } });
18
- var external_1 = require("./commands/external");
18
+ var external_1 = require("./commands/external/external");
19
19
  Object.defineProperty(exports, "externalCommand", { enumerable: true, get: function () { return external_1.externalCommand; } });
20
- var serve_1 = require("./commands/serve");
20
+ var serve_1 = require("./commands/serve/serve");
21
21
  Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return serve_1.serve; } });
22
22
  var start_1 = require("./commands/start/start");
23
23
  Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_1.start; } });
24
- var swizzle_1 = require("./commands/swizzle");
24
+ var swizzle_1 = require("./commands/swizzle/swizzle");
25
25
  Object.defineProperty(exports, "swizzle", { enumerable: true, get: function () { return swizzle_1.swizzle; } });
26
- var writeHeadingIds_1 = require("./commands/writeHeadingIds");
26
+ var writeHeadingIds_1 = require("./commands/writeHeadingIds/writeHeadingIds");
27
27
  Object.defineProperty(exports, "writeHeadingIds", { enumerable: true, get: function () { return writeHeadingIds_1.writeHeadingIds; } });
28
- var writeTranslations_1 = require("./commands/writeTranslations");
28
+ var writeTranslations_1 = require("./commands/writeTranslations/writeTranslations");
29
29
  Object.defineProperty(exports, "writeTranslations", { enumerable: true, get: function () { return writeTranslations_1.writeTranslations; } });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "4.0.0-canary-7029",
4
+ "version": "4.0.0-canary-7039",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -27,15 +27,15 @@
27
27
  "url": "https://github.com/meta/docusaurus/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@docusaurus/babel": "4.0.0-canary-7029",
31
- "@docusaurus/bundler": "4.0.0-canary-7029",
32
- "@docusaurus/fs": "4.0.0-canary-7029",
33
- "@docusaurus/glob": "4.0.0-canary-7029",
34
- "@docusaurus/logger": "4.0.0-canary-7029",
35
- "@docusaurus/mdx-loader": "4.0.0-canary-7029",
36
- "@docusaurus/utils": "4.0.0-canary-7029",
37
- "@docusaurus/utils-common": "4.0.0-canary-7029",
38
- "@docusaurus/utils-validation": "4.0.0-canary-7029",
30
+ "@docusaurus/babel": "4.0.0-canary-7039",
31
+ "@docusaurus/bundler": "4.0.0-canary-7039",
32
+ "@docusaurus/fs": "4.0.0-canary-7039",
33
+ "@docusaurus/glob": "4.0.0-canary-7039",
34
+ "@docusaurus/logger": "4.0.0-canary-7039",
35
+ "@docusaurus/mdx-loader": "4.0.0-canary-7039",
36
+ "@docusaurus/utils": "4.0.0-canary-7039",
37
+ "@docusaurus/utils-common": "4.0.0-canary-7039",
38
+ "@docusaurus/utils-validation": "4.0.0-canary-7039",
39
39
  "@rspack/core": "^2.3.0",
40
40
  "@rspack/dev-server": "^2.2.2",
41
41
  "boxen": "^9.0.0",
@@ -68,8 +68,8 @@
68
68
  "webpack-merge": "^6.0.1"
69
69
  },
70
70
  "devDependencies": {
71
- "@docusaurus/module-type-aliases": "4.0.0-canary-7029",
72
- "@docusaurus/types": "4.0.0-canary-7029",
71
+ "@docusaurus/module-type-aliases": "4.0.0-canary-7039",
72
+ "@docusaurus/types": "4.0.0-canary-7039",
73
73
  "@total-typescript/shoehorn": "^0.1.2",
74
74
  "@types/escape-html": "^1.0.4",
75
75
  "@types/history": "^4.7.11",
@@ -1,92 +0,0 @@
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.serve = serve;
10
- const tslib_1 = require("tslib");
11
- const node_http_1 = tslib_1.__importDefault(require("node:http"));
12
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
13
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
- const utils_1 = require("@docusaurus/utils");
15
- const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
16
- const utils_common_1 = require("@docusaurus/utils-common");
17
- const fs_1 = require("@docusaurus/fs");
18
- const openBrowser_1 = tslib_1.__importDefault(require("./utils/openBrowser/openBrowser"));
19
- const config_1 = require("../server/config");
20
- const build_1 = require("./build/build");
21
- const getHostPort_1 = require("../server/getHostPort");
22
- const listenToServer_1 = require("./utils/listenToServer");
23
- function redirect(res, location) {
24
- res.writeHead(302, {
25
- Location: location,
26
- });
27
- res.end();
28
- }
29
- async function serve(siteDirParam = '.', cliOptions = {}) {
30
- const siteDir = await (0, fs_1.realpath)(siteDirParam);
31
- const buildDir = cliOptions.dir ?? utils_1.DEFAULT_BUILD_DIR_NAME;
32
- const outDir = node_path_1.default.resolve(siteDir, buildDir);
33
- if (cliOptions.build) {
34
- await (0, build_1.build)(siteDir, {
35
- config: cliOptions.config,
36
- outDir,
37
- });
38
- }
39
- const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
40
- if (port === null) {
41
- process.exit();
42
- }
43
- const { siteConfig: { baseUrl, trailingSlash }, } = await (0, config_1.loadSiteConfig)({
44
- siteDir,
45
- customConfigFilePath: cliOptions.config,
46
- });
47
- const servingUrl = `http://${host}:${port}`;
48
- const server = node_http_1.default.createServer((req, res) => {
49
- // Automatically redirect requests to /baseUrl/
50
- if (!req.url?.startsWith(baseUrl)) {
51
- redirect(res, baseUrl);
52
- return;
53
- }
54
- // We do the redirect ourselves for a good reason
55
- // server-handler is annoying and won't include /baseUrl/ in redirects
56
- // See https://github.com/meta/docusaurus/issues/10078#issuecomment-2084932934
57
- if (baseUrl !== '/') {
58
- // Not super robust, but should be good enough for our use case
59
- // See https://github.com/meta/docusaurus/pull/10090
60
- const looksLikeAsset = !!req.url.match(/\.[a-z\d]{1,4}$/i);
61
- if (!looksLikeAsset) {
62
- const normalizedUrl = (0, utils_common_1.applyTrailingSlash)(req.url, {
63
- trailingSlash,
64
- baseUrl,
65
- });
66
- if (req.url !== normalizedUrl) {
67
- redirect(res, normalizedUrl);
68
- return;
69
- }
70
- }
71
- }
72
- // Remove baseUrl before calling serveHandler, because /baseUrl/ should
73
- // serve /build/index.html, not /build/baseUrl/index.html (does not exist)
74
- // Note server-handler is really annoying here:
75
- // - no easy way to do rewrites such as "/baseUrl/:path" => "/:path"
76
- // - no easy way to "reapply" the baseUrl to the redirect "Location" header
77
- // See also https://github.com/meta/docusaurus/pull/10090
78
- req.url = req.url.replace(baseUrl, '/');
79
- (0, serve_handler_1.default)(req, res, {
80
- cleanUrls: true,
81
- public: outDir,
82
- trailingSlash,
83
- directoryListing: false,
84
- });
85
- });
86
- const url = servingUrl + baseUrl;
87
- logger_1.default.success `Serving path=${buildDir} directory at: url=${url}`;
88
- await (0, listenToServer_1.listenToServer)({ server, host, port });
89
- if (cliOptions.open && !process.env.CI) {
90
- await (0, openBrowser_1.default)(url);
91
- }
92
- }
File without changes
File without changes
File without changes