@docusaurus/bundler 3.7.0 → 3.8.0-canary-6327
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/currentBundler.d.ts +3 -0
- package/lib/currentBundler.d.ts.map +1 -1
- package/lib/currentBundler.js +29 -0
- package/lib/currentBundler.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.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/currentBundler.ts +43 -0
- package/src/index.ts +1 -0
- 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","sourceRo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ChB,gBAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC5B,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;YACD,oCAAoC;YACpC,MAAM,cAAc,GAAG,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACxD,IAAI,KAAK,EAAE,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"}
|
package/lib/currentBundler.d.ts
CHANGED
|
@@ -29,5 +29,8 @@ export declare function getCopyPlugin({ currentBundler, }: {
|
|
|
29
29
|
export declare function getProgressBarPlugin({ currentBundler, }: {
|
|
30
30
|
currentBundler: CurrentBundler;
|
|
31
31
|
}): Promise<typeof WebpackBar>;
|
|
32
|
+
export declare function registerBundlerTracing({ currentBundler, }: {
|
|
33
|
+
currentBundler: CurrentBundler;
|
|
34
|
+
}): Promise<() => Promise<void>>;
|
|
32
35
|
export {};
|
|
33
36
|
//# sourceMappingURL=currentBundler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currentBundler.d.ts","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAGxE,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE;QACN,mBAAmB,EAAE,IAAI,CACvB,gBAAgB,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,EACjD,eAAe,CAChB,CAAC;KACH,CAAC;CACH,CAAC;AAMF,wBAAsB,iBAAiB,CAAC,EACtC,UAAU,GACX,EAAE;IACD,UAAU,EAAE,eAAe,CAAC;CAC7B,GAAG,OAAO,CAAC,cAAc,CAAC,CAW1B;AAED,wBAAgB,yBAAyB,CAAC,EACxC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAOzB;AAED,wBAAsB,mBAAmB,CAAC,EACxC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,oBAAoB,CAAC,CAMvC;AAED,wBAAsB,aAAa,CAAC,EAClC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAMpC;AAED,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,UAAU,CAAC,CAkB7B"}
|
|
1
|
+
{"version":3,"file":"currentBundler.d.ts","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,UAAU,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@@ exports.getCurrentBundlerAsRspack = getCurrentBundlerAsRspack;
|
|
|
11
11
|
exports.getCSSExtractPlugin = getCSSExtractPlugin;
|
|
12
12
|
exports.getCopyPlugin = getCopyPlugin;
|
|
13
13
|
exports.getProgressBarPlugin = getProgressBarPlugin;
|
|
14
|
+
exports.registerBundlerTracing = registerBundlerTracing;
|
|
14
15
|
const tslib_1 = require("tslib");
|
|
15
16
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
16
17
|
const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
@@ -70,4 +71,32 @@ async function getProgressBarPlugin({ currentBundler, }) {
|
|
|
70
71
|
}
|
|
71
72
|
return webpackbar_1.default;
|
|
72
73
|
}
|
|
74
|
+
async function registerBundlerTracing({ currentBundler, }) {
|
|
75
|
+
if (currentBundler.name === 'rspack') {
|
|
76
|
+
const Rspack = await (0, importFaster_1.importRspack)();
|
|
77
|
+
// See https://rspack.dev/contribute/development/profiling
|
|
78
|
+
// File can be opened with https://ui.perfetto.dev/
|
|
79
|
+
if (process.env.DOCUSAURUS_RSPACK_TRACE) {
|
|
80
|
+
// We use the env variable as the "filter" attribute
|
|
81
|
+
// See values here: https://rspack.dev/contribute/development/tracing#tracing-filter
|
|
82
|
+
let filter = process.env.DOCUSAURUS_RSPACK_TRACE;
|
|
83
|
+
if (filter === 'true' || filter === '1') {
|
|
84
|
+
// Default value recommended by the Rspack team
|
|
85
|
+
// It's also what the CLI uses for the "overview" preset:
|
|
86
|
+
// https://github.com/web-infra-dev/rspack/blob/v1.3.10/packages/rspack-cli/src/utils/profile.ts
|
|
87
|
+
filter = 'info';
|
|
88
|
+
}
|
|
89
|
+
await Rspack.experiments.globalTrace.register(filter, 'chrome', './rspack-tracing.json');
|
|
90
|
+
console.info(`Rspack tracing registered, filter=${filter}`);
|
|
91
|
+
return async () => {
|
|
92
|
+
await Rspack.experiments.globalTrace.cleanup();
|
|
93
|
+
console.log(`Rspack tracing cleaned up, filter=${filter}`);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// We don't support Webpack tracing at the moment
|
|
98
|
+
return async () => {
|
|
99
|
+
// noop
|
|
100
|
+
};
|
|
101
|
+
}
|
|
73
102
|
//# sourceMappingURL=currentBundler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currentBundler.js","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAwBH,8CAeC;AAED,8DAWC;AAED,kDAUC;AAED,sCAUC;AAED,oDAsBC;;
|
|
1
|
+
{"version":3,"file":"currentBundler.js","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAwBH,8CAeC;AAED,8DAWC;AAED,kDAUC;AAED,sCAUC;AAED,oDAsBC;AAED,wDAyCC;;AA7ID,8DAA8B;AAC9B,oEAAoC;AACpC,8FAA2D;AAC3D,sFAAoD;AACpD,iDAA4C;AAc5C,SAAS,QAAQ,CAAC,UAA2B;IAC3C,OAAO,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,aAAa,CAAC;AAC7D,CAAC;AAEM,KAAK,UAAU,iBAAiB,CAAC,EACtC,UAAU,GAGX;IACC,IAAI,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,MAAM,IAAA,2BAAY,GAAE,CAA8B;SAC9D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,iBAAO;KAClB,CAAC;AACJ,CAAC;AAED,SAAgB,yBAAyB,CAAC,EACxC,cAAc,GAGf;IACC,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,gEAAgE,cAAc,CAAC,IAAI,EAAE,CACtF,CAAC;IACJ,CAAC;IACD,OAAO,cAAc,CAAC,QA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EAAE,CAAC;YACxC,oDAAoD;YACpD,oFAAoF;YACpF,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;YAEjD,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBACxC,+CAA+C;gBAC/C,yDAAyD;gBACzD,gGAAgG;gBAChG,MAAM,GAAG,MAAM,CAAC;YAClB,CAAC;YAED,MAAM,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAC3C,MAAM,EACN,QAAQ,EACR,uBAAuB,CACxB,CAAC;YAEF,OAAO,CAAC,IAAI,CAAC,qCAAqC,MAAM,EAAE,CAAC,CAAC;YAE5D,OAAO,KAAK,IAAI,EAAE;gBAChB,MAAM,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;gBAC/C,OAAO,CAAC,GAAG,CAAC,qCAAqC,MAAM,EAAE,CAAC,CAAC;YAC7D,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,iDAAiD;IACjD,OAAO,KAAK,IAAI,EAAE;QAChB,OAAO;IACT,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export { printStatsWarnings, formatStatsErrorMessage, compile } from './compiler';
|
|
8
|
-
export { getCurrentBundler, getCSSExtractPlugin, getCopyPlugin, getProgressBarPlugin, } from './currentBundler';
|
|
8
|
+
export { getCurrentBundler, getCSSExtractPlugin, getCopyPlugin, getProgressBarPlugin, registerBundlerTracing, } from './currentBundler';
|
|
9
9
|
export { getMinimizers } from './minification';
|
|
10
10
|
export { getHtmlMinifier, type HtmlMinifier, type HtmlMinifierType, } from './minifyHtml';
|
|
11
11
|
export { createJsLoaderFactory } from './loaders/jsLoader';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAEhF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAEhF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAC,yBAAyB,EAAC,MAAM,uBAAuB,CAAC"}
|
package/lib/index.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.createStyleLoadersFactory = exports.createJsLoaderFactory = exports.getHtmlMinifier = exports.getMinimizers = exports.getProgressBarPlugin = exports.getCopyPlugin = exports.getCSSExtractPlugin = exports.getCurrentBundler = exports.compile = exports.formatStatsErrorMessage = exports.printStatsWarnings = void 0;
|
|
9
|
+
exports.createStyleLoadersFactory = exports.createJsLoaderFactory = exports.getHtmlMinifier = exports.getMinimizers = exports.registerBundlerTracing = exports.getProgressBarPlugin = exports.getCopyPlugin = exports.getCSSExtractPlugin = exports.getCurrentBundler = exports.compile = exports.formatStatsErrorMessage = exports.printStatsWarnings = void 0;
|
|
10
10
|
var compiler_1 = require("./compiler");
|
|
11
11
|
Object.defineProperty(exports, "printStatsWarnings", { enumerable: true, get: function () { return compiler_1.printStatsWarnings; } });
|
|
12
12
|
Object.defineProperty(exports, "formatStatsErrorMessage", { enumerable: true, get: function () { return compiler_1.formatStatsErrorMessage; } });
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "getCurrentBundler", { enumerable: true, get: fun
|
|
|
16
16
|
Object.defineProperty(exports, "getCSSExtractPlugin", { enumerable: true, get: function () { return currentBundler_1.getCSSExtractPlugin; } });
|
|
17
17
|
Object.defineProperty(exports, "getCopyPlugin", { enumerable: true, get: function () { return currentBundler_1.getCopyPlugin; } });
|
|
18
18
|
Object.defineProperty(exports, "getProgressBarPlugin", { enumerable: true, get: function () { return currentBundler_1.getProgressBarPlugin; } });
|
|
19
|
+
Object.defineProperty(exports, "registerBundlerTracing", { enumerable: true, get: function () { return currentBundler_1.registerBundlerTracing; } });
|
|
19
20
|
var minification_1 = require("./minification");
|
|
20
21
|
Object.defineProperty(exports, "getMinimizers", { enumerable: true, get: function () { return minification_1.getMinimizers; } });
|
|
21
22
|
var minifyHtml_1 = require("./minifyHtml");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uCAAgF;AAAxE,8GAAA,kBAAkB,OAAA;AAAE,mHAAA,uBAAuB,OAAA;AAAE,mGAAA,OAAO,OAAA;AAE5D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uCAAgF;AAAxE,8GAAA,kBAAkB,OAAA;AAAE,mHAAA,uBAAuB,OAAA;AAAE,mGAAA,OAAO,OAAA;AAE5D,mDAM0B;AALxB,mHAAA,iBAAiB,OAAA;AACjB,qHAAA,mBAAmB,OAAA;AACnB,+GAAA,aAAa,OAAA;AACb,sHAAA,oBAAoB,OAAA;AACpB,wHAAA,sBAAsB,OAAA;AAGxB,+CAA6C;AAArC,6GAAA,aAAa,OAAA;AACrB,2CAIsB;AAHpB,6GAAA,eAAe,OAAA;AAIjB,+CAAyD;AAAjD,iHAAA,qBAAqB,OAAA;AAC7B,qDAAgE;AAAxD,wHAAA,yBAAyB,OAAA"}
|
|
@@ -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;IAEf,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;QAChC,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,CAA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AC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE5B,6BAA6B;IAC7B,KAAK,GAAG,KAAK,CAAC,MAAM,CAClB,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CACnB,KAAK,KAAK,CAAC;QACX,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;QAClB,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CACxC,CAAC;IAEF,yBAAyB;IACzB,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,GAAG,SAAS,qBAAqB,CAAC,IAAI;IAClD,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACvD,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,EAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,iBAAiB,EAAC,CAAC;IACtE,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAC7C,kDAAkD;QAClD,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,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.
|
|
3
|
+
"version": "3.8.0-canary-6327",
|
|
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.
|
|
23
|
-
"@docusaurus/cssnano-preset": "3.
|
|
24
|
-
"@docusaurus/logger": "3.
|
|
25
|
-
"@docusaurus/types": "3.
|
|
26
|
-
"@docusaurus/utils": "3.
|
|
22
|
+
"@docusaurus/babel": "3.8.0-canary-6327",
|
|
23
|
+
"@docusaurus/cssnano-preset": "3.8.0-canary-6327",
|
|
24
|
+
"@docusaurus/logger": "3.8.0-canary-6327",
|
|
25
|
+
"@docusaurus/types": "3.8.0-canary-6327",
|
|
26
|
+
"@docusaurus/utils": "3.8.0-canary-6327",
|
|
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": "d50539dea74625c994ac3f78926ed7b37d704c84"
|
|
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
|
|
package/src/currentBundler.ts
CHANGED
|
@@ -104,3 +104,46 @@ export async function getProgressBarPlugin({
|
|
|
104
104
|
|
|
105
105
|
return WebpackBar;
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
export async function registerBundlerTracing({
|
|
109
|
+
currentBundler,
|
|
110
|
+
}: {
|
|
111
|
+
currentBundler: CurrentBundler;
|
|
112
|
+
}): Promise<() => Promise<void>> {
|
|
113
|
+
if (currentBundler.name === 'rspack') {
|
|
114
|
+
const Rspack = await importRspack();
|
|
115
|
+
|
|
116
|
+
// See https://rspack.dev/contribute/development/profiling
|
|
117
|
+
// File can be opened with https://ui.perfetto.dev/
|
|
118
|
+
if (process.env.DOCUSAURUS_RSPACK_TRACE) {
|
|
119
|
+
// We use the env variable as the "filter" attribute
|
|
120
|
+
// See values here: https://rspack.dev/contribute/development/tracing#tracing-filter
|
|
121
|
+
let filter = process.env.DOCUSAURUS_RSPACK_TRACE;
|
|
122
|
+
|
|
123
|
+
if (filter === 'true' || filter === '1') {
|
|
124
|
+
// Default value recommended by the Rspack team
|
|
125
|
+
// It's also what the CLI uses for the "overview" preset:
|
|
126
|
+
// https://github.com/web-infra-dev/rspack/blob/v1.3.10/packages/rspack-cli/src/utils/profile.ts
|
|
127
|
+
filter = 'info';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
await Rspack.experiments.globalTrace.register(
|
|
131
|
+
filter,
|
|
132
|
+
'chrome',
|
|
133
|
+
'./rspack-tracing.json',
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
console.info(`Rspack tracing registered, filter=${filter}`);
|
|
137
|
+
|
|
138
|
+
return async () => {
|
|
139
|
+
await Rspack.experiments.globalTrace.cleanup();
|
|
140
|
+
console.log(`Rspack tracing cleaned up, filter=${filter}`);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// We don't support Webpack tracing at the moment
|
|
146
|
+
return async () => {
|
|
147
|
+
// noop
|
|
148
|
+
};
|
|
149
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -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
|
+
};
|