@docusaurus/core 3.5.2 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +1 -1
- package/bin/docusaurus.mjs +15 -4
- package/lib/babel/preset.d.ts +2 -2
- package/lib/babel/preset.js +10 -71
- package/lib/client/renderToHtml.js +15 -51
- package/lib/client/serverEntry.d.ts +1 -1
- package/lib/client/serverEntry.js +2 -0
- package/lib/commands/{build.d.ts → build/build.d.ts} +4 -3
- package/lib/commands/build/build.js +94 -0
- package/lib/commands/build/buildLocale.d.ts +13 -0
- package/lib/commands/build/buildLocale.js +143 -0
- package/lib/commands/deploy.d.ts +2 -1
- package/lib/commands/deploy.js +2 -2
- package/lib/commands/serve.js +2 -2
- package/lib/commands/start/utils.js +5 -6
- package/lib/commands/start/webpack.js +15 -9
- package/lib/commands/writeHeadingIds.js +1 -2
- package/lib/commands/writeTranslations.js +6 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/server/configValidation.d.ts +3 -1
- package/lib/server/configValidation.js +35 -4
- package/lib/server/i18n.d.ts +1 -1
- package/lib/server/i18n.js +1 -1
- package/lib/server/plugins/plugins.js +13 -13
- package/lib/server/plugins/synthetic.d.ts +1 -1
- package/lib/server/plugins/synthetic.js +14 -17
- package/lib/server/site.js +10 -4
- package/lib/server/translations/translationsExtractor.d.ts +5 -11
- package/lib/server/translations/translationsExtractor.js +8 -196
- package/lib/ssg/ssg.d.ts +21 -0
- package/lib/{ssg.js → ssg/ssg.js} +91 -82
- package/lib/ssg/ssgExecutor.d.ts +16 -0
- package/lib/ssg/ssgExecutor.js +34 -0
- package/lib/{server/utils.d.ts → ssg/ssgNodeRequire.d.ts} +5 -2
- package/lib/ssg/ssgNodeRequire.js +40 -0
- package/lib/ssg/ssgParams.d.ts +28 -0
- package/lib/ssg/ssgParams.js +36 -0
- package/lib/{templates/templates.d.ts → ssg/ssgTemplate.d.ts} +7 -6
- package/lib/{templates/templates.js → ssg/ssgTemplate.js} +11 -9
- package/lib/ssg/ssgUtils.d.ts +17 -0
- package/lib/ssg/ssgUtils.js +58 -0
- package/lib/webpack/base.d.ts +4 -2
- package/lib/webpack/base.js +33 -20
- package/lib/webpack/client.d.ts +7 -3
- package/lib/webpack/client.js +32 -14
- package/lib/webpack/configure.d.ts +20 -6
- package/lib/webpack/configure.js +31 -16
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +0 -11
- package/lib/webpack/plugins/ChunkAssetPlugin.js +48 -33
- package/lib/webpack/plugins/ForceTerminatePlugin.js +2 -2
- package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.d.ts +2 -2
- package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.js +5 -2
- package/lib/webpack/server.d.ts +3 -2
- package/lib/webpack/server.js +12 -10
- package/lib/webpack/{minification.d.ts → utils/getHttpsConfig.d.ts} +4 -2
- package/lib/webpack/utils/getHttpsConfig.js +60 -0
- package/package.json +19 -44
- package/lib/commands/build.js +0 -240
- package/lib/server/utils.js +0 -20
- package/lib/ssg.d.ts +0 -35
- package/lib/utils.d.ts +0 -9
- package/lib/utils.js +0 -78
- package/lib/webpack/minification.js +0 -96
- package/lib/webpack/plugins/WaitPlugin.d.ts +0 -16
- package/lib/webpack/plugins/WaitPlugin.js +0 -47
- package/lib/webpack/utils.d.ts +0 -33
- package/lib/webpack/utils.js +0 -215
- /package/lib/{templates/ssr.html.template.d.ts → ssg/ssgTemplate.html.d.ts} +0 -0
- /package/lib/{templates/ssr.html.template.js → ssg/ssgTemplate.html.js} +0 -0
- /package/lib/{templates → webpack/templates}/dev.html.template.ejs +0 -0
|
@@ -10,12 +10,12 @@ exports.createWebpackDevServer = createWebpackDevServer;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
13
|
-
const
|
|
13
|
+
const bundler_1 = require("@docusaurus/bundler");
|
|
14
14
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
15
|
const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
|
|
16
16
|
const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
|
|
17
17
|
const watcher_1 = require("./watcher");
|
|
18
|
-
const
|
|
18
|
+
const getHttpsConfig_1 = tslib_1.__importDefault(require("../../webpack/utils/getHttpsConfig"));
|
|
19
19
|
const configure_1 = require("../../webpack/configure");
|
|
20
20
|
const client_1 = require("../../webpack/client");
|
|
21
21
|
// E2E_TEST=true docusaurus start
|
|
@@ -23,11 +23,11 @@ const client_1 = require("../../webpack/client");
|
|
|
23
23
|
function registerWebpackE2ETestHook(compiler) {
|
|
24
24
|
compiler.hooks.done.tap('done', (stats) => {
|
|
25
25
|
const errorsWarnings = stats.toJson('errors-warnings');
|
|
26
|
-
const statsErrorMessage = (0,
|
|
26
|
+
const statsErrorMessage = (0, bundler_1.formatStatsErrorMessage)(errorsWarnings);
|
|
27
27
|
if (statsErrorMessage) {
|
|
28
28
|
console.error(statsErrorMessage);
|
|
29
29
|
}
|
|
30
|
-
(0,
|
|
30
|
+
(0, bundler_1.printStatsWarnings)(errorsWarnings);
|
|
31
31
|
if (process.env.E2E_TEST) {
|
|
32
32
|
if (stats.hasErrors()) {
|
|
33
33
|
logger_1.default.error('E2E_TEST: Project has compiler errors.');
|
|
@@ -41,7 +41,7 @@ function registerWebpackE2ETestHook(compiler) {
|
|
|
41
41
|
async function createDevServerConfig({ cliOptions, props, host, port, }) {
|
|
42
42
|
const { baseUrl, siteDir, siteConfig } = props;
|
|
43
43
|
const pollingOptions = (0, watcher_1.createPollingOptions)(cliOptions);
|
|
44
|
-
const httpsConfig = await (0,
|
|
44
|
+
const httpsConfig = await (0, getHttpsConfig_1.default)();
|
|
45
45
|
// https://webpack.js.org/configuration/dev-server
|
|
46
46
|
return {
|
|
47
47
|
hot: cliOptions.hotOnly ? 'only' : true,
|
|
@@ -97,28 +97,34 @@ async function createDevServerConfig({ cliOptions, props, host, port, }) {
|
|
|
97
97
|
},
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
async function getStartClientConfig({ props, minify, poll, }) {
|
|
101
|
-
const { plugins
|
|
100
|
+
async function getStartClientConfig({ props, minify, poll, configureWebpackUtils, }) {
|
|
101
|
+
const { plugins } = props;
|
|
102
102
|
let { clientConfig: config } = await (0, client_1.createStartClientConfig)({
|
|
103
103
|
props,
|
|
104
104
|
minify,
|
|
105
|
+
faster: props.siteConfig.future.experimental_faster,
|
|
105
106
|
poll,
|
|
107
|
+
configureWebpackUtils,
|
|
106
108
|
});
|
|
107
109
|
config = (0, configure_1.executePluginsConfigureWebpack)({
|
|
108
110
|
plugins,
|
|
109
111
|
config,
|
|
110
112
|
isServer: false,
|
|
111
|
-
|
|
113
|
+
configureWebpackUtils,
|
|
112
114
|
});
|
|
113
115
|
return config;
|
|
114
116
|
}
|
|
115
117
|
async function createWebpackDevServer({ props, cliOptions, openUrlContext, }) {
|
|
118
|
+
const configureWebpackUtils = await (0, configure_1.createConfigureWebpackUtils)({
|
|
119
|
+
siteConfig: props.siteConfig,
|
|
120
|
+
});
|
|
116
121
|
const config = await getStartClientConfig({
|
|
117
122
|
props,
|
|
118
123
|
minify: cliOptions.minify ?? true,
|
|
119
124
|
poll: cliOptions.poll,
|
|
125
|
+
configureWebpackUtils,
|
|
120
126
|
});
|
|
121
|
-
const compiler =
|
|
127
|
+
const compiler = props.currentBundler.instance(config);
|
|
122
128
|
registerWebpackE2ETestHook(compiler);
|
|
123
129
|
const defaultDevServerConfig = await createDevServerConfig({
|
|
124
130
|
cliOptions,
|
|
@@ -13,7 +13,6 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
14
|
const site_1 = require("../server/site");
|
|
15
15
|
const init_1 = require("../server/plugins/init");
|
|
16
|
-
const utils_2 = require("../server/utils");
|
|
17
16
|
async function transformMarkdownFile(filepath, options) {
|
|
18
17
|
const content = await fs_extra_1.default.readFile(filepath, 'utf8');
|
|
19
18
|
const updatedContent = (0, utils_1.writeMarkdownHeadingId)(content, options);
|
|
@@ -36,7 +35,7 @@ async function getPathsToWatch(siteDir) {
|
|
|
36
35
|
}
|
|
37
36
|
async function writeHeadingIds(siteDirParam = '.', files = [], options = {}) {
|
|
38
37
|
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
39
|
-
const markdownFiles = await (0,
|
|
38
|
+
const markdownFiles = await (0, utils_1.safeGlobby)(files ?? (await getPathsToWatch(siteDir)), {
|
|
40
39
|
expandDirectories: ['**/*.{md,mdx}'],
|
|
41
40
|
});
|
|
42
41
|
const result = await Promise.all(markdownFiles.map((p) => transformMarkdownFile(p, options)));
|
|
@@ -10,11 +10,11 @@ exports.writeTranslations = writeTranslations;
|
|
|
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 utils_1 = require("@docusaurus/utils");
|
|
13
14
|
const site_1 = require("../server/site");
|
|
14
15
|
const init_1 = require("../server/plugins/init");
|
|
15
16
|
const translations_1 = require("../server/translations/translations");
|
|
16
17
|
const translationsExtractor_1 = require("../server/translations/translationsExtractor");
|
|
17
|
-
const utils_1 = require("../webpack/utils");
|
|
18
18
|
function resolveThemeCommonLibDir() {
|
|
19
19
|
try {
|
|
20
20
|
return path_1.default.dirname(require.resolve('@docusaurus/theme-common'));
|
|
@@ -35,7 +35,7 @@ async function getExtraSourceCodeFilePaths() {
|
|
|
35
35
|
if (!themeCommonLibDir) {
|
|
36
36
|
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
|
37
37
|
}
|
|
38
|
-
return (0,
|
|
38
|
+
return (0, utils_1.globTranslatableSourceFiles)([themeCommonLibDir]);
|
|
39
39
|
}
|
|
40
40
|
async function writePluginTranslationFiles({ localizationDir, plugin, options, }) {
|
|
41
41
|
if (plugin.getTranslationFiles) {
|
|
@@ -67,11 +67,11 @@ async function writeTranslations(siteDirParam = '.', options = {}) {
|
|
|
67
67
|
throw new Error(`Can't write-translation for locale "${locale}" that is not in the locale configuration file.
|
|
68
68
|
Available locales are: ${context.i18n.locales.join(',')}.`);
|
|
69
69
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const extractedCodeTranslations = await (0, translationsExtractor_1.extractSiteSourceCodeTranslations)({
|
|
71
|
+
siteDir,
|
|
72
|
+
plugins,
|
|
73
|
+
extraSourceCodeFilePaths: await getExtraSourceCodeFilePaths(),
|
|
73
74
|
});
|
|
74
|
-
const extractedCodeTranslations = await (0, translationsExtractor_1.extractSiteSourceCodeTranslations)(siteDir, plugins, babelOptions, await getExtraSourceCodeFilePaths());
|
|
75
75
|
const defaultCodeMessages = await (0, translations_1.loadPluginsDefaultCodeTranslationMessages)(plugins);
|
|
76
76
|
const codeTranslations = (0, translations_1.applyDefaultCodeTranslations)({
|
|
77
77
|
extractedCodeTranslations,
|
package/lib/index.d.ts
CHANGED
|
@@ -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
|
-
export { build } from './commands/build';
|
|
7
|
+
export { build } from './commands/build/build';
|
|
8
8
|
export { clear } from './commands/clear';
|
|
9
9
|
export { deploy } from './commands/deploy';
|
|
10
10
|
export { externalCommand } from './commands/external';
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.writeTranslations = exports.writeHeadingIds = exports.swizzle = exports.start = exports.serve = exports.externalCommand = exports.deploy = exports.clear = exports.build = void 0;
|
|
10
|
-
var build_1 = require("./commands/build");
|
|
10
|
+
var build_1 = require("./commands/build/build");
|
|
11
11
|
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
|
|
12
12
|
var clear_1 = require("./commands/clear");
|
|
13
13
|
Object.defineProperty(exports, "clear", { enumerable: true, get: function () { return clear_1.clear; } });
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { Joi } from '@docusaurus/utils-validation';
|
|
8
|
-
import type { FutureConfig, StorageConfig } from '@docusaurus/types/src/config';
|
|
8
|
+
import type { FasterConfig, FutureConfig, StorageConfig } from '@docusaurus/types/src/config';
|
|
9
9
|
import type { DocusaurusConfig, I18nConfig, MarkdownConfig } from '@docusaurus/types';
|
|
10
10
|
export declare const DEFAULT_I18N_CONFIG: I18nConfig;
|
|
11
11
|
export declare const DEFAULT_STORAGE_CONFIG: StorageConfig;
|
|
12
|
+
export declare const DEFAULT_FASTER_CONFIG: FasterConfig;
|
|
13
|
+
export declare const DEFAULT_FASTER_CONFIG_TRUE: FasterConfig;
|
|
12
14
|
export declare const DEFAULT_FUTURE_CONFIG: FutureConfig;
|
|
13
15
|
export declare const DEFAULT_MARKDOWN_CONFIG: MarkdownConfig;
|
|
14
16
|
export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'future' | 'onBrokenLinks' | 'onBrokenAnchors' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'headTags' | 'stylesheets' | 'scripts' | 'clientModules' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories' | 'markdown'>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
|
|
9
|
+
exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_FASTER_CONFIG_TRUE = exports.DEFAULT_FASTER_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
|
|
10
10
|
exports.validateConfig = validateConfig;
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
@@ -22,7 +22,25 @@ exports.DEFAULT_STORAGE_CONFIG = {
|
|
|
22
22
|
type: 'localStorage',
|
|
23
23
|
namespace: false,
|
|
24
24
|
};
|
|
25
|
+
exports.DEFAULT_FASTER_CONFIG = {
|
|
26
|
+
swcJsLoader: false,
|
|
27
|
+
swcJsMinimizer: false,
|
|
28
|
+
swcHtmlMinimizer: false,
|
|
29
|
+
lightningCssMinimizer: false,
|
|
30
|
+
mdxCrossCompilerCache: false,
|
|
31
|
+
rspackBundler: false,
|
|
32
|
+
};
|
|
33
|
+
// When using the "faster: true" shortcut
|
|
34
|
+
exports.DEFAULT_FASTER_CONFIG_TRUE = {
|
|
35
|
+
swcJsLoader: true,
|
|
36
|
+
swcJsMinimizer: true,
|
|
37
|
+
swcHtmlMinimizer: true,
|
|
38
|
+
lightningCssMinimizer: true,
|
|
39
|
+
mdxCrossCompilerCache: true,
|
|
40
|
+
rspackBundler: true,
|
|
41
|
+
};
|
|
25
42
|
exports.DEFAULT_FUTURE_CONFIG = {
|
|
43
|
+
experimental_faster: exports.DEFAULT_FASTER_CONFIG,
|
|
26
44
|
experimental_storage: exports.DEFAULT_STORAGE_CONFIG,
|
|
27
45
|
experimental_router: 'browser',
|
|
28
46
|
};
|
|
@@ -65,13 +83,12 @@ exports.DEFAULT_CONFIG = {
|
|
|
65
83
|
markdown: exports.DEFAULT_MARKDOWN_CONFIG,
|
|
66
84
|
};
|
|
67
85
|
function createPluginSchema(theme) {
|
|
68
|
-
return
|
|
86
|
+
return utils_validation_1.Joi.alternatives()
|
|
69
87
|
.try(utils_validation_1.Joi.function(), utils_validation_1.Joi.array()
|
|
70
88
|
.ordered(utils_validation_1.Joi.function().required(), utils_validation_1.Joi.object().required())
|
|
71
89
|
.length(2), utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
|
|
72
90
|
.ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
|
|
73
91
|
.length(2), utils_validation_1.Joi.any().valid(false, null))
|
|
74
|
-
// @ts-expect-error: bad lib def, doesn't recognize an array of reports
|
|
75
92
|
.error((errors) => {
|
|
76
93
|
errors.forEach((error) => {
|
|
77
94
|
const validConfigExample = theme
|
|
@@ -100,7 +117,7 @@ ${validConfigExample}
|
|
|
100
117
|
`;
|
|
101
118
|
});
|
|
102
119
|
return errors;
|
|
103
|
-
})
|
|
120
|
+
});
|
|
104
121
|
}
|
|
105
122
|
const PluginSchema = createPluginSchema(false);
|
|
106
123
|
const ThemeSchema = createPluginSchema(true);
|
|
@@ -130,6 +147,19 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
|
130
147
|
})
|
|
131
148
|
.optional()
|
|
132
149
|
.default(exports.DEFAULT_I18N_CONFIG);
|
|
150
|
+
const FASTER_CONFIG_SCHEMA = utils_validation_1.Joi.alternatives()
|
|
151
|
+
.try(utils_validation_1.Joi.object({
|
|
152
|
+
swcJsLoader: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsLoader),
|
|
153
|
+
swcJsMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsMinimizer),
|
|
154
|
+
swcHtmlMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcHtmlMinimizer),
|
|
155
|
+
lightningCssMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.lightningCssMinimizer),
|
|
156
|
+
mdxCrossCompilerCache: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.mdxCrossCompilerCache),
|
|
157
|
+
rspackBundler: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.rspackBundler),
|
|
158
|
+
}), utils_validation_1.Joi.boolean()
|
|
159
|
+
.required()
|
|
160
|
+
.custom((bool) => bool ? exports.DEFAULT_FASTER_CONFIG_TRUE : exports.DEFAULT_FASTER_CONFIG))
|
|
161
|
+
.optional()
|
|
162
|
+
.default(exports.DEFAULT_FASTER_CONFIG);
|
|
133
163
|
const STORAGE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
134
164
|
type: utils_validation_1.Joi.string()
|
|
135
165
|
.equal('localStorage', 'sessionStorage')
|
|
@@ -141,6 +171,7 @@ const STORAGE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
|
141
171
|
.optional()
|
|
142
172
|
.default(exports.DEFAULT_STORAGE_CONFIG);
|
|
143
173
|
const FUTURE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
174
|
+
experimental_faster: FASTER_CONFIG_SCHEMA,
|
|
144
175
|
experimental_storage: STORAGE_CONFIG_SCHEMA,
|
|
145
176
|
experimental_router: utils_validation_1.Joi.string()
|
|
146
177
|
.equal('browser', 'hash')
|
package/lib/server/i18n.d.ts
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
8
8
|
import type { LoadContextParams } from './site';
|
|
9
9
|
export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
|
|
10
|
-
export declare function loadI18n(config: DocusaurusConfig, options
|
|
10
|
+
export declare function loadI18n(config: DocusaurusConfig, options?: Pick<LoadContextParams, 'locale'>): Promise<I18n>;
|
package/lib/server/i18n.js
CHANGED
|
@@ -74,7 +74,7 @@ function getDefaultLocaleConfig(locale) {
|
|
|
74
74
|
}
|
|
75
75
|
async function loadI18n(config, options) {
|
|
76
76
|
const { i18n: i18nConfig } = config;
|
|
77
|
-
const currentLocale = options
|
|
77
|
+
const currentLocale = options?.locale ?? i18nConfig.defaultLocale;
|
|
78
78
|
if (!i18nConfig.locales.includes(currentLocale)) {
|
|
79
79
|
logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
|
|
80
80
|
Note: Docusaurus only support running one locale at a time.`;
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.loadPlugins = loadPlugins;
|
|
10
10
|
exports.reloadPlugin = reloadPlugin;
|
|
11
|
+
const logger_1 = require("@docusaurus/logger");
|
|
11
12
|
const init_1 = require("./init");
|
|
12
13
|
const synthetic_1 = require("./synthetic");
|
|
13
14
|
const translations_1 = require("../translations/translations");
|
|
14
15
|
const routeConfig_1 = require("./routeConfig");
|
|
15
|
-
const utils_1 = require("../../utils");
|
|
16
16
|
const actions_1 = require("./actions");
|
|
17
17
|
const pluginsUtils_1 = require("./pluginsUtils");
|
|
18
18
|
async function translatePluginContent({ plugin, content, context, }) {
|
|
@@ -35,14 +35,14 @@ async function translatePluginContent({ plugin, content, context, }) {
|
|
|
35
35
|
return translatedContent;
|
|
36
36
|
}
|
|
37
37
|
async function executePluginContentLoading({ plugin, context, }) {
|
|
38
|
-
return
|
|
39
|
-
let content = await
|
|
40
|
-
content = await
|
|
38
|
+
return logger_1.PerfLogger.async(`Load ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, async () => {
|
|
39
|
+
let content = await logger_1.PerfLogger.async('loadContent()', () => plugin.loadContent?.());
|
|
40
|
+
content = await logger_1.PerfLogger.async('translatePluginContent()', () => translatePluginContent({
|
|
41
41
|
plugin,
|
|
42
42
|
content,
|
|
43
43
|
context,
|
|
44
44
|
}));
|
|
45
|
-
const defaultCodeTranslations = (await
|
|
45
|
+
const defaultCodeTranslations = (await logger_1.PerfLogger.async('getDefaultCodeTranslationMessages()', () => plugin.getDefaultCodeTranslationMessages?.())) ?? {};
|
|
46
46
|
if (!plugin.contentLoaded) {
|
|
47
47
|
return {
|
|
48
48
|
...plugin,
|
|
@@ -58,7 +58,7 @@ async function executePluginContentLoading({ plugin, context, }) {
|
|
|
58
58
|
baseUrl: context.siteConfig.baseUrl,
|
|
59
59
|
trailingSlash: context.siteConfig.trailingSlash,
|
|
60
60
|
});
|
|
61
|
-
await
|
|
61
|
+
await logger_1.PerfLogger.async('contentLoaded()', () =>
|
|
62
62
|
// @ts-expect-error: should autofix with TS 5.4
|
|
63
63
|
plugin.contentLoaded({
|
|
64
64
|
content,
|
|
@@ -74,12 +74,12 @@ async function executePluginContentLoading({ plugin, context, }) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
async function executeAllPluginsContentLoading({ plugins, context, }) {
|
|
77
|
-
return
|
|
77
|
+
return logger_1.PerfLogger.async(`Load plugins content`, () => {
|
|
78
78
|
return Promise.all(plugins.map((plugin) => executePluginContentLoading({ plugin, context })));
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
async function executePluginAllContentLoaded({ plugin, context, allContent, }) {
|
|
82
|
-
return
|
|
82
|
+
return logger_1.PerfLogger.async(`allContentLoaded() - ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, async () => {
|
|
83
83
|
if (!plugin.allContentLoaded) {
|
|
84
84
|
return { routes: [], globalData: undefined };
|
|
85
85
|
}
|
|
@@ -100,7 +100,7 @@ async function executePluginAllContentLoaded({ plugin, context, allContent, }) {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
async function executeAllPluginsAllContentLoaded({ plugins, context, }) {
|
|
103
|
-
return
|
|
103
|
+
return logger_1.PerfLogger.async(`allContentLoaded()`, async () => {
|
|
104
104
|
const allContent = (0, pluginsUtils_1.aggregateAllContent)(plugins);
|
|
105
105
|
const allRoutes = [];
|
|
106
106
|
const allGlobalData = {};
|
|
@@ -133,10 +133,10 @@ function mergeResults({ baseUrl, plugins, allContentLoadedResult, }) {
|
|
|
133
133
|
* Initializes the plugins and run their lifecycle functions.
|
|
134
134
|
*/
|
|
135
135
|
async function loadPlugins(context) {
|
|
136
|
-
return
|
|
137
|
-
const initializedPlugins = await
|
|
136
|
+
return logger_1.PerfLogger.async('Load plugins', async () => {
|
|
137
|
+
const initializedPlugins = await logger_1.PerfLogger.async('Init plugins', () => (0, init_1.initPlugins)(context));
|
|
138
138
|
// TODO probably not the ideal place to hardcode those plugins
|
|
139
|
-
initializedPlugins.push((0, synthetic_1.createBootstrapPlugin)(context), (0, synthetic_1.createMDXFallbackPlugin)(context));
|
|
139
|
+
initializedPlugins.push((0, synthetic_1.createBootstrapPlugin)(context), await (0, synthetic_1.createMDXFallbackPlugin)(context));
|
|
140
140
|
const plugins = await executeAllPluginsContentLoading({
|
|
141
141
|
plugins: initializedPlugins,
|
|
142
142
|
context,
|
|
@@ -154,7 +154,7 @@ async function loadPlugins(context) {
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
async function reloadPlugin({ pluginIdentifier, plugins: previousPlugins, context, }) {
|
|
157
|
-
return
|
|
157
|
+
return logger_1.PerfLogger.async(`Reload plugin ${(0, pluginsUtils_1.formatPluginName)(pluginIdentifier)}`, async () => {
|
|
158
158
|
const previousPlugin = (0, pluginsUtils_1.getPluginByIdentifier)({
|
|
159
159
|
plugins: previousPlugins,
|
|
160
160
|
pluginIdentifier,
|
|
@@ -17,4 +17,4 @@ export declare function createBootstrapPlugin({ siteDir, siteConfig, }: LoadCont
|
|
|
17
17
|
* content plugins. This allows to do things such as importing repo/README.md as
|
|
18
18
|
* a partial from another doc. Not ideal solution, but good enough for now
|
|
19
19
|
*/
|
|
20
|
-
export declare function createMDXFallbackPlugin({ siteDir, siteConfig, }: LoadContext): InitializedPlugin
|
|
20
|
+
export declare function createMDXFallbackPlugin({ siteDir, siteConfig, }: LoadContext): Promise<InitializedPlugin>;
|
|
@@ -10,6 +10,7 @@ exports.createBootstrapPlugin = createBootstrapPlugin;
|
|
|
10
10
|
exports.createMDXFallbackPlugin = createMDXFallbackPlugin;
|
|
11
11
|
const tslib_1 = require("tslib");
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const mdx_loader_1 = require("@docusaurus/mdx-loader");
|
|
13
14
|
/**
|
|
14
15
|
* Make a synthetic plugin to:
|
|
15
16
|
* - Inject site client modules
|
|
@@ -57,7 +58,18 @@ function createBootstrapPlugin({ siteDir, siteConfig, }) {
|
|
|
57
58
|
* content plugins. This allows to do things such as importing repo/README.md as
|
|
58
59
|
* a partial from another doc. Not ideal solution, but good enough for now
|
|
59
60
|
*/
|
|
60
|
-
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
61
|
+
async function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
62
|
+
const mdxLoaderItem = await (0, mdx_loader_1.createMDXLoaderItem)({
|
|
63
|
+
useCrossCompilerCache: siteConfig.future.experimental_faster.mdxCrossCompilerCache,
|
|
64
|
+
admonitions: true,
|
|
65
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
66
|
+
siteDir,
|
|
67
|
+
// External MDX files are always meant to be imported as partials
|
|
68
|
+
isMDXPartial: () => true,
|
|
69
|
+
// External MDX files might have front matter, just disable the warning
|
|
70
|
+
isMDXPartialFrontMatterWarningDisabled: true,
|
|
71
|
+
markdownConfig: siteConfig.markdown,
|
|
72
|
+
});
|
|
61
73
|
return {
|
|
62
74
|
name: 'docusaurus-mdx-fallback-plugin',
|
|
63
75
|
options: {
|
|
@@ -77,28 +89,13 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
|
77
89
|
return isMDXRule ? rule.include : [];
|
|
78
90
|
});
|
|
79
91
|
}
|
|
80
|
-
const mdxLoaderOptions = {
|
|
81
|
-
admonitions: true,
|
|
82
|
-
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
83
|
-
siteDir,
|
|
84
|
-
// External MDX files are always meant to be imported as partials
|
|
85
|
-
isMDXPartial: () => true,
|
|
86
|
-
// External MDX files might have front matter, just disable the warning
|
|
87
|
-
isMDXPartialFrontMatterWarningDisabled: true,
|
|
88
|
-
markdownConfig: siteConfig.markdown,
|
|
89
|
-
};
|
|
90
92
|
return {
|
|
91
93
|
module: {
|
|
92
94
|
rules: [
|
|
93
95
|
{
|
|
94
96
|
test: /\.mdx?$/i,
|
|
95
97
|
exclude: getMDXFallbackExcludedPaths(),
|
|
96
|
-
use: [
|
|
97
|
-
{
|
|
98
|
-
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
99
|
-
options: mdxLoaderOptions,
|
|
100
|
-
},
|
|
101
|
-
],
|
|
98
|
+
use: [mdxLoaderItem],
|
|
102
99
|
},
|
|
103
100
|
],
|
|
104
101
|
},
|
package/lib/server/site.js
CHANGED
|
@@ -13,7 +13,9 @@ exports.reloadSitePlugin = reloadSitePlugin;
|
|
|
13
13
|
const tslib_1 = require("tslib");
|
|
14
14
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
15
|
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const logger_1 = require("@docusaurus/logger");
|
|
16
17
|
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
18
|
+
const bundler_1 = require("@docusaurus/bundler");
|
|
17
19
|
const config_1 = require("./config");
|
|
18
20
|
const clientModules_1 = require("./clientModules");
|
|
19
21
|
const plugins_1 = require("./plugins/plugins");
|
|
@@ -21,7 +23,6 @@ const htmlTags_1 = require("./htmlTags");
|
|
|
21
23
|
const siteMetadata_1 = require("./siteMetadata");
|
|
22
24
|
const i18n_1 = require("./i18n");
|
|
23
25
|
const translations_1 = require("./translations/translations");
|
|
24
|
-
const utils_2 = require("../utils");
|
|
25
26
|
const codegen_1 = require("./codegen/codegen");
|
|
26
27
|
const routes_1 = require("./routes");
|
|
27
28
|
const storage_1 = require("./storage");
|
|
@@ -41,6 +42,9 @@ async function loadContext(params) {
|
|
|
41
42
|
customConfigFilePath,
|
|
42
43
|
}),
|
|
43
44
|
});
|
|
45
|
+
const currentBundler = await (0, bundler_1.getCurrentBundler)({
|
|
46
|
+
siteConfig: initialSiteConfig,
|
|
47
|
+
});
|
|
44
48
|
const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
|
|
45
49
|
const baseUrl = (0, utils_1.localizePath)({
|
|
46
50
|
path: initialSiteConfig.baseUrl,
|
|
@@ -70,11 +74,12 @@ async function loadContext(params) {
|
|
|
70
74
|
baseUrl,
|
|
71
75
|
i18n,
|
|
72
76
|
codeTranslations,
|
|
77
|
+
currentBundler,
|
|
73
78
|
};
|
|
74
79
|
}
|
|
75
80
|
function createSiteProps(params) {
|
|
76
81
|
const { plugins, routes, context } = params;
|
|
77
|
-
const { generatedFilesDir, siteDir, siteVersion, siteConfig, siteConfigPath, siteStorage, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, } = context;
|
|
82
|
+
const { generatedFilesDir, siteDir, siteVersion, siteConfig, siteConfigPath, siteStorage, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, currentBundler, } = context;
|
|
78
83
|
const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)({
|
|
79
84
|
plugins,
|
|
80
85
|
router: siteConfig.future.experimental_router,
|
|
@@ -105,11 +110,12 @@ function createSiteProps(params) {
|
|
|
105
110
|
preBodyTags,
|
|
106
111
|
postBodyTags,
|
|
107
112
|
codeTranslations,
|
|
113
|
+
currentBundler,
|
|
108
114
|
};
|
|
109
115
|
}
|
|
110
116
|
// TODO global data should be part of site props?
|
|
111
117
|
async function createSiteFiles({ site, globalData, }) {
|
|
112
|
-
return
|
|
118
|
+
return logger_1.PerfLogger.async('Create site files', async () => {
|
|
113
119
|
const { props: { plugins, generatedFilesDir, siteConfig, siteMetadata, siteStorage, i18n, codeTranslations, routes, baseUrl, }, } = site;
|
|
114
120
|
const clientModules = (0, clientModules_1.getAllClientModules)(plugins);
|
|
115
121
|
await (0, codegen_1.generateSiteFiles)({
|
|
@@ -133,7 +139,7 @@ async function createSiteFiles({ site, globalData, }) {
|
|
|
133
139
|
* it generates temp files in the `.docusaurus` folder for the bundler.
|
|
134
140
|
*/
|
|
135
141
|
async function loadSite(params) {
|
|
136
|
-
const context = await
|
|
142
|
+
const context = await logger_1.PerfLogger.async('Load context', () => loadContext(params));
|
|
137
143
|
const { plugins, routes, globalData } = await (0, plugins_1.loadPlugins)(context);
|
|
138
144
|
const props = createSiteProps({ plugins, routes, globalData, context });
|
|
139
145
|
const site = { props, params };
|
|
@@ -4,15 +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 TransformOptions } from '@babel/core';
|
|
8
7
|
import type { InitializedPlugin, TranslationFileContent } from '@docusaurus/types';
|
|
9
|
-
export declare function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
warnings: string[];
|
|
15
|
-
};
|
|
16
|
-
export declare function extractAllSourceCodeFileTranslations(sourceCodeFilePaths: string[], babelOptions: TransformOptions): Promise<SourceCodeFileTranslations[]>;
|
|
17
|
-
export declare function extractSourceCodeFileTranslations(sourceCodeFilePath: string, babelOptions: TransformOptions): Promise<SourceCodeFileTranslations>;
|
|
18
|
-
export {};
|
|
8
|
+
export declare function extractSiteSourceCodeTranslations({ siteDir, plugins, extraSourceCodeFilePaths, }: {
|
|
9
|
+
siteDir: string;
|
|
10
|
+
plugins: InitializedPlugin[];
|
|
11
|
+
extraSourceCodeFilePaths?: string[];
|
|
12
|
+
}): Promise<TranslationFileContent>;
|