@docusaurus/core 2.0.0-beta.8bda3b2db → 2.0.0-beta.9
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 +125 -0
- package/bin/docusaurus.js +36 -105
- package/lib/.tsbuildinfo +1 -1
- package/lib/babel/preset.js +1 -1
- package/lib/choosePort.js +10 -11
- package/lib/client/.tsbuildinfo +1 -1
- package/lib/client/App.js +8 -22
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +1 -1
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +1 -0
- package/lib/client/docusaurus.js +0 -1
- package/lib/client/exports/BrowserOnly.js +5 -3
- package/lib/client/exports/Interpolate.js +4 -0
- 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 +1 -1
- 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/client/exports/useIsBrowser.js +11 -0
- package/lib/client/normalizeLocation.d.ts +1 -3
- package/lib/client/prefetch.js +0 -1
- package/lib/client/serverEntry.js +11 -27
- package/lib/commands/build.js +26 -23
- package/lib/commands/clear.js +2 -2
- package/lib/commands/commandUtils.js +2 -2
- package/lib/commands/deploy.js +24 -14
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.js +13 -13
- package/lib/commands/start.js +74 -72
- package/lib/commands/swizzle.js +33 -33
- package/lib/commands/writeHeadingIds.d.ts +8 -5
- package/lib/commands/writeHeadingIds.js +32 -31
- package/lib/commands/writeTranslations.js +25 -11
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +4 -1
- package/lib/server/brokenLinks.js +13 -13
- package/lib/server/config.js +4 -4
- package/lib/server/configValidation.js +4 -3
- package/lib/server/duplicateRoutes.js +2 -2
- package/lib/server/html-tags/htmlTags.js +5 -5
- package/lib/server/html-tags/index.d.ts +2 -2
- package/lib/server/html-tags/index.js +3 -3
- package/lib/server/i18n.js +4 -4
- package/lib/server/index.js +99 -62
- package/lib/server/loadSetup.js +3 -3
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -1
- package/lib/server/plugins/applyRouteTrailingSlash.js +3 -3
- package/lib/server/plugins/index.d.ts +3 -4
- package/lib/server/plugins/index.js +41 -27
- package/lib/server/plugins/init.d.ts +2 -6
- package/lib/server/plugins/init.js +7 -10
- package/lib/server/plugins/pluginIds.d.ts +2 -2
- package/lib/server/plugins/pluginIds.js +2 -2
- package/lib/server/presets/index.js +4 -7
- package/lib/server/routes.js +41 -23
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +24 -12
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +19 -9
- package/lib/server/translations/translations.d.ts +4 -5
- package/lib/server/translations/translations.js +9 -9
- package/lib/server/translations/translationsExtractor.d.ts +2 -3
- package/lib/server/translations/translationsExtractor.js +58 -47
- 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 +28 -19
- package/lib/webpack/client.js +8 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -5
- package/lib/webpack/plugins/LogPlugin.js +3 -4
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.d.ts +2 -0
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.d.ts +5 -0
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +1 -1
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.d.ts +1 -0
- package/lib/webpack/server.js +11 -7
- package/lib/webpack/sharedModuleAliases.js +1 -1
- package/lib/webpack/utils.d.ts +2 -1
- package/lib/webpack/utils.js +28 -25
- package/package.json +45 -39
- package/tsconfig.client.json +1 -2
- package/tsconfig.json +5 -4
package/lib/commands/start.js
CHANGED
|
@@ -9,23 +9,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const utils_1 = require("@docusaurus/utils");
|
|
11
11
|
const chalk = require("chalk");
|
|
12
|
-
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
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
23
|
const constants_1 = require("../constants");
|
|
28
|
-
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
24
|
+
const client_1 = (0, tslib_1.__importDefault)(require("../webpack/client"));
|
|
29
25
|
const utils_2 = require("../webpack/utils");
|
|
30
26
|
const commandUtils_1 = require("./commandUtils");
|
|
31
27
|
const translations_1 = require("../server/translations/translations");
|
|
@@ -34,7 +30,7 @@ async function start(siteDir, cliOptions) {
|
|
|
34
30
|
process.env.BABEL_ENV = 'development';
|
|
35
31
|
console.log(chalk.blue('Starting the development server...'));
|
|
36
32
|
function loadSite() {
|
|
37
|
-
return server_1.load(siteDir, {
|
|
33
|
+
return (0, server_1.load)(siteDir, {
|
|
38
34
|
customConfigFilePath: cliOptions.config,
|
|
39
35
|
locale: cliOptions.locale,
|
|
40
36
|
localizePath: undefined, // should this be configurable?
|
|
@@ -43,20 +39,20 @@ async function start(siteDir, cliOptions) {
|
|
|
43
39
|
// Process all related files as a prop.
|
|
44
40
|
const props = await loadSite();
|
|
45
41
|
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);
|
|
42
|
+
const host = (0, commandUtils_1.getCLIOptionHost)(cliOptions.host);
|
|
43
|
+
const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
|
|
48
44
|
if (port === null) {
|
|
49
45
|
process.exit();
|
|
50
46
|
}
|
|
51
47
|
const { baseUrl, headTags, preBodyTags, postBodyTags } = props;
|
|
52
|
-
const urls = WebpackDevServerUtils_1.prepareUrls(protocol, host, port);
|
|
53
|
-
const openUrl = utils_1.normalizeUrl([urls.localUrlForBrowser, baseUrl]);
|
|
48
|
+
const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
|
|
49
|
+
const openUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
|
|
54
50
|
console.log(chalk.cyanBright(`Docusaurus website is running at "${openUrl}".`));
|
|
55
51
|
// Reload files processing.
|
|
56
|
-
const reload = lodash_1.debounce(() => {
|
|
52
|
+
const reload = (0, lodash_1.debounce)(() => {
|
|
57
53
|
loadSite()
|
|
58
54
|
.then(({ baseUrl: newBaseUrl }) => {
|
|
59
|
-
const newOpenUrl = utils_1.normalizeUrl([urls.localUrlForBrowser, newBaseUrl]);
|
|
55
|
+
const newOpenUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, newBaseUrl]);
|
|
60
56
|
if (newOpenUrl !== openUrl) {
|
|
61
57
|
console.log(chalk.cyanBright(`Docusaurus website is running at "${newOpenUrl}".`));
|
|
62
58
|
}
|
|
@@ -68,9 +64,9 @@ async function start(siteDir, cliOptions) {
|
|
|
68
64
|
const { siteConfig, plugins = [] } = props;
|
|
69
65
|
const normalizeToSiteDir = (filepath) => {
|
|
70
66
|
if (filepath && path_1.default.isAbsolute(filepath)) {
|
|
71
|
-
return utils_1.posixPath(path_1.default.relative(siteDir, filepath));
|
|
67
|
+
return (0, utils_1.posixPath)(path_1.default.relative(siteDir, filepath));
|
|
72
68
|
}
|
|
73
|
-
return utils_1.posixPath(filepath);
|
|
69
|
+
return (0, utils_1.posixPath)(filepath);
|
|
74
70
|
};
|
|
75
71
|
const pluginPaths = []
|
|
76
72
|
.concat(...plugins
|
|
@@ -80,21 +76,28 @@ async function start(siteDir, cliOptions) {
|
|
|
80
76
|
const pathsToWatch = [
|
|
81
77
|
...pluginPaths,
|
|
82
78
|
props.siteConfigPath,
|
|
83
|
-
translations_1.getTranslationsLocaleDirPath({
|
|
79
|
+
(0, translations_1.getTranslationsLocaleDirPath)({
|
|
84
80
|
siteDir,
|
|
85
81
|
locale: props.i18n.currentLocale,
|
|
86
82
|
}),
|
|
87
83
|
];
|
|
88
|
-
const
|
|
89
|
-
cwd: siteDir,
|
|
90
|
-
ignoreInitial: true,
|
|
84
|
+
const pollingOptions = {
|
|
91
85
|
usePolling: !!cliOptions.poll,
|
|
92
86
|
interval: Number.isInteger(cliOptions.poll)
|
|
93
87
|
? cliOptions.poll
|
|
94
88
|
: undefined,
|
|
89
|
+
};
|
|
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,53 +117,57 @@ 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`.
|
|
123
|
-
config, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader);
|
|
123
|
+
config = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
124
|
+
config, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
|
|
124
125
|
}
|
|
125
126
|
});
|
|
126
127
|
// https://webpack.js.org/configuration/dev-server
|
|
127
128
|
const devServerConfig = {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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': '*',
|
|
129
|
+
hot: cliOptions.hotOnly ? 'only' : true,
|
|
130
|
+
liveReload: false,
|
|
131
|
+
client: {
|
|
132
|
+
progress: true,
|
|
133
|
+
overlay: {
|
|
134
|
+
warnings: false,
|
|
135
|
+
errors: true,
|
|
143
136
|
},
|
|
137
|
+
},
|
|
138
|
+
https: (0, utils_2.getHttpsConfig)(),
|
|
139
|
+
headers: {
|
|
140
|
+
'access-control-allow-origin': '*',
|
|
141
|
+
},
|
|
142
|
+
devMiddleware: {
|
|
144
143
|
publicPath: baseUrl,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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());
|
|
144
|
+
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
145
|
+
stats: 'summary',
|
|
146
|
+
},
|
|
147
|
+
static: {
|
|
148
|
+
directory: path_1.default.resolve(siteDir, constants_1.STATIC_DIR_NAME),
|
|
149
|
+
watch: {
|
|
150
|
+
// Useful options for our own monorepo using symlinks!
|
|
151
|
+
// See https://github.com/webpack/webpack/issues/11612#issuecomment-879259806
|
|
152
|
+
followSymlinks: true,
|
|
153
|
+
ignored: /node_modules\/(?!@docusaurus)/,
|
|
154
|
+
...{ pollingOptions },
|
|
162
155
|
},
|
|
163
156
|
},
|
|
157
|
+
historyApiFallback: {
|
|
158
|
+
rewrites: [{ from: /\/*/, to: baseUrl }],
|
|
159
|
+
},
|
|
160
|
+
allowedHosts: 'all',
|
|
161
|
+
host,
|
|
162
|
+
port,
|
|
163
|
+
onBeforeSetupMiddleware: (devServer) => {
|
|
164
|
+
// This lets us fetch source contents from webpack for the error overlay.
|
|
165
|
+
devServer.app.use((0, evalSourceMapMiddleware_1.default)(
|
|
166
|
+
// @ts-expect-error: bad types
|
|
167
|
+
devServer));
|
|
168
|
+
},
|
|
164
169
|
};
|
|
165
|
-
const compiler = webpack_1.default(config);
|
|
170
|
+
const compiler = (0, webpack_1.default)(config);
|
|
166
171
|
if (process.env.E2E_TEST) {
|
|
167
172
|
compiler.hooks.done.tap('done', (stats) => {
|
|
168
173
|
if (stats.hasErrors()) {
|
|
@@ -173,18 +178,15 @@ async function start(siteDir, cliOptions) {
|
|
|
173
178
|
process.exit(0);
|
|
174
179
|
});
|
|
175
180
|
}
|
|
176
|
-
const devServer = new webpack_dev_server_1.default(
|
|
177
|
-
devServer.
|
|
178
|
-
if (err) {
|
|
179
|
-
console.log(err);
|
|
180
|
-
}
|
|
181
|
+
const devServer = new webpack_dev_server_1.default(devServerConfig, compiler);
|
|
182
|
+
devServer.startCallback(() => {
|
|
181
183
|
if (cliOptions.open) {
|
|
182
|
-
openBrowser_1.default(openUrl);
|
|
184
|
+
(0, openBrowser_1.default)(openUrl);
|
|
183
185
|
}
|
|
184
186
|
});
|
|
185
187
|
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
|
186
188
|
process.on(sig, () => {
|
|
187
|
-
devServer.
|
|
189
|
+
devServer.stop();
|
|
188
190
|
process.exit();
|
|
189
191
|
});
|
|
190
192
|
});
|
package/lib/commands/swizzle.js
CHANGED
|
@@ -9,14 +9,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.getPluginNames = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const chalk = require("chalk");
|
|
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"));
|
|
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
17
|
const constants_1 = require("../constants");
|
|
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
|
|
@@ -104,7 +104,7 @@ function colorCode(themePath, plugin) {
|
|
|
104
104
|
const allowedComponent = getSwizzleComponentList
|
|
105
105
|
? getSwizzleComponentList()
|
|
106
106
|
: [];
|
|
107
|
-
const [greenComponents, redComponents] = lodash_1.partition(components, (comp) => allowedComponent.includes(comp));
|
|
107
|
+
const [greenComponents, redComponents] = (0, lodash_1.partition)(components, (comp) => allowedComponent.includes(comp));
|
|
108
108
|
return [
|
|
109
109
|
...greenComponents.map((component) => chalk.green(`safe: ${component}`)),
|
|
110
110
|
...redComponents.map((component) => chalk.red(`unsafe: ${component}`)),
|
|
@@ -112,10 +112,10 @@ function colorCode(themePath, plugin) {
|
|
|
112
112
|
}
|
|
113
113
|
async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
114
114
|
var _a, _b, _c, _d, _e;
|
|
115
|
-
const context = await server_1.loadContext(siteDir);
|
|
116
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
115
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
116
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
117
117
|
const pluginNames = getPluginNames(pluginConfigs);
|
|
118
|
-
const plugins = init_1.default({
|
|
118
|
+
const plugins = (0, init_1.default)({
|
|
119
119
|
pluginConfigs,
|
|
120
120
|
context,
|
|
121
121
|
});
|
|
@@ -128,12 +128,12 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
128
128
|
}
|
|
129
129
|
let pluginModule;
|
|
130
130
|
try {
|
|
131
|
-
pluginModule = import_fresh_1.default(themeName);
|
|
131
|
+
pluginModule = (0, import_fresh_1.default)(themeName);
|
|
132
132
|
}
|
|
133
133
|
catch {
|
|
134
134
|
let suggestion;
|
|
135
135
|
themeNames.forEach((name) => {
|
|
136
|
-
if (leven_1.default(name, themeName) < 4) {
|
|
136
|
+
if ((0, leven_1.default)(name, themeName) < 4) {
|
|
137
137
|
suggestion = name;
|
|
138
138
|
}
|
|
139
139
|
});
|
|
@@ -190,7 +190,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
190
190
|
components.forEach((component) => {
|
|
191
191
|
if (component.toLowerCase() === formattedComponentName.toLowerCase()) {
|
|
192
192
|
// may be components with same lowercase key, try to match closest component
|
|
193
|
-
const currentScore = leven_1.default(formattedComponentName, component);
|
|
193
|
+
const currentScore = (0, leven_1.default)(formattedComponentName, component);
|
|
194
194
|
if (currentScore < score) {
|
|
195
195
|
score = currentScore;
|
|
196
196
|
mostSuitableMatch = component;
|
|
@@ -199,7 +199,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
199
199
|
});
|
|
200
200
|
if (mostSuitableMatch !== componentName) {
|
|
201
201
|
mostSuitableComponent = mostSuitableMatch;
|
|
202
|
-
console.log(chalk.red(`Component "${componentName}" doesn't
|
|
202
|
+
console.log(chalk.red(`Component "${componentName}" doesn't exist.`), chalk.yellow(`"${mostSuitableComponent}" is swizzled instead of "${componentName}".`));
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
let fromPath = path_1.default.join(themePath, mostSuitableComponent);
|
|
@@ -219,7 +219,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
219
219
|
else {
|
|
220
220
|
let suggestion;
|
|
221
221
|
components.forEach((name) => {
|
|
222
|
-
if (leven_1.default(name, mostSuitableComponent) < 3) {
|
|
222
|
+
if ((0, leven_1.default)(name, mostSuitableComponent) < 3) {
|
|
223
223
|
suggestion = name;
|
|
224
224
|
}
|
|
225
225
|
});
|
|
@@ -231,7 +231,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
if (!components.includes(mostSuitableComponent) && !danger) {
|
|
234
|
-
console.warn(chalk.red(`${mostSuitableComponent} is an internal component
|
|
234
|
+
console.warn(chalk.red(`${mostSuitableComponent} is an internal component and has a higher breaking change probability. If you want to swizzle it, use the "--danger" flag.`));
|
|
235
235
|
process.exit(1);
|
|
236
236
|
}
|
|
237
237
|
await fs_extra_1.default.copy(fromPath, toPath);
|
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import GithubSlugger from 'github-slugger';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
8
|
+
declare type Options = {
|
|
9
|
+
maintainCase?: boolean;
|
|
10
|
+
overwrite?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function transformMarkdownHeadingLine(line: string, slugger: GithubSlugger, 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 {};
|
|
@@ -6,53 +6,54 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.transformMarkdownContent = exports.
|
|
9
|
+
exports.transformMarkdownContent = exports.transformMarkdownHeadingLine = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
-
const github_slugger_1 = tslib_1.__importDefault(require("github-slugger"));
|
|
13
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
11
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
|
+
const github_slugger_1 = (0, tslib_1.__importDefault)(require("github-slugger"));
|
|
13
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
14
14
|
const server_1 = require("../server");
|
|
15
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
16
|
-
const lodash_1 = require("lodash");
|
|
15
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
17
16
|
const utils_1 = require("@docusaurus/utils");
|
|
18
17
|
const utils_2 = require("../server/utils");
|
|
19
18
|
function unwrapMarkdownLinks(line) {
|
|
20
19
|
return line.replace(/\[([^\]]+)\]\([^)]+\)/g, (match, p1) => p1);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
function addHeadingId(line, slugger) {
|
|
21
|
+
function addHeadingId(line, slugger, maintainCase) {
|
|
24
22
|
let headingLevel = 0;
|
|
25
23
|
while (line.charAt(headingLevel) === '#') {
|
|
26
24
|
headingLevel += 1;
|
|
27
25
|
}
|
|
28
26
|
const headingText = line.slice(headingLevel).trimEnd();
|
|
29
27
|
const headingHashes = line.slice(0, headingLevel);
|
|
30
|
-
const slug = slugger
|
|
28
|
+
const slug = slugger
|
|
29
|
+
.slug(unwrapMarkdownLinks(headingText).trim(), maintainCase)
|
|
30
|
+
.replace(/^-+/, '')
|
|
31
|
+
.replace(/-+$/, '');
|
|
31
32
|
return `${headingHashes}${headingText} {#${slug}}`;
|
|
32
33
|
}
|
|
33
|
-
function transformMarkdownHeadingLine(line, slugger) {
|
|
34
|
+
function transformMarkdownHeadingLine(line, slugger, options = { maintainCase: false, overwrite: false }) {
|
|
35
|
+
const { maintainCase = false, overwrite = false } = options;
|
|
34
36
|
if (!line.startsWith('#')) {
|
|
35
37
|
throw new Error(`Line is not a Markdown heading: ${line}.`);
|
|
36
38
|
}
|
|
37
|
-
const parsedHeading = utils_1.parseMarkdownHeadingId(line);
|
|
38
|
-
// Do not process if id is already
|
|
39
|
-
if (parsedHeading.id) {
|
|
39
|
+
const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(line);
|
|
40
|
+
// Do not process if id is already there
|
|
41
|
+
if (parsedHeading.id && !overwrite) {
|
|
40
42
|
return line;
|
|
41
43
|
}
|
|
42
|
-
return addHeadingId(
|
|
44
|
+
return addHeadingId(parsedHeading.text, slugger, maintainCase);
|
|
43
45
|
}
|
|
44
46
|
exports.transformMarkdownHeadingLine = transformMarkdownHeadingLine;
|
|
45
|
-
function transformMarkdownLine(line, slugger) {
|
|
47
|
+
function transformMarkdownLine(line, slugger, options) {
|
|
46
48
|
// Ignore h1 headings on purpose, as we don't create anchor links for those
|
|
47
49
|
if (line.startsWith('##')) {
|
|
48
|
-
return transformMarkdownHeadingLine(line, slugger);
|
|
50
|
+
return transformMarkdownHeadingLine(line, slugger, options);
|
|
49
51
|
}
|
|
50
52
|
else {
|
|
51
53
|
return line;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
function transformMarkdownLines(lines) {
|
|
56
|
+
function transformMarkdownLines(lines, options) {
|
|
56
57
|
let inCode = false;
|
|
57
58
|
const slugger = new github_slugger_1.default();
|
|
58
59
|
return lines.map((line) => {
|
|
@@ -64,17 +65,17 @@ function transformMarkdownLines(lines) {
|
|
|
64
65
|
if (inCode) {
|
|
65
66
|
return line;
|
|
66
67
|
}
|
|
67
|
-
return transformMarkdownLine(line, slugger);
|
|
68
|
+
return transformMarkdownLine(line, slugger, options);
|
|
68
69
|
}
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
|
-
function transformMarkdownContent(content) {
|
|
72
|
-
return transformMarkdownLines(content.split('\n')).join('\n');
|
|
72
|
+
function transformMarkdownContent(content, options) {
|
|
73
|
+
return transformMarkdownLines(content.split('\n'), options).join('\n');
|
|
73
74
|
}
|
|
74
75
|
exports.transformMarkdownContent = transformMarkdownContent;
|
|
75
|
-
async function transformMarkdownFile(filepath) {
|
|
76
|
+
async function transformMarkdownFile(filepath, options) {
|
|
76
77
|
const content = await fs_extra_1.default.readFile(filepath, 'utf8');
|
|
77
|
-
const updatedContent = transformMarkdownLines(content.split('\n')).join('\n');
|
|
78
|
+
const updatedContent = transformMarkdownLines(content.split('\n'), options).join('\n');
|
|
78
79
|
if (content !== updatedContent) {
|
|
79
80
|
await fs_extra_1.default.writeFile(filepath, updatedContent);
|
|
80
81
|
return filepath;
|
|
@@ -85,26 +86,26 @@ async function transformMarkdownFile(filepath) {
|
|
|
85
86
|
// Also we don't want to transform the site md docs that do not belong to a content plugin
|
|
86
87
|
// For example ./README.md should not be transformed
|
|
87
88
|
async function getPathsToWatch(siteDir) {
|
|
88
|
-
const context = await server_1.loadContext(siteDir);
|
|
89
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
90
|
-
const plugins =
|
|
89
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
90
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
91
|
+
const plugins = (0, init_1.default)({
|
|
91
92
|
pluginConfigs,
|
|
92
93
|
context,
|
|
93
94
|
});
|
|
94
|
-
return
|
|
95
|
+
return plugins.flatMap((plugin) => { var _a, _b; return (_b = (_a = plugin === null || plugin === void 0 ? void 0 : plugin.getPathsToWatch) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; });
|
|
95
96
|
}
|
|
96
|
-
async function writeHeadingIds(siteDir) {
|
|
97
|
-
const markdownFiles = await utils_2.safeGlobby(await getPathsToWatch(siteDir), {
|
|
97
|
+
async function writeHeadingIds(siteDir, files, options) {
|
|
98
|
+
const markdownFiles = await (0, utils_2.safeGlobby)(files ? [files] : await getPathsToWatch(siteDir), {
|
|
98
99
|
expandDirectories: ['**/*.{md,mdx}'],
|
|
99
100
|
});
|
|
100
|
-
const result = await Promise.all(markdownFiles.map(transformMarkdownFile));
|
|
101
|
+
const result = await Promise.all(markdownFiles.map((p) => transformMarkdownFile(p, options)));
|
|
101
102
|
const pathsModified = result.filter(Boolean);
|
|
102
103
|
if (pathsModified.length) {
|
|
103
104
|
console.log(chalk_1.default.green(`Heading ids added to Markdown files (${pathsModified.length}/${markdownFiles.length} files):
|
|
104
105
|
- ${pathsModified.join('\n- ')}`));
|
|
105
106
|
}
|
|
106
107
|
else {
|
|
107
|
-
console.log(chalk_1.default.yellow(`${markdownFiles.length} Markdown files already have explicit heading
|
|
108
|
+
console.log(chalk_1.default.yellow(`${markdownFiles.length} Markdown files already have explicit heading IDs. If you intend to overwrite the existing heading IDs, use the ${chalk_1.default.cyan('--overwrite')} option.`));
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
exports.default = writeHeadingIds;
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
4
5
|
const server_1 = require("../server");
|
|
5
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
6
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
6
7
|
const translations_1 = require("../server/translations/translations");
|
|
7
8
|
const translationsExtractor_1 = require("../server/translations/translationsExtractor");
|
|
8
9
|
const utils_1 = require("../webpack/utils");
|
|
10
|
+
// This is a hack, so that @docusaurus/theme-common translations are extracted!
|
|
11
|
+
// A theme doesn't have a way to express that one of its dependency (like @docusaurus/theme-common) also has translations to extract
|
|
12
|
+
// Instead of introducing a new lifecycle (like plugin.getThemeTranslationPaths() ?)
|
|
13
|
+
// We just make an exception and assume that Docusaurus user is using an official theme
|
|
14
|
+
async function getExtraSourceCodeFilePaths() {
|
|
15
|
+
try {
|
|
16
|
+
const themeCommonSourceDir = path_1.default.dirname(require.resolve('@docusaurus/theme-common/lib'));
|
|
17
|
+
return (0, translationsExtractor_1.globSourceCodeFilePaths)([themeCommonSourceDir]);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
|
21
|
+
}
|
|
22
|
+
}
|
|
9
23
|
async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }) {
|
|
10
24
|
var _a;
|
|
11
25
|
if (plugin.getTranslationFiles) {
|
|
@@ -14,7 +28,7 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
14
28
|
content,
|
|
15
29
|
});
|
|
16
30
|
await Promise.all(translationFiles.map(async (translationFile) => {
|
|
17
|
-
await translations_1.writePluginTranslations({
|
|
31
|
+
await (0, translations_1.writePluginTranslations)({
|
|
18
32
|
siteDir,
|
|
19
33
|
plugin,
|
|
20
34
|
translationFile,
|
|
@@ -26,12 +40,12 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
26
40
|
}
|
|
27
41
|
async function writeTranslations(siteDir, options) {
|
|
28
42
|
var _a;
|
|
29
|
-
const context = await server_1.loadContext(siteDir, {
|
|
43
|
+
const context = await (0, server_1.loadContext)(siteDir, {
|
|
30
44
|
customConfigFilePath: options.config,
|
|
31
45
|
locale: options.locale,
|
|
32
46
|
});
|
|
33
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
34
|
-
const plugins = init_1.default({
|
|
47
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
48
|
+
const plugins = (0, init_1.default)({
|
|
35
49
|
pluginConfigs,
|
|
36
50
|
context,
|
|
37
51
|
});
|
|
@@ -40,17 +54,17 @@ async function writeTranslations(siteDir, options) {
|
|
|
40
54
|
throw new Error(`Can't write-translation for locale "${locale}" that is not in the locale configuration file.
|
|
41
55
|
Available locales are: ${context.i18n.locales.join(',')}.`);
|
|
42
56
|
}
|
|
43
|
-
const babelOptions = utils_1.getBabelOptions({
|
|
57
|
+
const babelOptions = (0, utils_1.getBabelOptions)({
|
|
44
58
|
isServer: true,
|
|
45
|
-
babelOptions: utils_1.getCustomBabelConfigFilePath(siteDir),
|
|
59
|
+
babelOptions: (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
|
|
46
60
|
});
|
|
47
|
-
const extractedCodeTranslations = await translationsExtractor_1.extractSiteSourceCodeTranslations(siteDir, plugins, babelOptions);
|
|
48
|
-
const defaultCodeMessages = await translations_1.getPluginsDefaultCodeTranslationMessages(plugins);
|
|
49
|
-
const codeTranslations = translations_1.applyDefaultCodeTranslations({
|
|
61
|
+
const extractedCodeTranslations = await (0, translationsExtractor_1.extractSiteSourceCodeTranslations)(siteDir, plugins, babelOptions, await getExtraSourceCodeFilePaths());
|
|
62
|
+
const defaultCodeMessages = await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins);
|
|
63
|
+
const codeTranslations = (0, translations_1.applyDefaultCodeTranslations)({
|
|
50
64
|
extractedCodeTranslations,
|
|
51
65
|
defaultCodeMessages,
|
|
52
66
|
});
|
|
53
|
-
await translations_1.writeCodeTranslations({ siteDir, locale }, codeTranslations, options);
|
|
67
|
+
await (0, translations_1.writeCodeTranslations)({ siteDir, locale }, codeTranslations, options);
|
|
54
68
|
await Promise.all(plugins.map(async (plugin) => {
|
|
55
69
|
await writePluginTranslationFiles({ siteDir, plugin, locale, options });
|
|
56
70
|
}));
|
package/lib/constants.d.ts
CHANGED
|
@@ -16,3 +16,4 @@ export declare const OUTPUT_STATIC_ASSETS_DIR_NAME = "assets";
|
|
|
16
16
|
export declare const THEME_PATH: string;
|
|
17
17
|
export declare const DEFAULT_PORT = 3000;
|
|
18
18
|
export declare const DEFAULT_PLUGIN_ID = "default";
|
|
19
|
+
export declare const WEBPACK_URL_LOADER_LIMIT: string | number;
|
package/lib/constants.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var _a;
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
|
|
10
|
+
exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
|
|
10
11
|
exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
|
|
11
12
|
exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
|
|
12
13
|
// Can be overridden with cli option --out-dir
|
|
@@ -21,3 +22,5 @@ exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, h
|
|
|
21
22
|
exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
|
|
22
23
|
exports.DEFAULT_PORT = 3000;
|
|
23
24
|
exports.DEFAULT_PLUGIN_ID = 'default';
|
|
25
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5493
|
|
26
|
+
exports.WEBPACK_URL_LOADER_LIMIT = (_a = process.env.WEBPACK_URL_LOADER_LIMIT) !== null && _a !== void 0 ? _a : 10000;
|