@docusaurus/core 0.0.0-5537 → 0.0.0-5542
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/docusaurus.mjs +5 -1
- package/lib/client/serverEntry.js +23 -16
- package/lib/commands/build.js +3 -2
- package/lib/commands/start.js +10 -4
- package/lib/webpack/client.js +5 -3
- package/lib/webpack/server.js +2 -2
- package/lib/webpack/utils.d.ts +3 -1
- package/lib/webpack/utils.js +24 -7
- package/package.json +10 -10
- package/lib/webpack/plugins/LogPlugin.d.ts +0 -11
- package/lib/webpack/plugins/LogPlugin.js +0 -33
package/bin/docusaurus.mjs
CHANGED
|
@@ -244,7 +244,11 @@ if (!process.argv.slice(2).length) {
|
|
|
244
244
|
cli.parse(process.argv);
|
|
245
245
|
|
|
246
246
|
process.on('unhandledRejection', (err) => {
|
|
247
|
-
|
|
247
|
+
console.log('');
|
|
248
|
+
// Do not use logger.error here: it does not print error causes
|
|
249
|
+
console.error(err);
|
|
250
|
+
console.log('');
|
|
251
|
+
|
|
248
252
|
logger.info`Docusaurus version: number=${DOCUSAURUS_VERSION}
|
|
249
253
|
Node version: number=${process.version}`;
|
|
250
254
|
process.exit(1);
|
|
@@ -9,7 +9,6 @@ import path from 'path';
|
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
10
|
// eslint-disable-next-line no-restricted-imports
|
|
11
11
|
import _ from 'lodash';
|
|
12
|
-
import chalk from 'chalk';
|
|
13
12
|
import * as eta from 'eta';
|
|
14
13
|
import { StaticRouter } from 'react-router-dom';
|
|
15
14
|
import ReactDOMServer from 'react-dom/server';
|
|
@@ -27,24 +26,31 @@ function renderSSRTemplate(ssrTemplate, data) {
|
|
|
27
26
|
const compiled = getCompiledSSRTemplate(ssrTemplate);
|
|
28
27
|
return compiled(data, eta.defaultConfig);
|
|
29
28
|
}
|
|
29
|
+
function buildSSRErrorMessage({ error, pathname, }) {
|
|
30
|
+
const parts = [
|
|
31
|
+
`Docusaurus server-side rendering could not render static page with path ${pathname} because of error: ${error.message}`,
|
|
32
|
+
];
|
|
33
|
+
const isNotDefinedErrorRegex = /(?:window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
|
|
34
|
+
if (isNotDefinedErrorRegex.test(error.message)) {
|
|
35
|
+
// prettier-ignore
|
|
36
|
+
parts.push(`It looks like you are using code that should run on the client-side only.
|
|
37
|
+
To get around it, try using \`<BrowserOnly>\` (https://docusaurus.io/docs/docusaurus-core/#browseronly) or \`ExecutionEnvironment\` (https://docusaurus.io/docs/docusaurus-core/#executionenvironment).
|
|
38
|
+
It might also require to wrap your client code in \`useEffect\` hook and/or import a third-party library dynamically (if any).`);
|
|
39
|
+
}
|
|
40
|
+
return parts.join('\n');
|
|
41
|
+
}
|
|
30
42
|
export default async function render(locals) {
|
|
31
43
|
try {
|
|
32
44
|
return await doRender(locals);
|
|
33
45
|
}
|
|
34
|
-
catch (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// prettier-ignore
|
|
43
|
-
console.info(`${chalk.cyan.bold('[INFO]')} It looks like you are using code that should run on the client-side only.
|
|
44
|
-
To get around it, try using ${chalk.cyan('`<BrowserOnly>`')} (${chalk.cyan.underline('https://docusaurus.io/docs/docusaurus-core/#browseronly')}) or ${chalk.cyan('`ExecutionEnvironment`')} (${chalk.cyan.underline('https://docusaurus.io/docs/docusaurus-core/#executionenvironment')}).
|
|
45
|
-
It might also require to wrap your client code in ${chalk.cyan('`useEffect`')} hook and/or import a third-party library dynamically (if any).`);
|
|
46
|
-
}
|
|
47
|
-
throw err;
|
|
46
|
+
catch (errorUnknown) {
|
|
47
|
+
const error = errorUnknown;
|
|
48
|
+
const message = buildSSRErrorMessage({ error, pathname: locals.path });
|
|
49
|
+
const ssrError = new Error(message, { cause: error });
|
|
50
|
+
// It is important to log the error here because the stacktrace causal chain
|
|
51
|
+
// is not available anymore upper in the tree (this SSR runs in eval)
|
|
52
|
+
console.error(ssrError);
|
|
53
|
+
throw ssrError;
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
// Renderer for static-site-generator-webpack-plugin (async rendering).
|
|
@@ -124,7 +130,8 @@ async function doRender(locals) {
|
|
|
124
130
|
}
|
|
125
131
|
catch (err) {
|
|
126
132
|
// prettier-ignore
|
|
127
|
-
console.error(
|
|
133
|
+
console.error(`Minification of page ${locals.path} failed.`);
|
|
134
|
+
console.error(err);
|
|
128
135
|
throw err;
|
|
129
136
|
}
|
|
130
137
|
}
|
package/lib/commands/build.js
CHANGED
|
@@ -47,8 +47,9 @@ forceTerminate = true) {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
catch (err) {
|
|
50
|
-
logger_1.default.
|
|
51
|
-
|
|
50
|
+
throw new Error(logger_1.default.interpolate `Unable to build website for locale name=${locale}.`, {
|
|
51
|
+
cause: err,
|
|
52
|
+
});
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
const context = await (0, server_1.loadContext)({
|
package/lib/commands/start.js
CHANGED
|
@@ -124,16 +124,22 @@ async function start(siteDirParam = '.', cliOptions = {}) {
|
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
const compiler = (0, webpack_1.default)(config);
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
compiler.hooks.done.tap('done', (stats) => {
|
|
128
|
+
const errorsWarnings = stats.toJson('errors-warnings');
|
|
129
|
+
const statsErrorMessage = (0, utils_2.formatStatsErrorMessage)(errorsWarnings);
|
|
130
|
+
if (statsErrorMessage) {
|
|
131
|
+
console.error(statsErrorMessage);
|
|
132
|
+
}
|
|
133
|
+
(0, utils_2.printStatsWarnings)(errorsWarnings);
|
|
134
|
+
if (process.env.E2E_TEST) {
|
|
129
135
|
if (stats.hasErrors()) {
|
|
130
136
|
logger_1.default.error('E2E_TEST: Project has compiler errors.');
|
|
131
137
|
process.exit(1);
|
|
132
138
|
}
|
|
133
139
|
logger_1.default.success('E2E_TEST: Project can compile.');
|
|
134
140
|
process.exit(0);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
137
143
|
// https://webpack.js.org/configuration/dev-server
|
|
138
144
|
const defaultDevServerConfig = {
|
|
139
145
|
hot: cliOptions.hotOnly ? 'only' : true,
|
package/lib/webpack/client.js
CHANGED
|
@@ -10,9 +10,10 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
12
|
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
13
|
+
const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
13
14
|
const base_1 = require("./base");
|
|
14
15
|
const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
|
|
15
|
-
const
|
|
16
|
+
const utils_1 = require("./utils");
|
|
16
17
|
async function createClientConfig(props, minify = true) {
|
|
17
18
|
const isBuilding = process.argv[2] === 'build';
|
|
18
19
|
const config = await (0, base_1.createBaseConfig)(props, false, minify);
|
|
@@ -29,7 +30,7 @@ async function createClientConfig(props, minify = true) {
|
|
|
29
30
|
plugins: [
|
|
30
31
|
new ChunkAssetPlugin_1.default(),
|
|
31
32
|
// Show compilation progress bar and build time.
|
|
32
|
-
new
|
|
33
|
+
new webpackbar_1.default({
|
|
33
34
|
name: 'Client',
|
|
34
35
|
}),
|
|
35
36
|
],
|
|
@@ -41,7 +42,8 @@ async function createClientConfig(props, minify = true) {
|
|
|
41
42
|
apply: (compiler) => {
|
|
42
43
|
compiler.hooks.done.tap('client:done', (stats) => {
|
|
43
44
|
if (stats.hasErrors()) {
|
|
44
|
-
|
|
45
|
+
const errorsWarnings = stats.toJson('errors-warnings');
|
|
46
|
+
logger_1.default.error(`Client bundle compiled with errors therefore further build is impossible.\n${(0, utils_1.formatStatsErrorMessage)(errorsWarnings)}`);
|
|
45
47
|
process.exit(1);
|
|
46
48
|
}
|
|
47
49
|
});
|
package/lib/webpack/server.js
CHANGED
|
@@ -12,9 +12,9 @@ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
// Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
|
|
14
14
|
const static_site_generator_webpack_plugin_1 = tslib_1.__importDefault(require("@slorber/static-site-generator-webpack-plugin"));
|
|
15
|
+
const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
15
16
|
const base_1 = require("./base");
|
|
16
17
|
const WaitPlugin_1 = tslib_1.__importDefault(require("./plugins/WaitPlugin"));
|
|
17
|
-
const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
|
|
18
18
|
const ssr_html_template_1 = tslib_1.__importDefault(require("./templates/ssr.html.template"));
|
|
19
19
|
async function createServerConfig({ props, onLinksCollected, onHeadTagsCollected, }) {
|
|
20
20
|
const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, siteConfig: { noIndex, trailingSlash, ssrTemplate }, } = props;
|
|
@@ -72,7 +72,7 @@ async function createServerConfig({ props, onLinksCollected, onHeadTagsCollected
|
|
|
72
72
|
: undefined,
|
|
73
73
|
}),
|
|
74
74
|
// Show compilation progress bar.
|
|
75
|
-
new
|
|
75
|
+
new webpackbar_1.default({
|
|
76
76
|
name: 'Server',
|
|
77
77
|
color: 'yellow',
|
|
78
78
|
}),
|
package/lib/webpack/utils.d.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="node" />
|
|
8
|
-
import { type Configuration, type RuleSetRule, type WebpackPluginInstance } from 'webpack';
|
|
8
|
+
import webpack, { type Configuration, type RuleSetRule, type WebpackPluginInstance } from 'webpack';
|
|
9
9
|
import type { TransformOptions } from '@babel/core';
|
|
10
10
|
import type { Plugin } from '@docusaurus/types';
|
|
11
|
+
export declare function formatStatsErrorMessage(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): string | undefined;
|
|
12
|
+
export declare function printStatsWarnings(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): void;
|
|
11
13
|
export declare function getStyleLoaders(isServer: boolean, cssOptionsArg?: {
|
|
12
14
|
[key: string]: unknown;
|
|
13
15
|
}): RuleSetRule[];
|
package/lib/webpack/utils.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getMinimizer = exports.getHttpsConfig = exports.compile = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = void 0;
|
|
9
|
+
exports.getMinimizer = exports.getHttpsConfig = exports.compile = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = exports.printStatsWarnings = exports.formatStatsErrorMessage = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -18,6 +18,26 @@ const webpack_merge_1 = require("webpack-merge");
|
|
|
18
18
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
19
19
|
const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
|
|
20
20
|
const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
|
|
21
|
+
const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
|
|
22
|
+
function formatStatsErrorMessage(statsJson) {
|
|
23
|
+
if (statsJson?.errors?.length) {
|
|
24
|
+
// TODO formatWebpackMessages does not print stack-traces
|
|
25
|
+
// Also the error causal chain is lost here
|
|
26
|
+
// We log the stacktrace inside serverEntry.tsx for now (not ideal)
|
|
27
|
+
const { errors } = (0, formatWebpackMessages_1.default)(statsJson);
|
|
28
|
+
return errors.join('\n---\n');
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
exports.formatStatsErrorMessage = formatStatsErrorMessage;
|
|
33
|
+
function printStatsWarnings(statsJson) {
|
|
34
|
+
if (statsJson?.warnings?.length) {
|
|
35
|
+
statsJson.warnings?.forEach((warning) => {
|
|
36
|
+
logger_1.default.warn(warning);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.printStatsWarnings = printStatsWarnings;
|
|
21
41
|
// Utility method to get style loaders
|
|
22
42
|
function getStyleLoaders(isServer, cssOptionsArg = {}) {
|
|
23
43
|
const cssOptions = {
|
|
@@ -177,13 +197,10 @@ function compile(config) {
|
|
|
177
197
|
// Let plugins consume all the stats
|
|
178
198
|
const errorsWarnings = stats?.toJson('errors-warnings');
|
|
179
199
|
if (stats?.hasErrors()) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (errorsWarnings && stats?.hasWarnings()) {
|
|
183
|
-
errorsWarnings.warnings?.forEach((warning) => {
|
|
184
|
-
logger_1.default.warn(warning);
|
|
185
|
-
});
|
|
200
|
+
const statsErrorMessage = formatStatsErrorMessage(errorsWarnings);
|
|
201
|
+
reject(new Error(`Failed to compile due to Webpack errors.\n${statsErrorMessage}`));
|
|
186
202
|
}
|
|
203
|
+
printStatsWarnings(errorsWarnings);
|
|
187
204
|
// Webpack 5 requires calling close() so that persistent caching works
|
|
188
205
|
// See https://github.com/webpack/webpack.js.org/pull/4775
|
|
189
206
|
compiler.close((errClose) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-5542",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"@babel/runtime": "^7.21.0",
|
|
44
44
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
45
45
|
"@babel/traverse": "^7.21.2",
|
|
46
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
47
|
-
"@docusaurus/logger": "0.0.0-
|
|
48
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
46
|
+
"@docusaurus/cssnano-preset": "0.0.0-5542",
|
|
47
|
+
"@docusaurus/logger": "0.0.0-5542",
|
|
48
|
+
"@docusaurus/mdx-loader": "0.0.0-5542",
|
|
49
49
|
"@docusaurus/react-loadable": "5.5.2",
|
|
50
|
-
"@docusaurus/utils": "0.0.0-
|
|
51
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
52
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
50
|
+
"@docusaurus/utils": "0.0.0-5542",
|
|
51
|
+
"@docusaurus/utils-common": "0.0.0-5542",
|
|
52
|
+
"@docusaurus/utils-validation": "0.0.0-5542",
|
|
53
53
|
"@slorber/static-site-generator-webpack-plugin": "^4.0.7",
|
|
54
54
|
"@svgr/webpack": "^6.5.1",
|
|
55
55
|
"autoprefixer": "^10.4.13",
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
"webpackbar": "^5.0.2"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
110
|
-
"@docusaurus/types": "0.0.0-
|
|
109
|
+
"@docusaurus/module-type-aliases": "0.0.0-5542",
|
|
110
|
+
"@docusaurus/types": "0.0.0-5542",
|
|
111
111
|
"@types/detect-port": "^1.3.2",
|
|
112
112
|
"@types/react-dom": "^18.0.11",
|
|
113
113
|
"@types/react-router-config": "^5.0.6",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"engines": {
|
|
128
128
|
"node": ">=16.14"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "58a3d23394f5e0101913369f54fbf70193e1d36a"
|
|
131
131
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
import WebpackBar from 'webpackbar';
|
|
8
|
-
import type { Compiler } from 'webpack';
|
|
9
|
-
export default class LogPlugin extends WebpackBar {
|
|
10
|
-
apply(compiler: Compiler): void;
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
const tslib_1 = require("tslib");
|
|
10
|
-
const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
11
|
-
const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
|
|
12
|
-
function showError(arr) {
|
|
13
|
-
console.log(`\n\n${arr.join('\n')}`);
|
|
14
|
-
}
|
|
15
|
-
class LogPlugin extends webpackbar_1.default {
|
|
16
|
-
apply(compiler) {
|
|
17
|
-
super.apply(compiler);
|
|
18
|
-
// TODO can't this be done in compile(configs) alongside the warnings???
|
|
19
|
-
compiler.hooks.done.tap('DocusaurusLogPlugin', (stats) => {
|
|
20
|
-
if (stats.hasErrors()) {
|
|
21
|
-
const errorsWarnings = stats.toJson('errors-warnings');
|
|
22
|
-
// TODO do we really want to keep this legacy logic?
|
|
23
|
-
// let's wait and see how the react-dev-utils support Webpack5
|
|
24
|
-
// we probably want to print the error stacktraces here
|
|
25
|
-
const messages = (0, formatWebpackMessages_1.default)(errorsWarnings);
|
|
26
|
-
if (messages.errors.length) {
|
|
27
|
-
showError(messages.errors);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.default = LogPlugin;
|