@shuvi/error-overlay 2.0.0-dev.19 → 2.0.0-dev.21
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/middleware/helper/createOriginalStackFrame.js +21 -8
- package/lib/middleware/helper/getModuleById.js +2 -6
- package/lib/middleware/helper/getOriginalStackFrame.js +4 -4
- package/lib/middleware/helper/getSourceById.js +26 -8
- package/lib/middleware/stackFrameMiddleware.js +2 -2
- package/package.json +3 -3
|
@@ -16,19 +16,32 @@ const getModuleById_1 = require("./getModuleById");
|
|
|
16
16
|
const findOriginalSourcePositionAndContent_1 = require("./findOriginalSourcePositionAndContent");
|
|
17
17
|
function createOriginalStackFrame(_a) {
|
|
18
18
|
return __awaiter(this, arguments, void 0, function* ({ line, column, source, modulePath, frame, errorMessage, compilation }) {
|
|
19
|
-
var _b, _c, _d, _e, _f, _g
|
|
19
|
+
var _b, _c, _d, _e, _f, _g;
|
|
20
20
|
const match = errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.match(/'([^']+)' module/);
|
|
21
21
|
const moduleNotFound = match && match[1];
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* Handle module not found errors by attempting to get import location.
|
|
24
|
+
* Falls back to normal source mapping if buildInfo API is not available or if no module error.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
let result = null;
|
|
27
|
+
if (moduleNotFound && compilation) {
|
|
28
|
+
try {
|
|
29
|
+
// Try to use buildInfo.importLocByPath if available (Webpack compatibility)
|
|
30
|
+
const module = (0, getModuleById_1.getModuleById)(modulePath, compilation);
|
|
31
|
+
result = (_d = (_c = (_b = module === null || module === void 0 ? void 0 : module.buildInfo) === null || _b === void 0 ? void 0 : _b.importLocByPath) === null || _c === void 0 ? void 0 : _c.get(moduleNotFound)) !== null && _d !== void 0 ? _d : null;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// Rspack may not support this API, fall back to source mapping
|
|
35
|
+
result = null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// If no module error or buildInfo lookup failed, use source mapping
|
|
39
|
+
if (!result) {
|
|
40
|
+
result = yield (0, findOriginalSourcePositionAndContent_1.findOriginalSourcePositionAndContent)(source, {
|
|
29
41
|
line,
|
|
30
42
|
column
|
|
31
43
|
});
|
|
44
|
+
}
|
|
32
45
|
if (result === null) {
|
|
33
46
|
return null;
|
|
34
47
|
}
|
|
@@ -44,13 +57,13 @@ function createOriginalStackFrame(_a) {
|
|
|
44
57
|
methodName: frame.methodName,
|
|
45
58
|
arguments: []
|
|
46
59
|
};
|
|
47
|
-
const originalCodeFrame = !((
|
|
60
|
+
const originalCodeFrame = !((_f = (_e = originalFrame.file) === null || _e === void 0 ? void 0 : _e.includes('node_modules')) !== null && _f !== void 0 ? _f : true) &&
|
|
48
61
|
sourceContent &&
|
|
49
62
|
sourcePosition.line
|
|
50
63
|
? (0, code_frame_1.codeFrameColumns)(sourceContent, {
|
|
51
64
|
start: {
|
|
52
65
|
line: sourcePosition.line,
|
|
53
|
-
column: (
|
|
66
|
+
column: (_g = sourcePosition.column) !== null && _g !== void 0 ? _g : 0
|
|
54
67
|
}
|
|
55
68
|
}, { forceColor: true })
|
|
56
69
|
: null;
|
|
@@ -3,12 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getModuleById = getModuleById;
|
|
4
4
|
function getModuleById(id, compilation) {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Find module by ID using ChunkGraph API.
|
|
7
|
+
* Both Webpack and Rspack support this API pattern.
|
|
8
8
|
*/
|
|
9
|
-
// return [...compilation.modules].find(
|
|
10
|
-
// searchModule => compilation.chunkGraph.getModuleId(searchModule) === id
|
|
11
|
-
// );
|
|
12
|
-
// Fallback implementation for Rspack
|
|
13
9
|
return [...compilation.modules].find(searchModule => compilation.chunkGraph.getModuleId(searchModule) === id);
|
|
14
10
|
}
|
|
@@ -15,8 +15,8 @@ function getOriginalStackFrame(frame, cache, resolveBuildFile, buildDir, errorMe
|
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Handle internal module URLs from both Webpack and Rspack.
|
|
19
|
+
* Rspack uses 'rspack-internal:' prefix, while Webpack uses 'webpack-internal:'.
|
|
20
20
|
*/
|
|
21
21
|
if (!(((_a = frame.file) === null || _a === void 0 ? void 0 : _a.startsWith('webpack-internal:')) ||
|
|
22
22
|
((_b = frame.file) === null || _b === void 0 ? void 0 : _b.startsWith('rspack-internal:')) ||
|
|
@@ -48,8 +48,8 @@ function getOriginalStackFrame(frame, cache, resolveBuildFile, buildDir, errorMe
|
|
|
48
48
|
frameColumn = null;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
51
|
+
* Strip internal URL prefixes to get the actual module path.
|
|
52
|
+
* Both Webpack and Rspack internal URLs are handled uniformly.
|
|
53
53
|
*/
|
|
54
54
|
const originalStackFrameResponse = yield (0, createOriginalStackFrame_1.createOriginalStackFrame)({
|
|
55
55
|
line: frameLine,
|
|
@@ -43,8 +43,7 @@ const getModuleById_1 = require("./getModuleById");
|
|
|
43
43
|
const readFileWrapper = (url, compiler) => {
|
|
44
44
|
return new Promise(resolve => {
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
* TODO: Verify Rspack's outputFileSystem implementation and update accordingly.
|
|
46
|
+
* Both Webpack and Rspack use the same outputFileSystem API pattern.
|
|
48
47
|
*/
|
|
49
48
|
if (!compiler.outputFileSystem) {
|
|
50
49
|
resolve(null);
|
|
@@ -104,7 +103,7 @@ function getRawSourceMap(fileUrl, compiler) {
|
|
|
104
103
|
}
|
|
105
104
|
function getSourceById(isFile, id, compiler, resolveBuildFile, buildDir, compilation) {
|
|
106
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
var _a
|
|
106
|
+
var _a;
|
|
108
107
|
if (isFile) {
|
|
109
108
|
const pathName = path.isAbsolute(id)
|
|
110
109
|
? id
|
|
@@ -125,12 +124,31 @@ function getSourceById(isFile, id, compiler, resolveBuildFile, buildDir, compila
|
|
|
125
124
|
}
|
|
126
125
|
const module = (0, getModuleById_1.getModuleById)(id, compilation);
|
|
127
126
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
127
|
+
* Try to get source from codeGenerationResults API.
|
|
128
|
+
* Handle potential differences between Webpack and Rspack gracefully.
|
|
130
129
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
if (module) {
|
|
131
|
+
try {
|
|
132
|
+
// Try the standard codeGenerationResults API
|
|
133
|
+
const codeGenResults = compilation.codeGenerationResults;
|
|
134
|
+
if (codeGenResults) {
|
|
135
|
+
const moduleResults = codeGenResults.get(module);
|
|
136
|
+
const source = (_a = moduleResults === null || moduleResults === void 0 ? void 0 : moduleResults.sources) === null || _a === void 0 ? void 0 : _a.get('javascript');
|
|
137
|
+
if (source) {
|
|
138
|
+
return source;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Fallback: try alternative source extraction methods
|
|
142
|
+
// This handles cases where Rspack might use different internal structures
|
|
143
|
+
if (module._source) {
|
|
144
|
+
return module._source;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
console.warn('Failed to extract source using codeGenerationResults, trying fallback methods');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
134
152
|
}
|
|
135
153
|
catch (err) {
|
|
136
154
|
console.error(`Failed to lookup module by ID ("${id}"):`, err);
|
|
@@ -33,8 +33,8 @@ function stackFrameMiddleware(originalStackFrameEndpoint, bundler, resolveBuildF
|
|
|
33
33
|
yield Promise.all(files.map((fileName) => __awaiter(this, void 0, void 0, function* () {
|
|
34
34
|
try {
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
36
|
+
* Strip internal URL prefixes to get module ID.
|
|
37
|
+
* Handles both Webpack (webpack-internal://) and Rspack (rspack-internal://) URL patterns.
|
|
38
38
|
*/
|
|
39
39
|
const moduleId = fileName.replace(/^(webpack-internal:\/\/\/|file:\/\/|rspack-internal:\/\/\/)/, '');
|
|
40
40
|
const source = yield (0, getSourceById_1.getSourceById)(fileName.startsWith('file:'), moduleId, compiler, resolveBuildFile, buildDir, compilation);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/error-overlay",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.21",
|
|
4
4
|
"main": "umd/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@babel/code-frame": "7.14.5",
|
|
26
|
-
"@shuvi/shared": "2.0.0-dev.
|
|
27
|
-
"@shuvi/toolpack": "2.0.0-dev.
|
|
26
|
+
"@shuvi/shared": "2.0.0-dev.21",
|
|
27
|
+
"@shuvi/toolpack": "2.0.0-dev.21",
|
|
28
28
|
"anser": "1.4.9",
|
|
29
29
|
"data-uri-to-buffer": "3.0.1",
|
|
30
30
|
"html-entities": "2.3.2",
|