@docusaurus/core 0.0.0-4521 → 0.0.0-4526
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/babel/preset.js +5 -4
- package/lib/client/PendingNavigation.d.ts +3 -3
- package/lib/client/PendingNavigation.js +2 -2
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +8 -5
- package/lib/client/clientEntry.js +5 -3
- package/lib/client/docusaurus.js +6 -4
- package/lib/client/exports/ComponentCreator.js +4 -1
- package/lib/client/exports/Interpolate.js +9 -13
- package/lib/client/exports/Link.js +4 -3
- package/lib/client/exports/Translate.js +2 -1
- package/lib/client/exports/browserContext.js +2 -1
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/preload.d.ts +2 -1
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.js +2 -2
- package/lib/client/theme-fallback/Error/index.js +5 -3
- package/lib/commands/build.js +15 -17
- package/lib/commands/deploy.js +4 -4
- package/lib/commands/external.js +1 -1
- package/lib/commands/serve.js +2 -2
- package/lib/commands/swizzle.js +7 -5
- package/lib/commands/writeHeadingIds.js +12 -13
- package/lib/commands/writeTranslations.js +8 -5
- package/lib/server/brokenLinks.js +14 -9
- package/lib/server/duplicateRoutes.js +2 -4
- package/lib/server/i18n.js +11 -15
- package/lib/server/index.d.ts +1 -1
- package/lib/server/index.js +13 -11
- package/lib/server/moduleShorthand.js +1 -1
- package/lib/server/plugins/index.js +6 -6
- package/lib/server/plugins/init.js +14 -24
- package/lib/server/presets/index.d.ts +2 -2
- package/lib/server/presets/index.js +3 -3
- package/lib/server/routes.js +3 -2
- package/lib/server/themes/index.js +3 -2
- package/lib/server/translations/translations.js +2 -4
- package/lib/server/translations/translationsExtractor.js +17 -14
- package/lib/server/versions/index.js +4 -2
- package/lib/webpack/base.js +23 -15
- package/lib/webpack/client.js +5 -2
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +11 -0
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +4 -3
- package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -1
- package/lib/webpack/server.js +4 -3
- package/lib/webpack/utils.js +8 -9
- package/package.json +10 -10
package/lib/server/index.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ export declare function loadSiteConfig({ siteDir, customConfigFilePath, }: {
|
|
|
19
19
|
siteConfigPath: string;
|
|
20
20
|
}>;
|
|
21
21
|
export declare function loadContext(siteDir: string, options?: LoadContextOptions): Promise<LoadContext>;
|
|
22
|
-
export declare function loadPluginConfigs(context: LoadContext): PluginConfig[]
|
|
22
|
+
export declare function loadPluginConfigs(context: LoadContext): Promise<PluginConfig[]>;
|
|
23
23
|
export declare function load(siteDir: string, options?: LoadContextOptions): Promise<Props>;
|
package/lib/server/index.js
CHANGED
|
@@ -82,8 +82,8 @@ async function loadContext(siteDir, options = {}) {
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
exports.loadContext = loadContext;
|
|
85
|
-
function loadPluginConfigs(context) {
|
|
86
|
-
let { plugins: presetPlugins, themes: presetThemes } = (0, presets_1.default)(context);
|
|
85
|
+
async function loadPluginConfigs(context) {
|
|
86
|
+
let { plugins: presetPlugins, themes: presetThemes } = await (0, presets_1.default)(context);
|
|
87
87
|
const { siteConfig, siteConfigPath } = context;
|
|
88
88
|
const require = (0, module_1.createRequire)(siteConfigPath);
|
|
89
89
|
function normalizeShorthand(pluginConfig, pluginType) {
|
|
@@ -150,10 +150,12 @@ function createBootstrapPlugin({ siteConfig, }) {
|
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
|
|
155
|
+
* folders. Adds a "fallback" mdx loader for mdx files that are not processed by
|
|
156
|
+
* content plugins. This allows to do things such as importing repo/README.md as
|
|
157
|
+
* a partial from another doc. Not ideal solution, but good enough for now
|
|
158
|
+
*/
|
|
157
159
|
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
158
160
|
return {
|
|
159
161
|
name: 'docusaurus-mdx-fallback-plugin',
|
|
@@ -161,9 +163,9 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
|
161
163
|
options: {},
|
|
162
164
|
version: { type: 'synthetic' },
|
|
163
165
|
configureWebpack(config, isServer, { getJSLoader }) {
|
|
164
|
-
// We need the mdx fallback loader to exclude files that were already
|
|
165
|
-
// This works, but a bit
|
|
166
|
-
// Not sure there's a way to handle that differently in webpack
|
|
166
|
+
// We need the mdx fallback loader to exclude files that were already
|
|
167
|
+
// processed by content plugins mdx loaders. This works, but a bit
|
|
168
|
+
// hacky... Not sure there's a way to handle that differently in webpack
|
|
167
169
|
function getMDXFallbackExcludedPaths() {
|
|
168
170
|
var _a;
|
|
169
171
|
const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
|
|
@@ -176,7 +178,7 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
|
176
178
|
module: {
|
|
177
179
|
rules: [
|
|
178
180
|
{
|
|
179
|
-
test:
|
|
181
|
+
test: /\.mdx?$/i,
|
|
180
182
|
exclude: getMDXFallbackExcludedPaths(),
|
|
181
183
|
use: [
|
|
182
184
|
getJSLoader({ isServer }),
|
|
@@ -203,7 +205,7 @@ async function load(siteDir, options = {}) {
|
|
|
203
205
|
const context = await loadContext(siteDir, options);
|
|
204
206
|
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
|
|
205
207
|
// Plugins.
|
|
206
|
-
const pluginConfigs = loadPluginConfigs(context);
|
|
208
|
+
const pluginConfigs = await loadPluginConfigs(context);
|
|
207
209
|
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
|
|
208
210
|
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
209
211
|
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
@@ -13,7 +13,7 @@ function getNamePatterns(moduleName, moduleType) {
|
|
|
13
13
|
if (!moduleName.includes('/')) {
|
|
14
14
|
return [`${moduleName}/docusaurus-${moduleType}`];
|
|
15
15
|
}
|
|
16
|
-
const [scope, packageName] = moduleName.split(/\/(
|
|
16
|
+
const [scope, packageName] = moduleName.split(/\/(?<rest>.*)/);
|
|
17
17
|
return [
|
|
18
18
|
`${scope}/${packageName}`,
|
|
19
19
|
`${scope}/docusaurus-${moduleType}-${packageName}`,
|
|
@@ -57,9 +57,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
57
57
|
context,
|
|
58
58
|
});
|
|
59
59
|
// 2. Plugin Lifecycle - loadContent.
|
|
60
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
61
|
-
// We could change this in future if there are plugins which
|
|
62
|
-
// run in certain order or depend on others for data.
|
|
60
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
61
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
62
|
+
// need to run in certain order or depend on others for data.
|
|
63
63
|
const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
|
|
64
64
|
const content = plugin.loadContent ? await plugin.loadContent() : null;
|
|
65
65
|
return { ...plugin, content };
|
|
@@ -134,9 +134,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
134
134
|
});
|
|
135
135
|
}));
|
|
136
136
|
// 4. Plugin Lifecycle - routesLoaded.
|
|
137
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
138
|
-
// We could change this in future if there are plugins which
|
|
139
|
-
// run in certain order or depend on others for data.
|
|
137
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
138
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
139
|
+
// need to run in certain order or depend on others for data.
|
|
140
140
|
await Promise.all(contentLoadedTranslatedPlugins.map(async (plugin) => {
|
|
141
141
|
if (!plugin.routesLoaded) {
|
|
142
142
|
return null;
|
|
@@ -13,7 +13,7 @@ const utils_1 = require("@docusaurus/utils");
|
|
|
13
13
|
const versions_1 = require("../versions");
|
|
14
14
|
const pluginIds_1 = require("./pluginIds");
|
|
15
15
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
16
|
+
async function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
17
17
|
var _a, _b, _c, _d;
|
|
18
18
|
// plugins: ['./plugin']
|
|
19
19
|
if (typeof pluginConfig === 'string') {
|
|
@@ -71,9 +71,7 @@ function getOptionValidationFunction(normalizedPluginConfig) {
|
|
|
71
71
|
// support both commonjs and ES modules
|
|
72
72
|
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
73
|
}
|
|
74
|
-
|
|
75
|
-
return normalizedPluginConfig.plugin.validateOptions;
|
|
76
|
-
}
|
|
74
|
+
return normalizedPluginConfig.plugin.validateOptions;
|
|
77
75
|
}
|
|
78
76
|
function getThemeValidationFunction(normalizedPluginConfig) {
|
|
79
77
|
var _a, _b;
|
|
@@ -81,13 +79,11 @@ function getThemeValidationFunction(normalizedPluginConfig) {
|
|
|
81
79
|
// support both commonjs and ES modules
|
|
82
80
|
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
81
|
}
|
|
84
|
-
|
|
85
|
-
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
86
|
-
}
|
|
82
|
+
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
87
83
|
}
|
|
88
84
|
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.
|
|
85
|
+
// We need to resolve plugins from the perspective of the siteDir, since the
|
|
86
|
+
// siteDir's package.json declares the dependency on these plugins.
|
|
91
87
|
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
92
88
|
function doGetPluginVersion(normalizedPluginConfig) {
|
|
93
89
|
var _a, _b;
|
|
@@ -96,9 +92,7 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
96
92
|
const pluginPath = pluginRequire.resolve((_b = normalizedPluginConfig.pluginModule) === null || _b === void 0 ? void 0 : _b.path);
|
|
97
93
|
return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
|
|
98
94
|
}
|
|
99
|
-
|
|
100
|
-
return { type: 'local' };
|
|
101
|
-
}
|
|
95
|
+
return { type: 'local' };
|
|
102
96
|
}
|
|
103
97
|
function doValidateThemeConfig(normalizedPluginConfig) {
|
|
104
98
|
const validateThemeConfig = getThemeValidationFunction(normalizedPluginConfig);
|
|
@@ -108,9 +102,7 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
108
102
|
themeConfig: context.siteConfig.themeConfig,
|
|
109
103
|
});
|
|
110
104
|
}
|
|
111
|
-
|
|
112
|
-
return context.siteConfig.themeConfig;
|
|
113
|
-
}
|
|
105
|
+
return context.siteConfig.themeConfig;
|
|
114
106
|
}
|
|
115
107
|
function doValidatePluginOptions(normalizedPluginConfig) {
|
|
116
108
|
var _a;
|
|
@@ -121,17 +113,15 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
121
113
|
options: normalizedPluginConfig.options,
|
|
122
114
|
});
|
|
123
115
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
131
|
-
}
|
|
116
|
+
// Important to ensure all plugins have an id
|
|
117
|
+
// as we don't go through the Joi schema that adds it
|
|
118
|
+
return {
|
|
119
|
+
...normalizedPluginConfig.options,
|
|
120
|
+
id: (_a = normalizedPluginConfig.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID,
|
|
121
|
+
};
|
|
132
122
|
}
|
|
133
123
|
async function initializePlugin(pluginConfig) {
|
|
134
|
-
const normalizedPluginConfig = normalizePluginConfig(pluginConfig, pluginRequire);
|
|
124
|
+
const normalizedPluginConfig = await normalizePluginConfig(pluginConfig, pluginRequire);
|
|
135
125
|
const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
|
|
136
126
|
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
|
137
127
|
// Side-effect: merge the normalized theme config in the original one
|
|
@@ -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
|
@@ -11,7 +11,7 @@ const lodash_1 = require("lodash");
|
|
|
11
11
|
const querystring_1 = require("querystring");
|
|
12
12
|
function indent(str) {
|
|
13
13
|
const spaces = ' ';
|
|
14
|
-
return `${spaces}${str.replace(
|
|
14
|
+
return `${spaces}${str.replace(/\n/g, `\n${spaces}`)}`;
|
|
15
15
|
}
|
|
16
16
|
const createRouteCodeString = ({ routePath, routeHash, exact, subroutesCodeStrings, props, }) => {
|
|
17
17
|
const parts = [
|
|
@@ -73,7 +73,8 @@ async function loadRoutes(pluginsRouteConfigs, baseUrl) {
|
|
|
73
73
|
}
|
|
74
74
|
// Collect all page paths for injecting it later in the plugin lifecycle
|
|
75
75
|
// This is useful for plugins like sitemaps, redirects etc...
|
|
76
|
-
// If a route has subroutes, it is not necessarily a valid page path (more
|
|
76
|
+
// If a route has subroutes, it is not necessarily a valid page path (more
|
|
77
|
+
// likely to be a wrapper)
|
|
77
78
|
if (!subroutes) {
|
|
78
79
|
routesPaths.push(routePath);
|
|
79
80
|
}
|
|
@@ -17,8 +17,9 @@ function loadThemeAliases(themePaths, userThemePaths) {
|
|
|
17
17
|
themePaths.forEach((themePath) => {
|
|
18
18
|
const themeAliases = (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}`;
|
|
@@ -56,7 +56,7 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
|
|
|
56
56
|
Object.entries(newContentTransformed).forEach(([key, { message, description }]) => {
|
|
57
57
|
var _a, _b;
|
|
58
58
|
result[key] = {
|
|
59
|
-
// If
|
|
59
|
+
// If messages already exist, we don't override them (unless requested)
|
|
60
60
|
message: options.override
|
|
61
61
|
? message
|
|
62
62
|
: (_b = (_a = existingContent[key]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : message,
|
|
@@ -162,9 +162,7 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
|
|
|
162
162
|
},
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
return translationFile;
|
|
167
|
-
}
|
|
165
|
+
return translationFile;
|
|
168
166
|
}
|
|
169
167
|
exports.localizePluginTranslationFile = localizePluginTranslationFile;
|
|
170
168
|
async function getPluginsDefaultCodeTranslationMessages(plugins) {
|
|
@@ -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,8 +95,9 @@ 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);
|
|
@@ -169,12 +173,10 @@ Full code: ${(0, generator_1.default)(node).code}`;
|
|
|
169
173
|
typeof attributeValueEvaluated.value === 'string') {
|
|
170
174
|
return attributeValueEvaluated.value;
|
|
171
175
|
}
|
|
172
|
-
|
|
173
|
-
warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.
|
|
176
|
+
warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.
|
|
174
177
|
Example: <Translate id="optional id" description="optional description">Message</Translate>
|
|
175
178
|
Dynamically constructed values are not allowed, because they prevent translations to be extracted.
|
|
176
179
|
${sourceWarningPart(path.node)}`);
|
|
177
|
-
}
|
|
178
180
|
}
|
|
179
181
|
return undefined;
|
|
180
182
|
}
|
|
@@ -191,7 +193,7 @@ ${sourceWarningPart(path.node)}`);
|
|
|
191
193
|
}
|
|
192
194
|
else {
|
|
193
195
|
translations[id] = {
|
|
194
|
-
message:
|
|
196
|
+
message: id,
|
|
195
197
|
...(description && { description }),
|
|
196
198
|
};
|
|
197
199
|
}
|
|
@@ -199,8 +201,9 @@ ${sourceWarningPart(path.node)}`);
|
|
|
199
201
|
}
|
|
200
202
|
// Handle single non-empty content
|
|
201
203
|
const singleChildren = childrenPath
|
|
202
|
-
// Remove empty/useless text nodes that might be around our
|
|
203
|
-
// Makes the translation system more reliable to JSX
|
|
204
|
+
// Remove empty/useless text nodes that might be around our
|
|
205
|
+
// translation! Makes the translation system more reliable to JSX
|
|
206
|
+
// formatting issues
|
|
204
207
|
.filter((children) => !(children.isJSXText() &&
|
|
205
208
|
children.node.value.replace('\n', '').trim() === ''))
|
|
206
209
|
.pop();
|
|
@@ -231,7 +234,7 @@ ${sourceWarningPart(path.node)}`);
|
|
|
231
234
|
const args = path.get('arguments');
|
|
232
235
|
if (args.length === 1 || args.length === 2) {
|
|
233
236
|
const firstArgPath = args[0];
|
|
234
|
-
//
|
|
237
|
+
// translate("x" + "y"); => translate("xy");
|
|
235
238
|
const firstArgEvaluated = firstArgPath.evaluate();
|
|
236
239
|
if (firstArgEvaluated.confident &&
|
|
237
240
|
typeof firstArgEvaluated.value === 'object') {
|
|
@@ -33,7 +33,8 @@ function getPluginVersion(pluginPath, siteDir) {
|
|
|
33
33
|
const packageJsonPath = (0, path_1.join)(potentialPluginPackageJsonDirectory, 'package.json');
|
|
34
34
|
if ((0, fs_extra_1.existsSync)(packageJsonPath) && (0, fs_extra_1.lstatSync)(packageJsonPath).isFile()) {
|
|
35
35
|
if (potentialPluginPackageJsonDirectory === siteDir) {
|
|
36
|
-
// If the plugin belongs to the same docusaurus project, we classify it
|
|
36
|
+
// If the plugin belongs to the same docusaurus project, we classify it
|
|
37
|
+
// as local plugin.
|
|
37
38
|
return { type: 'project' };
|
|
38
39
|
}
|
|
39
40
|
return {
|
|
@@ -44,7 +45,8 @@ function getPluginVersion(pluginPath, siteDir) {
|
|
|
44
45
|
}
|
|
45
46
|
potentialPluginPackageJsonDirectory = (0, path_1.dirname)(potentialPluginPackageJsonDirectory);
|
|
46
47
|
}
|
|
47
|
-
// In
|
|
48
|
+
// In the case where a plugin is a path where no parent directory contains
|
|
49
|
+
// package.json (e.g. inline plugin), we can only classify it as local.
|
|
48
50
|
return { type: 'local' };
|
|
49
51
|
}
|
|
50
52
|
exports.getPluginVersion = getPluginVersion;
|
package/lib/webpack/base.js
CHANGED
|
@@ -14,8 +14,8 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
15
|
const themes_1 = require("../server/themes");
|
|
16
16
|
const utils_2 = require("@docusaurus/utils");
|
|
17
|
-
const CSS_REGEX = /\.css
|
|
18
|
-
const CSS_MODULE_REGEX = /\.module\.css
|
|
17
|
+
const CSS_REGEX = /\.css$/i;
|
|
18
|
+
const CSS_MODULE_REGEX = /\.module\.css$/i;
|
|
19
19
|
exports.clientDir = path_1.default.join(__dirname, '..', 'client');
|
|
20
20
|
const LibrariesToTranspile = [
|
|
21
21
|
'copy-text-to-clipboard', // contains optional catch binding, incompatible with recent versions of Edge
|
|
@@ -28,7 +28,7 @@ function excludeJS(modulePath) {
|
|
|
28
28
|
}
|
|
29
29
|
// Don't transpile node_modules except any docusaurus npm package
|
|
30
30
|
return (/node_modules/.test(modulePath) &&
|
|
31
|
-
!/
|
|
31
|
+
!/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
|
|
32
32
|
!LibrariesToTranspileRegex.test(modulePath));
|
|
33
33
|
}
|
|
34
34
|
exports.excludeJS = excludeJS;
|
|
@@ -69,16 +69,19 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
69
69
|
// When version string changes, cache is evicted
|
|
70
70
|
version: [
|
|
71
71
|
siteMetadata.docusaurusVersion,
|
|
72
|
-
// Webpack does not evict the cache correctly on alias/swizzle change,
|
|
72
|
+
// Webpack does not evict the cache correctly on alias/swizzle change,
|
|
73
|
+
// so we force eviction.
|
|
73
74
|
// See https://github.com/webpack/webpack/issues/13627
|
|
74
75
|
(0, utils_2.md5Hash)(JSON.stringify(themeAliases)),
|
|
75
76
|
].join('-'),
|
|
76
|
-
// When one of those modules/dependencies change (including transitive
|
|
77
|
+
// When one of those modules/dependencies change (including transitive
|
|
78
|
+
// deps), cache is invalidated
|
|
77
79
|
buildDependencies: {
|
|
78
80
|
config: [
|
|
79
81
|
__filename,
|
|
80
82
|
path_1.default.join(__dirname, isServer ? 'server.js' : 'client.js'),
|
|
81
|
-
// Docusaurus config changes can affect MDX/JSX compilation, so we'd
|
|
83
|
+
// Docusaurus config changes can affect MDX/JSX compilation, so we'd
|
|
84
|
+
// rather evict the cache.
|
|
82
85
|
// See https://github.com/questdb/questdb.io/issues/493
|
|
83
86
|
siteConfigPath,
|
|
84
87
|
],
|
|
@@ -120,10 +123,11 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
120
123
|
...getDocusaurusAliases(),
|
|
121
124
|
...themeAliases,
|
|
122
125
|
},
|
|
123
|
-
// This allows you to set a fallback for where Webpack should look for
|
|
124
|
-
// We want `@docusaurus/core` own dependencies/`node_modules` to
|
|
125
|
-
// Example: if there is core-js@3 in user's
|
|
126
|
-
// core-js@2, we should use
|
|
126
|
+
// This allows you to set a fallback for where Webpack should look for
|
|
127
|
+
// modules. We want `@docusaurus/core` own dependencies/`node_modules` to
|
|
128
|
+
// "win" if there is conflict. Example: if there is core-js@3 in user's
|
|
129
|
+
// own node_modules, but core depends on core-js@2, we should use
|
|
130
|
+
// core-js@2.
|
|
127
131
|
modules: [
|
|
128
132
|
path_1.default.resolve(__dirname, '..', '..', 'node_modules'),
|
|
129
133
|
'node_modules',
|
|
@@ -135,7 +139,8 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
135
139
|
},
|
|
136
140
|
optimization: {
|
|
137
141
|
removeAvailableModules: false,
|
|
138
|
-
// Only minimize client bundle in production because server bundle is only
|
|
142
|
+
// Only minimize client bundle in production because server bundle is only
|
|
143
|
+
// used for static site generation
|
|
139
144
|
minimize: minimizeEnabled,
|
|
140
145
|
minimizer: minimizeEnabled
|
|
141
146
|
? (0, utils_1.getMinimizer)(useSimpleCssMinifier)
|
|
@@ -143,7 +148,9 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
143
148
|
splitChunks: isServer
|
|
144
149
|
? false
|
|
145
150
|
: {
|
|
146
|
-
// Since the chunk name includes all origin chunk names it's
|
|
151
|
+
// Since the chunk name includes all origin chunk names it's
|
|
152
|
+
// recommended for production builds with long term caching to NOT
|
|
153
|
+
// include [name] in the filenames
|
|
147
154
|
name: false,
|
|
148
155
|
cacheGroups: {
|
|
149
156
|
// disable the built-in cacheGroups
|
|
@@ -175,7 +182,7 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
175
182
|
fileLoaderUtils.rules.svg(),
|
|
176
183
|
fileLoaderUtils.rules.otherAssets(),
|
|
177
184
|
{
|
|
178
|
-
test: /\.
|
|
185
|
+
test: /\.[jt]sx?$/i,
|
|
179
186
|
exclude: excludeJS,
|
|
180
187
|
use: [
|
|
181
188
|
(0, utils_1.getCustomizableJSLoader)((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
|
|
@@ -217,8 +224,9 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
217
224
|
chunkFilename: isProd
|
|
218
225
|
? 'assets/css/[name].[contenthash:8].css'
|
|
219
226
|
: '[name].css',
|
|
220
|
-
// remove css order warnings if css imports are not sorted
|
|
221
|
-
//
|
|
227
|
+
// remove css order warnings if css imports are not sorted
|
|
228
|
+
// alphabetically. See https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422
|
|
229
|
+
// for more reasoning
|
|
222
230
|
ignoreOrder: true,
|
|
223
231
|
}),
|
|
224
232
|
],
|
package/lib/webpack/client.js
CHANGED
|
@@ -18,7 +18,9 @@ function createClientConfig(props, minify = true) {
|
|
|
18
18
|
const isBuilding = process.argv[2] === 'build';
|
|
19
19
|
const config = (0, base_1.createBaseConfig)(props, false, minify);
|
|
20
20
|
const clientConfig = (0, webpack_merge_1.default)(config, {
|
|
21
|
-
//
|
|
21
|
+
// useless, disabled on purpose (errors on existing sites with no
|
|
22
|
+
// browserslist config)
|
|
23
|
+
// target: 'browserslist',
|
|
22
24
|
entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
|
|
23
25
|
optimization: {
|
|
24
26
|
// Keep the runtime chunk separated to enable long term caching
|
|
@@ -33,7 +35,8 @@ function createClientConfig(props, minify = true) {
|
|
|
33
35
|
}),
|
|
34
36
|
],
|
|
35
37
|
});
|
|
36
|
-
// When building include the plugin to force terminate building if errors
|
|
38
|
+
// When building, include the plugin to force terminate building if errors
|
|
39
|
+
// happened in the client bundle.
|
|
37
40
|
if (isBuilding) {
|
|
38
41
|
(_a = clientConfig.plugins) === null || _a === void 0 ? void 0 : _a.push({
|
|
39
42
|
apply: (compiler) => {
|
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { type Compiler } from 'webpack';
|
|
8
|
+
/**
|
|
9
|
+
* We modify webpack runtime to add an extra function called
|
|
10
|
+
* "__webpack_require__.gca" that will allow us to get the corresponding chunk
|
|
11
|
+
* asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
|
|
12
|
+
* For example: if you have a chunk named "my-chunk-name" that will map to
|
|
13
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
14
|
+
* __webpack_require__.gca("my-chunk-name") will return
|
|
15
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
16
|
+
*
|
|
17
|
+
* "gca" stands for "get chunk asset"
|
|
18
|
+
*/
|
|
8
19
|
declare class ChunkAssetPlugin {
|
|
9
20
|
apply(compiler: Compiler): void;
|
|
10
21
|
}
|
|
@@ -8,16 +8,20 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const webpack_1 = require("webpack");
|
|
10
10
|
const pluginName = 'chunk-asset-plugin';
|
|
11
|
+
/**
|
|
12
|
+
* We modify webpack runtime to add an extra function called
|
|
13
|
+
* "__webpack_require__.gca" that will allow us to get the corresponding chunk
|
|
14
|
+
* asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
|
|
15
|
+
* For example: if you have a chunk named "my-chunk-name" that will map to
|
|
16
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
17
|
+
* __webpack_require__.gca("my-chunk-name") will return
|
|
18
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
19
|
+
*
|
|
20
|
+
* "gca" stands for "get chunk asset"
|
|
21
|
+
*/
|
|
11
22
|
class ChunkAssetPlugin {
|
|
12
23
|
apply(compiler) {
|
|
13
24
|
compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
|
|
14
|
-
/* We modify webpack runtime to add an extra function called "__webpack_require__.gca"
|
|
15
|
-
that will allow us to get the corresponding chunk asset for a webpack chunk.
|
|
16
|
-
Pass it the chunkName or chunkId you want to load.
|
|
17
|
-
For example: if you have a chunk named "my-chunk-name" that will map to "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
18
|
-
__webpack_require__.gca("my-chunk-name") will return "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
19
|
-
"gca" stands for "get chunk asset"
|
|
20
|
-
*/
|
|
21
25
|
mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
|
|
22
26
|
const chunkIdToName = chunk.getChunkMaps(false).name;
|
|
23
27
|
const chunkNameToId = Object.create(null);
|
|
@@ -30,10 +34,13 @@ class ChunkAssetPlugin {
|
|
|
30
34
|
buf.push(
|
|
31
35
|
// If chunkName is passed, we convert it to chunk asset url
|
|
32
36
|
// .p => public path url ("/" or "/baseUrl/")
|
|
33
|
-
// .u(chunkId) =>
|
|
34
|
-
//
|
|
37
|
+
// .u(chunkId) =>
|
|
38
|
+
// chunk asset url ("assets/js/x63b64xd.contentHash.js")
|
|
39
|
+
// not sure where this is documented, but this link was helpful:
|
|
40
|
+
// https://programmer.help/blogs/5d68849083e1a.html
|
|
35
41
|
//
|
|
36
|
-
// Note: __webpack_require__.gca() is called in docusaurus.ts for
|
|
42
|
+
// Note: __webpack_require__.gca() is called in docusaurus.ts for
|
|
43
|
+
// prefetching
|
|
37
44
|
// Note: we previously used jsonpScriptSrc (Webpack 4)
|
|
38
45
|
`__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
|
|
39
46
|
return webpack_1.Template.asString(buf);
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
14
|
* copies of the Software, and to permit persons to whom the Software is
|
|
15
15
|
* furnished to do so, subject to the following conditions:
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in
|
|
17
|
-
* copies or substantial portions of the Software.
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in
|
|
17
|
+
* all copies or substantial portions of the Software.
|
|
18
18
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
19
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
20
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -69,7 +69,8 @@ declare class CleanWebpackPlugin {
|
|
|
69
69
|
*
|
|
70
70
|
* Only happens once.
|
|
71
71
|
*
|
|
72
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
72
|
+
* Warning: It is recommended to initially clean your build directory outside
|
|
73
|
+
* of webpack to minimize unexpected behavior.
|
|
73
74
|
*/
|
|
74
75
|
handleInitial(): void;
|
|
75
76
|
handleDone(stats: Stats): void;
|
|
@@ -60,7 +60,8 @@ class CleanWebpackPlugin {
|
|
|
60
60
|
*
|
|
61
61
|
* Only happens once.
|
|
62
62
|
*
|
|
63
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
63
|
+
* Warning: It is recommended to initially clean your build directory outside
|
|
64
|
+
* of webpack to minimize unexpected behavior.
|
|
64
65
|
*/
|
|
65
66
|
handleInitial() {
|
|
66
67
|
if (this.initialClean) {
|
package/lib/webpack/server.js
CHANGED
|
@@ -57,9 +57,10 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
|
57
57
|
},
|
|
58
58
|
paths: ssgPaths,
|
|
59
59
|
preferFoldersOutput: trailingSlash,
|
|
60
|
-
// When using "new URL('file.js', import.meta.url)", Webpack will emit
|
|
61
|
-
//
|
|
62
|
-
//
|
|
60
|
+
// When using "new URL('file.js', import.meta.url)", Webpack will emit
|
|
61
|
+
// __filename, and this plugin will throw. not sure the __filename value
|
|
62
|
+
// has any importance for this plugin, just using an empty string to
|
|
63
|
+
// avoid the error. See https://github.com/facebook/docusaurus/issues/4922
|
|
63
64
|
globals: { __filename: '' },
|
|
64
65
|
}),
|
|
65
66
|
// Show compilation progress bar.
|