@shuvi/error-overlay 1.0.0-rc.6
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/client.d.ts +15 -0
- package/lib/client.js +168 -0
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +10 -0
- package/lib/iframe-bundle.js +2629 -0
- package/lib/iframeScript.d.ts +1 -0
- package/lib/iframeScript.js +66 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +22 -0
- package/lib/middleware/helper/createOriginalStackFrame.d.ts +15 -0
- package/lib/middleware/helper/createOriginalStackFrame.js +59 -0
- package/lib/middleware/helper/findOriginalSourcePositionAndContent.d.ts +7 -0
- package/lib/middleware/helper/findOriginalSourcePositionAndContent.js +49 -0
- package/lib/middleware/helper/getModuleById.d.ts +2 -0
- package/lib/middleware/helper/getModuleById.js +7 -0
- package/lib/middleware/helper/getOriginalStackFrame.d.ts +6 -0
- package/lib/middleware/helper/getOriginalStackFrame.js +79 -0
- package/lib/middleware/helper/getSourceById.d.ts +6 -0
- package/lib/middleware/helper/getSourceById.js +129 -0
- package/lib/middleware/helper/getSourceMapUrl.d.ts +1 -0
- package/lib/middleware/helper/getSourceMapUrl.js +19 -0
- package/lib/middleware/helper/getSourcePath.d.ts +1 -0
- package/lib/middleware/helper/getSourcePath.js +17 -0
- package/lib/middleware/index.d.ts +2 -0
- package/lib/middleware/index.js +7 -0
- package/lib/middleware/launchEditorMiddleware.d.ts +2 -0
- package/lib/middleware/launchEditorMiddleware.js +35 -0
- package/lib/middleware/stackFrameMiddleware.d.ts +2 -0
- package/lib/middleware/stackFrameMiddleware.js +103 -0
- package/lib/view/ErrorOverlay.d.ts +2 -0
- package/lib/view/ErrorOverlay.js +80 -0
- package/lib/view/components/Dialog/Dialog.d.ts +10 -0
- package/lib/view/components/Dialog/Dialog.js +75 -0
- package/lib/view/components/Dialog/DialogBody.d.ts +7 -0
- package/lib/view/components/Dialog/DialogBody.js +8 -0
- package/lib/view/components/Dialog/DialogContent.d.ts +7 -0
- package/lib/view/components/Dialog/DialogContent.js +8 -0
- package/lib/view/components/Dialog/DialogHeader.d.ts +7 -0
- package/lib/view/components/Dialog/DialogHeader.js +8 -0
- package/lib/view/components/Dialog/index.d.ts +5 -0
- package/lib/view/components/Dialog/index.js +13 -0
- package/lib/view/components/Dialog/styles.d.ts +2 -0
- package/lib/view/components/Dialog/styles.js +92 -0
- package/lib/view/components/Errors/CallStackFrame/CallStackFrame.d.ts +10 -0
- package/lib/view/components/Errors/CallStackFrame/CallStackFrame.js +50 -0
- package/lib/view/components/Errors/CallStackFrame/index.d.ts +1 -0
- package/lib/view/components/Errors/CallStackFrame/index.js +5 -0
- package/lib/view/components/Errors/CodeFrame/CodeFrame.d.ts +7 -0
- package/lib/view/components/Errors/CodeFrame/CodeFrame.js +79 -0
- package/lib/view/components/Errors/CodeFrame/index.d.ts +1 -0
- package/lib/view/components/Errors/CodeFrame/index.js +5 -0
- package/lib/view/components/Errors/Errors.d.ts +7 -0
- package/lib/view/components/Errors/Errors.js +62 -0
- package/lib/view/components/Errors/index.d.ts +2 -0
- package/lib/view/components/Errors/index.js +7 -0
- package/lib/view/components/Errors/styles.d.ts +1 -0
- package/lib/view/components/Errors/styles.js +99 -0
- package/lib/view/components/Icons/ArrowLeftIcon.d.ts +3 -0
- package/lib/view/components/Icons/ArrowLeftIcon.js +8 -0
- package/lib/view/components/Icons/ArrowRightIcon.d.ts +3 -0
- package/lib/view/components/Icons/ArrowRightIcon.js +8 -0
- package/lib/view/components/Icons/CloseIcon.d.ts +3 -0
- package/lib/view/components/Icons/CloseIcon.js +8 -0
- package/lib/view/components/Icons/ExternalLinkIcon.d.ts +3 -0
- package/lib/view/components/Icons/ExternalLinkIcon.js +8 -0
- package/lib/view/components/Icons/WarningIcon.d.ts +3 -0
- package/lib/view/components/Icons/WarningIcon.js +8 -0
- package/lib/view/components/Icons/index.d.ts +5 -0
- package/lib/view/components/Icons/index.js +13 -0
- package/lib/view/components/NavigationBar/NavigationBar.d.ts +10 -0
- package/lib/view/components/NavigationBar/NavigationBar.js +108 -0
- package/lib/view/components/NavigationBar/index.d.ts +2 -0
- package/lib/view/components/NavigationBar/index.js +7 -0
- package/lib/view/components/NavigationBar/styles.d.ts +2 -0
- package/lib/view/components/NavigationBar/styles.js +62 -0
- package/lib/view/components/Overlay/Overlay.d.ts +8 -0
- package/lib/view/components/Overlay/Overlay.js +39 -0
- package/lib/view/components/Overlay/body-locker.d.ts +2 -0
- package/lib/view/components/Overlay/body-locker.js +37 -0
- package/lib/view/components/Overlay/index.d.ts +2 -0
- package/lib/view/components/Overlay/index.js +7 -0
- package/lib/view/components/Overlay/styles.d.ts +2 -0
- package/lib/view/components/Overlay/styles.js +45 -0
- package/lib/view/components/ShadowPortal.d.ts +5 -0
- package/lib/view/components/ShadowPortal.js +47 -0
- package/lib/view/components/Terminal/Terminal.d.ts +5 -0
- package/lib/view/components/Terminal/Terminal.js +47 -0
- package/lib/view/components/Terminal/index.d.ts +2 -0
- package/lib/view/components/Terminal/index.js +7 -0
- package/lib/view/components/Terminal/styles.d.ts +2 -0
- package/lib/view/components/Terminal/styles.js +31 -0
- package/lib/view/components/Toast/Toast.d.ts +7 -0
- package/lib/view/components/Toast/Toast.js +8 -0
- package/lib/view/components/Toast/index.d.ts +2 -0
- package/lib/view/components/Toast/index.js +7 -0
- package/lib/view/components/Toast/styles.d.ts +2 -0
- package/lib/view/components/Toast/styles.js +31 -0
- package/lib/view/container/BuildError.d.ts +6 -0
- package/lib/view/container/BuildError.js +55 -0
- package/lib/view/container/RuntimeError.d.ts +11 -0
- package/lib/view/container/RuntimeError.js +205 -0
- package/lib/view/container/index.d.ts +2 -0
- package/lib/view/container/index.js +7 -0
- package/lib/view/errorTypeHandler.d.ts +27 -0
- package/lib/view/errorTypeHandler.js +42 -0
- package/lib/view/helpers/getErrorByType.d.ts +9 -0
- package/lib/view/helpers/getErrorByType.js +36 -0
- package/lib/view/helpers/nodeStackFrames.d.ts +7 -0
- package/lib/view/helpers/nodeStackFrames.js +70 -0
- package/lib/view/helpers/noop-template.d.ts +1 -0
- package/lib/view/helpers/noop-template.js +9 -0
- package/lib/view/helpers/parseStack.d.ts +3 -0
- package/lib/view/helpers/parseStack.js +31 -0
- package/lib/view/helpers/stack-frame.d.ts +12 -0
- package/lib/view/helpers/stack-frame.js +60 -0
- package/lib/view/hooks/use-on-click-outside.d.ts +1 -0
- package/lib/view/hooks/use-on-click-outside.js +49 -0
- package/lib/view/styles/Base.d.ts +2 -0
- package/lib/view/styles/Base.js +84 -0
- package/lib/view/styles/ComponentStyles.d.ts +2 -0
- package/lib/view/styles/ComponentStyles.js +27 -0
- package/lib/view/styles/CssReset.d.ts +2 -0
- package/lib/view/styles/CssReset.js +361 -0
- package/lib/view/styles/index.d.ts +3 -0
- package/lib/view/styles/index.js +9 -0
- package/package.json +50 -0
- package/umd/client.d.ts +15 -0
- package/umd/constants.d.ts +7 -0
- package/umd/iframeScript.d.ts +1 -0
- package/umd/index.d.ts +2 -0
- package/umd/index.js +460 -0
- package/umd/middleware/helper/createOriginalStackFrame.d.ts +15 -0
- package/umd/middleware/helper/findOriginalSourcePositionAndContent.d.ts +7 -0
- package/umd/middleware/helper/getModuleById.d.ts +2 -0
- package/umd/middleware/helper/getOriginalStackFrame.d.ts +6 -0
- package/umd/middleware/helper/getSourceById.d.ts +6 -0
- package/umd/middleware/helper/getSourceMapUrl.d.ts +1 -0
- package/umd/middleware/helper/getSourcePath.d.ts +1 -0
- package/umd/middleware/helper/index.d.ts +5 -0
- package/umd/middleware/index.d.ts +2 -0
- package/umd/middleware/launchEditorMiddleware.d.ts +2 -0
- package/umd/middleware/stackFrameMiddleware.d.ts +2 -0
- package/umd/view/ErrorOverlay.d.ts +2 -0
- package/umd/view/components/Dialog/Dialog.d.ts +10 -0
- package/umd/view/components/Dialog/DialogBody.d.ts +7 -0
- package/umd/view/components/Dialog/DialogContent.d.ts +7 -0
- package/umd/view/components/Dialog/DialogHeader.d.ts +7 -0
- package/umd/view/components/Dialog/index.d.ts +5 -0
- package/umd/view/components/Dialog/styles.d.ts +2 -0
- package/umd/view/components/Errors/CallStackFrame/CallStackFrame.d.ts +10 -0
- package/umd/view/components/Errors/CallStackFrame/index.d.ts +1 -0
- package/umd/view/components/Errors/CodeFrame/CodeFrame.d.ts +7 -0
- package/umd/view/components/Errors/CodeFrame/index.d.ts +1 -0
- package/umd/view/components/Errors/Errors.d.ts +7 -0
- package/umd/view/components/Errors/index.d.ts +2 -0
- package/umd/view/components/Errors/styles.d.ts +1 -0
- package/umd/view/components/Icons/ArrowLeftIcon.d.ts +3 -0
- package/umd/view/components/Icons/ArrowRightIcon.d.ts +3 -0
- package/umd/view/components/Icons/CloseIcon.d.ts +3 -0
- package/umd/view/components/Icons/ExternalLinkIcon.d.ts +3 -0
- package/umd/view/components/Icons/WarningIcon.d.ts +3 -0
- package/umd/view/components/Icons/index.d.ts +5 -0
- package/umd/view/components/NavigationBar/NavigationBar.d.ts +10 -0
- package/umd/view/components/NavigationBar/index.d.ts +2 -0
- package/umd/view/components/NavigationBar/styles.d.ts +2 -0
- package/umd/view/components/Overlay/Overlay.d.ts +8 -0
- package/umd/view/components/Overlay/body-locker.d.ts +2 -0
- package/umd/view/components/Overlay/index.d.ts +2 -0
- package/umd/view/components/Overlay/styles.d.ts +2 -0
- package/umd/view/components/ShadowPortal.d.ts +5 -0
- package/umd/view/components/Terminal/Terminal.d.ts +5 -0
- package/umd/view/components/Terminal/index.d.ts +2 -0
- package/umd/view/components/Terminal/styles.d.ts +2 -0
- package/umd/view/components/Toast/Toast.d.ts +7 -0
- package/umd/view/components/Toast/index.d.ts +2 -0
- package/umd/view/components/Toast/styles.d.ts +2 -0
- package/umd/view/container/BuildError.d.ts +6 -0
- package/umd/view/container/RuntimeError.d.ts +11 -0
- package/umd/view/container/index.d.ts +2 -0
- package/umd/view/errorTypeHandler.d.ts +27 -0
- package/umd/view/helpers/getErrorByType.d.ts +9 -0
- package/umd/view/helpers/nodeStackFrames.d.ts +7 -0
- package/umd/view/helpers/noop-template.d.ts +1 -0
- package/umd/view/helpers/parseStack.d.ts +3 -0
- package/umd/view/helpers/stack-frame.d.ts +12 -0
- package/umd/view/hooks/use-on-click-outside.d.ts +1 -0
- package/umd/view/styles/Base.d.ts +2 -0
- package/umd/view/styles/ComponentStyles.d.ts +2 -0
- package/umd/view/styles/CssReset.d.ts +2 -0
- package/umd/view/styles/index.d.ts +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
+
//@ts-nocheck
|
|
31
|
+
/**
|
|
32
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the MIT license found in the
|
|
35
|
+
* LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/
|
|
37
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
38
|
+
const ErrorOverlay_1 = require("./view/ErrorOverlay");
|
|
39
|
+
const errorTypeHandler = __importStar(require("./view/errorTypeHandler"));
|
|
40
|
+
let iframeRoot = null;
|
|
41
|
+
let errorBody = null;
|
|
42
|
+
let isFirstRender = true;
|
|
43
|
+
function render(errorOverlayProps) {
|
|
44
|
+
errorTypeHandler.emit(errorOverlayProps);
|
|
45
|
+
return (0, jsx_runtime_1.jsx)(ErrorOverlay_1.ErrorOverlay, {});
|
|
46
|
+
}
|
|
47
|
+
window.updateContent = function updateContent(errorOverlayProps) {
|
|
48
|
+
let renderedElement = render(errorOverlayProps);
|
|
49
|
+
if (renderedElement === null) {
|
|
50
|
+
errorBody.unmount();
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// Update the overlay
|
|
54
|
+
if (isFirstRender) {
|
|
55
|
+
errorBody = react_dom_1.default.createRoot(iframeRoot);
|
|
56
|
+
errorBody.render(renderedElement);
|
|
57
|
+
isFirstRender = false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
document.body.style.margin = '0';
|
|
62
|
+
// Keep popup within body boundaries for iOS Safari
|
|
63
|
+
document.body.style['max-width'] = '100vw';
|
|
64
|
+
iframeRoot = document.createElement('div');
|
|
65
|
+
document.body.appendChild(iframeRoot);
|
|
66
|
+
window.parent.__SHUVI_ERROR_OVERLAY_GLOBAL_HOOK__.iframeReady();
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This package 'error-overlay' is a modified version of the Next.js that can be found here:
|
|
3
|
+
// https://github.com/vercel/next.js/blob/canary/packages/react-dev-overlay/
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.getServerError = void 0;
|
|
20
|
+
__exportStar(require("./client"), exports);
|
|
21
|
+
var nodeStackFrames_1 = require("./view/helpers/nodeStackFrames");
|
|
22
|
+
Object.defineProperty(exports, "getServerError", { enumerable: true, get: function () { return nodeStackFrames_1.getServerError; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StackFrame } from 'stacktrace-parser';
|
|
2
|
+
import type webpack from '@shuvi/toolpack/lib/webpack';
|
|
3
|
+
export declare type OriginalStackFrameResponse = {
|
|
4
|
+
originalStackFrame: StackFrame;
|
|
5
|
+
originalCodeFrame: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function createOriginalStackFrame({ line, column, source, modulePath, frame, errorMessage, compilation }: {
|
|
8
|
+
line: number;
|
|
9
|
+
column: number | null;
|
|
10
|
+
source: any;
|
|
11
|
+
modulePath?: string;
|
|
12
|
+
frame: any;
|
|
13
|
+
errorMessage?: string;
|
|
14
|
+
compilation?: webpack.Compilation;
|
|
15
|
+
}): Promise<OriginalStackFrameResponse | null>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createOriginalStackFrame = void 0;
|
|
13
|
+
const code_frame_1 = require("@babel/code-frame");
|
|
14
|
+
const getSourcePath_1 = require("./getSourcePath");
|
|
15
|
+
const getModuleById_1 = require("./getModuleById");
|
|
16
|
+
const findOriginalSourcePositionAndContent_1 = require("./findOriginalSourcePositionAndContent");
|
|
17
|
+
function createOriginalStackFrame({ line, column, source, modulePath, frame, errorMessage, compilation }) {
|
|
18
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const match = errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.match(/'([^']+)' module/);
|
|
21
|
+
const moduleNotFound = match && match[1];
|
|
22
|
+
const result = moduleNotFound && compilation
|
|
23
|
+
? (_d = (_c = (_b = (_a = (0, getModuleById_1.getModuleById)(modulePath, compilation)) === null || _a === void 0 ? void 0 : _a.buildInfo) === null || _b === void 0 ? void 0 : _b.importLocByPath) === null || _c === void 0 ? void 0 : _c.get(moduleNotFound)) !== null && _d !== void 0 ? _d : null
|
|
24
|
+
: yield (0, findOriginalSourcePositionAndContent_1.findOriginalSourcePositionAndContent)(source, {
|
|
25
|
+
line,
|
|
26
|
+
column
|
|
27
|
+
});
|
|
28
|
+
if (result === null) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const { sourcePosition, sourceContent } = result;
|
|
32
|
+
if (!sourcePosition.source) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const filePath = (0, getSourcePath_1.getSourcePath)(sourcePosition.source) || modulePath || '';
|
|
36
|
+
const originalFrame = {
|
|
37
|
+
file: sourceContent ? filePath : sourcePosition.source,
|
|
38
|
+
lineNumber: sourcePosition.line,
|
|
39
|
+
column: sourcePosition.column,
|
|
40
|
+
methodName: frame.methodName,
|
|
41
|
+
arguments: []
|
|
42
|
+
};
|
|
43
|
+
const originalCodeFrame = !((_f = (_e = originalFrame.file) === null || _e === void 0 ? void 0 : _e.includes('node_modules')) !== null && _f !== void 0 ? _f : true) &&
|
|
44
|
+
sourceContent &&
|
|
45
|
+
sourcePosition.line
|
|
46
|
+
? (0, code_frame_1.codeFrameColumns)(sourceContent, {
|
|
47
|
+
start: {
|
|
48
|
+
line: sourcePosition.line,
|
|
49
|
+
column: (_g = sourcePosition.column) !== null && _g !== void 0 ? _g : 0
|
|
50
|
+
}
|
|
51
|
+
}, { forceColor: true })
|
|
52
|
+
: null;
|
|
53
|
+
return {
|
|
54
|
+
originalStackFrame: originalFrame,
|
|
55
|
+
originalCodeFrame
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.createOriginalStackFrame = createOriginalStackFrame;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.findOriginalSourcePositionAndContent = void 0;
|
|
13
|
+
const source_map_1 = require("source-map");
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const util_1 = require("source-map/lib/util");
|
|
16
|
+
function findOriginalSourcePositionAndContent(webpackSource, position) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
let consumer;
|
|
20
|
+
let content;
|
|
21
|
+
// the webpackSource.map() may be broken, check the validity in advance
|
|
22
|
+
try {
|
|
23
|
+
content = (0, util_1.parseSourceMapInput)(webpackSource.map());
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
consumer = yield new source_map_1.SourceMapConsumer(content);
|
|
30
|
+
const sourcePosition = consumer.originalPositionFor({
|
|
31
|
+
line: position.line,
|
|
32
|
+
column: (_a = position.column) !== null && _a !== void 0 ? _a : 0
|
|
33
|
+
});
|
|
34
|
+
if (!sourcePosition.source) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const sourceContent = (_b = consumer.sourceContentFor(sourcePosition.source,
|
|
38
|
+
/* returnNullOnMissing */ true)) !== null && _b !== void 0 ? _b : null;
|
|
39
|
+
return {
|
|
40
|
+
sourcePosition,
|
|
41
|
+
sourceContent
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
consumer && consumer.destroy();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.findOriginalSourcePositionAndContent = findOriginalSourcePositionAndContent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getModuleById = void 0;
|
|
4
|
+
function getModuleById(id, compilation) {
|
|
5
|
+
return [...compilation.modules].find(searchModule => compilation.chunkGraph.getModuleId(searchModule) === id);
|
|
6
|
+
}
|
|
7
|
+
exports.getModuleById = getModuleById;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StackFrame } from 'stacktrace-parser';
|
|
2
|
+
import type webpack from '@shuvi/toolpack/lib/webpack';
|
|
3
|
+
import type { Source } from './getSourceById';
|
|
4
|
+
import type { OriginalStackFrame } from '../../view/helpers/stack-frame';
|
|
5
|
+
export { OriginalStackFrame };
|
|
6
|
+
export declare function getOriginalStackFrame(frame: StackFrame, cache: Map<string, Source | null>, resolveBuildFile: (...paths: string[]) => string, buildDir: string, errorMessage?: string, compilation?: webpack.Compilation): Promise<OriginalStackFrame>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getOriginalStackFrame = void 0;
|
|
13
|
+
const createOriginalStackFrame_1 = require("./createOriginalStackFrame");
|
|
14
|
+
function getOriginalStackFrame(frame, cache, resolveBuildFile, buildDir, errorMessage, compilation) {
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (!(((_a = frame.file) === null || _a === void 0 ? void 0 : _a.startsWith('webpack-internal:')) ||
|
|
18
|
+
((_b = frame.file) === null || _b === void 0 ? void 0 : _b.startsWith('file:')))) {
|
|
19
|
+
return {
|
|
20
|
+
error: false,
|
|
21
|
+
reason: null,
|
|
22
|
+
external: true,
|
|
23
|
+
expanded: false,
|
|
24
|
+
sourceStackFrame: frame,
|
|
25
|
+
originalStackFrame: null,
|
|
26
|
+
originalCodeFrame: null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (cache.get(frame.file) === null) {
|
|
30
|
+
return {
|
|
31
|
+
error: true,
|
|
32
|
+
reason: 'No Content',
|
|
33
|
+
external: false,
|
|
34
|
+
expanded: false,
|
|
35
|
+
sourceStackFrame: frame,
|
|
36
|
+
originalStackFrame: null,
|
|
37
|
+
originalCodeFrame: null
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const frameLine = parseInt((_d = (_c = frame.lineNumber) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : '', 10);
|
|
41
|
+
let frameColumn = parseInt((_f = (_e = frame.column) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '', 10);
|
|
42
|
+
if (!frameColumn) {
|
|
43
|
+
frameColumn = null;
|
|
44
|
+
}
|
|
45
|
+
const originalStackFrameResponse = yield (0, createOriginalStackFrame_1.createOriginalStackFrame)({
|
|
46
|
+
line: frameLine,
|
|
47
|
+
column: frameColumn,
|
|
48
|
+
source: cache.get(frame.file),
|
|
49
|
+
frame,
|
|
50
|
+
modulePath: resolveBuildFile(buildDir, frame.file.replace(/^(webpack-internal:\/\/\/|file:\/\/)/, '')),
|
|
51
|
+
errorMessage,
|
|
52
|
+
compilation
|
|
53
|
+
});
|
|
54
|
+
if (originalStackFrameResponse === null) {
|
|
55
|
+
return {
|
|
56
|
+
error: true,
|
|
57
|
+
reason: 'No Content',
|
|
58
|
+
external: false,
|
|
59
|
+
expanded: false,
|
|
60
|
+
sourceStackFrame: frame,
|
|
61
|
+
originalStackFrame: null,
|
|
62
|
+
originalCodeFrame: null
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
error: false,
|
|
67
|
+
reason: null,
|
|
68
|
+
external: false,
|
|
69
|
+
expanded: !Boolean(
|
|
70
|
+
/* collapsed */
|
|
71
|
+
(_k = (((_g = frame.file) === null || _g === void 0 ? void 0 : _g.includes('node_modules')) ||
|
|
72
|
+
((_j = (_h = originalStackFrameResponse.originalStackFrame) === null || _h === void 0 ? void 0 : _h.file) === null || _j === void 0 ? void 0 : _j.includes('node_modules')))) !== null && _k !== void 0 ? _k : true),
|
|
73
|
+
sourceStackFrame: frame,
|
|
74
|
+
originalStackFrame: originalStackFrameResponse.originalStackFrame,
|
|
75
|
+
originalCodeFrame: originalStackFrameResponse.originalCodeFrame || null
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.getOriginalStackFrame = getOriginalStackFrame;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RawSourceMap } from 'source-map';
|
|
2
|
+
import type webpack from '@shuvi/toolpack/lib/webpack';
|
|
3
|
+
export declare type Source = {
|
|
4
|
+
map: () => RawSourceMap;
|
|
5
|
+
} | null;
|
|
6
|
+
export declare function getSourceById(isFile: boolean, id: string, compiler: webpack.Compiler, resolveBuildFile: (...paths: string[]) => string, buildDir: string, compilation?: webpack.Compilation): Promise<Source>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.getSourceById = void 0;
|
|
39
|
+
const data_uri_to_buffer_1 = __importDefault(require("data-uri-to-buffer"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const getSourceMapUrl_1 = require("./getSourceMapUrl");
|
|
42
|
+
const getModuleById_1 = require("./getModuleById");
|
|
43
|
+
const readFileWrapper = (url, compiler) => {
|
|
44
|
+
return new Promise(resolve => {
|
|
45
|
+
compiler.outputFileSystem.readFile(url, (err, res) => {
|
|
46
|
+
if (err) {
|
|
47
|
+
resolve(null);
|
|
48
|
+
}
|
|
49
|
+
resolve(res === null || res === void 0 ? void 0 : res.toString());
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
function getRawSourceMap(fileUrl, compiler) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
//fetch sourcemap directly first
|
|
56
|
+
const url = fileUrl + '.map';
|
|
57
|
+
let sourceMapContent = null;
|
|
58
|
+
sourceMapContent = yield readFileWrapper(url, compiler);
|
|
59
|
+
if (sourceMapContent !== null) {
|
|
60
|
+
return sourceMapContent;
|
|
61
|
+
}
|
|
62
|
+
//fetch sourcemap by fileContent
|
|
63
|
+
const fileContent = yield readFileWrapper(fileUrl, compiler);
|
|
64
|
+
if (fileContent == null) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const sourceUrl = (0, getSourceMapUrl_1.getSourceMapUrl)(fileContent);
|
|
68
|
+
if (!sourceUrl) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
if (!(sourceUrl === null || sourceUrl === void 0 ? void 0 : sourceUrl.startsWith('data:'))) {
|
|
72
|
+
const index = fileUrl.lastIndexOf('/');
|
|
73
|
+
const urlFromFile = fileUrl.substring(0, index + 1) + sourceUrl;
|
|
74
|
+
return yield readFileWrapper(urlFromFile, compiler);
|
|
75
|
+
}
|
|
76
|
+
let buffer;
|
|
77
|
+
try {
|
|
78
|
+
buffer = (0, data_uri_to_buffer_1.default)(sourceUrl);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error('Failed to parse source map URL:', err);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (buffer.type !== 'application/json') {
|
|
85
|
+
console.error(`Unknown source map type: ${buffer.typeFull}.`);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(buffer.toString());
|
|
90
|
+
}
|
|
91
|
+
catch (_a) {
|
|
92
|
+
console.error('Failed to parse source map.');
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function getSourceById(isFile, id, compiler, resolveBuildFile, buildDir, compilation) {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
if (isFile) {
|
|
101
|
+
const pathName = path.isAbsolute(id)
|
|
102
|
+
? id
|
|
103
|
+
: resolveBuildFile(buildDir, id);
|
|
104
|
+
const map = yield getRawSourceMap(pathName, compiler);
|
|
105
|
+
if (map === null) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
map() {
|
|
110
|
+
return map;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
if (!compilation) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const module = (0, getModuleById_1.getModuleById)(id, compilation);
|
|
119
|
+
return ((_b = (module &&
|
|
120
|
+
((_a = compilation.codeGenerationResults
|
|
121
|
+
.get(module)) === null || _a === void 0 ? void 0 : _a.sources.get('javascript')))) !== null && _b !== void 0 ? _b : null);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
console.error(`Failed to lookup module by ID ("${id}"):`, err);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
exports.getSourceById = getSourceById;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSourceMapUrl(fileContents: string): string | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSourceMapUrl = void 0;
|
|
4
|
+
function getSourceMapUrl(fileContents) {
|
|
5
|
+
const regex = /\/\/[#@] ?sourceMappingURL=([^\s'"]+)\s*$/gm;
|
|
6
|
+
let match = null;
|
|
7
|
+
for (;;) {
|
|
8
|
+
let next = regex.exec(fileContents);
|
|
9
|
+
if (next == null) {
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
match = next;
|
|
13
|
+
}
|
|
14
|
+
if (!(match && match[1])) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return match[1].toString();
|
|
18
|
+
}
|
|
19
|
+
exports.getSourceMapUrl = getSourceMapUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSourcePath(source: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSourcePath = void 0;
|
|
4
|
+
function getSourcePath(source) {
|
|
5
|
+
// Webpack prefixes certain source paths with this path
|
|
6
|
+
if (source.startsWith('webpack:///')) {
|
|
7
|
+
return source.substring(11);
|
|
8
|
+
}
|
|
9
|
+
if (source.startsWith('webpack://')) {
|
|
10
|
+
return source.replace(/^webpack:\/\/[^/]+/ /* webpack://namaspcae/resourcepath */, '');
|
|
11
|
+
}
|
|
12
|
+
if (source.startsWith('/')) {
|
|
13
|
+
return source.substring(1);
|
|
14
|
+
}
|
|
15
|
+
return source;
|
|
16
|
+
}
|
|
17
|
+
exports.getSourcePath = getSourcePath;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stackFrameMiddleware = exports.launchEditorMiddleware = void 0;
|
|
4
|
+
var launchEditorMiddleware_1 = require("./launchEditorMiddleware");
|
|
5
|
+
Object.defineProperty(exports, "launchEditorMiddleware", { enumerable: true, get: function () { return launchEditorMiddleware_1.launchEditorMiddleware; } });
|
|
6
|
+
var stackFrameMiddleware_1 = require("./stackFrameMiddleware");
|
|
7
|
+
Object.defineProperty(exports, "stackFrameMiddleware", { enumerable: true, get: function () { return stackFrameMiddleware_1.stackFrameMiddleware; } });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.launchEditorMiddleware = void 0;
|
|
7
|
+
const launch_editor_1 = __importDefault(require("launch-editor"));
|
|
8
|
+
const url_1 = __importDefault(require("url"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const getSourcePath_1 = require("./helper/getSourcePath");
|
|
11
|
+
function launchEditorMiddleware(launchEditorEndpoint, rootDir) {
|
|
12
|
+
return function (req, res, next) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (req.url.startsWith(launchEditorEndpoint)) {
|
|
15
|
+
const { query } = url_1.default.parse(req.url, true);
|
|
16
|
+
const lineNumber = parseInt(query.lineNumber, 10) || 1;
|
|
17
|
+
const colNumber = parseInt(query.colNumber, 10) || 1;
|
|
18
|
+
const frameFile = ((_a = query.file) === null || _a === void 0 ? void 0 : _a.toString()) || null;
|
|
19
|
+
if (frameFile == null) {
|
|
20
|
+
res.statusCode = 400;
|
|
21
|
+
res.write('Bad Request');
|
|
22
|
+
res.end();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const filePath = path_1.default.resolve(rootDir, (0, getSourcePath_1.getSourcePath)(`${frameFile}:${lineNumber}:${colNumber}`));
|
|
26
|
+
(0, launch_editor_1.default)(filePath);
|
|
27
|
+
res.end();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
next();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.launchEditorMiddleware = launchEditorMiddleware;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
export declare function stackFrameMiddleware(originalStackFrameEndpoint: string, bundler: any, resolveBuildFile: (...paths: string[]) => string, buildDefaultDir: string, buildServerDir: string): (req: IncomingMessage, res: ServerResponse, next: Function) => Promise<any>;
|