@tanstack/devtools-vite 0.8.1 → 0.8.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.
Files changed (81) hide show
  1. package/dist/esm/plugin.d.ts +4 -74
  2. package/dist/esm/plugin.js +2 -12
  3. package/dist/esm/plugin.js.map +1 -1
  4. package/package.json +2 -6
  5. package/src/plugin.ts +25 -97
  6. package/dist/esm/ast-utils.d.ts +0 -11
  7. package/dist/esm/ast-utils.js +0 -44
  8. package/dist/esm/ast-utils.js.map +0 -1
  9. package/dist/esm/ast-utils.test.d.ts +0 -1
  10. package/dist/esm/devtools-packages.d.ts +0 -2
  11. package/dist/esm/devtools-packages.js +0 -15
  12. package/dist/esm/devtools-packages.js.map +0 -1
  13. package/dist/esm/devtools-packages.test.d.ts +0 -1
  14. package/dist/esm/editor.d.ts +0 -25
  15. package/dist/esm/editor.js +0 -20
  16. package/dist/esm/editor.js.map +0 -1
  17. package/dist/esm/editor.test.d.ts +0 -1
  18. package/dist/esm/enhance-logs.d.ts +0 -4
  19. package/dist/esm/enhance-logs.js +0 -51
  20. package/dist/esm/enhance-logs.js.map +0 -1
  21. package/dist/esm/enhance-logs.test.d.ts +0 -1
  22. package/dist/esm/inject-plugin.d.ts +0 -22
  23. package/dist/esm/inject-plugin.js +0 -179
  24. package/dist/esm/inject-plugin.js.map +0 -1
  25. package/dist/esm/inject-plugin.test.d.ts +0 -1
  26. package/dist/esm/inject-source.d.ts +0 -7
  27. package/dist/esm/inject-source.js +0 -114
  28. package/dist/esm/inject-source.js.map +0 -1
  29. package/dist/esm/inject-source.test.d.ts +0 -1
  30. package/dist/esm/matcher.d.ts +0 -1
  31. package/dist/esm/matcher.js +0 -13
  32. package/dist/esm/matcher.js.map +0 -1
  33. package/dist/esm/matcher.test.d.ts +0 -1
  34. package/dist/esm/offset-to-loc.d.ts +0 -14
  35. package/dist/esm/offset-to-loc.js +0 -29
  36. package/dist/esm/offset-to-loc.js.map +0 -1
  37. package/dist/esm/offset-to-loc.test.d.ts +0 -1
  38. package/dist/esm/package-manager.d.ts +0 -16
  39. package/dist/esm/package-manager.js +0 -98
  40. package/dist/esm/package-manager.js.map +0 -1
  41. package/dist/esm/remove-devtools.d.ts +0 -4
  42. package/dist/esm/remove-devtools.js +0 -96
  43. package/dist/esm/remove-devtools.js.map +0 -1
  44. package/dist/esm/remove-devtools.test.d.ts +0 -1
  45. package/dist/esm/runtime-bridge.d.ts +0 -31
  46. package/dist/esm/runtime-bridge.js +0 -75
  47. package/dist/esm/runtime-bridge.js.map +0 -1
  48. package/dist/esm/runtime-bridge.test.d.ts +0 -1
  49. package/dist/esm/utils.d.ts +0 -31
  50. package/dist/esm/utils.js +0 -155
  51. package/dist/esm/utils.js.map +0 -1
  52. package/dist/esm/utils.test.d.ts +0 -1
  53. package/dist/esm/virtual-console.d.ts +0 -19
  54. package/dist/esm/virtual-console.js +0 -336
  55. package/dist/esm/virtual-console.js.map +0 -1
  56. package/dist/esm/virtual-console.test.d.ts +0 -1
  57. package/src/ast-utils.test.ts +0 -109
  58. package/src/ast-utils.ts +0 -58
  59. package/src/devtools-packages.test.ts +0 -58
  60. package/src/devtools-packages.ts +0 -12
  61. package/src/editor.test.ts +0 -75
  62. package/src/editor.ts +0 -53
  63. package/src/enhance-logs.test.ts +0 -132
  64. package/src/enhance-logs.ts +0 -71
  65. package/src/inject-plugin.test.ts +0 -1139
  66. package/src/inject-plugin.ts +0 -300
  67. package/src/inject-source.test.ts +0 -939
  68. package/src/inject-source.ts +0 -235
  69. package/src/matcher.test.ts +0 -33
  70. package/src/matcher.ts +0 -19
  71. package/src/offset-to-loc.test.ts +0 -34
  72. package/src/offset-to-loc.ts +0 -39
  73. package/src/package-manager.ts +0 -181
  74. package/src/remove-devtools.test.ts +0 -607
  75. package/src/remove-devtools.ts +0 -190
  76. package/src/runtime-bridge.test.ts +0 -179
  77. package/src/runtime-bridge.ts +0 -113
  78. package/src/utils.test.ts +0 -184
  79. package/src/utils.ts +0 -247
  80. package/src/virtual-console.test.ts +0 -244
  81. 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, '&quot;') + '"';
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, '&quot;') + '\"';\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 {};
@@ -1,109 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { forEachChild, walk } from './ast-utils'
3
- import type { Node } from 'oxc-parser'
4
-
5
- describe('forEachChild', () => {
6
- it('visits only direct typed children, skipping null and non-type values', () => {
7
- const childA = { type: 'ChildA', start: 0, end: 1 }
8
- const childB = { type: 'ChildB', start: 1, end: 2 }
9
- const nested = { type: 'Nested', start: 2, end: 3 }
10
- const root = {
11
- type: 'ForEachRoot',
12
- start: 0,
13
- end: 10,
14
- // array-valued key holding two typed children
15
- items: [childA, childB],
16
- // object-valued typed child
17
- body: nested,
18
- // null field: skipped
19
- optional: null,
20
- // primitive string value: not a child (and excluded from child keys)
21
- name: 'hello',
22
- // primitive number value: not a child
23
- count: 5,
24
- } as unknown as Node
25
-
26
- const visited: Array<Node> = []
27
- forEachChild(root, (child) => visited.push(child))
28
-
29
- expect(visited).toEqual([childA, childB, nested])
30
- expect(visited).toHaveLength(3)
31
- })
32
-
33
- it('skips non-object array items and array items without a type', () => {
34
- const real = { type: 'RealItem', start: 0, end: 1 }
35
- const root = {
36
- type: 'ForEachArrayRoot',
37
- start: 0,
38
- end: 10,
39
- items: [real, null, 'string-item', 42, { noType: true }],
40
- } as unknown as Node
41
-
42
- const visited: Array<Node> = []
43
- forEachChild(root, (child) => visited.push(child))
44
-
45
- expect(visited).toEqual([real])
46
- })
47
- })
48
-
49
- describe('walk', () => {
50
- it('visits every node depth-first with the correct parentNode', () => {
51
- const grandchild = { type: 'WalkGrandchild', start: 4, end: 5 }
52
- const childA = {
53
- type: 'WalkChildA',
54
- start: 1,
55
- end: 6,
56
- inner: grandchild,
57
- }
58
- const childB = { type: 'WalkChildB', start: 6, end: 7 }
59
- const root = {
60
- type: 'WalkRoot',
61
- start: 0,
62
- end: 10,
63
- children: [childA, childB],
64
- } as unknown as Node
65
-
66
- const visits: Array<{ node: Node; parent: Node | undefined }> = []
67
- walk(root, (node, parentNode) => {
68
- visits.push({ node, parent: parentNode })
69
- })
70
-
71
- // Depth-first order: root, childA, grandchild, childB
72
- expect(visits.map((v) => v.node.type)).toEqual([
73
- 'WalkRoot',
74
- 'WalkChildA',
75
- 'WalkGrandchild',
76
- 'WalkChildB',
77
- ])
78
-
79
- // Correct parent for each node
80
- expect(visits[0]!.parent).toBeUndefined()
81
- expect(visits[1]!.parent).toBe(root)
82
- expect(visits[2]!.parent).toBe(childA)
83
- expect(visits[3]!.parent).toBe(root)
84
- })
85
-
86
- it('passes the provided parentNode through to the root visit', () => {
87
- const fakeParent = {
88
- type: 'WalkExternalParent',
89
- start: 0,
90
- end: 1,
91
- } as unknown as Node
92
- const root = {
93
- type: 'WalkRootWithParent',
94
- start: 1,
95
- end: 2,
96
- } as unknown as Node
97
-
98
- const visits: Array<{ node: Node; parent: Node | undefined }> = []
99
- walk(
100
- root,
101
- (node, parentNode) => visits.push({ node, parent: parentNode }),
102
- fakeParent,
103
- )
104
-
105
- expect(visits).toHaveLength(1)
106
- expect(visits[0]!.node).toBe(root)
107
- expect(visits[0]!.parent).toBe(fakeParent)
108
- })
109
- })
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
- }
@@ -1,58 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import {
3
- TANSTACK_DEVTOOLS_PACKAGES,
4
- isTanStackDevtoolsImport,
5
- } from './devtools-packages'
6
-
7
- describe('TANSTACK_DEVTOOLS_PACKAGES', () => {
8
- it('contains exactly 7 entries', () => {
9
- expect(TANSTACK_DEVTOOLS_PACKAGES).toHaveLength(7)
10
- })
11
-
12
- it('includes the known framework-specific devtools packages', () => {
13
- expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/react-devtools')
14
- expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/preact-devtools')
15
- expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/solid-devtools')
16
- expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/vue-devtools')
17
- expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/svelte-devtools')
18
- expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/angular-devtools')
19
- })
20
-
21
- it('includes the framework-agnostic @tanstack/devtools entry', () => {
22
- expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/devtools')
23
- })
24
- })
25
-
26
- describe('isTanStackDevtoolsImport', () => {
27
- it('returns true for @tanstack/react-devtools', () => {
28
- expect(isTanStackDevtoolsImport('@tanstack/react-devtools')).toBe(true)
29
- })
30
-
31
- it('returns true for @tanstack/devtools', () => {
32
- expect(isTanStackDevtoolsImport('@tanstack/devtools')).toBe(true)
33
- })
34
-
35
- it('returns true for every entry in TANSTACK_DEVTOOLS_PACKAGES', () => {
36
- for (const pkg of TANSTACK_DEVTOOLS_PACKAGES) {
37
- expect(isTanStackDevtoolsImport(pkg)).toBe(true)
38
- }
39
- })
40
-
41
- it('returns false for an unrelated package', () => {
42
- expect(isTanStackDevtoolsImport('react')).toBe(false)
43
- })
44
-
45
- it('returns false for an empty string', () => {
46
- expect(isTanStackDevtoolsImport('')).toBe(false)
47
- })
48
-
49
- it('returns false for a @tanstack package that is not in the devtools list', () => {
50
- expect(isTanStackDevtoolsImport('@tanstack/other-thing')).toBe(false)
51
- })
52
-
53
- it('returns false for a prefix-only match (no partial matching)', () => {
54
- expect(isTanStackDevtoolsImport('@tanstack/react-devtools/extra')).toBe(
55
- false,
56
- )
57
- })
58
- })
@@ -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)
@@ -1,75 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest'
2
- import { handleOpenSource } from './editor'
3
-
4
- describe('handleOpenSource', () => {
5
- it('calls openInEditor with source, stringified line and column when all provided', async () => {
6
- const openInEditor = vi.fn().mockResolvedValue(undefined)
7
- await handleOpenSource({
8
- data: {
9
- type: 'open-source',
10
- data: { source: '/app/routes/foo.tsx', line: 10, column: 5 },
11
- },
12
- openInEditor,
13
- })
14
- expect(openInEditor).toHaveBeenCalledOnce()
15
- expect(openInEditor).toHaveBeenCalledWith('/app/routes/foo.tsx', '10', '5')
16
- })
17
-
18
- it('calls openInEditor with source only when line and column are undefined', async () => {
19
- const openInEditor = vi.fn().mockResolvedValue(undefined)
20
- await handleOpenSource({
21
- data: { type: 'open-source', data: { source: '/app/routes/bar.tsx' } },
22
- openInEditor,
23
- })
24
- expect(openInEditor).toHaveBeenCalledOnce()
25
- expect(openInEditor).toHaveBeenCalledWith(
26
- '/app/routes/bar.tsx',
27
- undefined,
28
- undefined,
29
- )
30
- })
31
-
32
- it('does NOT call openInEditor and returns undefined when source is absent', async () => {
33
- const openInEditor = vi.fn()
34
- const result = await handleOpenSource({
35
- data: { type: 'open-source', data: { line: 1, column: 2 } },
36
- openInEditor,
37
- })
38
- expect(openInEditor).not.toHaveBeenCalled()
39
- expect(result).toBeUndefined()
40
- })
41
-
42
- it('treats falsy line: 0 and column: 0 as undefined (truthy check in impl)', async () => {
43
- const openInEditor = vi.fn().mockResolvedValue(undefined)
44
- await handleOpenSource({
45
- data: {
46
- type: 'open-source',
47
- data: { source: '/app/routes/baz.tsx', line: 0, column: 0 },
48
- },
49
- openInEditor,
50
- })
51
- expect(openInEditor).toHaveBeenCalledOnce()
52
- expect(openInEditor).toHaveBeenCalledWith(
53
- '/app/routes/baz.tsx',
54
- undefined,
55
- undefined,
56
- )
57
- })
58
-
59
- it('calls openInEditor with stringified line and undefined column when only line is provided', async () => {
60
- const openInEditor = vi.fn().mockResolvedValue(undefined)
61
- await handleOpenSource({
62
- data: {
63
- type: 'open-source',
64
- data: { source: '/app/routes/qux.tsx', line: 42 },
65
- },
66
- openInEditor,
67
- })
68
- expect(openInEditor).toHaveBeenCalledOnce()
69
- expect(openInEditor).toHaveBeenCalledWith(
70
- '/app/routes/qux.tsx',
71
- '42',
72
- undefined,
73
- )
74
- })
75
- })