@docusaurus/core 0.0.0-4798 → 0.0.0-4801
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/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +6 -3
- package/lib/commands/clear.d.ts +1 -1
- package/lib/commands/clear.js +2 -1
- package/lib/commands/commandUtils.js +2 -3
- package/lib/commands/deploy.d.ts +1 -1
- package/lib/commands/deploy.js +6 -4
- package/lib/commands/external.d.ts +1 -1
- package/lib/commands/external.js +5 -6
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +6 -5
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +4 -2
- package/lib/commands/swizzle/common.d.ts +1 -2
- package/lib/commands/swizzle/context.js +6 -10
- package/lib/commands/swizzle/index.d.ts +1 -1
- package/lib/commands/swizzle/index.js +2 -1
- package/lib/commands/writeHeadingIds.d.ts +1 -1
- package/lib/commands/writeHeadingIds.js +5 -8
- package/lib/commands/writeTranslations.d.ts +1 -1
- package/lib/commands/writeTranslations.js +6 -8
- package/lib/index.d.ts +9 -10
- package/lib/index.js +18 -19
- package/lib/server/choosePort.d.ts +12 -0
- package/lib/{choosePort.js → server/choosePort.js} +8 -10
- package/lib/server/{client-modules/index.d.ts → clientModules.d.ts} +5 -1
- package/lib/server/{client-modules/index.js → clientModules.js} +6 -1
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +11 -6
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +2 -11
- package/lib/server/i18n.js +1 -18
- package/lib/server/index.d.ts +26 -11
- package/lib/server/index.js +40 -201
- package/lib/server/plugins/configs.d.ts +14 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +6 -6
- package/lib/server/plugins/index.js +29 -64
- package/lib/server/plugins/init.d.ts +6 -19
- package/lib/server/plugins/init.js +14 -65
- package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
- package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
- package/lib/server/plugins/pluginIds.d.ts +4 -0
- package/lib/server/plugins/pluginIds.js +4 -2
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/{presets/index.js → plugins/presets.js} +9 -4
- package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +2 -1
- package/lib/server/plugins/routeConfig.js +53 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +112 -0
- package/lib/server/routes.d.ts +3 -2
- package/lib/server/routes.js +50 -24
- package/lib/server/{versions/index.d.ts → siteMetadata.d.ts} +5 -2
- package/lib/server/{versions/index.js → siteMetadata.js} +36 -3
- package/lib/server/translations/translations.js +1 -4
- package/lib/webpack/aliases/index.d.ts +29 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +0 -3
- package/lib/webpack/base.js +4 -21
- package/package.json +10 -11
- package/lib/choosePort.d.ts +0 -11
- package/lib/server/duplicateRoutes.d.ts +0 -8
- package/lib/server/duplicateRoutes.js +0 -42
- package/lib/server/html-tags/htmlTags.d.ts +0 -7
- package/lib/server/html-tags/htmlTags.js +0 -38
- package/lib/server/html-tags/index.d.ts +0 -8
- package/lib/server/html-tags/index.js +0 -42
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/themes/alias.d.ts +0 -9
- package/lib/server/themes/alias.js +0 -50
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
|
@@ -0,0 +1,62 @@
|
|
|
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.loadHtmlTags = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
|
|
12
|
+
const void_1 = tslib_1.__importDefault(require("html-tags/void"));
|
|
13
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
|
+
function assertIsHtmlTagObject(val) {
|
|
16
|
+
if (typeof val !== 'object' || !val) {
|
|
17
|
+
throw new Error(`"${val}" is not a valid HTML tag object.`);
|
|
18
|
+
}
|
|
19
|
+
if (typeof val.tagName !== 'string') {
|
|
20
|
+
throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string.`);
|
|
21
|
+
}
|
|
22
|
+
if (!html_tags_1.default.includes(val.tagName)) {
|
|
23
|
+
throw new Error(`Error loading ${JSON.stringify(val)}, "${val.tagName}" is not a valid HTML tag.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function htmlTagObjectToString(tag) {
|
|
27
|
+
assertIsHtmlTagObject(tag);
|
|
28
|
+
const isVoidTag = void_1.default.includes(tag.tagName);
|
|
29
|
+
const tagAttributes = tag.attributes ?? {};
|
|
30
|
+
const attributes = Object.keys(tagAttributes)
|
|
31
|
+
.map((attr) => {
|
|
32
|
+
const value = tagAttributes[attr];
|
|
33
|
+
if (typeof value === 'boolean') {
|
|
34
|
+
return value ? attr : undefined;
|
|
35
|
+
}
|
|
36
|
+
return `${attr}="${(0, escape_html_1.default)(value)}"`;
|
|
37
|
+
})
|
|
38
|
+
.filter((str) => Boolean(str));
|
|
39
|
+
const openingTag = `<${[tag.tagName].concat(attributes).join(' ')}>`;
|
|
40
|
+
const innerHTML = (!isVoidTag && tag.innerHTML) || '';
|
|
41
|
+
const closingTag = isVoidTag ? '' : `</${tag.tagName}>`;
|
|
42
|
+
return openingTag + innerHTML + closingTag;
|
|
43
|
+
}
|
|
44
|
+
function createHtmlTagsString(tags) {
|
|
45
|
+
return (Array.isArray(tags) ? tags : [tags])
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.map((val) => (typeof val === 'string' ? val : htmlTagObjectToString(val)))
|
|
48
|
+
.join('\n');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Runs the `injectHtmlTags` lifecycle, and aggregates all plugins' tags into
|
|
52
|
+
* directly render-able HTML markup.
|
|
53
|
+
*/
|
|
54
|
+
function loadHtmlTags(plugins) {
|
|
55
|
+
const pluginHtmlTags = plugins.map((plugin) => plugin.injectHtmlTags?.({ content: plugin.content }) ?? {});
|
|
56
|
+
const tagTypes = ['headTags', 'preBodyTags', 'postBodyTags'];
|
|
57
|
+
return Object.fromEntries(lodash_1.default.zip(tagTypes, tagTypes.map((type) => pluginHtmlTags
|
|
58
|
+
.map((tags) => createHtmlTagsString(tags[type]))
|
|
59
|
+
.join('\n')
|
|
60
|
+
.trim())));
|
|
61
|
+
}
|
|
62
|
+
exports.loadHtmlTags = loadHtmlTags;
|
package/lib/server/i18n.d.ts
CHANGED
|
@@ -5,15 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
8
|
+
import type { LoadContextOptions } from './index';
|
|
8
9
|
export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
|
|
9
|
-
export declare function loadI18n(config: DocusaurusConfig, options:
|
|
10
|
-
locale?: string;
|
|
11
|
-
}): Promise<I18n>;
|
|
12
|
-
export declare function localizePath({ pathType, path: originalPath, i18n, options, }: {
|
|
13
|
-
pathType: 'fs' | 'url';
|
|
14
|
-
path: string;
|
|
15
|
-
i18n: I18n;
|
|
16
|
-
options?: {
|
|
17
|
-
localizePath?: boolean;
|
|
18
|
-
};
|
|
19
|
-
}): string;
|
|
10
|
+
export declare function loadI18n(config: DocusaurusConfig, options: Pick<LoadContextOptions, 'locale'>): Promise<I18n>;
|
package/lib/server/i18n.js
CHANGED
|
@@ -6,10 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const utils_1 = require("@docusaurus/utils");
|
|
13
11
|
const rtl_detect_1 = require("rtl-detect");
|
|
14
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
13
|
function getDefaultLocaleLabel(locale) {
|
|
@@ -49,18 +47,3 @@ Note: Docusaurus only support running one locale at a time.`;
|
|
|
49
47
|
};
|
|
50
48
|
}
|
|
51
49
|
exports.loadI18n = loadI18n;
|
|
52
|
-
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
53
|
-
const shouldLocalizePath =
|
|
54
|
-
// By default, we don't localize the path of defaultLocale
|
|
55
|
-
options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
|
56
|
-
if (!shouldLocalizePath) {
|
|
57
|
-
return originalPath;
|
|
58
|
-
}
|
|
59
|
-
// FS paths need special care, for Windows support
|
|
60
|
-
if (pathType === 'fs') {
|
|
61
|
-
return path_1.default.join(originalPath, i18n.currentLocale);
|
|
62
|
-
}
|
|
63
|
-
// Url paths; add a trailing slash so it's a valid base URL
|
|
64
|
-
return (0, utils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
|
|
65
|
-
}
|
|
66
|
-
exports.localizePath = localizePath;
|
package/lib/server/index.d.ts
CHANGED
|
@@ -4,20 +4,35 @@
|
|
|
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 {
|
|
7
|
+
import type { LoadContext, Props } from '@docusaurus/types';
|
|
8
8
|
export declare type LoadContextOptions = {
|
|
9
|
+
/** Usually the CWD; can be overridden with command argument. */
|
|
10
|
+
siteDir: string;
|
|
11
|
+
/** Can be customized with `--out-dir` option */
|
|
9
12
|
customOutDir?: string;
|
|
13
|
+
/** Can be customized with `--config` option */
|
|
10
14
|
customConfigFilePath?: string;
|
|
15
|
+
/** Default is `i18n.defaultLocale` */
|
|
11
16
|
locale?: string;
|
|
17
|
+
/**
|
|
18
|
+
* `true` means the paths will have the locale prepended; `false` means they
|
|
19
|
+
* won't (useful for `yarn build -l zh-Hans` where the output should be
|
|
20
|
+
* emitted into `build/` instead of `build/zh-Hans/`); `undefined` is like the
|
|
21
|
+
* "smart" option where only non-default locale paths are localized
|
|
22
|
+
*/
|
|
12
23
|
localizePath?: boolean;
|
|
13
24
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Loading context is the very first step in site building. Its options are
|
|
27
|
+
* directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
|
|
28
|
+
* context (which includes code translations). The `LoadContext` will be passed
|
|
29
|
+
* to plugin constructors.
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadContext(options: LoadContextOptions): Promise<LoadContext>;
|
|
32
|
+
/**
|
|
33
|
+
* This is the crux of the Docusaurus server-side. It reads everything it needs—
|
|
34
|
+
* code translations, config file, plugin modules... Plugins then use their
|
|
35
|
+
* lifecycles to generate content and other data. It is side-effect-ful because
|
|
36
|
+
* it generates temp files in the `.docusaurus` folder for the bundler.
|
|
37
|
+
*/
|
|
38
|
+
export declare function load(options: LoadContextOptions): Promise<Props>;
|
package/lib/server/index.js
CHANGED
|
@@ -6,50 +6,42 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.load = exports.
|
|
9
|
+
exports.load = exports.loadContext = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
13
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
-
const
|
|
14
|
+
const config_1 = require("./config");
|
|
14
15
|
const ssr_html_template_1 = tslib_1.__importDefault(require("../webpack/templates/ssr.html.template"));
|
|
15
|
-
const
|
|
16
|
-
const config_1 = tslib_1.__importDefault(require("./config"));
|
|
16
|
+
const clientModules_1 = require("./clientModules");
|
|
17
17
|
const plugins_1 = require("./plugins");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const versions_1 = require("./versions");
|
|
22
|
-
const duplicateRoutes_1 = require("./duplicateRoutes");
|
|
18
|
+
const routes_1 = require("./routes");
|
|
19
|
+
const htmlTags_1 = require("./htmlTags");
|
|
20
|
+
const siteMetadata_1 = require("./siteMetadata");
|
|
23
21
|
const i18n_1 = require("./i18n");
|
|
24
22
|
const translations_1 = require("./translations/translations");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
exports.loadSiteConfig = loadSiteConfig;
|
|
35
|
-
async function loadContext(siteDir, options = {}) {
|
|
36
|
-
const { customOutDir, locale, customConfigFilePath } = options;
|
|
23
|
+
/**
|
|
24
|
+
* Loading context is the very first step in site building. Its options are
|
|
25
|
+
* directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
|
|
26
|
+
* context (which includes code translations). The `LoadContext` will be passed
|
|
27
|
+
* to plugin constructors.
|
|
28
|
+
*/
|
|
29
|
+
async function loadContext(options) {
|
|
30
|
+
const { siteDir, customOutDir, locale, customConfigFilePath } = options;
|
|
37
31
|
const generatedFilesDir = path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
|
|
38
|
-
const { siteConfig: initialSiteConfig, siteConfigPath } = await loadSiteConfig({
|
|
32
|
+
const { siteConfig: initialSiteConfig, siteConfigPath } = await (0, config_1.loadSiteConfig)({
|
|
39
33
|
siteDir,
|
|
40
34
|
customConfigFilePath,
|
|
41
35
|
});
|
|
42
|
-
const { ssrTemplate } = initialSiteConfig;
|
|
43
|
-
const baseOutDir = path_1.default.resolve(siteDir, customOutDir ?? utils_1.DEFAULT_BUILD_DIR_NAME);
|
|
44
36
|
const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
|
|
45
|
-
const baseUrl = (0,
|
|
37
|
+
const baseUrl = (0, utils_1.localizePath)({
|
|
46
38
|
path: initialSiteConfig.baseUrl,
|
|
47
39
|
i18n,
|
|
48
40
|
options,
|
|
49
41
|
pathType: 'url',
|
|
50
42
|
});
|
|
51
|
-
const outDir = (0,
|
|
52
|
-
path:
|
|
43
|
+
const outDir = (0, utils_1.localizePath)({
|
|
44
|
+
path: path_1.default.resolve(siteDir, customOutDir ?? utils_1.DEFAULT_BUILD_DIR_NAME),
|
|
53
45
|
i18n,
|
|
54
46
|
options,
|
|
55
47
|
pathType: 'fs',
|
|
@@ -69,144 +61,33 @@ async function loadContext(siteDir, options = {}) {
|
|
|
69
61
|
outDir,
|
|
70
62
|
baseUrl,
|
|
71
63
|
i18n,
|
|
72
|
-
ssrTemplate: ssrTemplate ?? ssr_html_template_1.default,
|
|
64
|
+
ssrTemplate: siteConfig.ssrTemplate ?? ssr_html_template_1.default,
|
|
73
65
|
codeTranslations,
|
|
74
66
|
};
|
|
75
67
|
}
|
|
76
68
|
exports.loadContext = loadContext;
|
|
77
|
-
async function loadPluginConfigs(context) {
|
|
78
|
-
let { plugins: presetPlugins, themes: presetThemes } = await (0, presets_1.default)(context);
|
|
79
|
-
const { siteConfig, siteConfigPath } = context;
|
|
80
|
-
const require = (0, module_1.createRequire)(siteConfigPath);
|
|
81
|
-
function normalizeShorthand(pluginConfig, pluginType) {
|
|
82
|
-
if (typeof pluginConfig === 'string') {
|
|
83
|
-
return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
|
|
84
|
-
}
|
|
85
|
-
else if (Array.isArray(pluginConfig) &&
|
|
86
|
-
typeof pluginConfig[0] === 'string') {
|
|
87
|
-
return [
|
|
88
|
-
(0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
|
|
89
|
-
pluginConfig[1] ?? {},
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
return pluginConfig;
|
|
93
|
-
}
|
|
94
|
-
presetPlugins = presetPlugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
95
|
-
presetThemes = presetThemes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
96
|
-
const standalonePlugins = siteConfig.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
97
|
-
const standaloneThemes = siteConfig.themes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
98
|
-
return [
|
|
99
|
-
...presetPlugins,
|
|
100
|
-
...presetThemes,
|
|
101
|
-
// Site config should be the highest priority.
|
|
102
|
-
...standalonePlugins,
|
|
103
|
-
...standaloneThemes,
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
exports.loadPluginConfigs = loadPluginConfigs;
|
|
107
|
-
// Make a fake plugin to:
|
|
108
|
-
// - Resolve aliased theme components
|
|
109
|
-
// - Inject scripts/stylesheets
|
|
110
|
-
function createBootstrapPlugin({ siteDir, siteConfig, }) {
|
|
111
|
-
const { stylesheets, scripts, clientModules: siteConfigClientModules, } = siteConfig;
|
|
112
|
-
return {
|
|
113
|
-
name: 'docusaurus-bootstrap-plugin',
|
|
114
|
-
content: null,
|
|
115
|
-
options: {
|
|
116
|
-
id: 'default',
|
|
117
|
-
},
|
|
118
|
-
version: { type: 'synthetic' },
|
|
119
|
-
path: siteDir,
|
|
120
|
-
getClientModules() {
|
|
121
|
-
return siteConfigClientModules;
|
|
122
|
-
},
|
|
123
|
-
injectHtmlTags: () => {
|
|
124
|
-
const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
|
|
125
|
-
? `<link rel="stylesheet" href="${source}">`
|
|
126
|
-
: {
|
|
127
|
-
tagName: 'link',
|
|
128
|
-
attributes: {
|
|
129
|
-
rel: 'stylesheet',
|
|
130
|
-
...source,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
const scriptsTags = scripts.map((source) => typeof source === 'string'
|
|
134
|
-
? `<script src="${source}"></script>`
|
|
135
|
-
: {
|
|
136
|
-
tagName: 'script',
|
|
137
|
-
attributes: {
|
|
138
|
-
...source,
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
return {
|
|
142
|
-
headTags: [...stylesheetsTags, ...scriptsTags],
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
69
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
70
|
+
* This is the crux of the Docusaurus server-side. It reads everything it needs—
|
|
71
|
+
* code translations, config file, plugin modules... Plugins then use their
|
|
72
|
+
* lifecycles to generate content and other data. It is side-effect-ful because
|
|
73
|
+
* it generates temp files in the `.docusaurus` folder for the bundler.
|
|
152
74
|
*/
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
id: 'default',
|
|
159
|
-
},
|
|
160
|
-
version: { type: 'synthetic' },
|
|
161
|
-
// Synthetic, the path doesn't matter much
|
|
162
|
-
path: '.',
|
|
163
|
-
configureWebpack(config, isServer, { getJSLoader }) {
|
|
164
|
-
// We need the mdx fallback loader to exclude files that were already
|
|
165
|
-
// processed by content plugins mdx loaders. This works, but a bit
|
|
166
|
-
// hacky... Not sure there's a way to handle that differently in webpack
|
|
167
|
-
function getMDXFallbackExcludedPaths() {
|
|
168
|
-
const rules = config?.module?.rules;
|
|
169
|
-
return rules.flatMap((rule) => {
|
|
170
|
-
const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
|
|
171
|
-
return isMDXRule ? rule.include : [];
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
module: {
|
|
176
|
-
rules: [
|
|
177
|
-
{
|
|
178
|
-
test: /\.mdx?$/i,
|
|
179
|
-
exclude: getMDXFallbackExcludedPaths(),
|
|
180
|
-
use: [
|
|
181
|
-
getJSLoader({ isServer }),
|
|
182
|
-
{
|
|
183
|
-
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
184
|
-
options: {
|
|
185
|
-
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
186
|
-
siteDir,
|
|
187
|
-
isMDXPartial: () => true,
|
|
188
|
-
isMDXPartialFrontMatterWarningDisabled: true,
|
|
189
|
-
remarkPlugins: [remark_admonitions_1.default],
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
],
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
async function load(siteDir, options = {}) {
|
|
201
|
-
// Context.
|
|
202
|
-
const context = await loadContext(siteDir, options);
|
|
203
|
-
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
|
|
204
|
-
// Plugins.
|
|
205
|
-
const pluginConfigs = await loadPluginConfigs(context);
|
|
206
|
-
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
|
|
75
|
+
async function load(options) {
|
|
76
|
+
const { siteDir } = options;
|
|
77
|
+
const context = await loadContext(options);
|
|
78
|
+
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations: siteCodeTranslations, } = context;
|
|
79
|
+
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)(context);
|
|
207
80
|
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
208
81
|
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
209
|
-
(0,
|
|
82
|
+
const clientModules = (0, clientModules_1.loadClientModules)(plugins);
|
|
83
|
+
const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
|
|
84
|
+
const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.loadRoutes)(pluginsRouteConfigs, baseUrl, siteConfig.onDuplicateRoutes);
|
|
85
|
+
const codeTranslations = {
|
|
86
|
+
...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
|
|
87
|
+
...siteCodeTranslations,
|
|
88
|
+
};
|
|
89
|
+
const siteMetadata = await (0, siteMetadata_1.loadSiteMetadata)({ plugins, siteDir });
|
|
90
|
+
// === Side-effects part ===
|
|
210
91
|
const genWarning = (0, utils_1.generate)(generatedFilesDir, 'DONT-EDIT-THIS-FOLDER', `This folder stores temp files that Docusaurus' client bundler accesses.
|
|
211
92
|
|
|
212
93
|
DO NOT hand-modify files in this folder because they will be overwritten in the
|
|
@@ -222,9 +103,6 @@ next build. You can clear all build artifacts (including this folder) with the
|
|
|
222
103
|
*/
|
|
223
104
|
export default ${JSON.stringify(siteConfig, null, 2)};
|
|
224
105
|
`);
|
|
225
|
-
plugins.push(createBootstrapPlugin({ siteDir, siteConfig }), createMDXFallbackPlugin({ siteDir, siteConfig }));
|
|
226
|
-
// Load client modules.
|
|
227
|
-
const clientModules = (0, client_modules_1.default)(plugins);
|
|
228
106
|
const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [
|
|
229
107
|
${clientModules
|
|
230
108
|
// import() is async so we use require() because client modules can have
|
|
@@ -233,10 +111,6 @@ ${clientModules
|
|
|
233
111
|
.join('\n')}
|
|
234
112
|
];
|
|
235
113
|
`);
|
|
236
|
-
// Load extra head & body html tags.
|
|
237
|
-
const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
|
|
238
|
-
// Routing.
|
|
239
|
-
const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.default)(pluginsRouteConfigs, baseUrl);
|
|
240
114
|
const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
|
|
241
115
|
${Object.entries(registry)
|
|
242
116
|
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
@@ -247,23 +121,7 @@ ${Object.entries(registry)
|
|
|
247
121
|
const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
|
|
248
122
|
const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
249
123
|
const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
250
|
-
const
|
|
251
|
-
...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
|
|
252
|
-
...codeTranslations,
|
|
253
|
-
};
|
|
254
|
-
const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
|
|
255
|
-
// Version metadata.
|
|
256
|
-
const siteMetadata = {
|
|
257
|
-
docusaurusVersion: (await (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json'))),
|
|
258
|
-
siteVersion: await (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
|
|
259
|
-
pluginVersions: {},
|
|
260
|
-
};
|
|
261
|
-
plugins
|
|
262
|
-
.filter(({ version: { type } }) => type !== 'synthetic')
|
|
263
|
-
.forEach(({ name, version }) => {
|
|
264
|
-
siteMetadata.pluginVersions[name] = version;
|
|
265
|
-
});
|
|
266
|
-
checkDocusaurusPackagesVersion(siteMetadata);
|
|
124
|
+
const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslations, null, 2));
|
|
267
125
|
const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
|
|
268
126
|
await Promise.all([
|
|
269
127
|
genWarning,
|
|
@@ -277,7 +135,7 @@ ${Object.entries(registry)
|
|
|
277
135
|
genI18n,
|
|
278
136
|
genCodeTranslations,
|
|
279
137
|
]);
|
|
280
|
-
|
|
138
|
+
return {
|
|
281
139
|
siteConfig,
|
|
282
140
|
siteConfigPath,
|
|
283
141
|
siteMetadata,
|
|
@@ -295,24 +153,5 @@ ${Object.entries(registry)
|
|
|
295
153
|
ssrTemplate,
|
|
296
154
|
codeTranslations,
|
|
297
155
|
};
|
|
298
|
-
return props;
|
|
299
156
|
}
|
|
300
157
|
exports.load = load;
|
|
301
|
-
// We want all @docusaurus/* packages to have the exact same version!
|
|
302
|
-
// See https://github.com/facebook/docusaurus/issues/3371
|
|
303
|
-
// See https://github.com/facebook/docusaurus/pull/3386
|
|
304
|
-
function checkDocusaurusPackagesVersion(siteMetadata) {
|
|
305
|
-
const { docusaurusVersion } = siteMetadata;
|
|
306
|
-
Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
|
|
307
|
-
if (versionInfo.type === 'package' &&
|
|
308
|
-
versionInfo.name?.startsWith('@docusaurus/') &&
|
|
309
|
-
versionInfo.version &&
|
|
310
|
-
versionInfo.version !== docusaurusVersion) {
|
|
311
|
-
// should we throw instead?
|
|
312
|
-
// It still could work with different versions
|
|
313
|
-
logger_1.default.error `Invalid name=${plugin} version number=${versionInfo.version}.
|
|
314
|
-
All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
|
|
315
|
-
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { LoadContext, NormalizedPluginConfig } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Reads the site config's `presets`, `themes`, and `plugins`, imports them, and
|
|
10
|
+
* normalizes the return value. Plugin configs are ordered, mostly for theme
|
|
11
|
+
* alias shadowing. Site themes have the highest priority, and preset plugins
|
|
12
|
+
* are the lowest.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadPluginConfigs(context: LoadContext): Promise<NormalizedPluginConfig[]>;
|
|
@@ -0,0 +1,101 @@
|
|
|
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.loadPluginConfigs = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
|
+
const presets_1 = require("./presets");
|
|
14
|
+
const moduleShorthand_1 = require("./moduleShorthand");
|
|
15
|
+
async function normalizePluginConfig(pluginConfig, configPath, pluginRequire) {
|
|
16
|
+
// plugins: ["./plugin"]
|
|
17
|
+
if (typeof pluginConfig === 'string') {
|
|
18
|
+
const pluginModuleImport = pluginConfig;
|
|
19
|
+
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
20
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
21
|
+
return {
|
|
22
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
23
|
+
options: {},
|
|
24
|
+
pluginModule: {
|
|
25
|
+
path: pluginModuleImport,
|
|
26
|
+
module: pluginModule,
|
|
27
|
+
},
|
|
28
|
+
entryPath: pluginPath,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// plugins: [() => {...}]
|
|
32
|
+
if (typeof pluginConfig === 'function') {
|
|
33
|
+
return {
|
|
34
|
+
plugin: pluginConfig,
|
|
35
|
+
options: {},
|
|
36
|
+
entryPath: configPath,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// plugins: [
|
|
40
|
+
// ["./plugin",options],
|
|
41
|
+
// ]
|
|
42
|
+
if (typeof pluginConfig[0] === 'string') {
|
|
43
|
+
const pluginModuleImport = pluginConfig[0];
|
|
44
|
+
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
45
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
46
|
+
return {
|
|
47
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
48
|
+
options: pluginConfig[1],
|
|
49
|
+
pluginModule: {
|
|
50
|
+
path: pluginModuleImport,
|
|
51
|
+
module: pluginModule,
|
|
52
|
+
},
|
|
53
|
+
entryPath: pluginPath,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// plugins: [
|
|
57
|
+
// [() => {...}, options],
|
|
58
|
+
// ]
|
|
59
|
+
return {
|
|
60
|
+
plugin: pluginConfig[0],
|
|
61
|
+
options: pluginConfig[1],
|
|
62
|
+
entryPath: configPath,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reads the site config's `presets`, `themes`, and `plugins`, imports them, and
|
|
67
|
+
* normalizes the return value. Plugin configs are ordered, mostly for theme
|
|
68
|
+
* alias shadowing. Site themes have the highest priority, and preset plugins
|
|
69
|
+
* are the lowest.
|
|
70
|
+
*/
|
|
71
|
+
async function loadPluginConfigs(context) {
|
|
72
|
+
const preset = await (0, presets_1.loadPresets)(context);
|
|
73
|
+
const { siteConfig, siteConfigPath } = context;
|
|
74
|
+
const pluginRequire = (0, module_1.createRequire)(siteConfigPath);
|
|
75
|
+
function normalizeShorthand(pluginConfig, pluginType) {
|
|
76
|
+
if (typeof pluginConfig === 'string') {
|
|
77
|
+
return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, pluginRequire, pluginType);
|
|
78
|
+
}
|
|
79
|
+
else if (Array.isArray(pluginConfig) &&
|
|
80
|
+
typeof pluginConfig[0] === 'string') {
|
|
81
|
+
return [
|
|
82
|
+
(0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], pluginRequire, pluginType),
|
|
83
|
+
pluginConfig[1] ?? {},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
return pluginConfig;
|
|
87
|
+
}
|
|
88
|
+
preset.plugins = preset.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
89
|
+
preset.themes = preset.themes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
90
|
+
const standalonePlugins = siteConfig.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
91
|
+
const standaloneThemes = siteConfig.themes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
92
|
+
const pluginConfigs = [
|
|
93
|
+
...preset.plugins,
|
|
94
|
+
...preset.themes,
|
|
95
|
+
// Site config should be the highest priority.
|
|
96
|
+
...standalonePlugins,
|
|
97
|
+
...standaloneThemes,
|
|
98
|
+
];
|
|
99
|
+
return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, context.siteConfigPath, pluginRequire)));
|
|
100
|
+
}
|
|
101
|
+
exports.loadPluginConfigs = loadPluginConfigs;
|
|
@@ -4,12 +4,12 @@
|
|
|
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 { LoadContext,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import type { LoadContext, RouteConfig, GlobalData, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Initializes the plugins, runs `loadContent`, `translateContent`,
|
|
10
|
+
* `contentLoaded`, and `translateThemeConfig`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadPlugins(context: LoadContext): Promise<{
|
|
13
13
|
plugins: LoadedPlugin[];
|
|
14
14
|
pluginsRouteConfigs: RouteConfig[];
|
|
15
15
|
globalData: GlobalData;
|