@docusaurus/core 2.0.0-beta.138b4c997 → 2.0.0-beta.14
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 +124 -0
- package/bin/docusaurus.js +42 -109
- package/lib/babel/preset.d.ts +6 -0
- package/lib/babel/preset.js +3 -3
- package/lib/choosePort.js +19 -20
- package/lib/client/.eslintrc.js +0 -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 +11 -11
- 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 +20 -42
- 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 +39 -44
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +17 -18
- 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 +99 -64
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.js +12 -18
- package/lib/commands/start.js +98 -86
- package/lib/commands/swizzle.js +57 -66
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +33 -34
- 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 +14 -7
- 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 -16
- package/lib/server/index.js +132 -59
- 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.d.ts +2 -1
- package/lib/server/plugins/applyRouteTrailingSlash.js +3 -3
- package/lib/server/plugins/index.d.ts +1 -1
- package/lib/server/plugins/index.js +28 -21
- 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 +41 -23
- 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 +19 -26
- package/lib/server/translations/translationsExtractor.d.ts +7 -1
- package/lib/server/translations/translationsExtractor.js +66 -59
- 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 +13 -15
- package/lib/webpack/client.js +9 -18
- 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 +13 -9
- package/lib/webpack/utils.d.ts +0 -22
- package/lib/webpack/utils.js +37 -134
- package/package.json +55 -50
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- 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/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
package/lib/commands/external.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const server_1 = require("../server");
|
|
11
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
11
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
12
12
|
async function externalCommand(cli, siteDir) {
|
|
13
|
-
const context = await server_1.loadContext(siteDir);
|
|
14
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
15
|
-
const plugins = init_1.default({ pluginConfigs, context });
|
|
13
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
14
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
15
|
+
const plugins = (0, init_1.default)({ pluginConfigs, context });
|
|
16
16
|
// Plugin Lifecycle - extendCli.
|
|
17
17
|
plugins.forEach((plugin) => {
|
|
18
18
|
const { extendCli } = plugin;
|
package/lib/commands/serve.js
CHANGED
|
@@ -7,34 +7,33 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const http_1 = tslib_1.__importDefault(require("http"));
|
|
11
|
-
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const http_1 = (0, tslib_1.__importDefault)(require("http"));
|
|
11
|
+
const serve_handler_1 = (0, tslib_1.__importDefault)(require("serve-handler"));
|
|
12
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
15
14
|
const server_1 = require("../server");
|
|
16
|
-
const build_1 = tslib_1.__importDefault(require("./build"));
|
|
15
|
+
const build_1 = (0, tslib_1.__importDefault)(require("./build"));
|
|
17
16
|
const commandUtils_1 = require("./commandUtils");
|
|
18
17
|
async function serve(siteDir, cliOptions) {
|
|
19
18
|
let dir = path_1.default.isAbsolute(cliOptions.dir)
|
|
20
19
|
? cliOptions.dir
|
|
21
20
|
: path_1.default.join(siteDir, cliOptions.dir);
|
|
22
21
|
if (cliOptions.build) {
|
|
23
|
-
dir = await build_1.default(siteDir, {
|
|
22
|
+
dir = await (0, build_1.default)(siteDir, {
|
|
24
23
|
config: cliOptions.config,
|
|
25
24
|
outDir: dir,
|
|
26
25
|
}, false);
|
|
27
26
|
}
|
|
28
|
-
const host = commandUtils_1.getCLIOptionHost(cliOptions.host);
|
|
29
|
-
const port = await commandUtils_1.getCLIOptionPort(cliOptions.port, host);
|
|
27
|
+
const host = (0, commandUtils_1.getCLIOptionHost)(cliOptions.host);
|
|
28
|
+
const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
|
|
30
29
|
if (port === null) {
|
|
31
30
|
process.exit();
|
|
32
31
|
}
|
|
33
|
-
const { siteConfig: { baseUrl, trailingSlash }, } = await server_1.loadSiteConfig({
|
|
32
|
+
const { siteConfig: { baseUrl, trailingSlash }, } = await (0, server_1.loadSiteConfig)({
|
|
34
33
|
siteDir,
|
|
35
34
|
customConfigFilePath: cliOptions.config,
|
|
36
35
|
});
|
|
37
|
-
const servingUrl = `http://${
|
|
36
|
+
const servingUrl = `http://${host}:${port}`;
|
|
38
37
|
const server = http_1.default.createServer((req, res) => {
|
|
39
38
|
var _a, _b;
|
|
40
39
|
// Automatically redirect requests to /baseUrl/
|
|
@@ -48,18 +47,13 @@ async function serve(siteDir, cliOptions) {
|
|
|
48
47
|
// Remove baseUrl before calling serveHandler
|
|
49
48
|
// Reason: /baseUrl/ should serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
|
50
49
|
req.url = (_b = req.url) === null || _b === void 0 ? void 0 : _b.replace(baseUrl, '/');
|
|
51
|
-
serve_handler_1.default(req, res, {
|
|
50
|
+
(0, serve_handler_1.default)(req, res, {
|
|
52
51
|
cleanUrls: true,
|
|
53
52
|
public: dir,
|
|
54
53
|
trailingSlash,
|
|
55
54
|
});
|
|
56
55
|
});
|
|
57
|
-
|
|
58
|
-
borderColor: 'green',
|
|
59
|
-
padding: 1,
|
|
60
|
-
margin: 1,
|
|
61
|
-
align: 'center',
|
|
62
|
-
}));
|
|
56
|
+
logger_1.default.success `Serving path=${cliOptions.dir} directory at path=${servingUrl + baseUrl}.`;
|
|
63
57
|
server.listen(port);
|
|
64
58
|
}
|
|
65
59
|
exports.default = serve;
|
package/lib/commands/start.js
CHANGED
|
@@ -8,33 +8,28 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const utils_1 = require("@docusaurus/utils");
|
|
11
|
-
const
|
|
12
|
-
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
|
+
const chokidar_1 = (0, tslib_1.__importDefault)(require("chokidar"));
|
|
13
|
+
const html_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("html-webpack-plugin"));
|
|
14
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
16
15
|
const lodash_1 = require("lodash");
|
|
17
|
-
const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
|
|
16
|
+
const openBrowser_1 = (0, tslib_1.__importDefault)(require("react-dev-utils/openBrowser"));
|
|
18
17
|
const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
|
|
24
|
-
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
25
|
-
const HotModuleReplacementPlugin_1 = tslib_1.__importDefault(require("webpack/lib/HotModuleReplacementPlugin"));
|
|
18
|
+
const evalSourceMapMiddleware_1 = (0, tslib_1.__importDefault)(require("react-dev-utils/evalSourceMapMiddleware"));
|
|
19
|
+
const webpack_1 = (0, tslib_1.__importDefault)(require("webpack"));
|
|
20
|
+
const webpack_dev_server_1 = (0, tslib_1.__importDefault)(require("webpack-dev-server"));
|
|
21
|
+
const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
|
|
26
22
|
const server_1 = require("../server");
|
|
27
|
-
const
|
|
28
|
-
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
23
|
+
const client_1 = (0, tslib_1.__importDefault)(require("../webpack/client"));
|
|
29
24
|
const utils_2 = require("../webpack/utils");
|
|
30
25
|
const commandUtils_1 = require("./commandUtils");
|
|
31
26
|
const translations_1 = require("../server/translations/translations");
|
|
32
27
|
async function start(siteDir, cliOptions) {
|
|
33
28
|
process.env.NODE_ENV = 'development';
|
|
34
29
|
process.env.BABEL_ENV = 'development';
|
|
35
|
-
|
|
30
|
+
logger_1.default.info('Starting the development server...');
|
|
36
31
|
function loadSite() {
|
|
37
|
-
return server_1.load(siteDir, {
|
|
32
|
+
return (0, server_1.load)(siteDir, {
|
|
38
33
|
customConfigFilePath: cliOptions.config,
|
|
39
34
|
locale: cliOptions.locale,
|
|
40
35
|
localizePath: undefined, // should this be configurable?
|
|
@@ -43,34 +38,34 @@ async function start(siteDir, cliOptions) {
|
|
|
43
38
|
// Process all related files as a prop.
|
|
44
39
|
const props = await loadSite();
|
|
45
40
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
46
|
-
const host = commandUtils_1.getCLIOptionHost(cliOptions.host);
|
|
47
|
-
const port = await commandUtils_1.getCLIOptionPort(cliOptions.port, host);
|
|
41
|
+
const host = (0, commandUtils_1.getCLIOptionHost)(cliOptions.host);
|
|
42
|
+
const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
|
|
48
43
|
if (port === null) {
|
|
49
44
|
process.exit();
|
|
50
45
|
}
|
|
51
46
|
const { baseUrl, headTags, preBodyTags, postBodyTags } = props;
|
|
52
|
-
const urls = WebpackDevServerUtils_1.prepareUrls(protocol, host, port);
|
|
53
|
-
const openUrl = utils_1.normalizeUrl([urls.localUrlForBrowser, baseUrl]);
|
|
54
|
-
|
|
47
|
+
const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
|
|
48
|
+
const openUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
|
|
49
|
+
logger_1.default.success `Docusaurus website is running at path=${openUrl}.`;
|
|
55
50
|
// Reload files processing.
|
|
56
|
-
const reload = lodash_1.debounce(() => {
|
|
51
|
+
const reload = (0, lodash_1.debounce)(() => {
|
|
57
52
|
loadSite()
|
|
58
53
|
.then(({ baseUrl: newBaseUrl }) => {
|
|
59
|
-
const newOpenUrl = utils_1.normalizeUrl([urls.localUrlForBrowser, newBaseUrl]);
|
|
54
|
+
const newOpenUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, newBaseUrl]);
|
|
60
55
|
if (newOpenUrl !== openUrl) {
|
|
61
|
-
|
|
56
|
+
logger_1.default.success `Docusaurus website is running at path=${newOpenUrl}.`;
|
|
62
57
|
}
|
|
63
58
|
})
|
|
64
59
|
.catch((err) => {
|
|
65
|
-
|
|
60
|
+
logger_1.default.error(err.stack);
|
|
66
61
|
});
|
|
67
62
|
}, 500);
|
|
68
63
|
const { siteConfig, plugins = [] } = props;
|
|
69
64
|
const normalizeToSiteDir = (filepath) => {
|
|
70
65
|
if (filepath && path_1.default.isAbsolute(filepath)) {
|
|
71
|
-
return utils_1.posixPath(path_1.default.relative(siteDir, filepath));
|
|
66
|
+
return (0, utils_1.posixPath)(path_1.default.relative(siteDir, filepath));
|
|
72
67
|
}
|
|
73
|
-
return utils_1.posixPath(filepath);
|
|
68
|
+
return (0, utils_1.posixPath)(filepath);
|
|
74
69
|
};
|
|
75
70
|
const pluginPaths = []
|
|
76
71
|
.concat(...plugins
|
|
@@ -80,21 +75,29 @@ async function start(siteDir, cliOptions) {
|
|
|
80
75
|
const pathsToWatch = [
|
|
81
76
|
...pluginPaths,
|
|
82
77
|
props.siteConfigPath,
|
|
83
|
-
translations_1.getTranslationsLocaleDirPath({
|
|
78
|
+
(0, translations_1.getTranslationsLocaleDirPath)({
|
|
84
79
|
siteDir,
|
|
85
80
|
locale: props.i18n.currentLocale,
|
|
86
81
|
}),
|
|
87
82
|
];
|
|
88
|
-
const
|
|
89
|
-
cwd: siteDir,
|
|
90
|
-
ignoreInitial: true,
|
|
83
|
+
const pollingOptions = {
|
|
91
84
|
usePolling: !!cliOptions.poll,
|
|
92
85
|
interval: Number.isInteger(cliOptions.poll)
|
|
93
86
|
? cliOptions.poll
|
|
94
87
|
: undefined,
|
|
88
|
+
};
|
|
89
|
+
const httpsConfig = (0, utils_2.getHttpsConfig)();
|
|
90
|
+
const fsWatcher = chokidar_1.default.watch(pathsToWatch, {
|
|
91
|
+
cwd: siteDir,
|
|
92
|
+
ignoreInitial: true,
|
|
93
|
+
...{ pollingOptions },
|
|
95
94
|
});
|
|
96
95
|
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, reload));
|
|
97
|
-
let config = webpack_merge_1.default(client_1.default(props), {
|
|
96
|
+
let config = (0, webpack_merge_1.default)((0, client_1.default)(props), {
|
|
97
|
+
infrastructureLogging: {
|
|
98
|
+
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
99
|
+
level: 'warn',
|
|
100
|
+
},
|
|
98
101
|
plugins: [
|
|
99
102
|
// Generates an `index.html` file with the <script> injected.
|
|
100
103
|
new html_webpack_plugin_1.default({
|
|
@@ -107,8 +110,6 @@ async function start(siteDir, cliOptions) {
|
|
|
107
110
|
preBodyTags,
|
|
108
111
|
postBodyTags,
|
|
109
112
|
}),
|
|
110
|
-
// This is necessary to emit hot updates for webpack-dev-server.
|
|
111
|
-
new HotModuleReplacementPlugin_1.default(),
|
|
112
113
|
],
|
|
113
114
|
});
|
|
114
115
|
// Plugin Lifecycle - configureWebpack and configurePostCss.
|
|
@@ -116,75 +117,86 @@ async function start(siteDir, cliOptions) {
|
|
|
116
117
|
var _a;
|
|
117
118
|
const { configureWebpack, configurePostCss } = plugin;
|
|
118
119
|
if (configurePostCss) {
|
|
119
|
-
config = utils_2.applyConfigurePostCss(configurePostCss, config);
|
|
120
|
+
config = (0, utils_2.applyConfigurePostCss)(configurePostCss, config);
|
|
120
121
|
}
|
|
121
122
|
if (configureWebpack) {
|
|
122
|
-
config = utils_2.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
123
|
+
config = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
123
124
|
config, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
|
|
124
125
|
}
|
|
125
126
|
});
|
|
126
|
-
|
|
127
|
-
const devServerConfig = {
|
|
128
|
-
...{
|
|
129
|
-
compress: true,
|
|
130
|
-
clientLogLevel: 'error',
|
|
131
|
-
hot: true,
|
|
132
|
-
hotOnly: cliOptions.hotOnly,
|
|
133
|
-
// Use 'ws' instead of 'sockjs-node' on server since we're using native
|
|
134
|
-
// websockets in `webpackHotDevClient`.
|
|
135
|
-
transportMode: 'ws',
|
|
136
|
-
// Prevent a WS client from getting injected as we're already including
|
|
137
|
-
// `webpackHotDevClient`.
|
|
138
|
-
injectClient: false,
|
|
139
|
-
quiet: true,
|
|
140
|
-
https: utils_2.getHttpsConfig(),
|
|
141
|
-
headers: {
|
|
142
|
-
'access-control-allow-origin': '*',
|
|
143
|
-
},
|
|
144
|
-
publicPath: baseUrl,
|
|
145
|
-
watchOptions: {
|
|
146
|
-
ignored: /node_modules/,
|
|
147
|
-
poll: cliOptions.poll,
|
|
148
|
-
},
|
|
149
|
-
historyApiFallback: {
|
|
150
|
-
rewrites: [{ from: /\/*/, to: baseUrl }],
|
|
151
|
-
},
|
|
152
|
-
disableHostCheck: true,
|
|
153
|
-
// Disable overlay on browser since we use CRA's overlay error reporting.
|
|
154
|
-
overlay: false,
|
|
155
|
-
host,
|
|
156
|
-
before: (app, server) => {
|
|
157
|
-
app.use(baseUrl, express_1.default.static(path_1.default.resolve(siteDir, constants_1.STATIC_DIR_NAME)));
|
|
158
|
-
// This lets us fetch source contents from webpack for the error overlay.
|
|
159
|
-
app.use(evalSourceMapMiddleware_1.default(server));
|
|
160
|
-
// This lets us open files from the runtime error overlay.
|
|
161
|
-
app.use(errorOverlayMiddleware_1.default());
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
const compiler = webpack_1.default(config);
|
|
127
|
+
const compiler = (0, webpack_1.default)(config);
|
|
166
128
|
if (process.env.E2E_TEST) {
|
|
167
129
|
compiler.hooks.done.tap('done', (stats) => {
|
|
168
130
|
if (stats.hasErrors()) {
|
|
169
|
-
|
|
131
|
+
logger_1.default.error('E2E_TEST: Project has compiler errors.');
|
|
170
132
|
process.exit(1);
|
|
171
133
|
}
|
|
172
|
-
|
|
134
|
+
logger_1.default.success('E2E_TEST: Project can compile.');
|
|
173
135
|
process.exit(0);
|
|
174
136
|
});
|
|
175
137
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
138
|
+
// https://webpack.js.org/configuration/dev-server
|
|
139
|
+
const defaultDevServerConfig = {
|
|
140
|
+
hot: cliOptions.hotOnly ? 'only' : true,
|
|
141
|
+
liveReload: false,
|
|
142
|
+
client: {
|
|
143
|
+
progress: true,
|
|
144
|
+
overlay: {
|
|
145
|
+
warnings: false,
|
|
146
|
+
errors: true,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
headers: {
|
|
150
|
+
'access-control-allow-origin': '*',
|
|
151
|
+
},
|
|
152
|
+
devMiddleware: {
|
|
153
|
+
publicPath: baseUrl,
|
|
154
|
+
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
155
|
+
stats: 'summary',
|
|
156
|
+
},
|
|
157
|
+
static: siteConfig.staticDirectories.map((dir) => ({
|
|
158
|
+
publicPath: baseUrl,
|
|
159
|
+
directory: path_1.default.resolve(siteDir, dir),
|
|
160
|
+
watch: {
|
|
161
|
+
// Useful options for our own monorepo using symlinks!
|
|
162
|
+
// See https://github.com/webpack/webpack/issues/11612#issuecomment-879259806
|
|
163
|
+
followSymlinks: true,
|
|
164
|
+
ignored: /node_modules\/(?!@docusaurus)/,
|
|
165
|
+
...{ pollingOptions },
|
|
166
|
+
},
|
|
167
|
+
})),
|
|
168
|
+
...(httpsConfig && {
|
|
169
|
+
server: typeof httpsConfig === 'object'
|
|
170
|
+
? {
|
|
171
|
+
type: 'https',
|
|
172
|
+
options: httpsConfig,
|
|
173
|
+
}
|
|
174
|
+
: 'https',
|
|
175
|
+
}),
|
|
176
|
+
historyApiFallback: {
|
|
177
|
+
rewrites: [{ from: /\/*/, to: baseUrl }],
|
|
178
|
+
},
|
|
179
|
+
allowedHosts: 'all',
|
|
180
|
+
host,
|
|
181
|
+
port,
|
|
182
|
+
onBeforeSetupMiddleware: (devServer) => {
|
|
183
|
+
// This lets us fetch source contents from webpack for the error overlay.
|
|
184
|
+
devServer.app.use((0, evalSourceMapMiddleware_1.default)(
|
|
185
|
+
// @ts-expect-error: bad types
|
|
186
|
+
devServer));
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
// Allow plugin authors to customize/override devServer config
|
|
190
|
+
const devServerConfig = (0, webpack_merge_1.default)([defaultDevServerConfig, config.devServer].filter(Boolean));
|
|
191
|
+
const devServer = new webpack_dev_server_1.default(devServerConfig, compiler);
|
|
192
|
+
devServer.startCallback(() => {
|
|
181
193
|
if (cliOptions.open) {
|
|
182
|
-
openBrowser_1.default(openUrl);
|
|
194
|
+
(0, openBrowser_1.default)(openUrl);
|
|
183
195
|
}
|
|
184
196
|
});
|
|
185
197
|
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
|
186
198
|
process.on(sig, () => {
|
|
187
|
-
devServer.
|
|
199
|
+
devServer.stop();
|
|
188
200
|
process.exit();
|
|
189
201
|
});
|
|
190
202
|
});
|
package/lib/commands/swizzle.js
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getPluginNames = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
14
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
|
-
const leven_1 = tslib_1.__importDefault(require("leven"));
|
|
11
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
|
|
14
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
15
|
+
const leven_1 = (0, tslib_1.__importDefault)(require("leven"));
|
|
16
16
|
const lodash_1 = require("lodash");
|
|
17
|
-
const
|
|
17
|
+
const utils_1 = require("@docusaurus/utils");
|
|
18
18
|
const server_1 = require("../server");
|
|
19
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
19
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
20
20
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
21
21
|
function getPluginNames(plugins) {
|
|
22
22
|
return plugins
|
|
@@ -37,32 +37,32 @@ function getPluginNames(plugins) {
|
|
|
37
37
|
if (packagePath === '.') {
|
|
38
38
|
return pluginPath;
|
|
39
39
|
}
|
|
40
|
-
return import_fresh_1.default(path_1.default.join(packagePath, 'package.json')).name;
|
|
40
|
+
return (0, import_fresh_1.default)(path_1.default.join(packagePath, 'package.json')).name;
|
|
41
41
|
}
|
|
42
42
|
return '';
|
|
43
43
|
})
|
|
44
44
|
.filter((plugin) => plugin !== '');
|
|
45
45
|
}
|
|
46
46
|
exports.getPluginNames = getPluginNames;
|
|
47
|
-
function walk(dir) {
|
|
48
|
-
let results = [];
|
|
49
|
-
const list = fs_extra_1.default.readdirSync(dir);
|
|
50
|
-
list.forEach((file) => {
|
|
51
|
-
const fullPath = path_1.default.join(dir, file);
|
|
52
|
-
const stat = fs_extra_1.default.statSync(fullPath);
|
|
53
|
-
if (stat && stat.isDirectory()) {
|
|
54
|
-
results = results.concat(walk(fullPath));
|
|
55
|
-
}
|
|
56
|
-
else if (!/node_modules|.css|.d.ts|.d.map/.test(fullPath)) {
|
|
57
|
-
results.push(fullPath);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return results;
|
|
61
|
-
}
|
|
62
47
|
const formatComponentName = (componentName) => componentName
|
|
63
|
-
.replace(/(\/|\\)index
|
|
64
|
-
.replace(
|
|
48
|
+
.replace(/(\/|\\)index\.(js|tsx|ts|jsx)/, '')
|
|
49
|
+
.replace(/\.(js|tsx|ts|jsx)/, '');
|
|
65
50
|
function readComponent(themePath) {
|
|
51
|
+
function walk(dir) {
|
|
52
|
+
let results = [];
|
|
53
|
+
const list = fs_extra_1.default.readdirSync(dir);
|
|
54
|
+
list.forEach((file) => {
|
|
55
|
+
const fullPath = path_1.default.join(dir, file);
|
|
56
|
+
const stat = fs_extra_1.default.statSync(fullPath);
|
|
57
|
+
if (stat && stat.isDirectory()) {
|
|
58
|
+
results = results.concat(walk(fullPath));
|
|
59
|
+
}
|
|
60
|
+
else if (!/\.css|\.d\.ts|\.d\.map/.test(fullPath)) {
|
|
61
|
+
results.push(fullPath);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
66
|
return walk(themePath).map((filePath) => formatComponentName(path_1.default.relative(themePath, filePath)));
|
|
67
67
|
}
|
|
68
68
|
// load components from theme based on configurations
|
|
@@ -82,20 +82,16 @@ function getComponentName(themePath, plugin, danger) {
|
|
|
82
82
|
function themeComponents(themePath, plugin) {
|
|
83
83
|
const components = colorCode(themePath, plugin);
|
|
84
84
|
if (components.length === 0) {
|
|
85
|
-
return
|
|
85
|
+
return 'No component to swizzle.';
|
|
86
86
|
}
|
|
87
|
-
return `
|
|
88
|
-
${chalk.cyan('Theme components available for swizzle.')}
|
|
87
|
+
return `Theme components available for swizzle.
|
|
89
88
|
|
|
90
|
-
${
|
|
91
|
-
${
|
|
89
|
+
${logger_1.default.green(logger_1.default.bold('green =>'))} safe: lower breaking change risk
|
|
90
|
+
${logger_1.default.red(logger_1.default.bold('red =>'))} unsafe: higher breaking change risk
|
|
92
91
|
|
|
93
92
|
${components.join('\n')}
|
|
94
93
|
`;
|
|
95
94
|
}
|
|
96
|
-
function formattedThemeNames(themeNames) {
|
|
97
|
-
return `Themes available for swizzle:\n- ${themeNames.join('\n- ')}`;
|
|
98
|
-
}
|
|
99
95
|
function colorCode(themePath, plugin) {
|
|
100
96
|
var _a, _b;
|
|
101
97
|
// support both commonjs and ES style exports
|
|
@@ -104,18 +100,18 @@ function colorCode(themePath, plugin) {
|
|
|
104
100
|
const allowedComponent = getSwizzleComponentList
|
|
105
101
|
? getSwizzleComponentList()
|
|
106
102
|
: [];
|
|
107
|
-
const [greenComponents, redComponents] = lodash_1.partition(components, (comp) => allowedComponent.includes(comp));
|
|
103
|
+
const [greenComponents, redComponents] = (0, lodash_1.partition)(components, (comp) => allowedComponent.includes(comp));
|
|
108
104
|
return [
|
|
109
|
-
...greenComponents.map((component) =>
|
|
110
|
-
...redComponents.map((component) =>
|
|
105
|
+
...greenComponents.map((component) => `${logger_1.default.green(logger_1.default.bold('safe:'))} ${component}`),
|
|
106
|
+
...redComponents.map((component) => `${logger_1.default.red(logger_1.default.bold('unsafe:'))} ${component}`),
|
|
111
107
|
];
|
|
112
108
|
}
|
|
113
109
|
async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
114
110
|
var _a, _b, _c, _d, _e;
|
|
115
|
-
const context = await server_1.loadContext(siteDir);
|
|
116
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
111
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
112
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
117
113
|
const pluginNames = getPluginNames(pluginConfigs);
|
|
118
|
-
const plugins = init_1.default({
|
|
114
|
+
const plugins = (0, init_1.default)({
|
|
119
115
|
pluginConfigs,
|
|
120
116
|
context,
|
|
121
117
|
});
|
|
@@ -123,23 +119,23 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
123
119
|
? plugins[index].getTypeScriptThemePath
|
|
124
120
|
: plugins[index].getThemePath);
|
|
125
121
|
if (!themeName) {
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
logger_1.default.info `Themes available for swizzle: name=${themeNames}`;
|
|
123
|
+
return;
|
|
128
124
|
}
|
|
129
125
|
let pluginModule;
|
|
130
126
|
try {
|
|
131
|
-
pluginModule = import_fresh_1.default(themeName);
|
|
127
|
+
pluginModule = (0, import_fresh_1.default)(themeName);
|
|
132
128
|
}
|
|
133
129
|
catch {
|
|
134
130
|
let suggestion;
|
|
135
131
|
themeNames.forEach((name) => {
|
|
136
|
-
if (leven_1.default(name, themeName) < 4) {
|
|
132
|
+
if ((0, leven_1.default)(name, themeName) < 4) {
|
|
137
133
|
suggestion = name;
|
|
138
134
|
}
|
|
139
135
|
});
|
|
140
|
-
|
|
141
|
-
? `Did you mean
|
|
142
|
-
:
|
|
136
|
+
logger_1.default.error `Theme name=${themeName} not found. ${suggestion
|
|
137
|
+
? logger_1.default.interpolate `Did you mean name=${suggestion}?`
|
|
138
|
+
: logger_1.default.interpolate `Themes available for swizzle: ${themeNames}`}`;
|
|
143
139
|
process.exit(1);
|
|
144
140
|
}
|
|
145
141
|
let pluginOptions = {};
|
|
@@ -171,14 +167,14 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
171
167
|
? (_d = pluginInstance.getTypeScriptThemePath) === null || _d === void 0 ? void 0 : _d.call(pluginInstance)
|
|
172
168
|
: (_e = pluginInstance.getThemePath) === null || _e === void 0 ? void 0 : _e.call(pluginInstance);
|
|
173
169
|
if (!themePath) {
|
|
174
|
-
|
|
175
|
-
?
|
|
176
|
-
:
|
|
170
|
+
logger_1.default.warn(typescript
|
|
171
|
+
? logger_1.default.interpolate `name=${themeName} does not provide TypeScript theme code via ${'getTypeScriptThemePath()'}.`
|
|
172
|
+
: logger_1.default.interpolate `name=${themeName} does not provide any theme code.`);
|
|
177
173
|
process.exit(1);
|
|
178
174
|
}
|
|
179
175
|
if (!componentName) {
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
logger_1.default.info(themeComponents(themePath, pluginModule));
|
|
177
|
+
return;
|
|
182
178
|
}
|
|
183
179
|
const components = getComponentName(themePath, pluginModule, Boolean(danger));
|
|
184
180
|
const formattedComponentName = formatComponentName(componentName);
|
|
@@ -190,7 +186,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
190
186
|
components.forEach((component) => {
|
|
191
187
|
if (component.toLowerCase() === formattedComponentName.toLowerCase()) {
|
|
192
188
|
// may be components with same lowercase key, try to match closest component
|
|
193
|
-
const currentScore = leven_1.default(formattedComponentName, component);
|
|
189
|
+
const currentScore = (0, leven_1.default)(formattedComponentName, component);
|
|
194
190
|
if (currentScore < score) {
|
|
195
191
|
score = currentScore;
|
|
196
192
|
mostSuitableMatch = component;
|
|
@@ -199,11 +195,12 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
199
195
|
});
|
|
200
196
|
if (mostSuitableMatch !== componentName) {
|
|
201
197
|
mostSuitableComponent = mostSuitableMatch;
|
|
202
|
-
|
|
198
|
+
logger_1.default.error `Component name=${componentName} doesn't exist.`;
|
|
199
|
+
logger_1.default.info `name=${mostSuitableComponent} is swizzled instead of name=${componentName}.`;
|
|
203
200
|
}
|
|
204
201
|
}
|
|
205
202
|
let fromPath = path_1.default.join(themePath, mostSuitableComponent);
|
|
206
|
-
let toPath = path_1.default.resolve(siteDir,
|
|
203
|
+
let toPath = path_1.default.resolve(siteDir, utils_1.THEME_PATH, mostSuitableComponent);
|
|
207
204
|
// Handle single TypeScript/JavaScript file only.
|
|
208
205
|
// E.g: if <fromPath> does not exist, we try to swizzle <fromPath>.(ts|tsx|js) instead
|
|
209
206
|
if (!fs_extra_1.default.existsSync(fromPath)) {
|
|
@@ -219,27 +216,21 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
219
216
|
else {
|
|
220
217
|
let suggestion;
|
|
221
218
|
components.forEach((name) => {
|
|
222
|
-
if (leven_1.default(name, mostSuitableComponent) < 3) {
|
|
219
|
+
if ((0, leven_1.default)(name, mostSuitableComponent) < 3) {
|
|
223
220
|
suggestion = name;
|
|
224
221
|
}
|
|
225
222
|
});
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
: `${themeComponents(themePath, pluginModule)}`);
|
|
223
|
+
logger_1.default.error `Component name=${mostSuitableComponent} not found. ${suggestion
|
|
224
|
+
? logger_1.default.interpolate `Did you mean name=${suggestion} ?`
|
|
225
|
+
: themeComponents(themePath, pluginModule)}`;
|
|
230
226
|
process.exit(1);
|
|
231
227
|
}
|
|
232
228
|
}
|
|
233
229
|
if (!components.includes(mostSuitableComponent) && !danger) {
|
|
234
|
-
|
|
230
|
+
logger_1.default.error `name=${mostSuitableComponent} is an internal component and has a higher breaking change probability. If you want to swizzle it, use the code=${'--danger'} flag.`;
|
|
235
231
|
process.exit(1);
|
|
236
232
|
}
|
|
237
233
|
await fs_extra_1.default.copy(fromPath, toPath);
|
|
238
|
-
|
|
239
|
-
const fromMsg = chalk.blue(mostSuitableComponent
|
|
240
|
-
? `${themeName} ${chalk.yellow(mostSuitableComponent)}`
|
|
241
|
-
: themeName);
|
|
242
|
-
const toMsg = chalk.cyan(relativeDir);
|
|
243
|
-
console.log(`\n${chalk.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`);
|
|
234
|
+
logger_1.default.success `Copied code=${mostSuitableComponent ? `${themeName} ${mostSuitableComponent}` : themeName} to path=${path_1.default.relative(process.cwd(), toPath)}.`;
|
|
244
235
|
}
|
|
245
236
|
exports.default = swizzle;
|
|
@@ -4,9 +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
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
7
|
+
import { Slugger } from '@docusaurus/utils';
|
|
8
|
+
declare type Options = {
|
|
9
|
+
maintainCase?: boolean;
|
|
10
|
+
overwrite?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function transformMarkdownHeadingLine(line: string, slugger: Slugger, options?: Options): string;
|
|
13
|
+
export declare function transformMarkdownContent(content: string, options?: Options): string;
|
|
14
|
+
export default function writeHeadingIds(siteDir: string, files?: string, options?: Options): Promise<void>;
|
|
15
|
+
export {};
|