@docusaurus/core 2.0.0-beta.15 → 2.0.0-beta.16
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 +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +62 -40
- package/lib/babel/preset.d.ts +1 -2
- package/lib/babel/preset.js +5 -4
- package/lib/choosePort.js +22 -30
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +13 -8
- package/lib/client/LinksCollector.js +1 -1
- package/lib/client/PendingNavigation.d.ts +4 -4
- package/lib/client/PendingNavigation.js +4 -6
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +5 -7
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.js +6 -4
- package/lib/client/exports/BrowserOnly.d.ts +1 -2
- package/lib/client/exports/BrowserOnly.js +2 -3
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/ErrorBoundary.js +1 -2
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.js +9 -12
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +13 -7
- package/lib/client/exports/Translate.js +2 -1
- package/lib/client/exports/browserContext.js +3 -2
- package/lib/client/exports/docusaurusContext.js +1 -1
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useDocusaurusContext.d.ts +1 -2
- package/lib/client/exports/useDocusaurusContext.js +1 -2
- package/lib/client/flat.d.ts +1 -2
- package/lib/client/flat.js +1 -2
- package/lib/client/normalizeLocation.d.ts +2 -3
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -2
- package/lib/client/preload.d.ts +2 -1
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.js +23 -19
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +21 -29
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +46 -114
- package/lib/{server/versions/__tests/index.test.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -5
- package/lib/commands/build.js +33 -34
- package/lib/commands/clear.js +23 -11
- package/lib/commands/deploy.js +12 -11
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +1 -1
- package/lib/commands/serve.js +3 -2
- package/lib/commands/start.js +4 -4
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +57 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +165 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +77 -0
- package/lib/commands/swizzle/context.d.ts +8 -0
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/commands/swizzle/tables.d.ts +9 -0
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +105 -0
- package/lib/commands/writeHeadingIds.d.ts +1 -1
- package/lib/commands/writeHeadingIds.js +13 -14
- package/lib/commands/writeTranslations.js +10 -7
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.js +30 -20
- package/lib/server/config.js +1 -1
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +32 -23
- package/lib/server/duplicateRoutes.js +2 -4
- package/lib/server/html-tags/htmlTags.js +1 -2
- package/lib/server/i18n.d.ts +0 -1
- package/lib/server/i18n.js +16 -26
- package/lib/server/index.d.ts +1 -1
- package/lib/server/index.js +17 -15
- package/lib/server/loadSetup.d.ts +1 -2
- package/lib/server/loadSetup.js +2 -2
- package/lib/server/moduleShorthand.js +1 -1
- package/lib/server/plugins/index.js +9 -9
- package/lib/server/plugins/init.d.ts +11 -1
- package/lib/server/plugins/init.js +23 -28
- package/lib/server/plugins/pluginIds.js +4 -3
- package/lib/server/presets/index.d.ts +2 -2
- package/lib/server/presets/index.js +3 -3
- package/lib/server/routes.js +13 -7
- package/lib/server/themes/alias.d.ts +1 -1
- package/lib/server/themes/alias.js +5 -6
- package/lib/server/themes/index.d.ts +2 -2
- package/lib/server/themes/index.js +10 -9
- package/lib/server/translations/translations.js +10 -11
- package/lib/server/translations/translationsExtractor.js +20 -19
- package/lib/server/versions/index.d.ts +2 -3
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +2 -2
- package/lib/webpack/base.js +30 -22
- package/lib/webpack/client.d.ts +1 -1
- package/lib/webpack/client.js +7 -4
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +12 -2
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +5 -5
- package/lib/webpack/plugins/CleanWebpackPlugin.js +5 -4
- package/lib/webpack/server.d.ts +1 -1
- package/lib/webpack/server.js +6 -5
- package/lib/webpack/utils.d.ts +3 -3
- package/lib/webpack/utils.js +17 -37
- package/package.json +56 -56
- package/bin/beforeCli.js +0 -124
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -236
- package/lib/server/versions/__tests/index.test.js +0 -26
|
@@ -6,6 +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.normalizePluginConfigs = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const module_1 = require("module");
|
|
11
12
|
const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
|
|
@@ -13,7 +14,7 @@ const utils_1 = require("@docusaurus/utils");
|
|
|
13
14
|
const versions_1 = require("../versions");
|
|
14
15
|
const pluginIds_1 = require("./pluginIds");
|
|
15
16
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
17
|
+
async function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
17
18
|
var _a, _b, _c, _d;
|
|
18
19
|
// plugins: ['./plugin']
|
|
19
20
|
if (typeof pluginConfig === 'string') {
|
|
@@ -65,15 +66,17 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
65
66
|
}
|
|
66
67
|
throw new Error(`Unexpected: can't load plugin for following plugin config.\n${JSON.stringify(pluginConfig)}`);
|
|
67
68
|
}
|
|
69
|
+
async function normalizePluginConfigs(pluginConfigs, pluginRequire) {
|
|
70
|
+
return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, pluginRequire)));
|
|
71
|
+
}
|
|
72
|
+
exports.normalizePluginConfigs = normalizePluginConfigs;
|
|
68
73
|
function getOptionValidationFunction(normalizedPluginConfig) {
|
|
69
74
|
var _a, _b, _c, _d;
|
|
70
75
|
if (normalizedPluginConfig.pluginModule) {
|
|
71
76
|
// support both commonjs and ES modules
|
|
72
77
|
return ((_c = (_b = (_a = normalizedPluginConfig.pluginModule.module) === null || _a === void 0 ? void 0 : _a.default) === null || _b === void 0 ? void 0 : _b.validateOptions) !== null && _c !== void 0 ? _c : (_d = normalizedPluginConfig.pluginModule.module) === null || _d === void 0 ? void 0 : _d.validateOptions);
|
|
73
78
|
}
|
|
74
|
-
|
|
75
|
-
return normalizedPluginConfig.plugin.validateOptions;
|
|
76
|
-
}
|
|
79
|
+
return normalizedPluginConfig.plugin.validateOptions;
|
|
77
80
|
}
|
|
78
81
|
function getThemeValidationFunction(normalizedPluginConfig) {
|
|
79
82
|
var _a, _b;
|
|
@@ -81,24 +84,21 @@ function getThemeValidationFunction(normalizedPluginConfig) {
|
|
|
81
84
|
// support both commonjs and ES modules
|
|
82
85
|
return ((_b = (_a = normalizedPluginConfig.pluginModule.module.default) === null || _a === void 0 ? void 0 : _a.validateThemeConfig) !== null && _b !== void 0 ? _b : normalizedPluginConfig.pluginModule.module.validateThemeConfig);
|
|
83
86
|
}
|
|
84
|
-
|
|
85
|
-
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
86
|
-
}
|
|
87
|
+
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
87
88
|
}
|
|
88
89
|
async function initPlugins({ pluginConfigs, context, }) {
|
|
89
|
-
// We need to resolve plugins from the perspective of the siteDir, since the
|
|
90
|
-
// declares the dependency on these plugins.
|
|
90
|
+
// We need to resolve plugins from the perspective of the siteDir, since the
|
|
91
|
+
// siteDir's package.json declares the dependency on these plugins.
|
|
91
92
|
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
92
|
-
|
|
93
|
+
const pluginConfigsNormalized = await normalizePluginConfigs(pluginConfigs, pluginRequire);
|
|
94
|
+
async function doGetPluginVersion(normalizedPluginConfig) {
|
|
93
95
|
var _a, _b;
|
|
94
96
|
// get plugin version
|
|
95
97
|
if ((_a = normalizedPluginConfig.pluginModule) === null || _a === void 0 ? void 0 : _a.path) {
|
|
96
98
|
const pluginPath = pluginRequire.resolve((_b = normalizedPluginConfig.pluginModule) === null || _b === void 0 ? void 0 : _b.path);
|
|
97
99
|
return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
return { type: 'local' };
|
|
101
|
-
}
|
|
101
|
+
return { type: 'local' };
|
|
102
102
|
}
|
|
103
103
|
function doValidateThemeConfig(normalizedPluginConfig) {
|
|
104
104
|
const validateThemeConfig = getThemeValidationFunction(normalizedPluginConfig);
|
|
@@ -108,9 +108,7 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
108
108
|
themeConfig: context.siteConfig.themeConfig,
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
return context.siteConfig.themeConfig;
|
|
113
|
-
}
|
|
111
|
+
return context.siteConfig.themeConfig;
|
|
114
112
|
}
|
|
115
113
|
function doValidatePluginOptions(normalizedPluginConfig) {
|
|
116
114
|
var _a;
|
|
@@ -121,18 +119,15 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
121
119
|
options: normalizedPluginConfig.options,
|
|
122
120
|
});
|
|
123
121
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
131
|
-
}
|
|
122
|
+
// Important to ensure all plugins have an id
|
|
123
|
+
// as we don't go through the Joi schema that adds it
|
|
124
|
+
return {
|
|
125
|
+
...normalizedPluginConfig.options,
|
|
126
|
+
id: (_a = normalizedPluginConfig.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID,
|
|
127
|
+
};
|
|
132
128
|
}
|
|
133
|
-
async function initializePlugin(
|
|
134
|
-
const
|
|
135
|
-
const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
|
|
129
|
+
async function initializePlugin(normalizedPluginConfig) {
|
|
130
|
+
const pluginVersion = await doGetPluginVersion(normalizedPluginConfig);
|
|
136
131
|
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
|
137
132
|
// Side-effect: merge the normalized theme config in the original one
|
|
138
133
|
context.siteConfig.themeConfig = {
|
|
@@ -146,7 +141,7 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
146
141
|
version: pluginVersion,
|
|
147
142
|
};
|
|
148
143
|
}
|
|
149
|
-
const plugins = (await Promise.all(
|
|
144
|
+
const plugins = (await Promise.all(pluginConfigsNormalized.map((pluginConfig) => {
|
|
150
145
|
if (!pluginConfig) {
|
|
151
146
|
return null;
|
|
152
147
|
}
|
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ensureUniquePluginInstanceIds = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
12
|
const utils_1 = require("@docusaurus/utils");
|
|
12
13
|
// It is forbidden to have 2 plugins of the same name sharing the same id
|
|
13
14
|
// this is required to support multi-instance plugins without conflict
|
|
14
15
|
function ensureUniquePluginInstanceIds(plugins) {
|
|
15
|
-
const pluginsByName =
|
|
16
|
+
const pluginsByName = lodash_1.default.groupBy(plugins, (p) => p.name);
|
|
16
17
|
Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
|
|
17
|
-
const pluginInstancesById =
|
|
18
|
+
const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) => { var _a; return (_a = p.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID; });
|
|
18
19
|
Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
|
|
19
20
|
if (pluginInstancesWithId.length !== 1) {
|
|
20
21
|
throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with ID "${pluginId}".\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.${pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { LoadContext, PluginConfig } from '@docusaurus/types';
|
|
8
|
-
export default function loadPresets(context: LoadContext): {
|
|
8
|
+
export default function loadPresets(context: LoadContext): Promise<{
|
|
9
9
|
plugins: PluginConfig[];
|
|
10
10
|
themes: PluginConfig[];
|
|
11
|
-
}
|
|
11
|
+
}>;
|
|
@@ -10,9 +10,9 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
const module_1 = require("module");
|
|
11
11
|
const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
|
|
12
12
|
const moduleShorthand_1 = require("../moduleShorthand");
|
|
13
|
-
function loadPresets(context) {
|
|
14
|
-
// We need to resolve presets from the perspective of the siteDir, since the
|
|
15
|
-
// declares the dependency on these presets.
|
|
13
|
+
async function loadPresets(context) {
|
|
14
|
+
// We need to resolve presets from the perspective of the siteDir, since the
|
|
15
|
+
// siteDir's package.json declares the dependency on these presets.
|
|
16
16
|
const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
17
17
|
const presets = context.siteConfig.presets || [];
|
|
18
18
|
const unflatPlugins = [];
|
package/lib/server/routes.js
CHANGED
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const utils_1 = require("@docusaurus/utils");
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
10
|
const querystring_1 = require("querystring");
|
|
12
11
|
function indent(str) {
|
|
13
12
|
const spaces = ' ';
|
|
14
|
-
return `${spaces}${str.replace(
|
|
13
|
+
return `${spaces}${str.replace(/\n/g, `\n${spaces}`)}`;
|
|
15
14
|
}
|
|
16
15
|
const createRouteCodeString = ({ routePath, routeHash, exact, subroutesCodeStrings, props, }) => {
|
|
17
16
|
const parts = [
|
|
@@ -46,10 +45,15 @@ const RoutesImportsCode = [
|
|
|
46
45
|
`import ComponentCreator from '@docusaurus/ComponentCreator';`,
|
|
47
46
|
].join('\n');
|
|
48
47
|
function isModule(value) {
|
|
49
|
-
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if (typeof value === 'string') {
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
52
|
+
if (typeof value === 'object' &&
|
|
53
|
+
(
|
|
54
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
55
|
+
(_a = value) === null || _a === void 0 ? void 0 : _a.__import) &&
|
|
56
|
+
((_b = value) === null || _b === void 0 ? void 0 : _b.path)) {
|
|
53
57
|
return true;
|
|
54
58
|
}
|
|
55
59
|
return false;
|
|
@@ -68,12 +72,14 @@ async function loadRoutes(pluginsRouteConfigs, baseUrl) {
|
|
|
68
72
|
// This is the higher level overview of route code generation.
|
|
69
73
|
function generateRouteCode(routeConfig) {
|
|
70
74
|
const { path: routePath, component, modules = {}, routes: subroutes, exact, priority, ...props } = routeConfig;
|
|
71
|
-
if (
|
|
72
|
-
throw new Error(`Invalid route config: path must be a string and component is required
|
|
75
|
+
if (typeof routePath !== 'string' || !component) {
|
|
76
|
+
throw new Error(`Invalid route config: path must be a string and component is required.
|
|
77
|
+
${JSON.stringify(routeConfig)}`);
|
|
73
78
|
}
|
|
74
79
|
// Collect all page paths for injecting it later in the plugin lifecycle
|
|
75
80
|
// This is useful for plugins like sitemaps, redirects etc...
|
|
76
|
-
// If a route has subroutes, it is not necessarily a valid page path (more
|
|
81
|
+
// If a route has subroutes, it is not necessarily a valid page path (more
|
|
82
|
+
// likely to be a wrapper)
|
|
77
83
|
if (!subroutes) {
|
|
78
84
|
routesPaths.push(routePath);
|
|
79
85
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { ThemeAliases } from '@docusaurus/types';
|
|
8
8
|
export declare function sortAliases(aliases: ThemeAliases): ThemeAliases;
|
|
9
|
-
export default function themeAlias(themePath: string, addOriginalAlias: boolean): ThemeAliases
|
|
9
|
+
export default function themeAlias(themePath: string, addOriginalAlias: boolean): Promise<ThemeAliases>;
|
|
@@ -11,25 +11,24 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
12
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
14
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
15
15
|
// Order of Webpack aliases is important because one alias can shadow another
|
|
16
16
|
// This ensure @theme/NavbarItem alias is after @theme/NavbarItem/LocaleDropdown
|
|
17
17
|
// See https://github.com/facebook/docusaurus/pull/3922
|
|
18
18
|
// See https://github.com/facebook/docusaurus/issues/5382
|
|
19
19
|
function sortAliases(aliases) {
|
|
20
20
|
// Alphabetical order by default
|
|
21
|
-
const entries =
|
|
21
|
+
const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
|
|
22
22
|
// @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
|
|
23
23
|
entries.sort(([alias1], [alias2]) => alias1.includes(`${alias2}/`) ? -1 : 0);
|
|
24
24
|
return Object.fromEntries(entries);
|
|
25
25
|
}
|
|
26
26
|
exports.sortAliases = sortAliases;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (!fs_extra_1.default.pathExistsSync(themePath)) {
|
|
27
|
+
async function themeAlias(themePath, addOriginalAlias) {
|
|
28
|
+
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
|
30
29
|
return {};
|
|
31
30
|
}
|
|
32
|
-
const themeComponentFiles = utils_1.Globby
|
|
31
|
+
const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
|
|
33
32
|
cwd: themePath,
|
|
34
33
|
});
|
|
35
34
|
const aliases = {};
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
-
export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): ThemeAliases
|
|
8
|
+
export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): Promise<ThemeAliases>;
|
|
9
9
|
export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
|
|
10
10
|
siteDir: string;
|
|
11
11
|
plugins: LoadedPlugin[];
|
|
12
|
-
}): ThemeAliases
|
|
12
|
+
}): Promise<ThemeAliases>;
|
|
@@ -12,13 +12,14 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const alias_1 = (0, tslib_1.__importStar)(require("./alias"));
|
|
14
14
|
const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
|
|
15
|
-
function loadThemeAliases(themePaths, userThemePaths) {
|
|
15
|
+
async function loadThemeAliases(themePaths, userThemePaths) {
|
|
16
16
|
const aliases = {};
|
|
17
|
-
|
|
18
|
-
const themeAliases = (0, alias_1.default)(themePath, true);
|
|
17
|
+
for (const themePath of themePaths) {
|
|
18
|
+
const themeAliases = await (0, alias_1.default)(themePath, true);
|
|
19
19
|
Object.keys(themeAliases).forEach((aliasKey) => {
|
|
20
|
-
// If this alias shadows a previous one, use @theme-init to preserve the
|
|
21
|
-
// @theme-init is only applied once: to the initial theme
|
|
20
|
+
// If this alias shadows a previous one, use @theme-init to preserve the
|
|
21
|
+
// initial one. @theme-init is only applied once: to the initial theme
|
|
22
|
+
// that provided this component
|
|
22
23
|
if (aliasKey in aliases) {
|
|
23
24
|
const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
|
|
24
25
|
const initAlias = `@theme-init/${componentName}`;
|
|
@@ -28,11 +29,11 @@ function loadThemeAliases(themePaths, userThemePaths) {
|
|
|
28
29
|
}
|
|
29
30
|
aliases[aliasKey] = themeAliases[aliasKey];
|
|
30
31
|
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const userThemeAliases = (0, alias_1.default)(themePath, false);
|
|
32
|
+
}
|
|
33
|
+
for (const themePath of userThemePaths) {
|
|
34
|
+
const userThemeAliases = await (0, alias_1.default)(themePath, false);
|
|
34
35
|
Object.assign(aliases, userThemeAliases);
|
|
35
|
-
}
|
|
36
|
+
}
|
|
36
37
|
return (0, alias_1.sortAliases)(aliases);
|
|
37
38
|
}
|
|
38
39
|
exports.loadThemeAliases = loadThemeAliases;
|
|
@@ -10,7 +10,7 @@ exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationM
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
12
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
-
const lodash_1 = require("lodash");
|
|
13
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
15
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
16
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
@@ -35,8 +35,9 @@ async function readTranslationFileContent(filePath) {
|
|
|
35
35
|
ensureTranslationFileContent(content);
|
|
36
36
|
return content;
|
|
37
37
|
}
|
|
38
|
-
catch (
|
|
39
|
-
|
|
38
|
+
catch (err) {
|
|
39
|
+
logger_1.default.error `Invalid translation file at path=${filePath}.`;
|
|
40
|
+
throw err;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
return undefined;
|
|
@@ -44,7 +45,7 @@ async function readTranslationFileContent(filePath) {
|
|
|
44
45
|
exports.readTranslationFileContent = readTranslationFileContent;
|
|
45
46
|
function mergeTranslationFileContent({ existingContent = {}, newContent, options, }) {
|
|
46
47
|
// Apply messagePrefix to all messages
|
|
47
|
-
const newContentTransformed =
|
|
48
|
+
const newContentTransformed = lodash_1.default.mapValues(newContent, (value) => {
|
|
48
49
|
var _a;
|
|
49
50
|
return ({
|
|
50
51
|
...value,
|
|
@@ -56,7 +57,7 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
|
|
|
56
57
|
Object.entries(newContentTransformed).forEach(([key, { message, description }]) => {
|
|
57
58
|
var _a, _b;
|
|
58
59
|
result[key] = {
|
|
59
|
-
// If
|
|
60
|
+
// If messages already exist, we don't override them (unless requested)
|
|
60
61
|
message: options.override
|
|
61
62
|
? message
|
|
62
63
|
: (_b = (_a = existingContent[key]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : message,
|
|
@@ -68,7 +69,7 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
|
|
|
68
69
|
async function writeTranslationFileContent({ filePath, content: newContent, options = {}, }) {
|
|
69
70
|
const existingContent = await readTranslationFileContent(filePath);
|
|
70
71
|
// Warn about potential legacy keys
|
|
71
|
-
const unknownKeys =
|
|
72
|
+
const unknownKeys = lodash_1.default.difference(Object.keys(existingContent !== null && existingContent !== void 0 ? existingContent : {}), Object.keys(newContent));
|
|
72
73
|
if (unknownKeys.length > 0) {
|
|
73
74
|
logger_1.default.warn `Some translation keys looks unknown to us in file path=${filePath}.
|
|
74
75
|
Maybe you should remove them? ${unknownKeys}`;
|
|
@@ -162,9 +163,7 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
|
|
|
162
163
|
},
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
|
-
|
|
166
|
-
return translationFile;
|
|
167
|
-
}
|
|
166
|
+
return translationFile;
|
|
168
167
|
}
|
|
169
168
|
exports.localizePluginTranslationFile = localizePluginTranslationFile;
|
|
170
169
|
async function getPluginsDefaultCodeTranslationMessages(plugins) {
|
|
@@ -173,12 +172,12 @@ async function getPluginsDefaultCodeTranslationMessages(plugins) {
|
|
|
173
172
|
}
|
|
174
173
|
exports.getPluginsDefaultCodeTranslationMessages = getPluginsDefaultCodeTranslationMessages;
|
|
175
174
|
function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }) {
|
|
176
|
-
const unusedDefaultCodeMessages =
|
|
175
|
+
const unusedDefaultCodeMessages = lodash_1.default.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
|
|
177
176
|
if (unusedDefaultCodeMessages.length > 0) {
|
|
178
177
|
logger_1.default.warn `Unused default message codes found.
|
|
179
178
|
Please report this Docusaurus issue. name=${unusedDefaultCodeMessages}`;
|
|
180
179
|
}
|
|
181
|
-
return
|
|
180
|
+
return lodash_1.default.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
|
|
182
181
|
var _a;
|
|
183
182
|
return ({
|
|
184
183
|
...messageTranslation,
|
|
@@ -36,8 +36,9 @@ function getSiteSourceCodeFilePaths(siteDir) {
|
|
|
36
36
|
function getPluginSourceCodeFilePaths(plugin) {
|
|
37
37
|
var _a, _b, _c;
|
|
38
38
|
// The getPathsToWatch() generally returns the js/jsx/ts/tsx/md/mdx file paths
|
|
39
|
-
// We can use this method as well to know which folders we should try to
|
|
40
|
-
// Hacky/implicit, but do we want to introduce a
|
|
39
|
+
// We can use this method as well to know which folders we should try to
|
|
40
|
+
// extract translations from. Hacky/implicit, but do we want to introduce a
|
|
41
|
+
// new lifecycle method just for that???
|
|
41
42
|
const codePaths = (_b = (_a = plugin.getPathsToWatch) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : [];
|
|
42
43
|
// We also include theme code
|
|
43
44
|
const themePath = (_c = plugin.getThemePath) === null || _c === void 0 ? void 0 : _c.call(plugin);
|
|
@@ -54,14 +55,16 @@ exports.globSourceCodeFilePaths = globSourceCodeFilePaths;
|
|
|
54
55
|
async function getSourceCodeFilePaths(siteDir, plugins) {
|
|
55
56
|
const sitePaths = getSiteSourceCodeFilePaths(siteDir);
|
|
56
57
|
// The getPathsToWatch() generally returns the js/jsx/ts/tsx/md/mdx file paths
|
|
57
|
-
// We can use this method as well to know which folders we should try to
|
|
58
|
-
// Hacky/implicit, but do we want to introduce a
|
|
58
|
+
// We can use this method as well to know which folders we should try to
|
|
59
|
+
// extract translations from. Hacky/implicit, but do we want to introduce a
|
|
60
|
+
// new lifecycle method for that???
|
|
59
61
|
const pluginsPaths = plugins.flatMap(getPluginSourceCodeFilePaths);
|
|
60
62
|
const allPaths = [...sitePaths, ...pluginsPaths];
|
|
61
63
|
return globSourceCodeFilePaths(allPaths);
|
|
62
64
|
}
|
|
63
65
|
async function extractSiteSourceCodeTranslations(siteDir, plugins, babelOptions, extraSourceCodeFilePaths = []) {
|
|
64
|
-
// Should we warn here if the same translation "key" is found in multiple
|
|
66
|
+
// Should we warn here if the same translation "key" is found in multiple
|
|
67
|
+
// source code files?
|
|
65
68
|
function toTranslationFileContent(sourceCodeFileTranslations) {
|
|
66
69
|
return sourceCodeFileTranslations.reduce((acc, item) => ({ ...acc, ...item.translations }), {});
|
|
67
70
|
}
|
|
@@ -92,18 +95,17 @@ async function extractSourceCodeFileTranslations(sourceCodeFilePath, babelOption
|
|
|
92
95
|
const ast = (0, core_1.parse)(code, {
|
|
93
96
|
...babelOptions,
|
|
94
97
|
ast: true,
|
|
95
|
-
// filename is important, because babel does not process the same files
|
|
96
|
-
//
|
|
98
|
+
// filename is important, because babel does not process the same files
|
|
99
|
+
// according to their js/ts extensions.
|
|
100
|
+
// See https://twitter.com/NicoloRibaudo/status/1321130735605002243
|
|
97
101
|
filename: sourceCodeFilePath,
|
|
98
102
|
});
|
|
99
103
|
const translations = await extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
|
|
100
104
|
return translations;
|
|
101
105
|
}
|
|
102
|
-
catch (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
throw e;
|
|
106
|
+
catch (err) {
|
|
107
|
+
logger_1.default.error `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}.`;
|
|
108
|
+
throw err;
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
exports.extractSourceCodeFileTranslations = extractSourceCodeFileTranslations;
|
|
@@ -169,12 +171,10 @@ Full code: ${(0, generator_1.default)(node).code}`;
|
|
|
169
171
|
typeof attributeValueEvaluated.value === 'string') {
|
|
170
172
|
return attributeValueEvaluated.value;
|
|
171
173
|
}
|
|
172
|
-
|
|
173
|
-
warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.
|
|
174
|
+
warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.
|
|
174
175
|
Example: <Translate id="optional id" description="optional description">Message</Translate>
|
|
175
176
|
Dynamically constructed values are not allowed, because they prevent translations to be extracted.
|
|
176
177
|
${sourceWarningPart(path.node)}`);
|
|
177
|
-
}
|
|
178
178
|
}
|
|
179
179
|
return undefined;
|
|
180
180
|
}
|
|
@@ -191,7 +191,7 @@ ${sourceWarningPart(path.node)}`);
|
|
|
191
191
|
}
|
|
192
192
|
else {
|
|
193
193
|
translations[id] = {
|
|
194
|
-
message:
|
|
194
|
+
message: id,
|
|
195
195
|
...(description && { description }),
|
|
196
196
|
};
|
|
197
197
|
}
|
|
@@ -199,8 +199,9 @@ ${sourceWarningPart(path.node)}`);
|
|
|
199
199
|
}
|
|
200
200
|
// Handle single non-empty content
|
|
201
201
|
const singleChildren = childrenPath
|
|
202
|
-
// Remove empty/useless text nodes that might be around our
|
|
203
|
-
// Makes the translation system more reliable to JSX
|
|
202
|
+
// Remove empty/useless text nodes that might be around our
|
|
203
|
+
// translation! Makes the translation system more reliable to JSX
|
|
204
|
+
// formatting issues
|
|
204
205
|
.filter((children) => !(children.isJSXText() &&
|
|
205
206
|
children.node.value.replace('\n', '').trim() === ''))
|
|
206
207
|
.pop();
|
|
@@ -231,7 +232,7 @@ ${sourceWarningPart(path.node)}`);
|
|
|
231
232
|
const args = path.get('arguments');
|
|
232
233
|
if (args.length === 1 || args.length === 2) {
|
|
233
234
|
const firstArgPath = args[0];
|
|
234
|
-
//
|
|
235
|
+
// translate("x" + "y"); => translate("xy");
|
|
235
236
|
const firstArgEvaluated = firstArgPath.evaluate();
|
|
236
237
|
if (firstArgEvaluated.confident &&
|
|
237
238
|
typeof firstArgEvaluated.value === 'object') {
|
|
@@ -5,6 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { DocusaurusPluginVersionInformation } from '@docusaurus/types';
|
|
8
|
-
export declare function getPackageJsonVersion(packageJsonPath: string): string | undefined
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function getPluginVersion(pluginPath: string, siteDir: string): DocusaurusPluginVersionInformation;
|
|
8
|
+
export declare function getPackageJsonVersion(packageJsonPath: string): Promise<string | undefined>;
|
|
9
|
+
export declare function getPluginVersion(pluginPath: string, siteDir: string): Promise<DocusaurusPluginVersionInformation>;
|
|
@@ -6,45 +6,46 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getPluginVersion = exports.
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
exports.getPluginVersion = exports.getPackageJsonVersion = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
13
|
+
async function getPackageJsonVersion(packageJsonPath) {
|
|
14
|
+
if (await fs_extra_1.default.pathExists(packageJsonPath)) {
|
|
14
15
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
15
|
-
|
|
16
|
-
return typeof version === 'string' ? version : undefined;
|
|
16
|
+
return require(packageJsonPath).version;
|
|
17
17
|
}
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
exports.getPackageJsonVersion = getPackageJsonVersion;
|
|
21
|
-
function getPackageJsonName(packageJsonPath) {
|
|
22
|
-
if (
|
|
21
|
+
async function getPackageJsonName(packageJsonPath) {
|
|
22
|
+
if (await fs_extra_1.default.pathExists(packageJsonPath)) {
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
24
|
-
|
|
25
|
-
return typeof name === 'string' ? name : undefined;
|
|
24
|
+
return require(packageJsonPath).name;
|
|
26
25
|
}
|
|
27
26
|
return undefined;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let potentialPluginPackageJsonDirectory = (0, path_1.dirname)(pluginPath);
|
|
28
|
+
async function getPluginVersion(pluginPath, siteDir) {
|
|
29
|
+
let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
|
|
32
30
|
while (potentialPluginPackageJsonDirectory !== '/') {
|
|
33
|
-
const packageJsonPath =
|
|
34
|
-
if ((
|
|
31
|
+
const packageJsonPath = path_1.default.join(potentialPluginPackageJsonDirectory, 'package.json');
|
|
32
|
+
if ((await fs_extra_1.default.pathExists(packageJsonPath)) &&
|
|
33
|
+
(await fs_extra_1.default.lstat(packageJsonPath)).isFile()) {
|
|
35
34
|
if (potentialPluginPackageJsonDirectory === siteDir) {
|
|
36
|
-
// If the plugin belongs to the same docusaurus project, we classify it
|
|
35
|
+
// If the plugin belongs to the same docusaurus project, we classify it
|
|
36
|
+
// as local plugin.
|
|
37
37
|
return { type: 'project' };
|
|
38
38
|
}
|
|
39
39
|
return {
|
|
40
40
|
type: 'package',
|
|
41
|
-
name: getPackageJsonName(packageJsonPath),
|
|
42
|
-
version: getPackageJsonVersion(packageJsonPath),
|
|
41
|
+
name: await getPackageJsonName(packageJsonPath),
|
|
42
|
+
version: await getPackageJsonVersion(packageJsonPath),
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
potentialPluginPackageJsonDirectory =
|
|
45
|
+
potentialPluginPackageJsonDirectory = path_1.default.dirname(potentialPluginPackageJsonDirectory);
|
|
46
46
|
}
|
|
47
|
-
// In
|
|
47
|
+
// In the case where a plugin is a path where no parent directory contains
|
|
48
|
+
// package.json (e.g. inline plugin), we can only classify it as local.
|
|
48
49
|
return { type: 'local' };
|
|
49
50
|
}
|
|
50
51
|
exports.getPluginVersion = getPluginVersion;
|
package/lib/webpack/base.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ import type { Configuration } from 'webpack';
|
|
|
8
8
|
import type { Props } from '@docusaurus/types';
|
|
9
9
|
export declare const clientDir: string;
|
|
10
10
|
export declare function excludeJS(modulePath: string): boolean;
|
|
11
|
-
export declare function getDocusaurusAliases(): Record<string, string
|
|
12
|
-
export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Configuration
|
|
11
|
+
export declare function getDocusaurusAliases(): Promise<Record<string, string>>;
|
|
12
|
+
export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Promise<Configuration>;
|