@xiaou66/vite-plugin-vue-mcp-next 1.3.1 → 1.3.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/index.cjs +145 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +145 -17
- package/dist/index.js.map +1 -1
- package/dist/runtime/client.cjs +183 -34
- package/dist/runtime/client.cjs.map +1 -1
- package/dist/runtime/client.js +183 -35
- package/dist/runtime/client.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime/client.js
CHANGED
|
@@ -115,25 +115,153 @@ var DEFAULT_OPTIONS = {
|
|
|
115
115
|
import { nanoid } from "nanoid";
|
|
116
116
|
|
|
117
117
|
// src/shared/serialization.ts
|
|
118
|
+
var RPC_CIRCULAR_VALUE = "[Circular]";
|
|
119
|
+
var RPC_UNREADABLE_VALUE = "[Unreadable]";
|
|
120
|
+
function toRpcSafeValue(value) {
|
|
121
|
+
return toRpcSafeChildValue(value, createRpcSafeContext(), false);
|
|
122
|
+
}
|
|
118
123
|
function safeStringify(value) {
|
|
119
124
|
if (typeof value === "string") {
|
|
120
125
|
return value;
|
|
121
126
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
const safeValue = toRpcSafeValue(value);
|
|
128
|
+
return safeValue === void 0 ? "undefined" : JSON.stringify(safeValue);
|
|
129
|
+
}
|
|
130
|
+
function createRpcSafeContext() {
|
|
131
|
+
return {
|
|
132
|
+
cache: /* @__PURE__ */ new WeakMap(),
|
|
133
|
+
seen: /* @__PURE__ */ new WeakSet()
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function toRpcSafeChildValue(value, context, arrayItem) {
|
|
137
|
+
if (value === null) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
switch (typeof value) {
|
|
141
|
+
case "string":
|
|
142
|
+
case "boolean":
|
|
143
|
+
return value;
|
|
144
|
+
case "number":
|
|
145
|
+
return Number.isFinite(value) ? value : String(value);
|
|
146
|
+
case "bigint":
|
|
147
|
+
return value.toString();
|
|
148
|
+
case "symbol":
|
|
149
|
+
return toSymbolPlaceholder(value);
|
|
150
|
+
case "undefined":
|
|
151
|
+
case "function":
|
|
152
|
+
return arrayItem ? null : void 0;
|
|
153
|
+
case "object":
|
|
154
|
+
return toRpcSafeObject(value, context);
|
|
155
|
+
default:
|
|
156
|
+
return arrayItem ? null : void 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function toRpcSafeObject(value, context) {
|
|
160
|
+
if (context.seen.has(value)) {
|
|
161
|
+
return RPC_CIRCULAR_VALUE;
|
|
162
|
+
}
|
|
163
|
+
const cached = context.cache.get(value);
|
|
164
|
+
if (cached) {
|
|
165
|
+
return cached;
|
|
166
|
+
}
|
|
167
|
+
context.seen.add(value);
|
|
168
|
+
try {
|
|
169
|
+
let safeValue;
|
|
170
|
+
if (value instanceof Date) {
|
|
171
|
+
safeValue = toSafeDate(value);
|
|
172
|
+
} else if (value instanceof Error) {
|
|
173
|
+
safeValue = toSafeError(value, context);
|
|
174
|
+
} else if (Array.isArray(value)) {
|
|
175
|
+
safeValue = toSafeArray(value, context);
|
|
176
|
+
} else {
|
|
177
|
+
safeValue = toSafeRecord(value, context);
|
|
134
178
|
}
|
|
135
|
-
|
|
136
|
-
|
|
179
|
+
context.cache.set(value, safeValue);
|
|
180
|
+
return safeValue;
|
|
181
|
+
} finally {
|
|
182
|
+
context.seen.delete(value);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function toSafeArray(values, context) {
|
|
186
|
+
return values.map((item) => toRpcSafeChildValue(item, context, true) ?? null);
|
|
187
|
+
}
|
|
188
|
+
function toSafeRecord(value, context) {
|
|
189
|
+
const keys = getEnumerableKeys(value);
|
|
190
|
+
if (!keys) {
|
|
191
|
+
return RPC_UNREADABLE_VALUE;
|
|
192
|
+
}
|
|
193
|
+
if (keys.length === 0 && !isPlainRecord(value)) {
|
|
194
|
+
return toObjectSummary(value);
|
|
195
|
+
}
|
|
196
|
+
const result = {};
|
|
197
|
+
keys.forEach((key) => {
|
|
198
|
+
if (key === "toJSON") {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const field = readObjectField(value, key);
|
|
202
|
+
if (!field.ok) {
|
|
203
|
+
result[key] = RPC_UNREADABLE_VALUE;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const safeValue = toRpcSafeChildValue(field.value, context, false);
|
|
207
|
+
if (safeValue !== void 0) {
|
|
208
|
+
result[key] = safeValue;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
function toSafeError(error, context) {
|
|
214
|
+
const result = {
|
|
215
|
+
name: error.name,
|
|
216
|
+
message: error.message
|
|
217
|
+
};
|
|
218
|
+
const stack = readObjectField(error, "stack");
|
|
219
|
+
if (stack.ok && typeof stack.value === "string") {
|
|
220
|
+
result.stack = stack.value;
|
|
221
|
+
}
|
|
222
|
+
if ("cause" in error) {
|
|
223
|
+
const cause = readObjectField(error, "cause");
|
|
224
|
+
result.cause = cause.ok ? toRpcSafeChildValue(cause.value, context, false) ?? null : RPC_UNREADABLE_VALUE;
|
|
225
|
+
}
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
function toSafeDate(value) {
|
|
229
|
+
return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
|
|
230
|
+
}
|
|
231
|
+
function getEnumerableKeys(value) {
|
|
232
|
+
try {
|
|
233
|
+
return Object.keys(value);
|
|
234
|
+
} catch {
|
|
235
|
+
return void 0;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function readObjectField(value, key) {
|
|
239
|
+
try {
|
|
240
|
+
return {
|
|
241
|
+
ok: true,
|
|
242
|
+
value: value[key]
|
|
243
|
+
};
|
|
244
|
+
} catch {
|
|
245
|
+
return { ok: false };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function isPlainRecord(value) {
|
|
249
|
+
try {
|
|
250
|
+
const prototype = Object.getPrototypeOf(value);
|
|
251
|
+
return prototype === Object.prototype || prototype === null;
|
|
252
|
+
} catch {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function toObjectSummary(value) {
|
|
257
|
+
try {
|
|
258
|
+
return Object.prototype.toString.call(value);
|
|
259
|
+
} catch {
|
|
260
|
+
return "[Object]";
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function toSymbolPlaceholder(value) {
|
|
264
|
+
return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
|
|
137
265
|
}
|
|
138
266
|
|
|
139
267
|
// src/runtime/consoleHook.ts
|
|
@@ -1495,7 +1623,6 @@ import {
|
|
|
1495
1623
|
devtoolsRouterInfo,
|
|
1496
1624
|
devtoolsState,
|
|
1497
1625
|
getInspector,
|
|
1498
|
-
stringify,
|
|
1499
1626
|
toggleHighPerfMode
|
|
1500
1627
|
} from "@vue/devtools-kit";
|
|
1501
1628
|
import { createRPCClient } from "vite-dev-rpc";
|
|
@@ -2023,6 +2150,15 @@ function installVueBridge(hot) {
|
|
|
2023
2150
|
);
|
|
2024
2151
|
rpcRef.current = rpc;
|
|
2025
2152
|
}
|
|
2153
|
+
function toVueRpcPayload(value) {
|
|
2154
|
+
return toRpcSafeValue(value);
|
|
2155
|
+
}
|
|
2156
|
+
function toVueRpcJsonPayload(value) {
|
|
2157
|
+
return JSON.stringify(toRpcSafeValue(value) ?? null);
|
|
2158
|
+
}
|
|
2159
|
+
function toVueRpcPrettyJsonPayload(value) {
|
|
2160
|
+
return JSON.stringify(toRpcSafeValue(value), null, 2);
|
|
2161
|
+
}
|
|
2026
2162
|
function createClientVueRuntimeRpc(getRpc) {
|
|
2027
2163
|
return {
|
|
2028
2164
|
...createRuntimeDevtoolsRpc(getRpc),
|
|
@@ -2031,7 +2167,10 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2031
2167
|
inspectorId: COMPONENTS_INSPECTOR_ID,
|
|
2032
2168
|
filter: query.componentName ?? ""
|
|
2033
2169
|
});
|
|
2034
|
-
getRpc().onInspectorTreeUpdated(
|
|
2170
|
+
getRpc().onInspectorTreeUpdated(
|
|
2171
|
+
query.event,
|
|
2172
|
+
toVueRpcPayload(inspectorTree[0])
|
|
2173
|
+
);
|
|
2035
2174
|
},
|
|
2036
2175
|
onInspectorTreeUpdated: () => void 0,
|
|
2037
2176
|
async getInspectorState(query) {
|
|
@@ -2039,7 +2178,7 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2039
2178
|
if (!targetNode) {
|
|
2040
2179
|
getRpc().onInspectorStateUpdated(
|
|
2041
2180
|
query.event,
|
|
2042
|
-
createMissingComponentError(query.componentName)
|
|
2181
|
+
toVueRpcPayload(createMissingComponentError(query.componentName))
|
|
2043
2182
|
);
|
|
2044
2183
|
return;
|
|
2045
2184
|
}
|
|
@@ -2047,7 +2186,10 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2047
2186
|
inspectorId: COMPONENTS_INSPECTOR_ID,
|
|
2048
2187
|
nodeId: targetNode.id
|
|
2049
2188
|
});
|
|
2050
|
-
getRpc().onInspectorStateUpdated(
|
|
2189
|
+
getRpc().onInspectorStateUpdated(
|
|
2190
|
+
query.event,
|
|
2191
|
+
toVueRpcJsonPayload(inspectorState)
|
|
2192
|
+
);
|
|
2051
2193
|
},
|
|
2052
2194
|
onInspectorStateUpdated: () => void 0,
|
|
2053
2195
|
async editComponentState(query) {
|
|
@@ -2084,7 +2226,7 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2084
2226
|
getRouterInfo(query) {
|
|
2085
2227
|
getRpc().onRouterInfoUpdated(
|
|
2086
2228
|
query.event,
|
|
2087
|
-
|
|
2229
|
+
toVueRpcPrettyJsonPayload(devtoolsRouterInfo)
|
|
2088
2230
|
);
|
|
2089
2231
|
},
|
|
2090
2232
|
onRouterInfoUpdated: () => void 0,
|
|
@@ -2095,7 +2237,7 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2095
2237
|
filter: ""
|
|
2096
2238
|
})
|
|
2097
2239
|
);
|
|
2098
|
-
getRpc().onPiniaTreeUpdated(query.event, inspectorTree);
|
|
2240
|
+
getRpc().onPiniaTreeUpdated(query.event, toVueRpcPayload(inspectorTree));
|
|
2099
2241
|
},
|
|
2100
2242
|
onPiniaTreeUpdated: () => void 0,
|
|
2101
2243
|
async getPiniaState(query) {
|
|
@@ -2110,7 +2252,7 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2110
2252
|
}
|
|
2111
2253
|
return devtools.ctx.api.getInspectorState(payload);
|
|
2112
2254
|
});
|
|
2113
|
-
getRpc().onPiniaInfoUpdated(query.event,
|
|
2255
|
+
getRpc().onPiniaInfoUpdated(query.event, toVueRpcJsonPayload(result));
|
|
2114
2256
|
},
|
|
2115
2257
|
onPiniaInfoUpdated: () => void 0,
|
|
2116
2258
|
async recordPerformance(query) {
|
|
@@ -2118,7 +2260,7 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2118
2260
|
if (!collector) {
|
|
2119
2261
|
getRpc().onPerformanceRecorded(
|
|
2120
2262
|
query.event,
|
|
2121
|
-
createPerformanceUnavailableError()
|
|
2263
|
+
toVueRpcPayload(createPerformanceUnavailableError())
|
|
2122
2264
|
);
|
|
2123
2265
|
return;
|
|
2124
2266
|
}
|
|
@@ -2128,11 +2270,11 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2128
2270
|
includeMemory: query.includeMemory,
|
|
2129
2271
|
includeStacks: query.includeStacks
|
|
2130
2272
|
});
|
|
2131
|
-
getRpc().onPerformanceRecorded(query.event, report);
|
|
2273
|
+
getRpc().onPerformanceRecorded(query.event, toVueRpcPayload(report));
|
|
2132
2274
|
} catch (error) {
|
|
2133
2275
|
getRpc().onPerformanceRecorded(
|
|
2134
2276
|
query.event,
|
|
2135
|
-
createPerformanceError(error)
|
|
2277
|
+
toVueRpcPayload(createPerformanceError(error))
|
|
2136
2278
|
);
|
|
2137
2279
|
}
|
|
2138
2280
|
},
|
|
@@ -2142,7 +2284,7 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2142
2284
|
if (!collector) {
|
|
2143
2285
|
getRpc().onPerformanceRecordingStarted(
|
|
2144
2286
|
query.event,
|
|
2145
|
-
createPerformanceUnavailableError()
|
|
2287
|
+
toVueRpcPayload(createPerformanceUnavailableError())
|
|
2146
2288
|
);
|
|
2147
2289
|
return;
|
|
2148
2290
|
}
|
|
@@ -2151,16 +2293,19 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2151
2293
|
includeMemory: query.includeMemory,
|
|
2152
2294
|
includeStacks: query.includeStacks
|
|
2153
2295
|
});
|
|
2154
|
-
getRpc().onPerformanceRecordingStarted(
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2296
|
+
getRpc().onPerformanceRecordingStarted(
|
|
2297
|
+
query.event,
|
|
2298
|
+
toVueRpcPayload({
|
|
2299
|
+
ok: true,
|
|
2300
|
+
recordingId,
|
|
2301
|
+
startedAt: Date.now(),
|
|
2302
|
+
source: "hook"
|
|
2303
|
+
})
|
|
2304
|
+
);
|
|
2160
2305
|
} catch (error) {
|
|
2161
2306
|
getRpc().onPerformanceRecordingStarted(
|
|
2162
2307
|
query.event,
|
|
2163
|
-
createPerformanceError(error)
|
|
2308
|
+
toVueRpcPayload(createPerformanceError(error))
|
|
2164
2309
|
);
|
|
2165
2310
|
}
|
|
2166
2311
|
},
|
|
@@ -2170,17 +2315,20 @@ function createClientVueRuntimeRpc(getRpc) {
|
|
|
2170
2315
|
if (!collector) {
|
|
2171
2316
|
getRpc().onPerformanceRecordingStopped(
|
|
2172
2317
|
query.event,
|
|
2173
|
-
createPerformanceUnavailableError()
|
|
2318
|
+
toVueRpcPayload(createPerformanceUnavailableError())
|
|
2174
2319
|
);
|
|
2175
2320
|
return;
|
|
2176
2321
|
}
|
|
2177
2322
|
try {
|
|
2178
2323
|
const report = collector.stop(query.recordingId);
|
|
2179
|
-
getRpc().onPerformanceRecordingStopped(
|
|
2324
|
+
getRpc().onPerformanceRecordingStopped(
|
|
2325
|
+
query.event,
|
|
2326
|
+
toVueRpcPayload(report)
|
|
2327
|
+
);
|
|
2180
2328
|
} catch (error) {
|
|
2181
2329
|
getRpc().onPerformanceRecordingStopped(
|
|
2182
2330
|
query.event,
|
|
2183
|
-
createPerformanceError(error)
|
|
2331
|
+
toVueRpcPayload(createPerformanceError(error))
|
|
2184
2332
|
);
|
|
2185
2333
|
}
|
|
2186
2334
|
},
|