@docusaurus/core 0.0.0-5990 → 0.0.0-5994
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.
|
@@ -10,14 +10,26 @@ exports.initSwizzleContext = initSwizzleContext;
|
|
|
10
10
|
const site_1 = require("../../server/site");
|
|
11
11
|
const init_1 = require("../../server/plugins/init");
|
|
12
12
|
const configs_1 = require("../../server/plugins/configs");
|
|
13
|
+
async function getSwizzlePlugins(context) {
|
|
14
|
+
const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
|
|
15
|
+
const pluginConfigInitResults = await (0, init_1.initPluginsConfigs)(context, pluginConfigs);
|
|
16
|
+
return pluginConfigInitResults.flatMap((initResult) => {
|
|
17
|
+
// Ignore self-disabling plugins returning null
|
|
18
|
+
if (initResult.plugin === null) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return [
|
|
22
|
+
// TODO this is a bit confusing, need refactor
|
|
23
|
+
{
|
|
24
|
+
plugin: initResult.config,
|
|
25
|
+
instance: initResult.plugin,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
13
30
|
async function initSwizzleContext(siteDir, options) {
|
|
14
31
|
const context = await (0, site_1.loadContext)({ siteDir, config: options.config });
|
|
15
|
-
const plugins = await (0, init_1.initPlugins)(context);
|
|
16
|
-
const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
|
|
17
32
|
return {
|
|
18
|
-
plugins:
|
|
19
|
-
plugin: pluginConfigs[pluginIndex],
|
|
20
|
-
instance: plugin,
|
|
21
|
-
})),
|
|
33
|
+
plugins: await getSwizzlePlugins(context),
|
|
22
34
|
};
|
|
23
35
|
}
|
|
@@ -4,9 +4,20 @@
|
|
|
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 './configs';
|
|
7
8
|
import type { LoadContext, InitializedPlugin } from '@docusaurus/types';
|
|
9
|
+
type PluginConfigInitResult = {
|
|
10
|
+
config: NormalizedPluginConfig;
|
|
11
|
+
plugin: InitializedPlugin | null;
|
|
12
|
+
};
|
|
8
13
|
/**
|
|
9
14
|
* Runs the plugin constructors and returns their return values. It would load
|
|
10
15
|
* plugin configs from `plugins`, `themes`, and `presets`.
|
|
11
16
|
*/
|
|
17
|
+
export declare function initPluginsConfigs(context: LoadContext, pluginConfigs: NormalizedPluginConfig[]): Promise<PluginConfigInitResult[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Runs the plugin constructors and returns their return values
|
|
20
|
+
* for all the site context plugins that do not return null to self-disable.
|
|
21
|
+
*/
|
|
12
22
|
export declare function initPlugins(context: LoadContext): Promise<InitializedPlugin[]>;
|
|
23
|
+
export {};
|
|
@@ -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.initPluginsConfigs = initPluginsConfigs;
|
|
9
10
|
exports.initPlugins = initPlugins;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const module_1 = require("module");
|
|
@@ -31,15 +32,20 @@ function getThemeValidationFunction(normalizedPluginConfig) {
|
|
|
31
32
|
}
|
|
32
33
|
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
33
34
|
}
|
|
35
|
+
// This filters self-disabling plugins and returns only the initialized ones
|
|
36
|
+
function onlyInitializedPlugins(initPluginsConfigsResults) {
|
|
37
|
+
return initPluginsConfigsResults
|
|
38
|
+
.map((results) => results.plugin)
|
|
39
|
+
.filter((p) => p !== null);
|
|
40
|
+
}
|
|
34
41
|
/**
|
|
35
42
|
* Runs the plugin constructors and returns their return values. It would load
|
|
36
43
|
* plugin configs from `plugins`, `themes`, and `presets`.
|
|
37
44
|
*/
|
|
38
|
-
async function
|
|
45
|
+
async function initPluginsConfigs(context, pluginConfigs) {
|
|
39
46
|
// We need to resolve plugins from the perspective of the site config, as if
|
|
40
47
|
// we are using `require.resolve` on those module names.
|
|
41
48
|
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
42
|
-
const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
|
|
43
49
|
async function doLoadPluginVersion(normalizedPluginConfig) {
|
|
44
50
|
if (normalizedPluginConfig.pluginModule?.path) {
|
|
45
51
|
const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule.path);
|
|
@@ -76,23 +82,49 @@ async function initPlugins(context) {
|
|
|
76
82
|
const pluginVersion = await doLoadPluginVersion(normalizedPluginConfig);
|
|
77
83
|
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
|
78
84
|
// Side-effect: merge the normalized theme config in the original one
|
|
85
|
+
// Note: it's important to do this before calling the plugin constructor
|
|
86
|
+
// Example: the theme classic plugin will read siteConfig.themeConfig
|
|
79
87
|
context.siteConfig.themeConfig = {
|
|
80
88
|
...context.siteConfig.themeConfig,
|
|
81
89
|
...doValidateThemeConfig(normalizedPluginConfig),
|
|
82
90
|
};
|
|
83
91
|
const pluginInstance = await normalizedPluginConfig.plugin(context, pluginOptions);
|
|
84
|
-
|
|
92
|
+
// Returning null has been explicitly allowed
|
|
93
|
+
// It's a way for plugins to self-disable depending on context
|
|
94
|
+
// See https://github.com/facebook/docusaurus/pull/10286
|
|
95
|
+
if (pluginInstance === null) {
|
|
96
|
+
return { config: normalizedPluginConfig, plugin: null };
|
|
97
|
+
}
|
|
98
|
+
if (pluginInstance === undefined) {
|
|
99
|
+
throw new Error(`A Docusaurus plugin returned 'undefined', which is forbidden.
|
|
100
|
+
A plugin is expected to return an object having at least a 'name' property.
|
|
101
|
+
If you want a plugin to self-disable depending on context/options, you can explicitly return 'null' instead of 'undefined'`);
|
|
102
|
+
}
|
|
103
|
+
if (!pluginInstance?.name) {
|
|
85
104
|
throw new Error(`A Docusaurus plugin is missing a 'name' property.
|
|
86
105
|
Note that even inline/anonymous plugin functions require a 'name' property.`);
|
|
87
106
|
}
|
|
88
|
-
|
|
107
|
+
const plugin = {
|
|
89
108
|
...pluginInstance,
|
|
90
109
|
options: pluginOptions,
|
|
91
110
|
version: pluginVersion,
|
|
92
111
|
path: path_1.default.dirname(normalizedPluginConfig.entryPath),
|
|
93
112
|
};
|
|
113
|
+
return {
|
|
114
|
+
config: normalizedPluginConfig,
|
|
115
|
+
plugin,
|
|
116
|
+
};
|
|
94
117
|
}
|
|
95
|
-
const plugins = await Promise.all(pluginConfigs.map(initializePlugin));
|
|
96
|
-
(0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
|
|
118
|
+
const plugins = (await Promise.all(pluginConfigs.map(initializePlugin))).filter((p) => p !== null);
|
|
119
|
+
(0, pluginIds_1.ensureUniquePluginInstanceIds)(onlyInitializedPlugins(plugins));
|
|
97
120
|
return plugins;
|
|
98
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Runs the plugin constructors and returns their return values
|
|
124
|
+
* for all the site context plugins that do not return null to self-disable.
|
|
125
|
+
*/
|
|
126
|
+
async function initPlugins(context) {
|
|
127
|
+
const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
|
|
128
|
+
const initPluginsConfigsResults = await initPluginsConfigs(context, pluginConfigs);
|
|
129
|
+
return onlyInitializedPlugins(initPluginsConfigsResults);
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-5994",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"@babel/runtime": "^7.22.6",
|
|
44
44
|
"@babel/runtime-corejs3": "^7.22.6",
|
|
45
45
|
"@babel/traverse": "^7.22.8",
|
|
46
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
47
|
-
"@docusaurus/logger": "0.0.0-
|
|
48
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
49
|
-
"@docusaurus/utils": "0.0.0-
|
|
50
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
51
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
46
|
+
"@docusaurus/cssnano-preset": "0.0.0-5994",
|
|
47
|
+
"@docusaurus/logger": "0.0.0-5994",
|
|
48
|
+
"@docusaurus/mdx-loader": "0.0.0-5994",
|
|
49
|
+
"@docusaurus/utils": "0.0.0-5994",
|
|
50
|
+
"@docusaurus/utils-common": "0.0.0-5994",
|
|
51
|
+
"@docusaurus/utils-validation": "0.0.0-5994",
|
|
52
52
|
"autoprefixer": "^10.4.14",
|
|
53
53
|
"babel-loader": "^9.1.3",
|
|
54
54
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
@@ -103,8 +103,8 @@
|
|
|
103
103
|
"webpackbar": "^5.0.2"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
107
|
-
"@docusaurus/types": "0.0.0-
|
|
106
|
+
"@docusaurus/module-type-aliases": "0.0.0-5994",
|
|
107
|
+
"@docusaurus/types": "0.0.0-5994",
|
|
108
108
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
109
109
|
"@types/detect-port": "^1.3.3",
|
|
110
110
|
"@types/react-dom": "^18.2.7",
|
|
@@ -124,5 +124,5 @@
|
|
|
124
124
|
"engines": {
|
|
125
125
|
"node": ">=18.0"
|
|
126
126
|
},
|
|
127
|
-
"gitHead": "
|
|
127
|
+
"gitHead": "4905b76b4b39c2f102bbc78d018933f57ea39b78"
|
|
128
128
|
}
|