@docusaurus/bundler 3.7.0-canary-6244 → 3.7.0-canary-6246
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/lib/compiler.js +1 -1
- package/lib/compiler.js.map +1 -1
- package/lib/legacy/formatWebpackMessages.d.ts +6 -0
- package/lib/legacy/formatWebpackMessages.d.ts.map +1 -0
- package/lib/legacy/formatWebpackMessages.js +106 -0
- package/lib/legacy/formatWebpackMessages.js.map +1 -0
- package/package.json +7 -8
- package/src/compiler.ts +1 -1
- package/src/legacy/formatWebpackMessages.js +138 -0
package/lib/compiler.js
CHANGED
|
@@ -11,7 +11,7 @@ exports.printStatsWarnings = printStatsWarnings;
|
|
|
11
11
|
exports.compile = compile;
|
|
12
12
|
const tslib_1 = require("tslib");
|
|
13
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
-
const formatWebpackMessages_1 = tslib_1.__importDefault(require("
|
|
14
|
+
const formatWebpackMessages_1 = tslib_1.__importDefault(require("./legacy/formatWebpackMessages"));
|
|
15
15
|
function formatStatsErrorMessage(statsJson) {
|
|
16
16
|
if (statsJson?.errors?.length) {
|
|
17
17
|
// TODO formatWebpackMessages does not print stack-traces
|
package/lib/compiler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,0DAaC;AAED,gDAQC;AASD,0BAyCC;;AA9ED,wEAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,0DAaC;AAED,gDAQC;AASD,0BAyCC;;AA9ED,wEAAwC;AACxC,mGAAmE;AAInE,SAAgB,uBAAuB,CACrC,SAA0D;IAE1D,IAAI,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC9B,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AAE,SAAS,EAAE,EAAE,CAAC;gBACvB,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,cAAc,CAAC,CAAC;gBAClE,MAAM,CACJ,IAAI,KAAK,CACP,6CAA6C,iBAAiB,EAAE,CACjE,CACF,CAAC;YACJ,CAAC;YACD,kBAAkB,CAAC,cAAc,CAAC,CAAC;YAEnC,sEAAsE;YACtE,0DAA0D;YAC1D,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAC1B,IAAI,QAAQ,EAAE,CAAC;oBACb,gBAAM,CAAC,KAAK,CAAC,yCAAyC,QAAQ,EAAE,CAAC,CAAC;oBAClE,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAM,CAAC,CAAC;gBAClB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatWebpackMessages.d.ts","sourceRoot":"","sources":["../../src/legacy/formatWebpackMessages.js"],"names":[],"mappings":"AAgIiB,sCAFJ;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAWpD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
// TODO Legacy CRA react-dev-utils package code
|
|
9
|
+
// This code was in CRA/react-dev-utils (deprecated in 2025)
|
|
10
|
+
// We just copied the code as-is to remove a fat/useless dependency subtree
|
|
11
|
+
// See https://github.com/facebook/docusaurus/pull/10956
|
|
12
|
+
// See https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/formatWebpackMessages.js
|
|
13
|
+
/* eslint-disable */
|
|
14
|
+
const friendlySyntaxErrorLabel = 'Syntax error:';
|
|
15
|
+
function isLikelyASyntaxError(message) {
|
|
16
|
+
return message.indexOf(friendlySyntaxErrorLabel) !== -1;
|
|
17
|
+
}
|
|
18
|
+
// Cleans up webpack error messages.
|
|
19
|
+
function formatMessage(message) {
|
|
20
|
+
let lines = [];
|
|
21
|
+
if (typeof message === 'string') {
|
|
22
|
+
lines = message.split('\n');
|
|
23
|
+
}
|
|
24
|
+
else if ('message' in message) {
|
|
25
|
+
lines = message['message'].split('\n');
|
|
26
|
+
}
|
|
27
|
+
else if (Array.isArray(message)) {
|
|
28
|
+
message.forEach((message) => {
|
|
29
|
+
if ('message' in message) {
|
|
30
|
+
lines = message['message'].split('\n');
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Strip webpack-added headers off errors/warnings
|
|
35
|
+
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
|
36
|
+
lines = lines.filter((line) => !/Module [A-z ]+\(from/.test(line));
|
|
37
|
+
// Transform parsing error into syntax error
|
|
38
|
+
// TODO: move this to our ESLint formatter?
|
|
39
|
+
lines = lines.map((line) => {
|
|
40
|
+
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
|
|
41
|
+
if (!parsingError) {
|
|
42
|
+
return line;
|
|
43
|
+
}
|
|
44
|
+
const [, errorLine, errorColumn, errorMessage] = parsingError;
|
|
45
|
+
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
|
46
|
+
});
|
|
47
|
+
message = lines.join('\n');
|
|
48
|
+
// Smoosh syntax errors (commonly found in CSS)
|
|
49
|
+
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`);
|
|
50
|
+
// Clean up export errors
|
|
51
|
+
message = message.replace(/^.*export '(.+?)' was not found in '(.+?)'.*$/gm, `Attempted import error: '$1' is not exported from '$2'.`);
|
|
52
|
+
message = message.replace(/^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, `Attempted import error: '$2' does not contain a default export (imported as '$1').`);
|
|
53
|
+
message = message.replace(/^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, `Attempted import error: '$1' is not exported from '$3' (imported as '$2').`);
|
|
54
|
+
lines = message.split('\n');
|
|
55
|
+
// Remove leading newline
|
|
56
|
+
if (lines.length > 2 && lines[1].trim() === '') {
|
|
57
|
+
lines.splice(1, 1);
|
|
58
|
+
}
|
|
59
|
+
// Clean up file name
|
|
60
|
+
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
|
|
61
|
+
// Cleans up verbose "module not found" messages for files and packages.
|
|
62
|
+
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
|
63
|
+
lines = [
|
|
64
|
+
lines[0],
|
|
65
|
+
lines[1]
|
|
66
|
+
.replace('Error: ', '')
|
|
67
|
+
.replace('Module not found: Cannot find file:', 'Cannot find file:'),
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
// Add helpful message for users trying to use Sass for the first time
|
|
71
|
+
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
|
72
|
+
lines[1] = 'To import Sass files, you first need to install sass.\n';
|
|
73
|
+
lines[1] +=
|
|
74
|
+
'Run `npm install sass` or `yarn add sass` inside your workspace.';
|
|
75
|
+
}
|
|
76
|
+
message = lines.join('\n');
|
|
77
|
+
// Internal stacks are generally useless so we strip them... with the
|
|
78
|
+
// exception of stacks containing `webpack:` because they're normally
|
|
79
|
+
// from user code generated by webpack. For more information see
|
|
80
|
+
// https://github.com/facebook/create-react-app/pull/1050
|
|
81
|
+
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y
|
|
82
|
+
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
|
|
83
|
+
lines = message.split('\n');
|
|
84
|
+
// Remove duplicated newlines
|
|
85
|
+
lines = lines.filter((line, index, arr) => index === 0 ||
|
|
86
|
+
line.trim() !== '' ||
|
|
87
|
+
line.trim() !== arr[index - 1].trim());
|
|
88
|
+
// Reassemble the message
|
|
89
|
+
message = lines.join('\n');
|
|
90
|
+
return message.trim();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @param {import("webpack").Stats.ToJsonOutput} json.
|
|
94
|
+
* @returns {{ errors: string[], warnings: string[] }}
|
|
95
|
+
*/
|
|
96
|
+
module.exports = function formatWebpackMessages(json) {
|
|
97
|
+
const formattedErrors = json.errors.map(formatMessage);
|
|
98
|
+
const formattedWarnings = json.warnings.map(formatMessage);
|
|
99
|
+
const result = { errors: formattedErrors, warnings: formattedWarnings };
|
|
100
|
+
if (result.errors.some(isLikelyASyntaxError)) {
|
|
101
|
+
// If there are any syntax errors, show just them.
|
|
102
|
+
result.errors = result.errors.filter(isLikelyASyntaxError);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=formatWebpackMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatWebpackMessages.js","sourceRoot":"","sources":["../../src/legacy/formatWebpackMessages.js"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,+CAA+C;AAC/C,6DAA6D;AAC7D,4EAA4E;AAC5E,yDAAyD;AACzD,gHAAgH;AAEhH,oBAAoB;AAEpB,MAAM,wBAAwB,GAAG,eAAe,CAAC;AAEjD,SAAS,oBAAoB,CAAC,OAAO;IACnC,OAAO,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,oCAAoC;AACpC,SAAS,aAAa,CAAC,OAAO;IAC5B,IAAI,KAAK,GAAG,EAAE,CAAC;IAE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,CAAC,oBAAoB,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/bundler",
|
|
3
|
-
"version": "3.7.0-canary-
|
|
3
|
+
"version": "3.7.0-canary-6246",
|
|
4
4
|
"description": "Docusaurus util package to abstract the current bundler.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/core": "^7.25.9",
|
|
22
|
-
"@docusaurus/babel": "3.7.0-canary-
|
|
23
|
-
"@docusaurus/cssnano-preset": "3.7.0-canary-
|
|
24
|
-
"@docusaurus/logger": "3.7.0-canary-
|
|
25
|
-
"@docusaurus/types": "3.7.0-canary-
|
|
26
|
-
"@docusaurus/utils": "3.7.0-canary-
|
|
22
|
+
"@docusaurus/babel": "3.7.0-canary-6246",
|
|
23
|
+
"@docusaurus/cssnano-preset": "3.7.0-canary-6246",
|
|
24
|
+
"@docusaurus/logger": "3.7.0-canary-6246",
|
|
25
|
+
"@docusaurus/types": "3.7.0-canary-6246",
|
|
26
|
+
"@docusaurus/utils": "3.7.0-canary-6246",
|
|
27
27
|
"babel-loader": "^9.2.1",
|
|
28
28
|
"clean-css": "^5.3.2",
|
|
29
29
|
"copy-webpack-plugin": "^11.0.0",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"postcss": "^8.4.26",
|
|
38
38
|
"postcss-loader": "^7.3.3",
|
|
39
39
|
"postcss-preset-env": "^10.1.0",
|
|
40
|
-
"react-dev-utils": "^12.0.1",
|
|
41
40
|
"terser-webpack-plugin": "^5.3.9",
|
|
42
41
|
"tslib": "^2.6.0",
|
|
43
42
|
"url-loader": "^4.1.1",
|
|
@@ -58,5 +57,5 @@
|
|
|
58
57
|
"engines": {
|
|
59
58
|
"node": ">=18.0"
|
|
60
59
|
},
|
|
61
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "6e2458e85cfd031ba2930419774f37e0f0871d67"
|
|
62
61
|
}
|
package/src/compiler.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {type Configuration} from 'webpack';
|
|
9
9
|
import logger from '@docusaurus/logger';
|
|
10
|
-
import formatWebpackMessages from '
|
|
10
|
+
import formatWebpackMessages from './legacy/formatWebpackMessages';
|
|
11
11
|
import type webpack from 'webpack';
|
|
12
12
|
import type {CurrentBundler} from '@docusaurus/types';
|
|
13
13
|
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
|
|
8
|
+
// TODO Legacy CRA react-dev-utils package code
|
|
9
|
+
// This code was in CRA/react-dev-utils (deprecated in 2025)
|
|
10
|
+
// We just copied the code as-is to remove a fat/useless dependency subtree
|
|
11
|
+
// See https://github.com/facebook/docusaurus/pull/10956
|
|
12
|
+
// See https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/formatWebpackMessages.js
|
|
13
|
+
|
|
14
|
+
/* eslint-disable */
|
|
15
|
+
|
|
16
|
+
const friendlySyntaxErrorLabel = 'Syntax error:';
|
|
17
|
+
|
|
18
|
+
function isLikelyASyntaxError(message) {
|
|
19
|
+
return message.indexOf(friendlySyntaxErrorLabel) !== -1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Cleans up webpack error messages.
|
|
23
|
+
function formatMessage(message) {
|
|
24
|
+
let lines = [];
|
|
25
|
+
|
|
26
|
+
if (typeof message === 'string') {
|
|
27
|
+
lines = message.split('\n');
|
|
28
|
+
} else if ('message' in message) {
|
|
29
|
+
lines = message['message'].split('\n');
|
|
30
|
+
} else if (Array.isArray(message)) {
|
|
31
|
+
message.forEach((message) => {
|
|
32
|
+
if ('message' in message) {
|
|
33
|
+
lines = message['message'].split('\n');
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Strip webpack-added headers off errors/warnings
|
|
39
|
+
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
|
40
|
+
lines = lines.filter((line) => !/Module [A-z ]+\(from/.test(line));
|
|
41
|
+
|
|
42
|
+
// Transform parsing error into syntax error
|
|
43
|
+
// TODO: move this to our ESLint formatter?
|
|
44
|
+
lines = lines.map((line) => {
|
|
45
|
+
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
|
|
46
|
+
line,
|
|
47
|
+
);
|
|
48
|
+
if (!parsingError) {
|
|
49
|
+
return line;
|
|
50
|
+
}
|
|
51
|
+
const [, errorLine, errorColumn, errorMessage] = parsingError;
|
|
52
|
+
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
message = lines.join('\n');
|
|
56
|
+
// Smoosh syntax errors (commonly found in CSS)
|
|
57
|
+
message = message.replace(
|
|
58
|
+
/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
|
|
59
|
+
`${friendlySyntaxErrorLabel} $3 ($1:$2)\n`,
|
|
60
|
+
);
|
|
61
|
+
// Clean up export errors
|
|
62
|
+
message = message.replace(
|
|
63
|
+
/^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
|
|
64
|
+
`Attempted import error: '$1' is not exported from '$2'.`,
|
|
65
|
+
);
|
|
66
|
+
message = message.replace(
|
|
67
|
+
/^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
|
|
68
|
+
`Attempted import error: '$2' does not contain a default export (imported as '$1').`,
|
|
69
|
+
);
|
|
70
|
+
message = message.replace(
|
|
71
|
+
/^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
|
|
72
|
+
`Attempted import error: '$1' is not exported from '$3' (imported as '$2').`,
|
|
73
|
+
);
|
|
74
|
+
lines = message.split('\n');
|
|
75
|
+
|
|
76
|
+
// Remove leading newline
|
|
77
|
+
if (lines.length > 2 && lines[1].trim() === '') {
|
|
78
|
+
lines.splice(1, 1);
|
|
79
|
+
}
|
|
80
|
+
// Clean up file name
|
|
81
|
+
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
|
|
82
|
+
|
|
83
|
+
// Cleans up verbose "module not found" messages for files and packages.
|
|
84
|
+
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
|
85
|
+
lines = [
|
|
86
|
+
lines[0],
|
|
87
|
+
lines[1]
|
|
88
|
+
.replace('Error: ', '')
|
|
89
|
+
.replace('Module not found: Cannot find file:', 'Cannot find file:'),
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Add helpful message for users trying to use Sass for the first time
|
|
94
|
+
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
|
95
|
+
lines[1] = 'To import Sass files, you first need to install sass.\n';
|
|
96
|
+
lines[1] +=
|
|
97
|
+
'Run `npm install sass` or `yarn add sass` inside your workspace.';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
message = lines.join('\n');
|
|
101
|
+
// Internal stacks are generally useless so we strip them... with the
|
|
102
|
+
// exception of stacks containing `webpack:` because they're normally
|
|
103
|
+
// from user code generated by webpack. For more information see
|
|
104
|
+
// https://github.com/facebook/create-react-app/pull/1050
|
|
105
|
+
message = message.replace(
|
|
106
|
+
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
|
|
107
|
+
'',
|
|
108
|
+
); // at ... ...:x:y
|
|
109
|
+
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
|
|
110
|
+
lines = message.split('\n');
|
|
111
|
+
|
|
112
|
+
// Remove duplicated newlines
|
|
113
|
+
lines = lines.filter(
|
|
114
|
+
(line, index, arr) =>
|
|
115
|
+
index === 0 ||
|
|
116
|
+
line.trim() !== '' ||
|
|
117
|
+
line.trim() !== arr[index - 1].trim(),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// Reassemble the message
|
|
121
|
+
message = lines.join('\n');
|
|
122
|
+
return message.trim();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {import("webpack").Stats.ToJsonOutput} json.
|
|
127
|
+
* @returns {{ errors: string[], warnings: string[] }}
|
|
128
|
+
*/
|
|
129
|
+
module.exports = function formatWebpackMessages(json) {
|
|
130
|
+
const formattedErrors = json.errors.map(formatMessage);
|
|
131
|
+
const formattedWarnings = json.warnings.map(formatMessage);
|
|
132
|
+
const result = {errors: formattedErrors, warnings: formattedWarnings};
|
|
133
|
+
if (result.errors.some(isLikelyASyntaxError)) {
|
|
134
|
+
// If there are any syntax errors, show just them.
|
|
135
|
+
result.errors = result.errors.filter(isLikelyASyntaxError);
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
};
|