@forge-kit/plugin-source-map-prase 0.0.1 → 0.0.3
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/dist/app.js +3 -5
- package/dist/node.js +2556 -0
- package/package.json +5 -3
- package/src/App.less +43 -74
- package/src/App.tsx +98 -54
- package/src/components/map-input-panel/index.less +71 -79
- package/src/components/map-input-panel/index.tsx +65 -69
- package/src/components/panel-card/index.less +21 -0
- package/src/components/panel-card/index.tsx +6 -8
- package/src/components/trace-chain/index.less +126 -125
- package/src/components/trace-chain/index.tsx +25 -24
- package/src/main.tsx +1 -1
- package/src/node/index.ts +6 -0
- package/src/{utils/source-map → node/trace/core}/base/registry.ts +14 -11
- package/src/{utils/source-map → node/trace/core}/base/types.ts +1 -0
- package/src/node/trace/core/domain/chain-slots.ts +33 -0
- package/src/{utils/source-map → node/trace/core}/domain/source-content.ts +15 -2
- package/src/node/trace/core/domain/trace-resolver.ts +179 -0
- package/src/node/trace/core/domain/view-model.ts +57 -0
- package/src/node/trace/resolve/context.ts +59 -0
- package/src/node/trace/resolve/index.ts +97 -0
- package/src/node/trace/resolve/input.ts +35 -0
- package/src/node/trace/resolve/snippet-limit.ts +35 -0
- package/src/node/trace/resolve/types.ts +37 -0
- package/src/node/trace/runner.ts +149 -0
- package/src/shared/trace-common.ts +104 -0
- package/src/shared/trace-contract.ts +29 -0
- package/src/types.ts +19 -0
- package/src/utils/trace-ui/index.ts +12 -0
- package/src/utils/trace-ui/state.ts +81 -0
- package/src/utils/source-map/domain/chain-slots.ts +0 -59
- package/src/utils/source-map/domain/trace-resolver.ts +0 -165
- package/src/utils/source-map/domain/view-model.ts +0 -20
- package/src/utils/source-map/facade/source-map-utils.ts +0 -212
- package/src/utils/source-map/index.ts +0 -18
- /package/src/{utils/source-map → node/trace/core}/base/constants.ts +0 -0
- /package/src/{utils/source-map → node/trace/core}/base/path.ts +0 -0
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import {DEFAULT_CONTEXT_LINE_RADIUS, MAX_TRACE_DEPTH} from "../base/constants";
|
|
2
|
-
import {createChainSlotFromFile, buildRegistryFromChainSlots, getAutoEntryFileNameFromSlots} from "../domain/chain-slots";
|
|
3
|
-
import {resolveSourceCodeFromTrace, getLastResolvedOutput} from "../domain/source-content";
|
|
4
|
-
import {resolveTraceBySourceMaps} from "../domain/trace-resolver";
|
|
5
|
-
import {toDisplayLocation, createCodeExcerpt} from "../domain/view-model";
|
|
6
|
-
import type {
|
|
7
|
-
ChainMapSlot,
|
|
8
|
-
ResolvedSourceMeta,
|
|
9
|
-
SourceMapRegistry,
|
|
10
|
-
TraceHop,
|
|
11
|
-
TraceLocation,
|
|
12
|
-
} from "../base/types";
|
|
13
|
-
|
|
14
|
-
export interface TraceOutputState {
|
|
15
|
-
traceData: TraceHop[]
|
|
16
|
-
traceCode: string
|
|
17
|
-
resolvedSourceMeta: ResolvedSourceMeta | null
|
|
18
|
-
traceHighlightLines: number[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SourceMapChainState {
|
|
22
|
-
sourceMaps: SourceMapRegistry
|
|
23
|
-
sourceMapFileNames: string[]
|
|
24
|
-
chainMapSlots: ChainMapSlot[]
|
|
25
|
-
entryFileName: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface TraceDisplayHop {
|
|
29
|
-
input: TraceLocation
|
|
30
|
-
output?: TraceLocation
|
|
31
|
-
mapFileName?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ResolveInputConfig {
|
|
35
|
-
entryFileName: string
|
|
36
|
-
entryLine: string
|
|
37
|
-
entryColumn: string
|
|
38
|
-
contextLineRadius: string
|
|
39
|
-
mapCount: number
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ResolveTaskContext {
|
|
43
|
-
entry: TraceLocation
|
|
44
|
-
contextLineRadius: number
|
|
45
|
-
sourceMaps: SourceMapRegistry
|
|
46
|
-
sourceMapFileNames: string[]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
type ResolveInputValidation =
|
|
50
|
-
| { ok: true; entry: TraceLocation; contextLineRadius: number }
|
|
51
|
-
| { ok: false; message: string }
|
|
52
|
-
|
|
53
|
-
export class SourceMapUtils {
|
|
54
|
-
static readonly MAX_TRACE_DEPTH = MAX_TRACE_DEPTH
|
|
55
|
-
static readonly DEFAULT_CONTEXT_LINE_RADIUS = DEFAULT_CONTEXT_LINE_RADIUS
|
|
56
|
-
|
|
57
|
-
static createInitialOutputState(): TraceOutputState {
|
|
58
|
-
return {
|
|
59
|
-
traceData: [],
|
|
60
|
-
traceCode: "请先上传一个或多个 .map 文件。",
|
|
61
|
-
resolvedSourceMeta: null,
|
|
62
|
-
traceHighlightLines: [],
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static patchOutputMessage(prev: TraceOutputState, message: string): TraceOutputState {
|
|
67
|
-
return {
|
|
68
|
-
...prev,
|
|
69
|
-
traceCode: message,
|
|
70
|
-
traceHighlightLines: [],
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static createChainSlotFromFile(file: File): Promise<ChainMapSlot> {
|
|
75
|
-
return createChainSlotFromFile(file)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static buildChainStateFromSlots(slots: ChainMapSlot[]): SourceMapChainState {
|
|
79
|
-
const {registry, orderedMapFileNames} = buildRegistryFromChainSlots(slots)
|
|
80
|
-
return {
|
|
81
|
-
sourceMaps: registry,
|
|
82
|
-
sourceMapFileNames: orderedMapFileNames,
|
|
83
|
-
chainMapSlots: slots,
|
|
84
|
-
entryFileName: getAutoEntryFileNameFromSlots(slots),
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static removeChainSlot(slots: ChainMapSlot[], slotId: string): ChainMapSlot[] {
|
|
89
|
-
return slots.filter((item) => item.id !== slotId)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static reorderChainSlots(slots: ChainMapSlot[], nextIds: string[]): ChainMapSlot[] {
|
|
93
|
-
const idOrder = new Map(nextIds.map((id, index) => [id, index]))
|
|
94
|
-
return [...slots].sort((a, b) => {
|
|
95
|
-
const aIndex = idOrder.get(a.id) ?? Number.MAX_SAFE_INTEGER
|
|
96
|
-
const bIndex = idOrder.get(b.id) ?? Number.MAX_SAFE_INTEGER
|
|
97
|
-
return aIndex - bIndex
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static mapTraceForDisplay(traceData: TraceHop[]): TraceDisplayHop[] {
|
|
102
|
-
return traceData.map((item) => {
|
|
103
|
-
let output: TraceLocation | undefined
|
|
104
|
-
if (item.output) {
|
|
105
|
-
output = toDisplayLocation(item.output)
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
input: toDisplayLocation(item.input),
|
|
109
|
-
output,
|
|
110
|
-
mapFileName: item.mapFileName,
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
static validateResolveInput(config: ResolveInputConfig): ResolveInputValidation {
|
|
116
|
-
const parsedLine = Number(config.entryLine)
|
|
117
|
-
const parsedColumn = Number(config.entryColumn)
|
|
118
|
-
const parsedContextLineRadius = Number(config.contextLineRadius)
|
|
119
|
-
const normalizedFileName = config.entryFileName.replace(/\\/g, "/").trim()
|
|
120
|
-
|
|
121
|
-
if (!normalizedFileName) {
|
|
122
|
-
return {ok: false, message: "请输入入口文件名,例如 index.js"}
|
|
123
|
-
}
|
|
124
|
-
if (!config.entryLine.trim()) {
|
|
125
|
-
return {ok: false, message: "请输入入口行号(1-based)。"}
|
|
126
|
-
}
|
|
127
|
-
if (!config.entryColumn.trim()) {
|
|
128
|
-
return {ok: false, message: "请输入入口列号(0-based)。"}
|
|
129
|
-
}
|
|
130
|
-
if (!Number.isInteger(parsedLine) || parsedLine < 1) {
|
|
131
|
-
return {ok: false, message: "行号必须是大于等于 1 的整数。"}
|
|
132
|
-
}
|
|
133
|
-
if (!Number.isInteger(parsedColumn) || parsedColumn < 0) {
|
|
134
|
-
return {ok: false, message: "列号必须是大于等于 0 的整数。"}
|
|
135
|
-
}
|
|
136
|
-
if (!Number.isInteger(parsedContextLineRadius) || parsedContextLineRadius < 0) {
|
|
137
|
-
return {ok: false, message: "上下文行数必须是大于等于 0 的整数。"}
|
|
138
|
-
}
|
|
139
|
-
if (config.mapCount === 0) {
|
|
140
|
-
return {ok: false, message: "未加载可用 map 文件,请先上传。"}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
ok: true,
|
|
145
|
-
entry: {
|
|
146
|
-
fileName: normalizedFileName,
|
|
147
|
-
lineNumber: parsedLine,
|
|
148
|
-
columnNumber: parsedColumn,
|
|
149
|
-
},
|
|
150
|
-
contextLineRadius: parsedContextLineRadius,
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
static async resolveTraceOutput(context: ResolveTaskContext): Promise<TraceOutputState> {
|
|
155
|
-
try {
|
|
156
|
-
const traceChain = await resolveTraceBySourceMaps(
|
|
157
|
-
context.entry,
|
|
158
|
-
context.sourceMaps,
|
|
159
|
-
context.sourceMapFileNames,
|
|
160
|
-
{maxDepth: this.MAX_TRACE_DEPTH},
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
const sourceCode = resolveSourceCodeFromTrace(traceChain, context.sourceMaps)
|
|
164
|
-
if (sourceCode) {
|
|
165
|
-
const excerpt = createCodeExcerpt(sourceCode.code, sourceCode.lineNumber, context.contextLineRadius)
|
|
166
|
-
return {
|
|
167
|
-
traceData: traceChain,
|
|
168
|
-
traceCode: excerpt.code,
|
|
169
|
-
resolvedSourceMeta: {
|
|
170
|
-
sourceFile: sourceCode.sourceFile,
|
|
171
|
-
lineNumber: sourceCode.lineNumber,
|
|
172
|
-
columnNumber: sourceCode.columnNumber,
|
|
173
|
-
},
|
|
174
|
-
traceHighlightLines: [excerpt.highlightLine],
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const lastResolved = getLastResolvedOutput(traceChain)
|
|
179
|
-
if (lastResolved) {
|
|
180
|
-
const display = toDisplayLocation(lastResolved)
|
|
181
|
-
return {
|
|
182
|
-
traceData: traceChain,
|
|
183
|
-
traceCode: [
|
|
184
|
-
`已定位到源码位置:${display.fileName}:${display.lineNumber}:${display.columnNumber}`,
|
|
185
|
-
"当前 map 不包含 sourcesContent,无法直接渲染源码内容。",
|
|
186
|
-
].join("\n"),
|
|
187
|
-
resolvedSourceMeta: {
|
|
188
|
-
sourceFile: display.fileName,
|
|
189
|
-
lineNumber: display.lineNumber,
|
|
190
|
-
columnNumber: display.columnNumber,
|
|
191
|
-
},
|
|
192
|
-
traceHighlightLines: [],
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
traceData: traceChain,
|
|
198
|
-
traceCode: "未命中映射,未定位到源码位置。",
|
|
199
|
-
resolvedSourceMeta: null,
|
|
200
|
-
traceHighlightLines: [],
|
|
201
|
-
}
|
|
202
|
-
} catch (error) {
|
|
203
|
-
const message = error instanceof Error ? error.message : "unknown error"
|
|
204
|
-
return {
|
|
205
|
-
traceData: [{input: context.entry}],
|
|
206
|
-
traceCode: `source-map trace failed: ${message}`,
|
|
207
|
-
resolvedSourceMeta: null,
|
|
208
|
-
traceHighlightLines: [],
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export {SourceMapUtils} from "./facade/source-map-utils"
|
|
2
|
-
|
|
3
|
-
export type {
|
|
4
|
-
TraceOutputState,
|
|
5
|
-
SourceMapChainState,
|
|
6
|
-
TraceDisplayHop,
|
|
7
|
-
ResolveInputConfig,
|
|
8
|
-
} from "./facade/source-map-utils"
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
ChainMapSlot,
|
|
12
|
-
SourceMapRegistry,
|
|
13
|
-
TraceLocation,
|
|
14
|
-
TraceHop,
|
|
15
|
-
ResolvedSourceMeta,
|
|
16
|
-
ResolveTraceOptions,
|
|
17
|
-
SourceMapRecord,
|
|
18
|
-
} from "./base/types"
|
|
File without changes
|
|
File without changes
|