@docusaurus/core 2.0.0-beta.ff31de0ff → 2.0.0-rc.1
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/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/docusaurus.mjs +221 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -7
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/ExecutionEnvironment.js +7 -8
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +44 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- 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/useBaseUrl.js +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +8 -15
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +109 -136
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +50 -116
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +102 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +40 -20
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +111 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +119 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +48 -28
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +5 -3
- package/lib/server/configValidation.js +105 -44
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -6
- package/lib/server/index.js +86 -173
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +10 -10
- package/lib/server/plugins/index.js +76 -128
- package/lib/server/plugins/init.d.ts +6 -9
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +6 -2
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +16 -22
- package/lib/server/translations/translations.js +41 -73
- package/lib/server/translations/translationsExtractor.d.ts +10 -5
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +56 -58
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +34 -18
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +23 -8
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
- package/lib/webpack/utils.d.ts +16 -31
- package/lib/webpack/utils.js +63 -183
- package/package.json +83 -77
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5682
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -4127
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -39
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -39
- package/lib/server/themes/index.d.ts +0 -8
- package/lib/server/themes/index.js +0 -35
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
package/lib/server/routes.js
CHANGED
|
@@ -6,115 +6,202 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadRoutes = exports.handleDuplicateRoutes = exports.genChunkName = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const querystring_1 = tslib_1.__importDefault(require("querystring"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
9
14
|
const utils_1 = require("@docusaurus/utils");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
const utils_2 = require("./utils");
|
|
16
|
+
/** Indents every line of `str` by one level. */
|
|
17
|
+
function indent(str) {
|
|
18
|
+
return ` ${str.replace(/\n/g, `\n `)}`;
|
|
19
|
+
}
|
|
20
|
+
const chunkNameCache = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* Generates a unique chunk name that can be used in the chunk registry.
|
|
23
|
+
*
|
|
24
|
+
* @param modulePath A path to generate chunk name from. The actual value has no
|
|
25
|
+
* semantic significance.
|
|
26
|
+
* @param prefix A prefix to append to the chunk name, to avoid name clash.
|
|
27
|
+
* @param preferredName Chunk names default to `modulePath`, and this can supply
|
|
28
|
+
* a more human-readable name.
|
|
29
|
+
* @param shortId When `true`, the chunk name would only be a hash without any
|
|
30
|
+
* other characters. Useful for bundle size. Defaults to `true` in production.
|
|
31
|
+
*/
|
|
32
|
+
function genChunkName(modulePath, prefix, preferredName, shortId = process.env.NODE_ENV === 'production') {
|
|
33
|
+
let chunkName = chunkNameCache.get(modulePath);
|
|
34
|
+
if (!chunkName) {
|
|
35
|
+
if (shortId) {
|
|
36
|
+
chunkName = (0, utils_1.simpleHash)(modulePath, 8);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
let str = modulePath;
|
|
40
|
+
if (preferredName) {
|
|
41
|
+
const shortHash = (0, utils_1.simpleHash)(modulePath, 3);
|
|
42
|
+
str = `${preferredName}${shortHash}`;
|
|
43
|
+
}
|
|
44
|
+
const name = str === '/' ? 'index' : (0, utils_1.docuHash)(str);
|
|
45
|
+
chunkName = prefix ? `${prefix}---${name}` : name;
|
|
46
|
+
}
|
|
47
|
+
chunkNameCache.set(modulePath, chunkName);
|
|
48
|
+
}
|
|
49
|
+
return chunkName;
|
|
50
|
+
}
|
|
51
|
+
exports.genChunkName = genChunkName;
|
|
52
|
+
/**
|
|
53
|
+
* Takes a piece of route config, and serializes it into raw JS code. The shape
|
|
54
|
+
* is the same as react-router's `RouteConfig`. Formatting is similar to
|
|
55
|
+
* `JSON.stringify` but without all the quotes.
|
|
56
|
+
*/
|
|
57
|
+
function serializeRouteConfig({ routePath, routeHash, exact, subroutesCodeStrings, props, }) {
|
|
58
|
+
const parts = [
|
|
59
|
+
`path: '${routePath}'`,
|
|
60
|
+
`component: ComponentCreator('${routePath}', '${routeHash}')`,
|
|
61
|
+
];
|
|
62
|
+
if (exact) {
|
|
63
|
+
parts.push(`exact: true`);
|
|
36
64
|
}
|
|
37
|
-
if (
|
|
38
|
-
|
|
65
|
+
if (subroutesCodeStrings) {
|
|
66
|
+
parts.push(`routes: [
|
|
67
|
+
${indent(subroutesCodeStrings.join(',\n'))}
|
|
68
|
+
]`);
|
|
39
69
|
}
|
|
40
|
-
|
|
70
|
+
Object.entries(props).forEach(([propName, propValue]) => {
|
|
71
|
+
// Inspired by https://github.com/armanozak/should-quote/blob/main/packages/should-quote/src/lib/should-quote.ts
|
|
72
|
+
const shouldQuote = ((key) => {
|
|
73
|
+
// Pre-sanitation to prevent injection
|
|
74
|
+
if (/[.,;:}/\s]/.test(key)) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
// If this key can be used in an expression like ({a:0}).a
|
|
79
|
+
// eslint-disable-next-line no-eval
|
|
80
|
+
eval(`({${key}:0}).${key}`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
})(propName);
|
|
87
|
+
// Escape quotes as well
|
|
88
|
+
const key = shouldQuote ? JSON.stringify(propName) : propName;
|
|
89
|
+
parts.push(`${key}: ${JSON.stringify(propValue)}`);
|
|
90
|
+
});
|
|
91
|
+
return `{
|
|
92
|
+
${indent(parts.join(',\n'))}
|
|
93
|
+
}`;
|
|
41
94
|
}
|
|
95
|
+
const isModule = (value) => typeof value === 'string' ||
|
|
96
|
+
(typeof value === 'object' &&
|
|
97
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
98
|
+
!!value?.__import);
|
|
99
|
+
/**
|
|
100
|
+
* Takes a {@link Module} (which is nothing more than a path plus some metadata
|
|
101
|
+
* like query) and returns the string path it represents.
|
|
102
|
+
*/
|
|
42
103
|
function getModulePath(target) {
|
|
43
104
|
if (typeof target === 'string') {
|
|
44
105
|
return target;
|
|
45
106
|
}
|
|
46
|
-
const queryStr = target.query ? `?${querystring_1.stringify(target.query)}` : '';
|
|
107
|
+
const queryStr = target.query ? `?${querystring_1.default.stringify(target.query)}` : '';
|
|
47
108
|
return `${target.path}${queryStr}`;
|
|
48
109
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!lodash_1.isString(routePath) || !component) {
|
|
57
|
-
throw new Error(`Invalid routeConfig (Path must be a string and component is required) \n${JSON.stringify(routeConfig)}`);
|
|
58
|
-
}
|
|
59
|
-
// Collect all page paths for injecting it later in the plugin lifecycle
|
|
60
|
-
// This is useful for plugins like sitemaps, redirects etc...
|
|
61
|
-
// If a route has subroutes, it is not necessarily a valid page path (more likely to be a wrapper)
|
|
62
|
-
if (!subroutes) {
|
|
63
|
-
routesPaths.push(routePath);
|
|
64
|
-
}
|
|
65
|
-
// We hash the route to generate the key, because 2 routes can conflict with
|
|
66
|
-
// each others if they have the same path, ex: parent=/docs, child=/docs
|
|
67
|
-
// see https://github.com/facebook/docusaurus/issues/2917
|
|
68
|
-
const routeHash = utils_1.simpleHash(JSON.stringify(routeConfig), 3);
|
|
69
|
-
const chunkNamesKey = `${routePath}-${routeHash}`;
|
|
70
|
-
routesChunkNames[chunkNamesKey] = {
|
|
71
|
-
...genRouteChunkNames(registry, { component }, 'component', component),
|
|
72
|
-
...genRouteChunkNames(registry, modules, 'module', routePath),
|
|
73
|
-
};
|
|
74
|
-
return createRouteCodeString({
|
|
75
|
-
routePath: routeConfig.path.replace(/'/g, "\\'"),
|
|
76
|
-
routeHash,
|
|
77
|
-
exact,
|
|
78
|
-
subroutesCodeStrings: subroutes === null || subroutes === void 0 ? void 0 : subroutes.map(generateRouteCode),
|
|
79
|
-
});
|
|
110
|
+
function genChunkNames(routeModule, prefix, name, res) {
|
|
111
|
+
if (isModule(routeModule)) {
|
|
112
|
+
// This is a leaf node, no need to recurse
|
|
113
|
+
const modulePath = getModulePath(routeModule);
|
|
114
|
+
const chunkName = genChunkName(modulePath, prefix, name);
|
|
115
|
+
res.registry[chunkName] = (0, utils_1.escapePath)(modulePath);
|
|
116
|
+
return chunkName;
|
|
80
117
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
${NotFoundRouteCode}
|
|
86
|
-
];\n`;
|
|
87
|
-
return {
|
|
88
|
-
registry,
|
|
89
|
-
routesConfig,
|
|
90
|
-
routesChunkNames,
|
|
91
|
-
routesPaths,
|
|
92
|
-
};
|
|
118
|
+
if (Array.isArray(routeModule)) {
|
|
119
|
+
return routeModule.map((val, index) => genChunkNames(val, `${index}`, name, res));
|
|
120
|
+
}
|
|
121
|
+
return lodash_1.default.mapValues(routeModule, (v, key) => genChunkNames(v, key, name, res));
|
|
93
122
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
registry, value, prefix, name) {
|
|
98
|
-
if (!value) {
|
|
99
|
-
return null;
|
|
123
|
+
function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
|
|
124
|
+
if (onDuplicateRoutes === 'ignore') {
|
|
125
|
+
return;
|
|
100
126
|
}
|
|
101
|
-
|
|
102
|
-
|
|
127
|
+
const allRoutes = (0, utils_2.getAllFinalRoutes)(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
|
|
128
|
+
const seenRoutes = new Set();
|
|
129
|
+
const duplicatePaths = allRoutes.filter((route) => {
|
|
130
|
+
if (seenRoutes.has(route)) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
seenRoutes.add(route);
|
|
134
|
+
return false;
|
|
135
|
+
});
|
|
136
|
+
if (duplicatePaths.length > 0) {
|
|
137
|
+
logger_1.default.report(onDuplicateRoutes) `Duplicate routes found!${duplicatePaths.map((duplicateRoute) => logger_1.default.interpolate `Attempting to create page at url=${duplicateRoute}, but a page already exists at this route.`)}
|
|
138
|
+
This could lead to non-deterministic routing behavior.`;
|
|
103
139
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
140
|
+
}
|
|
141
|
+
exports.handleDuplicateRoutes = handleDuplicateRoutes;
|
|
142
|
+
/**
|
|
143
|
+
* This is the higher level overview of route code generation. For each route
|
|
144
|
+
* config node, it returns the node's serialized form, and mutates `registry`,
|
|
145
|
+
* `routesPaths`, and `routesChunkNames` accordingly.
|
|
146
|
+
*/
|
|
147
|
+
function genRouteCode(routeConfig, res) {
|
|
148
|
+
const { path: routePath, component, modules = {}, context, routes: subroutes, priority, exact, ...props } = routeConfig;
|
|
149
|
+
if (typeof routePath !== 'string' || !component) {
|
|
150
|
+
throw new Error(`Invalid route config: path must be a string and component is required.
|
|
151
|
+
${JSON.stringify(routeConfig)}`);
|
|
114
152
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
153
|
+
if (!subroutes) {
|
|
154
|
+
res.routesPaths.push(routePath);
|
|
155
|
+
}
|
|
156
|
+
const routeHash = (0, utils_1.simpleHash)(JSON.stringify(routeConfig), 3);
|
|
157
|
+
res.routesChunkNames[`${routePath}-${routeHash}`] = {
|
|
158
|
+
// Avoid clash with a prop called "component"
|
|
159
|
+
...genChunkNames({ __comp: component }, 'component', component, res),
|
|
160
|
+
...(context &&
|
|
161
|
+
genChunkNames({ __context: context }, 'context', routePath, res)),
|
|
162
|
+
...genChunkNames(modules, 'module', routePath, res),
|
|
163
|
+
};
|
|
164
|
+
return serializeRouteConfig({
|
|
165
|
+
routePath: routePath.replace(/'/g, "\\'"),
|
|
166
|
+
routeHash,
|
|
167
|
+
subroutesCodeStrings: subroutes?.map((r) => genRouteCode(r, res)),
|
|
168
|
+
exact,
|
|
169
|
+
props,
|
|
118
170
|
});
|
|
119
|
-
return newValue;
|
|
120
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Routes are prepared into three temp files:
|
|
174
|
+
*
|
|
175
|
+
* - `routesConfig`, the route config passed to react-router. This file is kept
|
|
176
|
+
* minimal, because it can't be code-splitted.
|
|
177
|
+
* - `routesChunkNames`, a mapping from route paths (hashed) to code-splitted
|
|
178
|
+
* chunk names.
|
|
179
|
+
* - `registry`, a mapping from chunk names to options for react-loadable.
|
|
180
|
+
*/
|
|
181
|
+
function loadRoutes(routeConfigs, baseUrl, onDuplicateRoutes) {
|
|
182
|
+
handleDuplicateRoutes(routeConfigs, onDuplicateRoutes);
|
|
183
|
+
const res = {
|
|
184
|
+
// To be written by `genRouteCode`
|
|
185
|
+
routesConfig: '',
|
|
186
|
+
routesChunkNames: {},
|
|
187
|
+
registry: {},
|
|
188
|
+
routesPaths: [(0, utils_1.normalizeUrl)([baseUrl, '404.html'])],
|
|
189
|
+
};
|
|
190
|
+
// `genRouteCode` would mutate `res`
|
|
191
|
+
const routeConfigSerialized = routeConfigs
|
|
192
|
+
.map((r) => genRouteCode(r, res))
|
|
193
|
+
.join(',\n');
|
|
194
|
+
res.routesConfig = `import React from 'react';
|
|
195
|
+
import ComponentCreator from '@docusaurus/ComponentCreator';
|
|
196
|
+
|
|
197
|
+
export default [
|
|
198
|
+
${indent(routeConfigSerialized)},
|
|
199
|
+
{
|
|
200
|
+
path: '*',
|
|
201
|
+
component: ComponentCreator('*'),
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
`;
|
|
205
|
+
return res;
|
|
206
|
+
}
|
|
207
|
+
exports.loadRoutes = loadRoutes;
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { LoadedPlugin, PluginVersionInformation, SiteMetadata } from '@docusaurus/types';
|
|
8
|
+
export declare function getPluginVersion(pluginPath: string, siteDir: string): Promise<PluginVersionInformation>;
|
|
9
|
+
export declare function loadSiteMetadata({ plugins, siteDir, }: {
|
|
10
|
+
plugins: LoadedPlugin[];
|
|
11
|
+
siteDir: string;
|
|
12
|
+
}): Promise<SiteMetadata>;
|
|
@@ -0,0 +1,81 @@
|
|
|
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.loadSiteMetadata = exports.getPluginVersion = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
async function getPackageJsonVersion(packageJsonPath) {
|
|
16
|
+
if (await fs_extra_1.default.pathExists(packageJsonPath)) {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
18
|
+
return require(packageJsonPath).version;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
async function getPackageJsonName(packageJsonPath) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
24
|
+
return require(packageJsonPath).name;
|
|
25
|
+
}
|
|
26
|
+
async function getPluginVersion(pluginPath, siteDir) {
|
|
27
|
+
let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
|
|
28
|
+
while (potentialPluginPackageJsonDirectory !== '/') {
|
|
29
|
+
const packageJsonPath = path_1.default.join(potentialPluginPackageJsonDirectory, 'package.json');
|
|
30
|
+
if ((await fs_extra_1.default.pathExists(packageJsonPath)) &&
|
|
31
|
+
(await fs_extra_1.default.lstat(packageJsonPath)).isFile()) {
|
|
32
|
+
if (potentialPluginPackageJsonDirectory === siteDir) {
|
|
33
|
+
// If the plugin belongs to the same docusaurus project, we classify it
|
|
34
|
+
// as local plugin.
|
|
35
|
+
return { type: 'project' };
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
type: 'package',
|
|
39
|
+
name: await getPackageJsonName(packageJsonPath),
|
|
40
|
+
version: await getPackageJsonVersion(packageJsonPath),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
potentialPluginPackageJsonDirectory = path_1.default.dirname(potentialPluginPackageJsonDirectory);
|
|
44
|
+
}
|
|
45
|
+
// In the case where a plugin is a path where no parent directory contains
|
|
46
|
+
// package.json, we can only classify it as local. Could happen if one puts a
|
|
47
|
+
// script in the parent directory of the site.
|
|
48
|
+
return { type: 'local' };
|
|
49
|
+
}
|
|
50
|
+
exports.getPluginVersion = getPluginVersion;
|
|
51
|
+
/**
|
|
52
|
+
* We want all `@docusaurus/*` packages to have the exact same version!
|
|
53
|
+
* @see https://github.com/facebook/docusaurus/issues/3371
|
|
54
|
+
* @see https://github.com/facebook/docusaurus/pull/3386
|
|
55
|
+
*/
|
|
56
|
+
function checkDocusaurusPackagesVersion(siteMetadata) {
|
|
57
|
+
const { docusaurusVersion } = siteMetadata;
|
|
58
|
+
Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
|
|
59
|
+
if (versionInfo.type === 'package' &&
|
|
60
|
+
versionInfo.name?.startsWith('@docusaurus/') &&
|
|
61
|
+
versionInfo.version &&
|
|
62
|
+
versionInfo.version !== docusaurusVersion) {
|
|
63
|
+
// Should we throw instead? It still could work with different versions
|
|
64
|
+
logger_1.default.error `Invalid name=${plugin} version number=${versionInfo.version}.
|
|
65
|
+
All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
|
|
66
|
+
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function loadSiteMetadata({ plugins, siteDir, }) {
|
|
71
|
+
const siteMetadata = {
|
|
72
|
+
docusaurusVersion: utils_1.DOCUSAURUS_VERSION,
|
|
73
|
+
siteVersion: await getPackageJsonVersion(path_1.default.join(siteDir, 'package.json')),
|
|
74
|
+
pluginVersions: Object.fromEntries(plugins
|
|
75
|
+
.filter(({ version: { type } }) => type !== 'synthetic')
|
|
76
|
+
.map(({ name, version }) => [name, version])),
|
|
77
|
+
};
|
|
78
|
+
checkDocusaurusPackagesVersion(siteMetadata);
|
|
79
|
+
return siteMetadata;
|
|
80
|
+
}
|
|
81
|
+
exports.loadSiteMetadata = loadSiteMetadata;
|
|
@@ -1,37 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { TranslationFileContent, TranslationFile, CodeTranslations, InitializedPlugin } from '@docusaurus/types';
|
|
3
8
|
export declare type WriteTranslationsOptions = {
|
|
4
9
|
override?: boolean;
|
|
5
10
|
messagePrefix?: string;
|
|
6
11
|
};
|
|
7
12
|
declare type TranslationContext = {
|
|
8
|
-
|
|
9
|
-
locale: string;
|
|
13
|
+
localizationDir: string;
|
|
10
14
|
};
|
|
11
|
-
export declare function ensureTranslationFileContent(content: unknown): asserts content is TranslationFileContent;
|
|
12
|
-
export declare function readTranslationFileContent(filePath: string): Promise<TranslationFileContent | undefined>;
|
|
13
|
-
export declare function writeTranslationFileContent({ filePath, content: newContent, options, }: {
|
|
14
|
-
filePath: string;
|
|
15
|
-
content: TranslationFileContent;
|
|
16
|
-
options?: WriteTranslationsOptions;
|
|
17
|
-
}): Promise<void>;
|
|
18
|
-
export declare function getTranslationsDirPath(context: TranslationContext): string;
|
|
19
|
-
export declare function getTranslationsLocaleDirPath(context: TranslationContext): string;
|
|
20
|
-
export declare function getCodeTranslationsFilePath(context: TranslationContext): string;
|
|
21
15
|
export declare function readCodeTranslationFileContent(context: TranslationContext): Promise<TranslationFileContent | undefined>;
|
|
22
16
|
export declare function writeCodeTranslations(context: TranslationContext, content: TranslationFileContent, options: WriteTranslationsOptions): Promise<void>;
|
|
23
|
-
export declare function writePluginTranslations({
|
|
24
|
-
plugin:
|
|
17
|
+
export declare function writePluginTranslations({ localizationDir, plugin, translationFile, options, }: TranslationContext & {
|
|
18
|
+
plugin: InitializedPlugin;
|
|
25
19
|
translationFile: TranslationFile;
|
|
26
20
|
options?: WriteTranslationsOptions;
|
|
27
21
|
}): Promise<void>;
|
|
28
|
-
export declare function localizePluginTranslationFile({
|
|
29
|
-
plugin:
|
|
22
|
+
export declare function localizePluginTranslationFile({ localizationDir, plugin, translationFile, }: TranslationContext & {
|
|
23
|
+
plugin: InitializedPlugin;
|
|
30
24
|
translationFile: TranslationFile;
|
|
31
25
|
}): Promise<TranslationFile>;
|
|
32
|
-
export declare function getPluginsDefaultCodeTranslationMessages(plugins:
|
|
26
|
+
export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<CodeTranslations>;
|
|
33
27
|
export declare function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }: {
|
|
34
|
-
extractedCodeTranslations:
|
|
35
|
-
defaultCodeMessages:
|
|
36
|
-
}):
|
|
28
|
+
extractedCodeTranslations: TranslationFileContent;
|
|
29
|
+
defaultCodeMessages: CodeTranslations;
|
|
30
|
+
}): TranslationFileContent;
|
|
37
31
|
export {};
|