@docusaurus/core 2.0.0-beta.18 → 2.0.0-beta.19
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 +12 -7
- package/bin/docusaurus.mjs +21 -72
- package/lib/client/.eslintrc.js +2 -3
- package/lib/client/App.d.ts +1 -1
- package/lib/client/App.js +9 -5
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts} +10 -5
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +14 -9
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +34 -0
- package/lib/client/LinksCollector.js +1 -2
- package/lib/client/PendingNavigation.d.ts +8 -17
- package/lib/client/PendingNavigation.js +39 -70
- package/lib/client/clientEntry.js +1 -2
- package/lib/client/docusaurus.d.ts +5 -5
- package/lib/client/docusaurus.js +25 -29
- package/lib/client/exports/BrowserOnly.d.ts +3 -4
- package/lib/client/exports/BrowserOnly.js +1 -1
- package/lib/client/exports/ComponentCreator.js +51 -46
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +16 -39
- package/lib/client/exports/Link.d.ts +3 -15
- package/lib/client/exports/Link.js +21 -26
- package/lib/client/exports/useBaseUrl.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +3 -3
- package/lib/client/exports/useGlobalData.js +5 -5
- package/lib/client/flat.d.ts +10 -2
- package/lib/client/flat.js +11 -3
- package/lib/client/normalizeLocation.js +14 -5
- package/lib/client/prefetch.js +7 -25
- package/lib/client/preload.d.ts +1 -3
- package/lib/client/preload.js +2 -2
- package/lib/client/routeContext.js +1 -1
- package/lib/client/serverEntry.js +12 -11
- package/lib/client/theme-fallback/Error/index.js +2 -0
- package/lib/client/theme-fallback/Loading/index.js +2 -0
- package/lib/client/theme-fallback/NotFound/index.js +2 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +35 -15
- package/lib/commands/clear.d.ts +1 -1
- package/lib/commands/clear.js +3 -2
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +12 -9
- package/lib/commands/external.d.ts +1 -1
- package/lib/commands/external.js +5 -6
- package/lib/commands/serve.d.ts +7 -2
- package/lib/commands/serve.js +12 -12
- package/lib/commands/start.d.ts +8 -2
- package/lib/commands/start.js +14 -9
- package/lib/commands/swizzle/actions.d.ts +2 -2
- package/lib/commands/swizzle/actions.js +5 -4
- package/lib/commands/swizzle/common.d.ts +3 -3
- package/lib/commands/swizzle/components.js +41 -3
- package/lib/commands/swizzle/config.js +14 -11
- package/lib/commands/swizzle/context.js +6 -10
- package/lib/commands/swizzle/index.d.ts +2 -2
- package/lib/commands/swizzle/index.js +4 -3
- package/lib/commands/writeHeadingIds.d.ts +1 -1
- package/lib/commands/writeHeadingIds.js +5 -8
- package/lib/commands/writeTranslations.d.ts +3 -4
- package/lib/commands/writeTranslations.js +7 -9
- package/lib/index.d.ts +9 -10
- package/lib/index.js +18 -19
- package/lib/server/brokenLinks.js +1 -2
- package/lib/server/{client-modules/index.d.ts → clientModules.d.ts} +5 -1
- package/lib/server/{client-modules/index.js → clientModules.js} +6 -1
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +11 -6
- package/lib/server/configValidation.js +6 -5
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/{choosePort.js → server/getHostPort.js} +21 -35
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +2 -11
- package/lib/server/i18n.js +4 -19
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +42 -210
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +8 -7
- package/lib/server/plugins/index.js +59 -134
- package/lib/server/plugins/init.d.ts +6 -19
- package/lib/server/plugins/init.js +16 -68
- package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
- package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
- package/lib/server/plugins/pluginIds.d.ts +4 -0
- package/lib/server/plugins/pluginIds.js +4 -2
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/{presets/index.js → plugins/presets.js} +14 -6
- package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +3 -1
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +112 -0
- package/lib/server/routes.d.ts +42 -8
- package/lib/server/routes.js +150 -92
- package/lib/server/{versions/index.d.ts → siteMetadata.d.ts} +5 -2
- package/lib/server/{versions/index.js → siteMetadata.js} +36 -3
- package/lib/server/translations/translations.d.ts +5 -13
- package/lib/server/translations/translations.js +5 -8
- package/lib/server/translations/translationsExtractor.d.ts +2 -4
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +0 -3
- package/lib/webpack/base.js +8 -25
- package/lib/webpack/client.js +1 -1
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
- package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
- package/lib/webpack/server.d.ts +2 -2
- package/lib/webpack/server.js +5 -3
- package/lib/webpack/utils.d.ts +3 -3
- package/lib/webpack/utils.js +3 -3
- package/package.json +33 -36
- package/lib/choosePort.d.ts +0 -11
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -9
- package/lib/client/client-lifecycles-dispatcher.js +0 -23
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/commandUtils.d.ts +0 -9
- package/lib/commands/commandUtils.js +0 -21
- package/lib/server/duplicateRoutes.d.ts +0 -8
- package/lib/server/duplicateRoutes.js +0 -42
- package/lib/server/html-tags/htmlTags.d.ts +0 -7
- package/lib/server/html-tags/htmlTags.js +0 -38
- package/lib/server/html-tags/index.d.ts +0 -8
- package/lib/server/html-tags/index.js +0 -42
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/themes/alias.d.ts +0 -9
- package/lib/server/themes/alias.js +0 -50
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
|
@@ -32,7 +32,7 @@ async function eject({ siteDir, themePath, componentName, }) {
|
|
|
32
32
|
const fromPath = path_1.default.join(themePath, componentName);
|
|
33
33
|
const isDirectory = await isDir(fromPath);
|
|
34
34
|
const globPattern = isDirectory
|
|
35
|
-
? //
|
|
35
|
+
? // Do we really want to copy all components?
|
|
36
36
|
path_1.default.join(fromPath, '*')
|
|
37
37
|
: `${fromPath}.*`;
|
|
38
38
|
const globPatternPosix = (0, utils_1.posixPath)(globPattern);
|
|
@@ -51,10 +51,11 @@ async function eject({ siteDir, themePath, componentName, }) {
|
|
|
51
51
|
const fileName = path_1.default.basename(sourceFile);
|
|
52
52
|
const targetFile = path_1.default.join(toPath, fileName);
|
|
53
53
|
try {
|
|
54
|
-
await fs_extra_1.default.
|
|
54
|
+
const fileContents = await fs_extra_1.default.readFile(sourceFile, 'utf-8');
|
|
55
|
+
await fs_extra_1.default.outputFile(targetFile, fileContents.trimStart().replace(/^\/\*.+?\*\/\s*/ms, ''));
|
|
55
56
|
}
|
|
56
57
|
catch (err) {
|
|
57
|
-
throw new Error(logger_1.default.interpolate `Could not copy file from
|
|
58
|
+
throw new Error(logger_1.default.interpolate `Could not copy file from path=${sourceFile} to path=${targetFile}`);
|
|
58
59
|
}
|
|
59
60
|
return targetFile;
|
|
60
61
|
}));
|
|
@@ -74,7 +75,7 @@ async function wrap({ siteDir, themePath, componentName: themeComponentName, typ
|
|
|
74
75
|
import type ${componentName}Type from '@theme/${themeComponentName}';
|
|
75
76
|
import ${componentName} from '@theme-${importType}/${themeComponentName}';
|
|
76
77
|
|
|
77
|
-
type Props = ComponentProps<typeof ${componentName}Type
|
|
78
|
+
type Props = ComponentProps<typeof ${componentName}Type>;
|
|
78
79
|
|
|
79
80
|
export default function ${wrapperComponentName}(props: Props): JSX.Element {
|
|
80
81
|
return (
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import type { NormalizedPluginConfig } from '../../server/plugins/configs';
|
|
7
8
|
import type { InitializedPlugin, SwizzleAction, SwizzleActionStatus } from '@docusaurus/types';
|
|
8
|
-
import type { NormalizedPluginConfig } from '../../server/plugins/init';
|
|
9
9
|
export declare const SwizzleActions: SwizzleAction[];
|
|
10
10
|
export declare const SwizzleActionsStatuses: SwizzleActionStatus[];
|
|
11
11
|
export declare const PartiallySafeHint: string;
|
|
@@ -21,13 +21,13 @@ export declare type SwizzlePlugin = {
|
|
|
21
21
|
export declare type SwizzleContext = {
|
|
22
22
|
plugins: SwizzlePlugin[];
|
|
23
23
|
};
|
|
24
|
-
export declare type
|
|
24
|
+
export declare type SwizzleCLIOptions = {
|
|
25
25
|
typescript: boolean;
|
|
26
26
|
danger: boolean;
|
|
27
27
|
list: boolean;
|
|
28
28
|
wrap: boolean;
|
|
29
29
|
eject: boolean;
|
|
30
30
|
};
|
|
31
|
-
export declare function normalizeOptions(options: Partial<
|
|
31
|
+
export declare function normalizeOptions(options: Partial<SwizzleCLIOptions>): SwizzleCLIOptions;
|
|
32
32
|
export declare function findStringIgnoringCase(str: string, values: string[]): string | undefined;
|
|
33
33
|
export declare function findClosestValue(str: string, values: string[], maxLevenshtein?: number): string | undefined;
|
|
@@ -18,6 +18,25 @@ const common_1 = require("./common");
|
|
|
18
18
|
const tables_1 = require("./tables");
|
|
19
19
|
const actions_1 = require("./actions");
|
|
20
20
|
const formatComponentName = (componentName) => componentName.replace(/[/\\]index\.[jt]sx?/, '').replace(/\.[jt]sx?/, '');
|
|
21
|
+
function sortComponentNames(componentNames) {
|
|
22
|
+
return componentNames.sort(); // Algo may change?
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Expand a list of components to include and return parent folders.
|
|
26
|
+
* If a folder is not directly a component (no Folder/index.tsx file),
|
|
27
|
+
* we still want to be able to swizzle --eject that folder.
|
|
28
|
+
* See https://github.com/facebook/docusaurus/pull/7175#issuecomment-1103757218
|
|
29
|
+
*
|
|
30
|
+
* @param componentNames the original list of component names
|
|
31
|
+
*/
|
|
32
|
+
function getMissingIntermediateComponentFolderNames(componentNames) {
|
|
33
|
+
function getAllIntermediatePaths(componentName) {
|
|
34
|
+
const paths = componentName.split('/');
|
|
35
|
+
return lodash_1.default.range(1, paths.length + 1).map((i) => paths.slice(0, i).join('/'));
|
|
36
|
+
}
|
|
37
|
+
const expandedComponentNames = lodash_1.default.uniq(componentNames.flatMap((componentName) => getAllIntermediatePaths(componentName)));
|
|
38
|
+
return lodash_1.default.difference(expandedComponentNames, componentNames);
|
|
39
|
+
}
|
|
21
40
|
const skipReadDirNames = ['__test__', '__tests__', '__mocks__', '__fixtures__'];
|
|
22
41
|
async function readComponentNames(themePath) {
|
|
23
42
|
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
|
@@ -48,8 +67,8 @@ async function readComponentNames(themePath) {
|
|
|
48
67
|
}))).flat();
|
|
49
68
|
}
|
|
50
69
|
const componentFiles = await walk(themePath);
|
|
51
|
-
const
|
|
52
|
-
return
|
|
70
|
+
const componentNames = componentFiles.map((f) => f.componentName);
|
|
71
|
+
return sortComponentNames(componentNames);
|
|
53
72
|
}
|
|
54
73
|
exports.readComponentNames = readComponentNames;
|
|
55
74
|
function listComponentNames(themeComponents) {
|
|
@@ -72,11 +91,30 @@ async function getThemeComponents({ themeName, themePath, swizzleConfig, }) {
|
|
|
72
91
|
},
|
|
73
92
|
description: FallbackSwizzleComponentDescription,
|
|
74
93
|
};
|
|
75
|
-
const
|
|
94
|
+
const FallbackIntermediateFolderSwizzleComponentConfig = {
|
|
95
|
+
actions: {
|
|
96
|
+
// It doesn't make sense to wrap an intermediate folder
|
|
97
|
+
// because it has not any index component
|
|
98
|
+
wrap: 'forbidden',
|
|
99
|
+
eject: FallbackSwizzleActionStatus,
|
|
100
|
+
},
|
|
101
|
+
description: FallbackSwizzleComponentDescription,
|
|
102
|
+
};
|
|
103
|
+
const allInitialComponents = await readComponentNames(themePath);
|
|
104
|
+
const missingIntermediateComponentFolderNames = getMissingIntermediateComponentFolderNames(allInitialComponents);
|
|
105
|
+
const allComponents = sortComponentNames(allInitialComponents.concat(missingIntermediateComponentFolderNames));
|
|
76
106
|
function getConfig(component) {
|
|
77
107
|
if (!allComponents.includes(component)) {
|
|
78
108
|
throw new Error(`Can't get component config: component doesn't exist: ${component}`);
|
|
79
109
|
}
|
|
110
|
+
const config = swizzleConfig.components[component];
|
|
111
|
+
if (config) {
|
|
112
|
+
return config;
|
|
113
|
+
}
|
|
114
|
+
const isIntermediateFolder = missingIntermediateComponentFolderNames.includes(component);
|
|
115
|
+
if (isIntermediateFolder) {
|
|
116
|
+
return FallbackIntermediateFolderSwizzleComponentConfig;
|
|
117
|
+
}
|
|
80
118
|
return (swizzleConfig.components[component] ?? FallbackSwizzleComponentConfig);
|
|
81
119
|
}
|
|
82
120
|
function getDescription(component) {
|
|
@@ -36,20 +36,23 @@ function getModuleSwizzleConfig(swizzlePlugin) {
|
|
|
36
36
|
}
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const result =
|
|
39
|
+
const SwizzleConfigSchema = utils_validation_1.Joi.object({
|
|
40
|
+
components: utils_validation_1.Joi.object()
|
|
41
|
+
.pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
|
|
42
|
+
actions: utils_validation_1.Joi.object().pattern(utils_validation_1.Joi.string().valid(...common_1.SwizzleActions), utils_validation_1.Joi.string().valid(...common_1.SwizzleActionsStatuses)),
|
|
43
|
+
description: utils_validation_1.Joi.string(),
|
|
44
|
+
}))
|
|
45
|
+
.required(),
|
|
46
|
+
});
|
|
47
|
+
function validateSwizzleConfig(unsafeSwizzleConfig) {
|
|
48
|
+
const result = SwizzleConfigSchema.validate(unsafeSwizzleConfig);
|
|
49
49
|
if (result.error) {
|
|
50
50
|
throw new Error(`Swizzle config does not match expected schema: ${result.error.message}`);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
return result.value;
|
|
53
|
+
}
|
|
54
|
+
function normalizeSwizzleConfig(unsafeSwizzleConfig) {
|
|
55
|
+
const swizzleConfig = validateSwizzleConfig(unsafeSwizzleConfig);
|
|
53
56
|
// Ensure all components always declare all actions
|
|
54
57
|
Object.values(swizzleConfig.components).forEach((componentConfig) => {
|
|
55
58
|
common_1.SwizzleActions.forEach((action) => {
|
|
@@ -7,20 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.initSwizzleContext = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
10
|
const server_1 = require("../../server");
|
|
12
|
-
const init_1 =
|
|
11
|
+
const init_1 = require("../../server/plugins/init");
|
|
12
|
+
const configs_1 = require("../../server/plugins/configs");
|
|
13
13
|
async function initSwizzleContext(siteDir) {
|
|
14
|
-
const context = await (0, server_1.loadContext)(siteDir);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
pluginConfigs,
|
|
18
|
-
context,
|
|
19
|
-
});
|
|
20
|
-
const pluginsNormalized = await (0, init_1.normalizePluginConfigs)(pluginConfigs, context.siteConfigPath);
|
|
14
|
+
const context = await (0, server_1.loadContext)({ siteDir });
|
|
15
|
+
const plugins = await (0, init_1.initPlugins)(context);
|
|
16
|
+
const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
|
|
21
17
|
return {
|
|
22
18
|
plugins: plugins.map((plugin, pluginIndex) => ({
|
|
23
|
-
plugin:
|
|
19
|
+
plugin: pluginConfigs[pluginIndex],
|
|
24
20
|
instance: plugin,
|
|
25
21
|
})),
|
|
26
22
|
};
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
export
|
|
7
|
+
import type { SwizzleCLIOptions } from './common';
|
|
8
|
+
export declare function swizzle(siteDir: string, themeNameParam: string | undefined, componentNameParam: string | undefined, optionsParam: Partial<SwizzleCLIOptions>): Promise<void>;
|
|
@@ -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.swizzle = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
12
|
const themes_1 = require("./themes");
|
|
@@ -90,7 +91,7 @@ async function swizzle(siteDir, themeNameParam, componentNameParam, optionsParam
|
|
|
90
91
|
typescript,
|
|
91
92
|
});
|
|
92
93
|
logger_1.default.success `
|
|
93
|
-
Created wrapper of name=${componentName} from name=${themeName} in path=${result.createdFiles}
|
|
94
|
+
Created wrapper of name=${componentName} from name=${themeName} in path=${result.createdFiles}
|
|
94
95
|
`;
|
|
95
96
|
return result;
|
|
96
97
|
}
|
|
@@ -101,7 +102,7 @@ Created wrapper of name=${componentName} from name=${themeName} in path=${result
|
|
|
101
102
|
componentName,
|
|
102
103
|
});
|
|
103
104
|
logger_1.default.success `
|
|
104
|
-
Ejected name=${componentName} from name=${themeName} to path=${result.createdFiles}
|
|
105
|
+
Ejected name=${componentName} from name=${themeName} to path=${result.createdFiles}
|
|
105
106
|
`;
|
|
106
107
|
return result;
|
|
107
108
|
}
|
|
@@ -112,4 +113,4 @@ Ejected name=${componentName} from name=${themeName} to path=${result.createdFil
|
|
|
112
113
|
await executeAction();
|
|
113
114
|
return process.exit(0);
|
|
114
115
|
}
|
|
115
|
-
exports.
|
|
116
|
+
exports.swizzle = swizzle;
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { type WriteHeadingIDOptions } from '@docusaurus/utils';
|
|
8
|
-
export
|
|
8
|
+
export declare function writeHeadingIds(siteDir: string, files: string[], options: WriteHeadingIDOptions): Promise<void>;
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.writeHeadingIds = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
13
|
const utils_1 = require("@docusaurus/utils");
|
|
13
14
|
const server_1 = require("../server");
|
|
14
|
-
const init_1 =
|
|
15
|
+
const init_1 = require("../server/plugins/init");
|
|
15
16
|
const utils_2 = require("../server/utils");
|
|
16
17
|
async function transformMarkdownFile(filepath, options) {
|
|
17
18
|
const content = await fs_extra_1.default.readFile(filepath, 'utf8');
|
|
@@ -29,12 +30,8 @@ async function transformMarkdownFile(filepath, options) {
|
|
|
29
30
|
* transformed
|
|
30
31
|
*/
|
|
31
32
|
async function getPathsToWatch(siteDir) {
|
|
32
|
-
const context = await (0, server_1.loadContext)(siteDir);
|
|
33
|
-
const
|
|
34
|
-
const plugins = await (0, init_1.default)({
|
|
35
|
-
pluginConfigs,
|
|
36
|
-
context,
|
|
37
|
-
});
|
|
33
|
+
const context = await (0, server_1.loadContext)({ siteDir });
|
|
34
|
+
const plugins = await (0, init_1.initPlugins)(context);
|
|
38
35
|
return plugins.flatMap((plugin) => plugin?.getPathsToWatch?.() ?? []);
|
|
39
36
|
}
|
|
40
37
|
async function writeHeadingIds(siteDir, files, options) {
|
|
@@ -50,4 +47,4 @@ async function writeHeadingIds(siteDir, files, options) {
|
|
|
50
47
|
logger_1.default.warn `number=${markdownFiles.length} Markdown files already have explicit heading IDs. If you intend to overwrite the existing heading IDs, use the code=${'--overwrite'} option.`;
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
|
-
exports.
|
|
50
|
+
exports.writeHeadingIds = writeHeadingIds;
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
7
|
+
import { type LoadContextOptions } from '../server';
|
|
8
8
|
import { type WriteTranslationsOptions } from '../server/translations/translations';
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
}): Promise<void>;
|
|
9
|
+
export declare type WriteTranslationsCLIOptions = Pick<LoadContextOptions, 'config' | 'locale'> & WriteTranslationsOptions;
|
|
10
|
+
export declare function writeTranslations(siteDir: string, options: Partial<WriteTranslationsCLIOptions>): Promise<void>;
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.writeTranslations = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
12
|
const server_1 = require("../server");
|
|
12
|
-
const init_1 =
|
|
13
|
+
const init_1 = require("../server/plugins/init");
|
|
13
14
|
const translations_1 = require("../server/translations/translations");
|
|
14
15
|
const translationsExtractor_1 = require("../server/translations/translationsExtractor");
|
|
15
16
|
const utils_1 = require("../webpack/utils");
|
|
@@ -47,15 +48,12 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
async function writeTranslations(siteDir, options) {
|
|
50
|
-
const context = await (0, server_1.loadContext)(
|
|
51
|
-
|
|
51
|
+
const context = await (0, server_1.loadContext)({
|
|
52
|
+
siteDir,
|
|
53
|
+
config: options.config,
|
|
52
54
|
locale: options.locale,
|
|
53
55
|
});
|
|
54
|
-
const
|
|
55
|
-
const plugins = await (0, init_1.default)({
|
|
56
|
-
pluginConfigs,
|
|
57
|
-
context,
|
|
58
|
-
});
|
|
56
|
+
const plugins = await (0, init_1.initPlugins)(context);
|
|
59
57
|
const locale = options.locale ?? context.i18n.defaultLocale;
|
|
60
58
|
if (!context.i18n.locales.includes(locale)) {
|
|
61
59
|
throw new Error(`Can't write-translation for locale "${locale}" that is not in the locale configuration file.
|
|
@@ -76,4 +74,4 @@ Available locales are: ${context.i18n.locales.join(',')}.`);
|
|
|
76
74
|
await writePluginTranslationFiles({ siteDir, plugin, locale, options });
|
|
77
75
|
}));
|
|
78
76
|
}
|
|
79
|
-
exports.
|
|
77
|
+
exports.writeTranslations = writeTranslations;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export { build, clear, deploy, externalCommand, serve, start, swizzle, writeHeadingIds, writeTranslations, };
|
|
7
|
+
export { build } from './commands/build';
|
|
8
|
+
export { clear } from './commands/clear';
|
|
9
|
+
export { deploy } from './commands/deploy';
|
|
10
|
+
export { externalCommand } from './commands/external';
|
|
11
|
+
export { serve } from './commands/serve';
|
|
12
|
+
export { start } from './commands/start';
|
|
13
|
+
export { swizzle } from './commands/swizzle';
|
|
14
|
+
export { writeHeadingIds } from './commands/writeHeadingIds';
|
|
15
|
+
export { writeTranslations } from './commands/writeTranslations';
|
package/lib/index.js
CHANGED
|
@@ -7,22 +7,21 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.writeTranslations = exports.writeHeadingIds = exports.swizzle = exports.start = exports.serve = exports.externalCommand = exports.deploy = exports.clear = exports.build = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
exports.writeTranslations = writeTranslations_1.default;
|
|
10
|
+
var build_1 = require("./commands/build");
|
|
11
|
+
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
|
|
12
|
+
var clear_1 = require("./commands/clear");
|
|
13
|
+
Object.defineProperty(exports, "clear", { enumerable: true, get: function () { return clear_1.clear; } });
|
|
14
|
+
var deploy_1 = require("./commands/deploy");
|
|
15
|
+
Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return deploy_1.deploy; } });
|
|
16
|
+
var external_1 = require("./commands/external");
|
|
17
|
+
Object.defineProperty(exports, "externalCommand", { enumerable: true, get: function () { return external_1.externalCommand; } });
|
|
18
|
+
var serve_1 = require("./commands/serve");
|
|
19
|
+
Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return serve_1.serve; } });
|
|
20
|
+
var start_1 = require("./commands/start");
|
|
21
|
+
Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_1.start; } });
|
|
22
|
+
var swizzle_1 = require("./commands/swizzle");
|
|
23
|
+
Object.defineProperty(exports, "swizzle", { enumerable: true, get: function () { return swizzle_1.swizzle; } });
|
|
24
|
+
var writeHeadingIds_1 = require("./commands/writeHeadingIds");
|
|
25
|
+
Object.defineProperty(exports, "writeHeadingIds", { enumerable: true, get: function () { return writeHeadingIds_1.writeHeadingIds; } });
|
|
26
|
+
var writeTranslations_1 = require("./commands/writeTranslations");
|
|
27
|
+
Object.defineProperty(exports, "writeTranslations", { enumerable: true, get: function () { return writeTranslations_1.writeTranslations; } });
|
|
@@ -34,7 +34,7 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
|
|
|
34
34
|
// component, but we load route components with string paths.
|
|
35
35
|
// We don't actually access component here, so it's fine.
|
|
36
36
|
.map((l) => (0, react_router_config_1.matchRoutes)(routes, l))
|
|
37
|
-
.
|
|
37
|
+
.flat();
|
|
38
38
|
return matchedRoutes.length === 0;
|
|
39
39
|
}
|
|
40
40
|
return pageLinks.map(resolveLink).filter((l) => isBrokenLink(l.resolvedLink));
|
|
@@ -52,7 +52,6 @@ function filterIntermediateRoutes(routesInput) {
|
|
|
52
52
|
function getAllBrokenLinks({ allCollectedLinks, routes, }) {
|
|
53
53
|
const filteredRoutes = filterIntermediateRoutes(routes);
|
|
54
54
|
const allBrokenLinks = lodash_1.default.mapValues(allCollectedLinks, (pageLinks, pagePath) => getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes }));
|
|
55
|
-
// remove pages without any broken link
|
|
56
55
|
return lodash_1.default.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
57
56
|
}
|
|
58
57
|
function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
@@ -5,4 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { LoadedPlugin } from '@docusaurus/types';
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Runs the `getClientModules` lifecycle. The returned file paths are all
|
|
10
|
+
* absolute.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadClientModules(plugins: LoadedPlugin[]): string[];
|
|
@@ -6,10 +6,15 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadClientModules = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
/**
|
|
13
|
+
* Runs the `getClientModules` lifecycle. The returned file paths are all
|
|
14
|
+
* absolute.
|
|
15
|
+
*/
|
|
11
16
|
function loadClientModules(plugins) {
|
|
12
17
|
return plugins.flatMap((plugin) => plugin.getClientModules?.().map((p) => path_1.default.resolve(plugin.path, p)) ??
|
|
13
18
|
[]);
|
|
14
19
|
}
|
|
15
|
-
exports.
|
|
20
|
+
exports.loadClientModules = loadClientModules;
|
package/lib/server/config.d.ts
CHANGED
|
@@ -4,5 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
export
|
|
7
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
8
|
+
export declare function loadSiteConfig({ siteDir, customConfigFilePath, }: {
|
|
9
|
+
siteDir: string;
|
|
10
|
+
customConfigFilePath?: string;
|
|
11
|
+
}): Promise<Pick<LoadContext, 'siteConfig' | 'siteConfigPath'>>;
|
package/lib/server/config.js
CHANGED
|
@@ -6,18 +6,23 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadSiteConfig = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
13
|
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
15
|
const configValidation_1 = require("./configValidation");
|
|
13
|
-
async function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
|
|
17
|
+
const siteConfigPath = path_1.default.resolve(siteDir, customConfigFilePath ?? utils_1.DEFAULT_CONFIG_FILE_NAME);
|
|
18
|
+
if (!(await fs_extra_1.default.pathExists(siteConfigPath))) {
|
|
19
|
+
throw new Error(`Config file at "${siteConfigPath}" not found.`);
|
|
16
20
|
}
|
|
17
|
-
const importedConfig = (0, import_fresh_1.default)(
|
|
21
|
+
const importedConfig = (0, import_fresh_1.default)(siteConfigPath);
|
|
18
22
|
const loadedConfig = typeof importedConfig === 'function'
|
|
19
23
|
? await importedConfig()
|
|
20
24
|
: await importedConfig;
|
|
21
|
-
|
|
25
|
+
const siteConfig = (0, configValidation_1.validateConfig)(loadedConfig);
|
|
26
|
+
return { siteConfig, siteConfigPath };
|
|
22
27
|
}
|
|
23
|
-
exports.
|
|
28
|
+
exports.loadSiteConfig = loadSiteConfig;
|
|
@@ -40,7 +40,7 @@ function createPluginSchema(theme) {
|
|
|
40
40
|
.ordered(utils_validation_1.Joi.function().required(), utils_validation_1.Joi.object().required())
|
|
41
41
|
.length(2), utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
|
|
42
42
|
.ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
|
|
43
|
-
.length(2), utils_validation_1.Joi.
|
|
43
|
+
.length(2), utils_validation_1.Joi.any().valid(false, null))
|
|
44
44
|
// @ts-expect-error: bad lib def, doesn't recognize an array of reports
|
|
45
45
|
.error((errors) => {
|
|
46
46
|
errors.forEach((error) => {
|
|
@@ -77,7 +77,7 @@ const ThemeSchema = createPluginSchema(true);
|
|
|
77
77
|
const PresetSchema = utils_validation_1.Joi.alternatives()
|
|
78
78
|
.try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
|
|
79
79
|
.items(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
|
|
80
|
-
.length(2))
|
|
80
|
+
.length(2), utils_validation_1.Joi.any().valid(false, null))
|
|
81
81
|
.messages({
|
|
82
82
|
'alternatives.types': `{#label} does not look like a valid preset config. A preset config entry should be one of:
|
|
83
83
|
- A tuple of [presetName, options], like \`["classic", \\{ blog: false \\}]\`, or
|
|
@@ -87,6 +87,7 @@ const LocaleConfigSchema = utils_validation_1.Joi.object({
|
|
|
87
87
|
label: utils_validation_1.Joi.string(),
|
|
88
88
|
htmlLang: utils_validation_1.Joi.string(),
|
|
89
89
|
direction: utils_validation_1.Joi.string().equal('ltr', 'rtl').default('ltr'),
|
|
90
|
+
calendar: utils_validation_1.Joi.string(),
|
|
90
91
|
});
|
|
91
92
|
const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
92
93
|
defaultLocale: utils_validation_1.Joi.string().required(),
|
|
@@ -168,8 +169,8 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
168
169
|
.items(utils_validation_1.Joi.string())
|
|
169
170
|
.default(exports.DEFAULT_CONFIG.clientModules),
|
|
170
171
|
tagline: utils_validation_1.Joi.string().allow('').default(exports.DEFAULT_CONFIG.tagline),
|
|
171
|
-
titleDelimiter: utils_validation_1.Joi.string().default(
|
|
172
|
-
noIndex: utils_validation_1.Joi.bool().default(
|
|
172
|
+
titleDelimiter: utils_validation_1.Joi.string().default(exports.DEFAULT_CONFIG.titleDelimiter),
|
|
173
|
+
noIndex: utils_validation_1.Joi.bool().default(exports.DEFAULT_CONFIG.noIndex),
|
|
173
174
|
webpack: utils_validation_1.Joi.object({
|
|
174
175
|
jsLoader: utils_validation_1.Joi.alternatives()
|
|
175
176
|
.try(utils_validation_1.Joi.string().equal('babel'), utils_validation_1.Joi.function())
|
|
@@ -195,7 +196,7 @@ function validateConfig(config) {
|
|
|
195
196
|
? `${accumulatedErr}${err.message}\n`
|
|
196
197
|
: accumulatedErr, '');
|
|
197
198
|
formattedError = unknownFields
|
|
198
|
-
? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${utils_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the "customFields" field.\nSee https://docusaurus.io/docs/docusaurus
|
|
199
|
+
? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${utils_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the "customFields" field.\nSee https://docusaurus.io/docs/api/docusaurus-config/#customfields`
|
|
199
200
|
: formattedError;
|
|
200
201
|
throw new Error(formattedError);
|
|
201
202
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export declare type HostPortOptions = {
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function getHostPort(options: HostPortOptions): Promise<{
|
|
12
|
+
host: string;
|
|
13
|
+
port: number | null;
|
|
14
|
+
}>;
|