@docusaurus/core 2.0.0-beta.12faed89d → 2.0.0-beta.13
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.js +33 -8
- package/bin/docusaurus.js +36 -40
- package/lib/.tsbuildinfo +1 -1
- package/lib/babel/preset.d.ts +6 -0
- package/lib/babel/preset.js +3 -3
- package/lib/choosePort.js +12 -13
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/.tsbuildinfo +1 -1
- package/lib/client/App.js +12 -22
- package/lib/client/LinksCollector.d.ts +2 -2
- package/lib/client/LinksCollector.js +4 -8
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +1 -1
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +5 -0
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -2
- package/lib/client/client-lifecycles-dispatcher.js +0 -2
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +11 -19
- package/lib/client/exports/BrowserOnly.js +5 -3
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Interpolate.js +12 -15
- package/lib/client/exports/Link.js +9 -9
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +13 -9
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +21 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/useBaseUrl.js +2 -4
- package/lib/client/exports/useDocusaurusContext.js +2 -7
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
- package/lib/{webpack/sharedModuleAliases.d.ts → client/exports/useIsBrowser.js} +5 -4
- package/lib/client/flat.d.ts +2 -1
- package/lib/client/flat.js +7 -9
- package/lib/client/normalizeLocation.d.ts +1 -3
- package/lib/client/prefetch.js +0 -1
- package/lib/client/serverEntry.js +15 -31
- package/lib/client/theme-fallback/Error/index.js +47 -0
- package/lib/client/theme-fallback/Layout/index.js +1 -1
- package/lib/client/theme-fallback/Loading/index.js +2 -2
- package/lib/client/theme-fallback/Root/index.js +1 -3
- package/lib/commands/build.js +34 -37
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +9 -9
- package/lib/commands/commandUtils.d.ts +6 -0
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +3 -0
- package/lib/commands/deploy.js +90 -53
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.js +13 -13
- package/lib/commands/start.js +82 -72
- package/lib/commands/swizzle.js +34 -34
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +32 -32
- package/lib/commands/writeTranslations.js +31 -11
- package/lib/server/brokenLinks.js +13 -17
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.js +4 -4
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +11 -6
- package/lib/server/duplicateRoutes.js +8 -2
- package/lib/server/html-tags/htmlTags.js +5 -6
- package/lib/server/html-tags/index.js +2 -2
- package/lib/server/i18n.js +16 -13
- package/lib/server/index.js +128 -58
- package/lib/server/loadSetup.js +3 -3
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +42 -0
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +1 -1
- package/lib/server/plugins/index.js +24 -20
- package/lib/server/plugins/init.js +9 -12
- package/lib/server/plugins/pluginIds.js +6 -4
- package/lib/server/presets/index.js +12 -12
- package/lib/server/routes.js +9 -11
- package/lib/server/themes/alias.d.ts +1 -0
- package/lib/server/themes/alias.js +21 -12
- package/lib/server/themes/index.d.ts +1 -1
- package/lib/server/themes/index.js +22 -23
- package/lib/server/translations/translations.d.ts +6 -0
- package/lib/server/translations/translations.js +15 -17
- package/lib/server/translations/translationsExtractor.d.ts +7 -1
- package/lib/server/translations/translationsExtractor.js +65 -56
- package/lib/server/utils.d.ts +8 -2
- package/lib/server/utils.js +8 -10
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__tests/index.test.js +5 -5
- package/lib/server/versions/index.js +6 -6
- package/lib/webpack/base.js +14 -16
- package/lib/webpack/client.js +8 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.js +4 -11
- package/lib/webpack/plugins/LogPlugin.js +5 -6
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/server.js +9 -9
- package/lib/webpack/utils.d.ts +0 -22
- package/lib/webpack/utils.js +26 -125
- package/package.json +55 -50
- package/tsconfig.client.json +1 -2
- package/tsconfig.json +5 -4
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- 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.js +0 -18
package/lib/server/index.js
CHANGED
|
@@ -9,36 +9,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.load = exports.loadPluginConfigs = exports.loadContext = exports.loadSiteConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const path_1 = tslib_1.__importStar(require("path"));
|
|
13
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
|
-
const ssr_html_template_1 = tslib_1.__importDefault(require("../client/templates/ssr.html.template"));
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const config_1 = tslib_1.__importDefault(require("./config"));
|
|
12
|
+
const path_1 = (0, tslib_1.__importStar)(require("path"));
|
|
13
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
14
|
+
const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../client/templates/ssr.html.template"));
|
|
15
|
+
const client_modules_1 = (0, tslib_1.__importDefault)(require("./client-modules"));
|
|
16
|
+
const config_1 = (0, tslib_1.__importDefault)(require("./config"));
|
|
18
17
|
const plugins_1 = require("./plugins");
|
|
19
|
-
const presets_1 = tslib_1.__importDefault(require("./presets"));
|
|
20
|
-
const routes_1 = tslib_1.__importDefault(require("./routes"));
|
|
18
|
+
const presets_1 = (0, tslib_1.__importDefault)(require("./presets"));
|
|
19
|
+
const routes_1 = (0, tslib_1.__importDefault)(require("./routes"));
|
|
21
20
|
const html_tags_1 = require("./html-tags");
|
|
22
21
|
const versions_1 = require("./versions");
|
|
23
22
|
const duplicateRoutes_1 = require("./duplicateRoutes");
|
|
24
23
|
const i18n_1 = require("./i18n");
|
|
25
24
|
const translations_1 = require("./translations/translations");
|
|
26
25
|
const lodash_1 = require("lodash");
|
|
26
|
+
const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
|
|
27
|
+
const module_1 = require("module");
|
|
28
|
+
const moduleShorthand_1 = require("./moduleShorthand");
|
|
27
29
|
async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
|
|
28
|
-
const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath :
|
|
30
|
+
const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath : utils_1.DEFAULT_CONFIG_FILE_NAME;
|
|
29
31
|
const siteConfigPath = path_1.default.isAbsolute(siteConfigPathUnresolved)
|
|
30
32
|
? siteConfigPathUnresolved
|
|
31
33
|
: path_1.default.resolve(siteDir, siteConfigPathUnresolved);
|
|
32
|
-
const siteConfig = await config_1.default(siteConfigPath);
|
|
34
|
+
const siteConfig = await (0, config_1.default)(siteConfigPath);
|
|
33
35
|
return { siteConfig, siteConfigPath };
|
|
34
36
|
}
|
|
35
37
|
exports.loadSiteConfig = loadSiteConfig;
|
|
36
38
|
async function loadContext(siteDir, options = {}) {
|
|
37
39
|
var _a;
|
|
38
40
|
const { customOutDir, locale, customConfigFilePath } = options;
|
|
39
|
-
const generatedFilesDir = path_1.default.isAbsolute(
|
|
40
|
-
?
|
|
41
|
-
: path_1.default.resolve(siteDir,
|
|
41
|
+
const generatedFilesDir = path_1.default.isAbsolute(utils_1.GENERATED_FILES_DIR_NAME)
|
|
42
|
+
? utils_1.GENERATED_FILES_DIR_NAME
|
|
43
|
+
: path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
|
|
42
44
|
const { siteConfig: initialSiteConfig, siteConfigPath } = await loadSiteConfig({
|
|
43
45
|
siteDir,
|
|
44
46
|
customConfigFilePath,
|
|
@@ -46,27 +48,27 @@ async function loadContext(siteDir, options = {}) {
|
|
|
46
48
|
const { ssrTemplate } = initialSiteConfig;
|
|
47
49
|
const baseOutDir = customOutDir
|
|
48
50
|
? path_1.default.resolve(customOutDir)
|
|
49
|
-
: path_1.default.resolve(siteDir,
|
|
50
|
-
const i18n = await i18n_1.loadI18n(initialSiteConfig, { locale });
|
|
51
|
-
const baseUrl = i18n_1.localizePath({
|
|
51
|
+
: path_1.default.resolve(siteDir, utils_1.DEFAULT_BUILD_DIR_NAME);
|
|
52
|
+
const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
|
|
53
|
+
const baseUrl = (0, i18n_1.localizePath)({
|
|
52
54
|
path: initialSiteConfig.baseUrl,
|
|
53
55
|
i18n,
|
|
54
56
|
options,
|
|
55
57
|
pathType: 'url',
|
|
56
58
|
});
|
|
57
|
-
const outDir = i18n_1.localizePath({
|
|
59
|
+
const outDir = (0, i18n_1.localizePath)({
|
|
58
60
|
path: baseOutDir,
|
|
59
61
|
i18n,
|
|
60
62
|
options,
|
|
61
63
|
pathType: 'fs',
|
|
62
64
|
});
|
|
63
65
|
const siteConfig = { ...initialSiteConfig, baseUrl };
|
|
64
|
-
const codeTranslationFileContent = (_a = (await translations_1.readCodeTranslationFileContent({
|
|
66
|
+
const codeTranslationFileContent = (_a = (await (0, translations_1.readCodeTranslationFileContent)({
|
|
65
67
|
siteDir,
|
|
66
68
|
locale: i18n.currentLocale,
|
|
67
69
|
}))) !== null && _a !== void 0 ? _a : {};
|
|
68
70
|
// We only need key->message for code translations
|
|
69
|
-
const codeTranslations = lodash_1.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
71
|
+
const codeTranslations = (0, lodash_1.mapValues)(codeTranslationFileContent, (value) => value.message);
|
|
70
72
|
return {
|
|
71
73
|
siteDir,
|
|
72
74
|
generatedFilesDir,
|
|
@@ -81,38 +83,42 @@ async function loadContext(siteDir, options = {}) {
|
|
|
81
83
|
}
|
|
82
84
|
exports.loadContext = loadContext;
|
|
83
85
|
function loadPluginConfigs(context) {
|
|
84
|
-
|
|
85
|
-
const { siteConfig } = context;
|
|
86
|
+
let { plugins: presetPlugins, themes: presetThemes } = (0, presets_1.default)(context);
|
|
87
|
+
const { siteConfig, siteConfigPath } = context;
|
|
88
|
+
const require = (0, module_1.createRequire)(siteConfigPath);
|
|
89
|
+
function normalizeShorthand(pluginConfig, pluginType) {
|
|
90
|
+
var _a;
|
|
91
|
+
if (typeof pluginConfig === 'string') {
|
|
92
|
+
return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
|
|
93
|
+
}
|
|
94
|
+
else if (Array.isArray(pluginConfig) &&
|
|
95
|
+
typeof pluginConfig[0] === 'string') {
|
|
96
|
+
return [
|
|
97
|
+
(0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
|
|
98
|
+
(_a = pluginConfig[1]) !== null && _a !== void 0 ? _a : {},
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
return pluginConfig;
|
|
102
|
+
}
|
|
103
|
+
presetPlugins = presetPlugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
104
|
+
presetThemes = presetThemes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
105
|
+
const standalonePlugins = (siteConfig.plugins || []).map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
106
|
+
const standaloneThemes = (siteConfig.themes || []).map((theme) => normalizeShorthand(theme, 'theme'));
|
|
86
107
|
return [
|
|
87
108
|
...presetPlugins,
|
|
88
109
|
...presetThemes,
|
|
89
110
|
// Site config should be the highest priority.
|
|
90
|
-
...
|
|
91
|
-
...
|
|
111
|
+
...standalonePlugins,
|
|
112
|
+
...standaloneThemes,
|
|
92
113
|
];
|
|
93
114
|
}
|
|
94
115
|
exports.loadPluginConfigs = loadPluginConfigs;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// Plugins.
|
|
100
|
-
const pluginConfigs = loadPluginConfigs(context);
|
|
101
|
-
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated, } = await plugins_1.loadPlugins({
|
|
102
|
-
pluginConfigs,
|
|
103
|
-
context,
|
|
104
|
-
});
|
|
105
|
-
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
106
|
-
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
107
|
-
duplicateRoutes_1.handleDuplicateRoutes(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
|
|
108
|
-
// Site config must be generated after plugins
|
|
109
|
-
// We want the generated config to have been normalized by the plugins!
|
|
110
|
-
const genSiteConfig = utils_1.generate(generatedFilesDir, constants_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
|
|
111
|
-
// Make a fake plugin to:
|
|
112
|
-
// - Resolve aliased theme components
|
|
113
|
-
// - Inject scripts/stylesheets
|
|
116
|
+
// Make a fake plugin to:
|
|
117
|
+
// - Resolve aliased theme components
|
|
118
|
+
// - Inject scripts/stylesheets
|
|
119
|
+
function createBootstrapPlugin({ siteConfig, }) {
|
|
114
120
|
const { stylesheets = [], scripts = [], clientModules: siteConfigClientModules = [], } = siteConfig;
|
|
115
|
-
|
|
121
|
+
return {
|
|
116
122
|
name: 'docusaurus-bootstrap-plugin',
|
|
117
123
|
content: null,
|
|
118
124
|
options: {},
|
|
@@ -142,39 +148,103 @@ async function load(siteDir, options = {}) {
|
|
|
142
148
|
headTags: [...stylesheetsTags, ...scriptsTags],
|
|
143
149
|
};
|
|
144
150
|
},
|
|
145
|
-
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// Configurer Webpack fallback mdx loader for md/mdx files out of content-plugin folders
|
|
154
|
+
// Adds a "fallback" mdx loader for mdx files that are not processed by content plugins
|
|
155
|
+
// This allows to do things such as importing repo/README.md as a partial from another doc
|
|
156
|
+
// Not ideal solution though, but good enough for now
|
|
157
|
+
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
158
|
+
return {
|
|
159
|
+
name: 'docusaurus-mdx-fallback-plugin',
|
|
160
|
+
content: null,
|
|
161
|
+
options: {},
|
|
162
|
+
version: { type: 'synthetic' },
|
|
163
|
+
configureWebpack(config, isServer, { getJSLoader }) {
|
|
164
|
+
// We need the mdx fallback loader to exclude files that were already processed by content plugins mdx loaders
|
|
165
|
+
// This works, but a bit hacky...
|
|
166
|
+
// Not sure there's a way to handle that differently in webpack :s
|
|
167
|
+
function getMDXFallbackExcludedPaths() {
|
|
168
|
+
var _a;
|
|
169
|
+
const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
|
|
170
|
+
return rules.flatMap((rule) => {
|
|
171
|
+
const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
|
|
172
|
+
return isMDXRule ? rule.include : [];
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
module: {
|
|
177
|
+
rules: [
|
|
178
|
+
{
|
|
179
|
+
test: /(\.mdx?)$/,
|
|
180
|
+
exclude: getMDXFallbackExcludedPaths(),
|
|
181
|
+
use: [
|
|
182
|
+
getJSLoader({ isServer }),
|
|
183
|
+
{
|
|
184
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
185
|
+
options: {
|
|
186
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
187
|
+
siteDir,
|
|
188
|
+
isMDXPartial: (_filename) => true,
|
|
189
|
+
isMDXPartialFrontMatterWarningDisabled: true,
|
|
190
|
+
remarkPlugins: [remark_admonitions_1.default],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async function load(siteDir, options = {}) {
|
|
202
|
+
// Context.
|
|
203
|
+
const context = await loadContext(siteDir, options);
|
|
204
|
+
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
|
|
205
|
+
// Plugins.
|
|
206
|
+
const pluginConfigs = loadPluginConfigs(context);
|
|
207
|
+
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
|
|
208
|
+
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
209
|
+
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
210
|
+
(0, duplicateRoutes_1.handleDuplicateRoutes)(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
|
|
211
|
+
// Site config must be generated after plugins
|
|
212
|
+
// We want the generated config to have been normalized by the plugins!
|
|
213
|
+
const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, utils_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
|
|
214
|
+
plugins.push(createBootstrapPlugin({ siteConfig }));
|
|
215
|
+
plugins.push(createMDXFallbackPlugin({ siteDir, siteConfig }));
|
|
146
216
|
// Load client modules.
|
|
147
|
-
const clientModules = client_modules_1.default(plugins);
|
|
148
|
-
const genClientModules = utils_1.generate(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
|
|
217
|
+
const clientModules = (0, client_modules_1.default)(plugins);
|
|
218
|
+
const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
|
|
149
219
|
// import() is async so we use require() because client modules can have
|
|
150
220
|
// CSS and the order matters for loading CSS.
|
|
151
221
|
// We need to JSON.stringify so that if its on windows, backslash are escaped.
|
|
152
222
|
.map((module) => ` require(${JSON.stringify(module)}),`)
|
|
153
223
|
.join('\n')}\n];\n`);
|
|
154
224
|
// Load extra head & body html tags.
|
|
155
|
-
const { headTags, preBodyTags, postBodyTags } = html_tags_1.loadHtmlTags(plugins);
|
|
225
|
+
const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
|
|
156
226
|
// Routing.
|
|
157
|
-
const { registry, routesChunkNames, routesConfig, routesPaths
|
|
158
|
-
const genRegistry = utils_1.generate(generatedFilesDir, 'registry.js', `export default {
|
|
227
|
+
const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.default)(pluginsRouteConfigs, baseUrl);
|
|
228
|
+
const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
|
|
159
229
|
${Object.keys(registry)
|
|
160
230
|
.sort()
|
|
161
231
|
.map((key) =>
|
|
162
232
|
// We need to JSON.stringify so that if its on windows, backslash are escaped.
|
|
163
233
|
` '${key}': [${registry[key].loader}, ${JSON.stringify(registry[key].modulePath)}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`)
|
|
164
234
|
.join('\n')}};\n`);
|
|
165
|
-
const genRoutesChunkNames = utils_1.generate(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
|
|
166
|
-
const genRoutes = utils_1.generate(generatedFilesDir, 'routes.js', routesConfig);
|
|
167
|
-
const genGlobalData = utils_1.generate(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
168
|
-
const genI18n = utils_1.generate(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
235
|
+
const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
|
|
236
|
+
const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
|
|
237
|
+
const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
238
|
+
const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
169
239
|
const codeTranslationsWithFallbacks = {
|
|
170
|
-
...(await translations_1.getPluginsDefaultCodeTranslationMessages(plugins)),
|
|
240
|
+
...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
|
|
171
241
|
...codeTranslations,
|
|
172
242
|
};
|
|
173
|
-
const genCodeTranslations = utils_1.generate(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
|
|
243
|
+
const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
|
|
174
244
|
// Version metadata.
|
|
175
245
|
const siteMetadata = {
|
|
176
|
-
docusaurusVersion: versions_1.getPackageJsonVersion(path_1.join(__dirname, '../../package.json')),
|
|
177
|
-
siteVersion: versions_1.getPackageJsonVersion(path_1.join(siteDir, 'package.json')),
|
|
246
|
+
docusaurusVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(__dirname, '../../package.json')),
|
|
247
|
+
siteVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(siteDir, 'package.json')),
|
|
178
248
|
pluginVersions: {},
|
|
179
249
|
};
|
|
180
250
|
plugins
|
|
@@ -183,7 +253,7 @@ ${Object.keys(registry)
|
|
|
183
253
|
siteMetadata.pluginVersions[name] = version;
|
|
184
254
|
});
|
|
185
255
|
checkDocusaurusPackagesVersion(siteMetadata);
|
|
186
|
-
const genSiteMetadata = utils_1.generate(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
|
|
256
|
+
const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
|
|
187
257
|
await Promise.all([
|
|
188
258
|
genClientModules,
|
|
189
259
|
genSiteConfig,
|
package/lib/server/loadSetup.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
11
11
|
const index_1 = require("./index");
|
|
12
12
|
// Helper methods to setup dummy/fake projects.
|
|
13
13
|
const loadSetup = async (name) => {
|
|
@@ -16,10 +16,10 @@ const loadSetup = async (name) => {
|
|
|
16
16
|
const customSite = path_1.default.join(fixtures, 'custom-site');
|
|
17
17
|
switch (name) {
|
|
18
18
|
case 'custom':
|
|
19
|
-
return index_1.load(customSite);
|
|
19
|
+
return (0, index_1.load)(customSite);
|
|
20
20
|
case 'simple':
|
|
21
21
|
default:
|
|
22
|
-
return index_1.load(simpleSite);
|
|
22
|
+
return (0, index_1.load)(simpleSite);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
exports.default = loadSetup;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
/// <reference types="node" />
|
|
8
|
+
export declare function getNamePatterns(moduleName: string, moduleType: 'preset' | 'theme' | 'plugin'): string[];
|
|
9
|
+
export declare function resolveModuleName(moduleName: string, moduleRequire: NodeRequire, moduleType: 'preset' | 'theme' | 'plugin'): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
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.resolveModuleName = exports.getNamePatterns = void 0;
|
|
10
|
+
function getNamePatterns(moduleName, moduleType) {
|
|
11
|
+
if (moduleName.startsWith('@')) {
|
|
12
|
+
// Pure scope: `@scope` => `@scope/docusaurus-plugin`
|
|
13
|
+
if (!moduleName.includes('/')) {
|
|
14
|
+
return [`${moduleName}/docusaurus-${moduleType}`];
|
|
15
|
+
}
|
|
16
|
+
const [scope, packageName] = moduleName.split(/\/(.*)/);
|
|
17
|
+
return [
|
|
18
|
+
`${scope}/${packageName}`,
|
|
19
|
+
`${scope}/docusaurus-${moduleType}-${packageName}`,
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
moduleName,
|
|
24
|
+
`@docusaurus/${moduleType}-${moduleName}`,
|
|
25
|
+
`docusaurus-${moduleType}-${moduleName}`,
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
exports.getNamePatterns = getNamePatterns;
|
|
29
|
+
function resolveModuleName(moduleName, moduleRequire, moduleType) {
|
|
30
|
+
const modulePatterns = getNamePatterns(moduleName, moduleType);
|
|
31
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
32
|
+
for (const module of modulePatterns) {
|
|
33
|
+
try {
|
|
34
|
+
moduleRequire.resolve(module);
|
|
35
|
+
return module;
|
|
36
|
+
}
|
|
37
|
+
catch (e) { }
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Docusaurus was unable to resolve the "${moduleName}" ${moduleType}. Make sure one of the following packages are installed:
|
|
40
|
+
${modulePatterns.map((module) => `- ${module}`).join('\n')}`);
|
|
41
|
+
}
|
|
42
|
+
exports.resolveModuleName = resolveModuleName;
|
|
@@ -10,7 +10,7 @@ const utils_common_1 = require("@docusaurus/utils-common");
|
|
|
10
10
|
function applyRouteTrailingSlash(route, params) {
|
|
11
11
|
return {
|
|
12
12
|
...route,
|
|
13
|
-
path: utils_common_1.applyTrailingSlash(route.path, params),
|
|
13
|
+
path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
|
|
14
14
|
...(route.routes && {
|
|
15
15
|
routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
|
|
16
16
|
}),
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { LoadContext, PluginConfig, RouteConfig, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
-
export declare function sortConfig(routeConfigs: RouteConfig[]): void;
|
|
8
|
+
export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
|
|
9
9
|
export declare function loadPlugins({ pluginConfigs, context, }: {
|
|
10
10
|
pluginConfigs: PluginConfig[];
|
|
11
11
|
context: LoadContext;
|
|
@@ -9,18 +9,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.loadPlugins = exports.sortConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
-
const init_1 = tslib_1.__importDefault(require("./init"));
|
|
15
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
16
|
-
const constants_1 = require("../../constants");
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
|
+
const init_1 = (0, tslib_1.__importDefault)(require("./init"));
|
|
15
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
17
16
|
const lodash_1 = require("lodash");
|
|
18
17
|
const translations_1 = require("../translations/translations");
|
|
19
|
-
const applyRouteTrailingSlash_1 = tslib_1.__importDefault(require("./applyRouteTrailingSlash"));
|
|
20
|
-
function sortConfig(routeConfigs) {
|
|
18
|
+
const applyRouteTrailingSlash_1 = (0, tslib_1.__importDefault)(require("./applyRouteTrailingSlash"));
|
|
19
|
+
function sortConfig(routeConfigs, baseUrl = '/') {
|
|
21
20
|
// Sort the route config. This ensures that route with nested
|
|
22
21
|
// routes is always placed last.
|
|
23
22
|
routeConfigs.sort((a, b) => {
|
|
23
|
+
// Root route should get placed last.
|
|
24
|
+
if (a.path === baseUrl && b.path !== baseUrl) {
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
if (a.path !== baseUrl && b.path === baseUrl) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
24
30
|
if (a.routes && !b.routes) {
|
|
25
31
|
return 1;
|
|
26
32
|
}
|
|
@@ -46,7 +52,7 @@ function sortConfig(routeConfigs) {
|
|
|
46
52
|
exports.sortConfig = sortConfig;
|
|
47
53
|
async function loadPlugins({ pluginConfigs, context, }) {
|
|
48
54
|
// 1. Plugin Lifecycle - Initialization/Constructor.
|
|
49
|
-
const plugins = init_1.default({
|
|
55
|
+
const plugins = (0, init_1.default)({
|
|
50
56
|
pluginConfigs,
|
|
51
57
|
context,
|
|
52
58
|
});
|
|
@@ -63,7 +69,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
63
69
|
const translationFiles = (_b = (await ((_a = contentLoadedPlugin === null || contentLoadedPlugin === void 0 ? void 0 : contentLoadedPlugin.getTranslationFiles) === null || _a === void 0 ? void 0 : _a.call(contentLoadedPlugin, {
|
|
64
70
|
content: contentLoadedPlugin.content,
|
|
65
71
|
})))) !== null && _b !== void 0 ? _b : [];
|
|
66
|
-
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => translations_1.localizePluginTranslationFile({
|
|
72
|
+
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
67
73
|
locale: context.i18n.currentLocale,
|
|
68
74
|
siteDir: context.siteDir,
|
|
69
75
|
translationFile,
|
|
@@ -74,14 +80,12 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
74
80
|
translationFiles: localizedTranslationFiles,
|
|
75
81
|
};
|
|
76
82
|
}));
|
|
77
|
-
const allContent = lodash_1.chain(loadedPlugins)
|
|
83
|
+
const allContent = (0, lodash_1.chain)(loadedPlugins)
|
|
78
84
|
.groupBy((item) => item.name)
|
|
79
|
-
.mapValues((nameItems) =>
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.value();
|
|
84
|
-
})
|
|
85
|
+
.mapValues((nameItems) => (0, lodash_1.chain)(nameItems)
|
|
86
|
+
.groupBy((item) => { var _a; return (_a = item.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID; })
|
|
87
|
+
.mapValues((idItems) => idItems[0].content)
|
|
88
|
+
.value())
|
|
85
89
|
.value();
|
|
86
90
|
// 3. Plugin Lifecycle - contentLoaded.
|
|
87
91
|
const pluginsRouteConfigs = [];
|
|
@@ -91,13 +95,13 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
91
95
|
if (!plugin.contentLoaded) {
|
|
92
96
|
return;
|
|
93
97
|
}
|
|
94
|
-
const pluginId = (_a = plugin.options.id) !== null && _a !== void 0 ? _a :
|
|
98
|
+
const pluginId = (_a = plugin.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID;
|
|
95
99
|
// plugins data files are namespaced by pluginName/pluginId
|
|
96
100
|
const dataDirRoot = path_1.default.join(context.generatedFilesDir, plugin.name);
|
|
97
101
|
const dataDir = path_1.default.join(dataDirRoot, pluginId);
|
|
98
102
|
const addRoute = (initialRouteConfig) => {
|
|
99
103
|
// Trailing slash behavior is handled in a generic way for all plugins
|
|
100
|
-
const finalRouteConfig = applyRouteTrailingSlash_1.default(initialRouteConfig, {
|
|
104
|
+
const finalRouteConfig = (0, applyRouteTrailingSlash_1.default)(initialRouteConfig, {
|
|
101
105
|
trailingSlash: context.siteConfig.trailingSlash,
|
|
102
106
|
baseUrl: context.siteConfig.baseUrl,
|
|
103
107
|
});
|
|
@@ -106,7 +110,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
106
110
|
const createData = async (name, data) => {
|
|
107
111
|
const modulePath = path_1.default.join(dataDir, name);
|
|
108
112
|
await fs_extra_1.default.ensureDir(path_1.default.dirname(modulePath));
|
|
109
|
-
await utils_1.generate(dataDir, name, data);
|
|
113
|
+
await (0, utils_1.generate)(dataDir, name, data);
|
|
110
114
|
return modulePath;
|
|
111
115
|
};
|
|
112
116
|
// the plugins global data are namespaced to avoid data conflicts:
|
|
@@ -145,7 +149,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
145
149
|
}));
|
|
146
150
|
// Sort the route config. This ensures that route with nested
|
|
147
151
|
// routes are always placed last.
|
|
148
|
-
sortConfig(pluginsRouteConfigs);
|
|
152
|
+
sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);
|
|
149
153
|
// Apply each plugin one after the other to translate the theme config
|
|
150
154
|
function translateThemeConfig(untranslatedThemeConfig) {
|
|
151
155
|
return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const module_1 =
|
|
11
|
-
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
12
|
-
const
|
|
10
|
+
const module_1 = require("module");
|
|
11
|
+
const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
|
|
12
|
+
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");
|
|
@@ -19,7 +19,7 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
19
19
|
if (typeof pluginConfig === 'string') {
|
|
20
20
|
const pluginModuleImport = pluginConfig;
|
|
21
21
|
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
22
|
-
const pluginModule = import_fresh_1.default(pluginPath);
|
|
22
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
23
23
|
return {
|
|
24
24
|
plugin: (_a = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) !== null && _a !== void 0 ? _a : pluginModule,
|
|
25
25
|
options: {},
|
|
@@ -43,7 +43,7 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
43
43
|
if (typeof pluginConfig[0] === 'string') {
|
|
44
44
|
const pluginModuleImport = pluginConfig[0];
|
|
45
45
|
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
46
|
-
const pluginModule = import_fresh_1.default(pluginPath);
|
|
46
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
47
47
|
return {
|
|
48
48
|
plugin: (_b = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) !== null && _b !== void 0 ? _b : pluginModule,
|
|
49
49
|
options: (_c = pluginConfig[1]) !== null && _c !== void 0 ? _c : {},
|
|
@@ -88,16 +88,13 @@ function getThemeValidationFunction(normalizedPluginConfig) {
|
|
|
88
88
|
function initPlugins({ pluginConfigs, context, }) {
|
|
89
89
|
// We need to resolve plugins from the perspective of the siteDir, since the siteDir's package.json
|
|
90
90
|
// declares the dependency on these plugins.
|
|
91
|
-
|
|
92
|
-
// See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
|
|
93
|
-
const createRequire = module_1.default.createRequire || module_1.default.createRequireFromPath;
|
|
94
|
-
const pluginRequire = createRequire(context.siteConfigPath);
|
|
91
|
+
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
95
92
|
function doGetPluginVersion(normalizedPluginConfig) {
|
|
96
93
|
var _a, _b;
|
|
97
94
|
// get plugin version
|
|
98
95
|
if ((_a = normalizedPluginConfig.pluginModule) === null || _a === void 0 ? void 0 : _a.path) {
|
|
99
96
|
const pluginPath = pluginRequire.resolve((_b = normalizedPluginConfig.pluginModule) === null || _b === void 0 ? void 0 : _b.path);
|
|
100
|
-
return versions_1.getPluginVersion(pluginPath, context.siteDir);
|
|
97
|
+
return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
|
|
101
98
|
}
|
|
102
99
|
else {
|
|
103
100
|
return { type: 'local' };
|
|
@@ -129,7 +126,7 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
129
126
|
// as we don't go through the Joi schema that adds it
|
|
130
127
|
return {
|
|
131
128
|
...normalizedPluginConfig.options,
|
|
132
|
-
id: (_a = normalizedPluginConfig.options.id) !== null && _a !== void 0 ? _a :
|
|
129
|
+
id: (_a = normalizedPluginConfig.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID,
|
|
133
130
|
};
|
|
134
131
|
}
|
|
135
132
|
}
|
|
@@ -154,7 +151,7 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
154
151
|
};
|
|
155
152
|
})
|
|
156
153
|
.filter((item) => Boolean(item));
|
|
157
|
-
pluginIds_1.ensureUniquePluginInstanceIds(plugins);
|
|
154
|
+
(0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
|
|
158
155
|
return plugins;
|
|
159
156
|
}
|
|
160
157
|
exports.default = initPlugins;
|
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ensureUniquePluginInstanceIds = void 0;
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
|
-
const
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
// It is forbidden to have 2 plugins of the same name sharing the same id
|
|
13
13
|
// this is required to support multi-instance plugins without conflict
|
|
14
14
|
function ensureUniquePluginInstanceIds(plugins) {
|
|
15
|
-
const pluginsByName = lodash_1.groupBy(plugins, (p) => p.name);
|
|
15
|
+
const pluginsByName = (0, lodash_1.groupBy)(plugins, (p) => p.name);
|
|
16
16
|
Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
|
|
17
|
-
const pluginInstancesById = lodash_1.groupBy(pluginInstances, (p) => { var _a; return (_a = p.options.id) !== null && _a !== void 0 ? _a :
|
|
17
|
+
const pluginInstancesById = (0, lodash_1.groupBy)(pluginInstances, (p) => { var _a; return (_a = p.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID; });
|
|
18
18
|
Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
|
|
19
19
|
if (pluginInstancesWithId.length !== 1) {
|
|
20
|
-
throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with
|
|
20
|
+
throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with ID "${pluginId}".\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.${pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
21
|
+
? `\n\nThe plugin ID is "${utils_1.DEFAULT_PLUGIN_ID}" by default. It's possible that the preset you are using already includes a plugin instance, in which case you either want to disable the plugin in the preset (to use a single instance), or assign another ID to your extra plugin instance (to use multiple instances).`
|
|
22
|
+
: ''}`);
|
|
21
23
|
}
|
|
22
24
|
});
|
|
23
25
|
});
|
|
@@ -7,19 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const module_1 =
|
|
11
|
-
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
10
|
+
const module_1 = require("module");
|
|
11
|
+
const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
|
|
12
|
+
const moduleShorthand_1 = require("../moduleShorthand");
|
|
12
13
|
function loadPresets(context) {
|
|
13
|
-
// We need to resolve
|
|
14
|
-
// declares the dependency on these
|
|
15
|
-
|
|
16
|
-
// See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
|
|
17
|
-
const createRequire = module_1.default.createRequire || module_1.default.createRequireFromPath;
|
|
18
|
-
const pluginRequire = createRequire(context.siteConfigPath);
|
|
14
|
+
// We need to resolve presets from the perspective of the siteDir, since the siteDir's package.json
|
|
15
|
+
// declares the dependency on these presets.
|
|
16
|
+
const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
19
17
|
const presets = (context.siteConfig || {}).presets || [];
|
|
20
18
|
const unflatPlugins = [];
|
|
21
19
|
const unflatThemes = [];
|
|
22
20
|
presets.forEach((presetItem) => {
|
|
21
|
+
var _a;
|
|
23
22
|
let presetModuleImport;
|
|
24
23
|
let presetOptions = {};
|
|
25
24
|
if (typeof presetItem === 'string') {
|
|
@@ -31,8 +30,9 @@ function loadPresets(context) {
|
|
|
31
30
|
else {
|
|
32
31
|
throw new Error('Invalid presets format detected in config.');
|
|
33
32
|
}
|
|
34
|
-
const
|
|
35
|
-
const
|
|
33
|
+
const presetName = (0, moduleShorthand_1.resolveModuleName)(presetModuleImport, presetRequire, 'preset');
|
|
34
|
+
const presetModule = (0, import_fresh_1.default)(presetRequire.resolve(presetName));
|
|
35
|
+
const preset = ((_a = presetModule.default) !== null && _a !== void 0 ? _a : presetModule)(context, presetOptions);
|
|
36
36
|
if (preset.plugins) {
|
|
37
37
|
unflatPlugins.push(preset.plugins);
|
|
38
38
|
}
|
|
@@ -41,8 +41,8 @@ function loadPresets(context) {
|
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
return {
|
|
44
|
-
plugins:
|
|
45
|
-
themes:
|
|
44
|
+
plugins: unflatPlugins.flat().filter(Boolean),
|
|
45
|
+
themes: unflatThemes.flat().filter(Boolean),
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
exports.default = loadPresets;
|