@tanstack/devtools-vite 0.8.0 → 0.8.2
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/esm/plugin.d.ts +4 -74
- package/dist/esm/plugin.js +2 -12
- package/dist/esm/plugin.js.map +1 -1
- package/package.json +6 -7
- package/src/plugin.ts +25 -97
- package/dist/esm/ast-utils.d.ts +0 -11
- package/dist/esm/ast-utils.js +0 -44
- package/dist/esm/ast-utils.js.map +0 -1
- package/dist/esm/devtools-packages.d.ts +0 -2
- package/dist/esm/devtools-packages.js +0 -15
- package/dist/esm/devtools-packages.js.map +0 -1
- package/dist/esm/editor.d.ts +0 -25
- package/dist/esm/editor.js +0 -20
- package/dist/esm/editor.js.map +0 -1
- package/dist/esm/enhance-logs.d.ts +0 -4
- package/dist/esm/enhance-logs.js +0 -51
- package/dist/esm/enhance-logs.js.map +0 -1
- package/dist/esm/enhance-logs.test.d.ts +0 -1
- package/dist/esm/inject-plugin.d.ts +0 -22
- package/dist/esm/inject-plugin.js +0 -179
- package/dist/esm/inject-plugin.js.map +0 -1
- package/dist/esm/inject-plugin.test.d.ts +0 -1
- package/dist/esm/inject-source.d.ts +0 -7
- package/dist/esm/inject-source.js +0 -114
- package/dist/esm/inject-source.js.map +0 -1
- package/dist/esm/inject-source.test.d.ts +0 -1
- package/dist/esm/matcher.d.ts +0 -1
- package/dist/esm/matcher.js +0 -13
- package/dist/esm/matcher.js.map +0 -1
- package/dist/esm/matcher.test.d.ts +0 -1
- package/dist/esm/offset-to-loc.d.ts +0 -14
- package/dist/esm/offset-to-loc.js +0 -29
- package/dist/esm/offset-to-loc.js.map +0 -1
- package/dist/esm/package-manager.d.ts +0 -16
- package/dist/esm/package-manager.js +0 -98
- package/dist/esm/package-manager.js.map +0 -1
- package/dist/esm/remove-devtools.d.ts +0 -4
- package/dist/esm/remove-devtools.js +0 -96
- package/dist/esm/remove-devtools.js.map +0 -1
- package/dist/esm/remove-devtools.test.d.ts +0 -1
- package/dist/esm/runtime-bridge.d.ts +0 -31
- package/dist/esm/runtime-bridge.js +0 -75
- package/dist/esm/runtime-bridge.js.map +0 -1
- package/dist/esm/runtime-bridge.test.d.ts +0 -1
- package/dist/esm/utils.d.ts +0 -31
- package/dist/esm/utils.js +0 -155
- package/dist/esm/utils.js.map +0 -1
- package/dist/esm/utils.test.d.ts +0 -1
- package/dist/esm/virtual-console.d.ts +0 -19
- package/dist/esm/virtual-console.js +0 -336
- package/dist/esm/virtual-console.js.map +0 -1
- package/dist/esm/virtual-console.test.d.ts +0 -1
- package/src/ast-utils.ts +0 -58
- package/src/devtools-packages.ts +0 -12
- package/src/editor.ts +0 -53
- package/src/enhance-logs.test.ts +0 -132
- package/src/enhance-logs.ts +0 -71
- package/src/inject-plugin.test.ts +0 -1139
- package/src/inject-plugin.ts +0 -300
- package/src/inject-source.test.ts +0 -939
- package/src/inject-source.ts +0 -235
- package/src/matcher.test.ts +0 -33
- package/src/matcher.ts +0 -19
- package/src/offset-to-loc.ts +0 -39
- package/src/package-manager.ts +0 -181
- package/src/remove-devtools.test.ts +0 -607
- package/src/remove-devtools.ts +0 -190
- package/src/runtime-bridge.test.ts +0 -179
- package/src/runtime-bridge.ts +0 -113
- package/src/utils.test.ts +0 -184
- package/src/utils.ts +0 -247
- package/src/virtual-console.test.ts +0 -244
- package/src/virtual-console.ts +0 -341
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
//#region src/virtual-console.ts
|
|
2
|
-
/**
|
|
3
|
-
* Generates inline code to inject into entry files (both client and server).
|
|
4
|
-
* This code detects the environment at runtime and:
|
|
5
|
-
*
|
|
6
|
-
* CLIENT:
|
|
7
|
-
* 1. Store original console methods
|
|
8
|
-
* 2. Create batched wrappers that POST to server via fetch
|
|
9
|
-
* 3. Override global console with the wrapped methods
|
|
10
|
-
* 4. Listen for server console logs via SSE
|
|
11
|
-
*
|
|
12
|
-
* SERVER (Nitro/Vinxi runtime):
|
|
13
|
-
* 1. Store original console methods
|
|
14
|
-
* 2. Create batched wrappers that POST to Vite dev server
|
|
15
|
-
* 3. Override global console - original logging still happens, just also pipes to Vite
|
|
16
|
-
*
|
|
17
|
-
* Returns the inline code as a string - no imports needed since we use fetch.
|
|
18
|
-
*/
|
|
19
|
-
function generateConsolePipeCode(levels, viteServerUrl) {
|
|
20
|
-
return `
|
|
21
|
-
;(function __tsdConsolePipe() {
|
|
22
|
-
// Detect environment
|
|
23
|
-
var isServer = typeof window === 'undefined';
|
|
24
|
-
var envKey = isServer ? '__TSD_SERVER_CONSOLE_PIPE_INITIALIZED__' : '__TSD_CONSOLE_PIPE_INITIALIZED__';
|
|
25
|
-
var globalObj = isServer ? globalThis : window;
|
|
26
|
-
|
|
27
|
-
// Only run once per environment
|
|
28
|
-
if (globalObj[envKey]) return;
|
|
29
|
-
globalObj[envKey] = true;
|
|
30
|
-
|
|
31
|
-
var CONSOLE_LEVELS = ${JSON.stringify(levels)};
|
|
32
|
-
var VITE_SERVER_URL = ${JSON.stringify(viteServerUrl)};
|
|
33
|
-
|
|
34
|
-
// Store original console methods before we override them
|
|
35
|
-
var originalConsole = {};
|
|
36
|
-
for (var i = 0; i < CONSOLE_LEVELS.length; i++) {
|
|
37
|
-
var level = CONSOLE_LEVELS[i];
|
|
38
|
-
originalConsole[level] = console[level].bind(console);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Simple inline batcher implementation
|
|
42
|
-
var batchedEntries = [];
|
|
43
|
-
var batchTimeout = null;
|
|
44
|
-
var BATCH_WAIT = isServer ? 50 : 100;
|
|
45
|
-
var BATCH_MAX_SIZE = isServer ? 20 : 50;
|
|
46
|
-
|
|
47
|
-
function flushBatch() {
|
|
48
|
-
if (batchedEntries.length === 0) return;
|
|
49
|
-
|
|
50
|
-
var entries = batchedEntries;
|
|
51
|
-
batchedEntries = [];
|
|
52
|
-
batchTimeout = null;
|
|
53
|
-
|
|
54
|
-
// Determine endpoint based on environment
|
|
55
|
-
var endpoint = isServer
|
|
56
|
-
? VITE_SERVER_URL + '/__tsd/console-pipe/server'
|
|
57
|
-
: '/__tsd/console-pipe';
|
|
58
|
-
|
|
59
|
-
// Send to Vite server via fetch
|
|
60
|
-
fetch(endpoint, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
headers: { 'Content-Type': 'application/json' },
|
|
63
|
-
body: JSON.stringify({ entries: entries }),
|
|
64
|
-
}).catch(function( ) {
|
|
65
|
-
// Swallow errors
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function addToBatch(entry) {
|
|
70
|
-
batchedEntries.push(entry);
|
|
71
|
-
|
|
72
|
-
if (batchedEntries.length >= BATCH_MAX_SIZE) {
|
|
73
|
-
if (batchTimeout) {
|
|
74
|
-
clearTimeout(batchTimeout);
|
|
75
|
-
batchTimeout = null;
|
|
76
|
-
}
|
|
77
|
-
flushBatch();
|
|
78
|
-
} else if (!batchTimeout) {
|
|
79
|
-
batchTimeout = setTimeout(flushBatch, BATCH_WAIT);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
var MAX_DEPTH = 6;
|
|
84
|
-
var MAX_ARRAY_LEN = 100;
|
|
85
|
-
var MAX_OBJECT_KEYS = 100;
|
|
86
|
-
var MAX_STRING_LENGTH = 10000;
|
|
87
|
-
|
|
88
|
-
function truncateString(value) {
|
|
89
|
-
if (value.length <= MAX_STRING_LENGTH) return value;
|
|
90
|
-
return value.slice(0, MAX_STRING_LENGTH) + '... (' + (value.length - MAX_STRING_LENGTH) + ' more chars)';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function formatDomElement(element) {
|
|
94
|
-
var tagName = element.tagName ? element.tagName.toLowerCase() : 'element';
|
|
95
|
-
var output = '<' + tagName;
|
|
96
|
-
var attrs = ['id', 'class', 'name', 'type', 'role', 'aria-label', 'data-testid'];
|
|
97
|
-
|
|
98
|
-
for (var attrIndex = 0; attrIndex < attrs.length; attrIndex++) {
|
|
99
|
-
var attrName = attrs[attrIndex];
|
|
100
|
-
var attrValue = element.getAttribute && element.getAttribute(attrName);
|
|
101
|
-
if (attrValue) {
|
|
102
|
-
output += ' ' + attrName + '="' + truncateString(String(attrValue)).replace(/"/g, '"') + '"';
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return output + '>';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function getObjectTypeName(arg) {
|
|
110
|
-
return arg && arg.constructor && arg.constructor.name ? arg.constructor.name : 'Object';
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function formatArrayBufferView(arg) {
|
|
114
|
-
var length = typeof arg.length === 'number' ? arg.length : arg.byteLength;
|
|
115
|
-
return '[' + getObjectTypeName(arg) + '(' + length + ')]';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function serializeConsoleArg(arg, seen, depth) {
|
|
119
|
-
if (depth === undefined) depth = 0;
|
|
120
|
-
if (arg === undefined) return 'undefined';
|
|
121
|
-
if (arg === null) return null;
|
|
122
|
-
|
|
123
|
-
var argType = typeof arg;
|
|
124
|
-
|
|
125
|
-
if (argType === 'function') return '[Function' + (arg.name ? ': ' + arg.name : '') + ']';
|
|
126
|
-
if (argType === 'symbol') return arg.toString();
|
|
127
|
-
if (argType === 'bigint') return arg.toString() + 'n';
|
|
128
|
-
if (argType === 'string') return truncateString(arg);
|
|
129
|
-
if (argType !== 'object') return arg;
|
|
130
|
-
|
|
131
|
-
if (!isServer) {
|
|
132
|
-
if (
|
|
133
|
-
arg.nodeType === 1 &&
|
|
134
|
-
typeof arg.tagName === 'string' &&
|
|
135
|
-
typeof arg.getAttribute === 'function'
|
|
136
|
-
) {
|
|
137
|
-
return formatDomElement(arg);
|
|
138
|
-
}
|
|
139
|
-
if (arg.nodeType === 9) {
|
|
140
|
-
return '[Document]';
|
|
141
|
-
}
|
|
142
|
-
if (typeof Window !== 'undefined' && arg instanceof Window) {
|
|
143
|
-
return '[Window]';
|
|
144
|
-
}
|
|
145
|
-
if (typeof Event !== 'undefined' && arg instanceof Event) {
|
|
146
|
-
return {
|
|
147
|
-
type: arg.type,
|
|
148
|
-
target: serializeConsoleArg(arg.target, seen, depth + 1),
|
|
149
|
-
currentTarget: serializeConsoleArg(arg.currentTarget, seen, depth + 1),
|
|
150
|
-
defaultPrevented: arg.defaultPrevented,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
if (typeof Node !== 'undefined' && arg instanceof Node) {
|
|
154
|
-
return '[Node: ' + arg.nodeName + ']';
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (arg instanceof Error) {
|
|
159
|
-
return {
|
|
160
|
-
name: arg.name,
|
|
161
|
-
message: truncateString(arg.message),
|
|
162
|
-
stack: arg.stack ? truncateString(arg.stack) : arg.stack,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (arg instanceof Date) {
|
|
167
|
-
return arg.toISOString();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (arg instanceof RegExp) {
|
|
171
|
-
return arg.toString();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (typeof ArrayBuffer !== 'undefined') {
|
|
175
|
-
if (ArrayBuffer.isView && ArrayBuffer.isView(arg)) {
|
|
176
|
-
return formatArrayBufferView(arg);
|
|
177
|
-
}
|
|
178
|
-
if (arg instanceof ArrayBuffer) {
|
|
179
|
-
return '[ArrayBuffer(' + arg.byteLength + ')]';
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (typeof SharedArrayBuffer !== 'undefined' && arg instanceof SharedArrayBuffer) {
|
|
184
|
-
return '[SharedArrayBuffer(' + arg.byteLength + ')]';
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (depth >= MAX_DEPTH) {
|
|
188
|
-
return '[MaxDepth]';
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (seen.indexOf(arg) !== -1) {
|
|
192
|
-
return '[Circular]';
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
seen.push(arg);
|
|
196
|
-
|
|
197
|
-
if (Array.isArray(arg)) {
|
|
198
|
-
var arrayResult = [];
|
|
199
|
-
var arrayLength = Math.min(arg.length, MAX_ARRAY_LEN);
|
|
200
|
-
for (var arrayIndex = 0; arrayIndex < arrayLength; arrayIndex++) {
|
|
201
|
-
arrayResult.push(serializeConsoleArg(arg[arrayIndex], seen, depth + 1));
|
|
202
|
-
}
|
|
203
|
-
if (arg.length > MAX_ARRAY_LEN) {
|
|
204
|
-
arrayResult.push('... (' + (arg.length - MAX_ARRAY_LEN) + ' more)');
|
|
205
|
-
}
|
|
206
|
-
seen.pop();
|
|
207
|
-
return arrayResult;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
var objectResult = {};
|
|
211
|
-
var keys = Object.keys(arg);
|
|
212
|
-
var keyLength = Math.min(keys.length, MAX_OBJECT_KEYS);
|
|
213
|
-
for (var keyIndex = 0; keyIndex < keyLength; keyIndex++) {
|
|
214
|
-
var key = keys[keyIndex];
|
|
215
|
-
try {
|
|
216
|
-
objectResult[key] = serializeConsoleArg(arg[key], seen, depth + 1);
|
|
217
|
-
} catch (error) {
|
|
218
|
-
objectResult[key] = '[Thrown: ' + String(error) + ']';
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (keys.length > MAX_OBJECT_KEYS) {
|
|
222
|
-
objectResult['...'] = '(' + (keys.length - MAX_OBJECT_KEYS) + ' more keys)';
|
|
223
|
-
}
|
|
224
|
-
seen.pop();
|
|
225
|
-
return objectResult;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Override global console methods
|
|
229
|
-
for (var j = 0; j < CONSOLE_LEVELS.length; j++) {
|
|
230
|
-
(function(level) {
|
|
231
|
-
var original = originalConsole[level];
|
|
232
|
-
console[level] = function() {
|
|
233
|
-
var args = Array.prototype.slice.call(arguments);
|
|
234
|
-
|
|
235
|
-
// Always call original first so logs appear normally
|
|
236
|
-
original.apply(console, args);
|
|
237
|
-
|
|
238
|
-
// Skip our own TSD Console Pipe logs to avoid recursion/noise
|
|
239
|
-
if (args.length > 0 && typeof args[0] === 'string' &&
|
|
240
|
-
(args[0].indexOf('[TSD Console Pipe]') !== -1 ||
|
|
241
|
-
args[0].indexOf('[@tanstack/devtools') !== -1)) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
var safeArgs = args.map(function(arg) {
|
|
246
|
-
try {
|
|
247
|
-
return serializeConsoleArg(arg, [], 0);
|
|
248
|
-
} catch (e) {
|
|
249
|
-
return String(arg);
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
var entry = {
|
|
254
|
-
level: level,
|
|
255
|
-
args: safeArgs,
|
|
256
|
-
source: isServer ? 'server' : 'client',
|
|
257
|
-
timestamp: Date.now(),
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
addToBatch(entry);
|
|
261
|
-
};
|
|
262
|
-
})(CONSOLE_LEVELS[j]);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// CLIENT ONLY: Listen for server console logs via SSE
|
|
266
|
-
if (!isServer) {
|
|
267
|
-
// Transform server log args - strip ANSI codes and convert source paths to clickable URLs
|
|
268
|
-
function transformServerLogArgs(args) {
|
|
269
|
-
var escChar = String.fromCharCode(27);
|
|
270
|
-
var transformed = [];
|
|
271
|
-
|
|
272
|
-
for (var k = 0; k < args.length; k++) {
|
|
273
|
-
var arg = args[k];
|
|
274
|
-
if (typeof arg === 'string') {
|
|
275
|
-
// Strip ANSI escape sequences (ESC[...m patterns)
|
|
276
|
-
var cleaned = arg;
|
|
277
|
-
// Remove ESC character followed by [...m] - need to build regex dynamically
|
|
278
|
-
while (cleaned.indexOf(escChar) !== -1) {
|
|
279
|
-
cleaned = cleaned.split(escChar).join('');
|
|
280
|
-
}
|
|
281
|
-
// Also remove any leftover bracket codes like [35m
|
|
282
|
-
cleaned = cleaned.replace(/\\[[0-9;]*m/g, '');
|
|
283
|
-
|
|
284
|
-
// Transform source paths to clickable URLs
|
|
285
|
-
// Match patterns like /src/components/Header.tsx:17:3
|
|
286
|
-
var sourceRegex = /(\\/[^\\s]+:\\d+:\\d+)/g;
|
|
287
|
-
cleaned = cleaned.replace(sourceRegex, function(match) {
|
|
288
|
-
return window.location.origin + '/__tsd/open-source?source=' + encodeURIComponent(match);
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
if (cleaned.trim()) {
|
|
292
|
-
transformed.push(cleaned);
|
|
293
|
-
}
|
|
294
|
-
} else {
|
|
295
|
-
transformed.push(arg);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return transformed;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
var eventSource = new EventSource('/__tsd/console-pipe/sse');
|
|
303
|
-
|
|
304
|
-
eventSource.onmessage = function(event) {
|
|
305
|
-
try {
|
|
306
|
-
var data = JSON.parse(event.data);
|
|
307
|
-
if (data.entries) {
|
|
308
|
-
for (var m = 0; m < data.entries.length; m++) {
|
|
309
|
-
var entry = data.entries[m];
|
|
310
|
-
var transformedArgs = transformServerLogArgs(entry.args);
|
|
311
|
-
var prefix = '%c[Server]%c';
|
|
312
|
-
var prefixStyle = 'color: #9333ea; font-weight: bold;';
|
|
313
|
-
var resetStyle = 'color: inherit;';
|
|
314
|
-
var logMethod = originalConsole[entry.level] || originalConsole.log;
|
|
315
|
-
logMethod.apply(console, [prefix, prefixStyle, resetStyle].concat(transformedArgs));
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
} catch (err) {
|
|
319
|
-
// Swallow errors
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
eventSource.onerror = function() {
|
|
324
|
-
// Swallow errors
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
// Flush on page unload
|
|
328
|
-
window.addEventListener('beforeunload', flushBatch);
|
|
329
|
-
}
|
|
330
|
-
})();
|
|
331
|
-
`;
|
|
332
|
-
}
|
|
333
|
-
//#endregion
|
|
334
|
-
export { generateConsolePipeCode };
|
|
335
|
-
|
|
336
|
-
//# sourceMappingURL=virtual-console.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-console.js","names":[],"sources":["../../src/virtual-console.ts"],"sourcesContent":["import type { ConsoleLevel } from './plugin'\n\n// export const VIRTUAL_MODULE_ID = 'virtual:tanstack-devtools-console'\n// export const RESOLVED_VIRTUAL_MODULE_ID = '\\0' + VIRTUAL_MODULE_ID\n\n/**\n * Generates inline code to inject into entry files (both client and server).\n * This code detects the environment at runtime and:\n *\n * CLIENT:\n * 1. Store original console methods\n * 2. Create batched wrappers that POST to server via fetch\n * 3. Override global console with the wrapped methods\n * 4. Listen for server console logs via SSE\n *\n * SERVER (Nitro/Vinxi runtime):\n * 1. Store original console methods\n * 2. Create batched wrappers that POST to Vite dev server\n * 3. Override global console - original logging still happens, just also pipes to Vite\n *\n * Returns the inline code as a string - no imports needed since we use fetch.\n */\nexport function generateConsolePipeCode(\n levels: Array<ConsoleLevel>,\n viteServerUrl: string,\n): string {\n const levelsArray = JSON.stringify(levels)\n\n return `\n;(function __tsdConsolePipe() {\n // Detect environment\n var isServer = typeof window === 'undefined';\n var envKey = isServer ? '__TSD_SERVER_CONSOLE_PIPE_INITIALIZED__' : '__TSD_CONSOLE_PIPE_INITIALIZED__';\n var globalObj = isServer ? globalThis : window;\n \n // Only run once per environment\n if (globalObj[envKey]) return;\n globalObj[envKey] = true;\n\n var CONSOLE_LEVELS = ${levelsArray};\n var VITE_SERVER_URL = ${JSON.stringify(viteServerUrl)};\n\n // Store original console methods before we override them\n var originalConsole = {};\n for (var i = 0; i < CONSOLE_LEVELS.length; i++) {\n var level = CONSOLE_LEVELS[i];\n originalConsole[level] = console[level].bind(console);\n }\n\n // Simple inline batcher implementation\n var batchedEntries = [];\n var batchTimeout = null;\n var BATCH_WAIT = isServer ? 50 : 100;\n var BATCH_MAX_SIZE = isServer ? 20 : 50;\n\n function flushBatch() {\n if (batchedEntries.length === 0) return;\n \n var entries = batchedEntries;\n batchedEntries = [];\n batchTimeout = null;\n \n // Determine endpoint based on environment\n var endpoint = isServer \n ? VITE_SERVER_URL + '/__tsd/console-pipe/server'\n : '/__tsd/console-pipe';\n \n // Send to Vite server via fetch\n fetch(endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ entries: entries }),\n }).catch(function( ) {\n // Swallow errors \n });\n }\n\n function addToBatch(entry) {\n batchedEntries.push(entry);\n \n if (batchedEntries.length >= BATCH_MAX_SIZE) {\n if (batchTimeout) {\n clearTimeout(batchTimeout);\n batchTimeout = null;\n }\n flushBatch();\n } else if (!batchTimeout) {\n batchTimeout = setTimeout(flushBatch, BATCH_WAIT);\n }\n }\n\n var MAX_DEPTH = 6;\n var MAX_ARRAY_LEN = 100;\n var MAX_OBJECT_KEYS = 100;\n var MAX_STRING_LENGTH = 10000;\n\n function truncateString(value) {\n if (value.length <= MAX_STRING_LENGTH) return value;\n return value.slice(0, MAX_STRING_LENGTH) + '... (' + (value.length - MAX_STRING_LENGTH) + ' more chars)';\n }\n\n function formatDomElement(element) {\n var tagName = element.tagName ? element.tagName.toLowerCase() : 'element';\n var output = '<' + tagName;\n var attrs = ['id', 'class', 'name', 'type', 'role', 'aria-label', 'data-testid'];\n\n for (var attrIndex = 0; attrIndex < attrs.length; attrIndex++) {\n var attrName = attrs[attrIndex];\n var attrValue = element.getAttribute && element.getAttribute(attrName);\n if (attrValue) {\n output += ' ' + attrName + '=\"' + truncateString(String(attrValue)).replace(/\"/g, '"') + '\"';\n }\n }\n\n return output + '>';\n }\n\n function getObjectTypeName(arg) {\n return arg && arg.constructor && arg.constructor.name ? arg.constructor.name : 'Object';\n }\n\n function formatArrayBufferView(arg) {\n var length = typeof arg.length === 'number' ? arg.length : arg.byteLength;\n return '[' + getObjectTypeName(arg) + '(' + length + ')]';\n }\n\n function serializeConsoleArg(arg, seen, depth) {\n if (depth === undefined) depth = 0;\n if (arg === undefined) return 'undefined';\n if (arg === null) return null;\n\n var argType = typeof arg;\n\n if (argType === 'function') return '[Function' + (arg.name ? ': ' + arg.name : '') + ']';\n if (argType === 'symbol') return arg.toString();\n if (argType === 'bigint') return arg.toString() + 'n';\n if (argType === 'string') return truncateString(arg);\n if (argType !== 'object') return arg;\n\n if (!isServer) {\n if (\n arg.nodeType === 1 &&\n typeof arg.tagName === 'string' &&\n typeof arg.getAttribute === 'function'\n ) {\n return formatDomElement(arg);\n }\n if (arg.nodeType === 9) {\n return '[Document]';\n }\n if (typeof Window !== 'undefined' && arg instanceof Window) {\n return '[Window]';\n }\n if (typeof Event !== 'undefined' && arg instanceof Event) {\n return {\n type: arg.type,\n target: serializeConsoleArg(arg.target, seen, depth + 1),\n currentTarget: serializeConsoleArg(arg.currentTarget, seen, depth + 1),\n defaultPrevented: arg.defaultPrevented,\n };\n }\n if (typeof Node !== 'undefined' && arg instanceof Node) {\n return '[Node: ' + arg.nodeName + ']';\n }\n }\n\n if (arg instanceof Error) {\n return {\n name: arg.name,\n message: truncateString(arg.message),\n stack: arg.stack ? truncateString(arg.stack) : arg.stack,\n };\n }\n\n if (arg instanceof Date) {\n return arg.toISOString();\n }\n\n if (arg instanceof RegExp) {\n return arg.toString();\n }\n\n if (typeof ArrayBuffer !== 'undefined') {\n if (ArrayBuffer.isView && ArrayBuffer.isView(arg)) {\n return formatArrayBufferView(arg);\n }\n if (arg instanceof ArrayBuffer) {\n return '[ArrayBuffer(' + arg.byteLength + ')]';\n }\n }\n\n if (typeof SharedArrayBuffer !== 'undefined' && arg instanceof SharedArrayBuffer) {\n return '[SharedArrayBuffer(' + arg.byteLength + ')]';\n }\n\n if (depth >= MAX_DEPTH) {\n return '[MaxDepth]';\n }\n\n if (seen.indexOf(arg) !== -1) {\n return '[Circular]';\n }\n\n seen.push(arg);\n\n if (Array.isArray(arg)) {\n var arrayResult = [];\n var arrayLength = Math.min(arg.length, MAX_ARRAY_LEN);\n for (var arrayIndex = 0; arrayIndex < arrayLength; arrayIndex++) {\n arrayResult.push(serializeConsoleArg(arg[arrayIndex], seen, depth + 1));\n }\n if (arg.length > MAX_ARRAY_LEN) {\n arrayResult.push('... (' + (arg.length - MAX_ARRAY_LEN) + ' more)');\n }\n seen.pop();\n return arrayResult;\n }\n\n var objectResult = {};\n var keys = Object.keys(arg);\n var keyLength = Math.min(keys.length, MAX_OBJECT_KEYS);\n for (var keyIndex = 0; keyIndex < keyLength; keyIndex++) {\n var key = keys[keyIndex];\n try {\n objectResult[key] = serializeConsoleArg(arg[key], seen, depth + 1);\n } catch (error) {\n objectResult[key] = '[Thrown: ' + String(error) + ']';\n }\n }\n if (keys.length > MAX_OBJECT_KEYS) {\n objectResult['...'] = '(' + (keys.length - MAX_OBJECT_KEYS) + ' more keys)';\n }\n seen.pop();\n return objectResult;\n }\n\n // Override global console methods\n for (var j = 0; j < CONSOLE_LEVELS.length; j++) {\n (function(level) {\n var original = originalConsole[level];\n console[level] = function() {\n var args = Array.prototype.slice.call(arguments);\n \n // Always call original first so logs appear normally\n original.apply(console, args);\n \n // Skip our own TSD Console Pipe logs to avoid recursion/noise\n if (args.length > 0 && typeof args[0] === 'string' && \n (args[0].indexOf('[TSD Console Pipe]') !== -1 || \n args[0].indexOf('[@tanstack/devtools') !== -1)) {\n return;\n }\n\n var safeArgs = args.map(function(arg) {\n try {\n return serializeConsoleArg(arg, [], 0);\n } catch (e) {\n return String(arg);\n }\n });\n\n var entry = {\n level: level,\n args: safeArgs,\n source: isServer ? 'server' : 'client',\n timestamp: Date.now(),\n };\n \n addToBatch(entry);\n };\n })(CONSOLE_LEVELS[j]);\n }\n\n // CLIENT ONLY: Listen for server console logs via SSE\n if (!isServer) {\n // Transform server log args - strip ANSI codes and convert source paths to clickable URLs\n function transformServerLogArgs(args) {\n var escChar = String.fromCharCode(27);\n var transformed = [];\n \n for (var k = 0; k < args.length; k++) {\n var arg = args[k];\n if (typeof arg === 'string') {\n // Strip ANSI escape sequences (ESC[...m patterns)\n var cleaned = arg;\n // Remove ESC character followed by [...m] - need to build regex dynamically\n while (cleaned.indexOf(escChar) !== -1) {\n cleaned = cleaned.split(escChar).join('');\n }\n // Also remove any leftover bracket codes like [35m\n cleaned = cleaned.replace(/\\\\[[0-9;]*m/g, '');\n \n // Transform source paths to clickable URLs\n // Match patterns like /src/components/Header.tsx:17:3\n var sourceRegex = /(\\\\/[^\\\\s]+:\\\\d+:\\\\d+)/g;\n cleaned = cleaned.replace(sourceRegex, function(match) {\n return window.location.origin + '/__tsd/open-source?source=' + encodeURIComponent(match);\n });\n \n if (cleaned.trim()) {\n transformed.push(cleaned);\n }\n } else {\n transformed.push(arg);\n }\n }\n \n return transformed;\n }\n\n var eventSource = new EventSource('/__tsd/console-pipe/sse');\n \n eventSource.onmessage = function(event) {\n try {\n var data = JSON.parse(event.data);\n if (data.entries) {\n for (var m = 0; m < data.entries.length; m++) {\n var entry = data.entries[m];\n var transformedArgs = transformServerLogArgs(entry.args);\n var prefix = '%c[Server]%c';\n var prefixStyle = 'color: #9333ea; font-weight: bold;';\n var resetStyle = 'color: inherit;';\n var logMethod = originalConsole[entry.level] || originalConsole.log;\n logMethod.apply(console, [prefix, prefixStyle, resetStyle].concat(transformedArgs));\n }\n }\n } catch (err) {\n // Swallow errors \n }\n };\n\n eventSource.onerror = function() {\n // Swallow errors \n };\n\n // Flush on page unload\n window.addEventListener('beforeunload', flushBatch);\n }\n})();\n`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,SAAgB,wBACd,QACA,eACQ;CAGR,OAAO;;;;;;;;;;;yBAFa,KAAK,UAAU,OAaZ,CAAY;0BACX,KAAK,UAAU,cAAc,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/ast-utils.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { Node } from 'oxc-parser'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cache of keys that hold child nodes (objects/arrays) per AST node type.
|
|
5
|
-
* Since oxc-parser produces AST via JSON.parse, every instance of a given
|
|
6
|
-
* node type has the same set of keys, so we only need to discover them once.
|
|
7
|
-
*/
|
|
8
|
-
const childKeysCache = new Map<string, Array<string>>()
|
|
9
|
-
|
|
10
|
-
function getChildKeys(node: Node): Array<string> {
|
|
11
|
-
let keys = childKeysCache.get(node.type)
|
|
12
|
-
if (keys) return keys
|
|
13
|
-
|
|
14
|
-
keys = []
|
|
15
|
-
for (const key in node) {
|
|
16
|
-
if (key === 'type' || key === 'start' || key === 'end') continue
|
|
17
|
-
// typeof null === 'object', so nullable node fields get cached too
|
|
18
|
-
if (typeof (node as any)[key] === 'object') {
|
|
19
|
-
keys.push(key)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
childKeysCache.set(node.type, keys)
|
|
23
|
-
return keys
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Iterate over the direct child nodes of an AST node.
|
|
28
|
-
* Uses a per-type cache of which keys hold child nodes to avoid
|
|
29
|
-
* allocating Object.entries() arrays on every call.
|
|
30
|
-
*/
|
|
31
|
-
export function forEachChild(node: Node, callback: (child: Node) => void) {
|
|
32
|
-
const keys = getChildKeys(node)
|
|
33
|
-
for (const key of keys) {
|
|
34
|
-
const value = (node as any)[key]
|
|
35
|
-
if (value === null) continue
|
|
36
|
-
if (Array.isArray(value)) {
|
|
37
|
-
for (const item of value) {
|
|
38
|
-
if (typeof item === 'object' && item !== null && 'type' in item) {
|
|
39
|
-
callback(item)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
} else if ('type' in value) {
|
|
43
|
-
callback(value as Node)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Recursively walk AST nodes, calling `visitor` for each node with a `type`.
|
|
50
|
-
*/
|
|
51
|
-
export function walk(
|
|
52
|
-
node: Node,
|
|
53
|
-
visitor: (node: Node, parentNode?: Node) => void,
|
|
54
|
-
parentNode?: Node,
|
|
55
|
-
) {
|
|
56
|
-
visitor(node, parentNode)
|
|
57
|
-
forEachChild(node, (child) => walk(child, visitor, node))
|
|
58
|
-
}
|
package/src/devtools-packages.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const TANSTACK_DEVTOOLS_PACKAGES = [
|
|
2
|
-
'@tanstack/react-devtools',
|
|
3
|
-
'@tanstack/preact-devtools',
|
|
4
|
-
'@tanstack/solid-devtools',
|
|
5
|
-
'@tanstack/vue-devtools',
|
|
6
|
-
'@tanstack/svelte-devtools',
|
|
7
|
-
'@tanstack/angular-devtools',
|
|
8
|
-
'@tanstack/devtools',
|
|
9
|
-
] as const
|
|
10
|
-
|
|
11
|
-
export const isTanStackDevtoolsImport = (source: string): boolean =>
|
|
12
|
-
(TANSTACK_DEVTOOLS_PACKAGES as ReadonlyArray<string>).includes(source)
|
package/src/editor.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
type OpenSourceData = {
|
|
2
|
-
type: 'open-source'
|
|
3
|
-
data: {
|
|
4
|
-
/** The source file to open */
|
|
5
|
-
source?: string
|
|
6
|
-
/** The react router route ID, usually discovered via the hook useMatches */
|
|
7
|
-
routeID?: string
|
|
8
|
-
/** The line number in the source file */
|
|
9
|
-
line?: number
|
|
10
|
-
/** The column number in the source file */
|
|
11
|
-
column?: number
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type EditorConfig = {
|
|
16
|
-
/** The name of the editor, used for debugging purposes */
|
|
17
|
-
name: string
|
|
18
|
-
/** Callback to open a file in the editor */
|
|
19
|
-
open: (
|
|
20
|
-
path: string,
|
|
21
|
-
lineNumber: string | undefined,
|
|
22
|
-
columnNumber?: string,
|
|
23
|
-
) => Promise<void>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const DEFAULT_EDITOR_CONFIG: EditorConfig = {
|
|
27
|
-
name: 'VSCode',
|
|
28
|
-
open: async (path, lineNumber, columnNumber) => {
|
|
29
|
-
const launch = (await import('launch-editor')).default
|
|
30
|
-
launch(
|
|
31
|
-
`${path}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}`,
|
|
32
|
-
undefined,
|
|
33
|
-
(filename, err) => {
|
|
34
|
-
console.warn(`Failed to open ${filename} in editor: ${err}`)
|
|
35
|
-
},
|
|
36
|
-
)
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const handleOpenSource = async ({
|
|
41
|
-
data,
|
|
42
|
-
openInEditor,
|
|
43
|
-
}: {
|
|
44
|
-
data: OpenSourceData
|
|
45
|
-
openInEditor: EditorConfig['open']
|
|
46
|
-
}) => {
|
|
47
|
-
const { source, line, column } = data.data
|
|
48
|
-
const lineNum = line ? `${line}` : undefined
|
|
49
|
-
const columnNum = column ? `${column}` : undefined
|
|
50
|
-
if (source) {
|
|
51
|
-
return openInEditor(source, lineNum, columnNum)
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src/enhance-logs.test.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import { enhanceConsoleLog } from './enhance-logs'
|
|
3
|
-
|
|
4
|
-
const removeEmptySpace = (str: string) => {
|
|
5
|
-
return str.replace(/\s/g, '').trim()
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
describe('enhance-logs', () => {
|
|
9
|
-
test('it adds enhanced console.logs to console.log()', () => {
|
|
10
|
-
const output = removeEmptySpace(
|
|
11
|
-
enhanceConsoleLog(
|
|
12
|
-
`
|
|
13
|
-
console.log('This is a log')
|
|
14
|
-
`,
|
|
15
|
-
'test.jsx',
|
|
16
|
-
3000,
|
|
17
|
-
)!.code,
|
|
18
|
-
)
|
|
19
|
-
expect(
|
|
20
|
-
output.includes(
|
|
21
|
-
'http://localhost:3000/__tsd/open-source?source=test.jsx',
|
|
22
|
-
),
|
|
23
|
-
).toEqual(true)
|
|
24
|
-
expect(output.includes('test.jsx:2:9')).toEqual(true)
|
|
25
|
-
expect(output.includes(removeEmptySpace("'This is a log'"))).toEqual(true)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('it does not add enhanced console.logs to console.log that is not called', () => {
|
|
29
|
-
const output = enhanceConsoleLog(
|
|
30
|
-
`
|
|
31
|
-
console.log
|
|
32
|
-
`,
|
|
33
|
-
'test.jsx',
|
|
34
|
-
3000,
|
|
35
|
-
)
|
|
36
|
-
expect(output).toBe(undefined)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('it does not add enhanced console.logs to console.log that is inside a comment', () => {
|
|
40
|
-
const output = enhanceConsoleLog(
|
|
41
|
-
`
|
|
42
|
-
// console.log('This is a log')
|
|
43
|
-
`,
|
|
44
|
-
'test.jsx',
|
|
45
|
-
3000,
|
|
46
|
-
)
|
|
47
|
-
expect(output).toBe(undefined)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('it does not add enhanced console.logs to console.log that is inside a multiline comment', () => {
|
|
51
|
-
const output = enhanceConsoleLog(
|
|
52
|
-
`
|
|
53
|
-
/*
|
|
54
|
-
console.log('This is a log')
|
|
55
|
-
*/
|
|
56
|
-
`,
|
|
57
|
-
'test.jsx',
|
|
58
|
-
3000,
|
|
59
|
-
)
|
|
60
|
-
expect(output).toBe(undefined)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
test('it does not add enhanced console.error to console.error that is inside a comment', () => {
|
|
64
|
-
const output = enhanceConsoleLog(
|
|
65
|
-
`
|
|
66
|
-
// console.error('This is a log')
|
|
67
|
-
`,
|
|
68
|
-
'test.jsx',
|
|
69
|
-
3000,
|
|
70
|
-
)
|
|
71
|
-
expect(output).toBe(undefined)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
test('it does not add enhanced console.error to console.error that is inside a multiline comment', () => {
|
|
75
|
-
const output = enhanceConsoleLog(
|
|
76
|
-
`
|
|
77
|
-
/*
|
|
78
|
-
console.error('This is a log')
|
|
79
|
-
*/
|
|
80
|
-
`,
|
|
81
|
-
'test.jsx',
|
|
82
|
-
3000,
|
|
83
|
-
)
|
|
84
|
-
expect(output).toBe(undefined)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('it adds enhanced console.error to console.error()', () => {
|
|
88
|
-
const output = removeEmptySpace(
|
|
89
|
-
enhanceConsoleLog(
|
|
90
|
-
`
|
|
91
|
-
console.error('This is a log')
|
|
92
|
-
`,
|
|
93
|
-
'test.jsx',
|
|
94
|
-
3000,
|
|
95
|
-
)!.code,
|
|
96
|
-
)
|
|
97
|
-
expect(
|
|
98
|
-
output.includes(
|
|
99
|
-
'http://localhost:3000/__tsd/open-source?source=test.jsx',
|
|
100
|
-
),
|
|
101
|
-
).toEqual(true)
|
|
102
|
-
expect(output.includes('test.jsx:2:9')).toEqual(true)
|
|
103
|
-
expect(output.includes(removeEmptySpace("'This is a log'"))).toEqual(true)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('it does not add enhanced console.error to console.error that is not called', () => {
|
|
107
|
-
const output = enhanceConsoleLog(
|
|
108
|
-
`
|
|
109
|
-
console.log
|
|
110
|
-
`,
|
|
111
|
-
'test.jsx',
|
|
112
|
-
3000,
|
|
113
|
-
)
|
|
114
|
-
expect(output).toBe(undefined)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
test('it adds enhanced console.log with css formatting to console.log()', () => {
|
|
118
|
-
const output = removeEmptySpace(
|
|
119
|
-
enhanceConsoleLog(
|
|
120
|
-
`
|
|
121
|
-
console.log('This is a log')
|
|
122
|
-
`,
|
|
123
|
-
'test.jsx',
|
|
124
|
-
3000,
|
|
125
|
-
)!.code,
|
|
126
|
-
)
|
|
127
|
-
expect(output.includes('color:#A0A')).toEqual(true)
|
|
128
|
-
expect(output.includes('color:#FFF')).toEqual(true)
|
|
129
|
-
expect(output.includes('color:#55F')).toEqual(true)
|
|
130
|
-
expect(output.includes('color:#FFF')).toEqual(true)
|
|
131
|
-
})
|
|
132
|
-
})
|
package/src/enhance-logs.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import { normalizePath } from 'vite'
|
|
3
|
-
import MagicString from 'magic-string'
|
|
4
|
-
import { parseSync } from 'oxc-parser'
|
|
5
|
-
import { createLocMapper } from './offset-to-loc'
|
|
6
|
-
import { walk } from './ast-utils'
|
|
7
|
-
|
|
8
|
-
function escapeForStringLiteral(str: string): string {
|
|
9
|
-
return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function enhanceConsoleLog(code: string, id: string, port: number) {
|
|
13
|
-
const filePath = id.split('?')[0]!
|
|
14
|
-
const location = filePath.replace(normalizePath(process.cwd()), '')
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const result = parseSync(filePath, code, {
|
|
18
|
-
sourceType: 'module',
|
|
19
|
-
lang: 'tsx',
|
|
20
|
-
})
|
|
21
|
-
if (result.errors.length > 0) return
|
|
22
|
-
|
|
23
|
-
const offsetToLoc = createLocMapper(code)
|
|
24
|
-
const s = new MagicString(code)
|
|
25
|
-
|
|
26
|
-
walk(result.program, (node) => {
|
|
27
|
-
if (node.type !== 'CallExpression') return
|
|
28
|
-
|
|
29
|
-
const callee = node.callee
|
|
30
|
-
if (
|
|
31
|
-
callee.type === 'MemberExpression' &&
|
|
32
|
-
!callee.computed &&
|
|
33
|
-
callee.object.type === 'Identifier' &&
|
|
34
|
-
callee.object.name === 'console' &&
|
|
35
|
-
callee.property.type === 'Identifier' &&
|
|
36
|
-
(callee.property.name === 'log' || callee.property.name === 'error')
|
|
37
|
-
) {
|
|
38
|
-
const loc = offsetToLoc(node.start)
|
|
39
|
-
const [lineNumber, column] = [loc.line, loc.column]
|
|
40
|
-
const finalPath = `${location}:${lineNumber}:${column + 1}`
|
|
41
|
-
const logMessage = `${chalk.magenta('LOG')} ${chalk.blueBright(`${finalPath}`)}\n → `
|
|
42
|
-
|
|
43
|
-
const serverLogMessage = `["${escapeForStringLiteral(logMessage)}"]`
|
|
44
|
-
const browserLogMessage = `["%c${'LOG'}%c %c${`Go to Source: http://localhost:${port}/__tsd/open-source?source=${encodeURIComponent(finalPath)}`}%c \\n \\u2192 ","color:#A0A","color:#FFF","color:#55F","color:#FFF"]`
|
|
45
|
-
|
|
46
|
-
const spreadStr = `...(typeof window === "undefined" ? ${serverLogMessage} : ${browserLogMessage}), `
|
|
47
|
-
|
|
48
|
-
// Find the opening '(' of the call by scanning forward from callee end
|
|
49
|
-
let parenOffset = callee.end
|
|
50
|
-
while (parenOffset < code.length && code[parenOffset] !== '(') {
|
|
51
|
-
parenOffset++
|
|
52
|
-
}
|
|
53
|
-
// Insert right after '('
|
|
54
|
-
s.appendRight(parenOffset + 1, spreadStr)
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
if (!s.hasChanged()) return
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
code: s.toString(),
|
|
62
|
-
map: s.generateMap({
|
|
63
|
-
source: filePath,
|
|
64
|
-
file: id,
|
|
65
|
-
includeContent: true,
|
|
66
|
-
}),
|
|
67
|
-
}
|
|
68
|
-
} catch (e) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
}
|