@tanstack/devtools-vite 0.5.5 → 0.6.1
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/babel.js +7 -15
- package/dist/esm/babel.js.map +1 -1
- package/dist/esm/editor.js +18 -27
- package/dist/esm/editor.js.map +1 -1
- package/dist/esm/enhance-logs.js +48 -80
- package/dist/esm/enhance-logs.js.map +1 -1
- package/dist/esm/index.js +1 -5
- package/dist/esm/inject-plugin.js +160 -220
- package/dist/esm/inject-plugin.js.map +1 -1
- package/dist/esm/inject-source.js +108 -201
- package/dist/esm/inject-source.js.map +1 -1
- package/dist/esm/matcher.js +11 -16
- package/dist/esm/matcher.js.map +1 -1
- package/dist/esm/package-manager.js +90 -131
- package/dist/esm/package-manager.js.map +1 -1
- package/dist/esm/plugin.js +334 -448
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/remove-devtools.js +97 -131
- package/dist/esm/remove-devtools.js.map +1 -1
- package/dist/esm/utils.js +149 -162
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/virtual-console.js +170 -14
- package/dist/esm/virtual-console.js.map +1 -1
- package/package.json +3 -3
- package/src/plugin.ts +9 -1
- package/src/virtual-console.test.ts +172 -1
- package/src/virtual-console.ts +146 -7
- package/dist/esm/index.js.map +0 -1
package/dist/esm/plugin.js
CHANGED
|
@@ -1,456 +1,342 @@
|
|
|
1
|
-
import { devtoolsEventClient } from "@tanstack/devtools-client";
|
|
2
|
-
import { ServerEventBus } from "@tanstack/devtools-event-bus/server";
|
|
3
|
-
import { normalizePath } from "vite";
|
|
4
|
-
import chalk from "chalk";
|
|
5
1
|
import { handleDevToolsViteRequest, readPackageJson, stripEnhancedLogPrefix } from "./utils.js";
|
|
6
2
|
import { DEFAULT_EDITOR_CONFIG, handleOpenSource } from "./editor.js";
|
|
7
3
|
import { removeDevtools } from "./remove-devtools.js";
|
|
8
4
|
import { addSourceToJsx } from "./inject-source.js";
|
|
9
5
|
import { enhanceConsoleLog } from "./enhance-logs.js";
|
|
10
6
|
import { detectDevtoolsFile, injectPluginIntoFile } from "./inject-plugin.js";
|
|
11
|
-
import { emitOutdatedDeps, installPackage
|
|
7
|
+
import { addPluginToDevtools, emitOutdatedDeps, installPackage } from "./package-manager.js";
|
|
12
8
|
import { generateConsolePipeCode } from "./virtual-console.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
},
|
|
343
|
-
async handleHotUpdate({ file }) {
|
|
344
|
-
if (file.endsWith("package.json")) {
|
|
345
|
-
const newPackageJson = await readPackageJson();
|
|
346
|
-
devtoolsEventClient.emit("package-json-read", {
|
|
347
|
-
packageJson: newPackageJson
|
|
348
|
-
});
|
|
349
|
-
emitOutdatedDeps();
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
// Inject console piping code into entry files (both client and server)
|
|
354
|
-
{
|
|
355
|
-
name: "@tanstack/devtools:console-pipe-transform",
|
|
356
|
-
enforce: "pre",
|
|
357
|
-
apply(config, { command }) {
|
|
358
|
-
return config.mode === "development" && command === "serve" && (consolePipingConfig.enabled ?? true);
|
|
359
|
-
},
|
|
360
|
-
transform: {
|
|
361
|
-
filter: {
|
|
362
|
-
id: {
|
|
363
|
-
include: /\.(tsx?|jsx?)$/,
|
|
364
|
-
exclude: [/node_modules/, /\/dist\//, /\?/]
|
|
365
|
-
},
|
|
366
|
-
code: {
|
|
367
|
-
exclude: /__tsdConsolePipe/
|
|
368
|
-
// avoid transforming files that already contain the console pipe code
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
handler(code) {
|
|
372
|
-
const isRootEntry = /<html[\s>]/i.test(code) || code.includes("StartClient") || code.includes("hydrateRoot") || code.includes("createRoot") || code.includes("solid-js/web") && code.includes("render(");
|
|
373
|
-
if (isRootEntry) {
|
|
374
|
-
const viteServerUrl = `http://localhost:${port}`;
|
|
375
|
-
const inlineCode = generateConsolePipeCode(
|
|
376
|
-
consolePipingLevels,
|
|
377
|
-
viteServerUrl
|
|
378
|
-
);
|
|
379
|
-
return `${inlineCode}
|
|
380
|
-
${code}`;
|
|
381
|
-
}
|
|
382
|
-
return void 0;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
name: "@tanstack/devtools:better-console-logs",
|
|
388
|
-
enforce: "pre",
|
|
389
|
-
apply(config) {
|
|
390
|
-
return config.mode === "development" && enhancedLogsConfig.enabled;
|
|
391
|
-
},
|
|
392
|
-
transform: {
|
|
393
|
-
filter: {
|
|
394
|
-
id: {
|
|
395
|
-
exclude: [/node_modules/, /\?raw/, /\/dist\//, /\/build\//]
|
|
396
|
-
},
|
|
397
|
-
code: {
|
|
398
|
-
include: "console."
|
|
399
|
-
}
|
|
400
|
-
},
|
|
401
|
-
handler(code, id) {
|
|
402
|
-
return enhanceConsoleLog(code, id, port);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
name: "@tanstack/devtools:inject-plugin",
|
|
408
|
-
apply(config, { command }) {
|
|
409
|
-
return config.mode === "development" && command === "serve";
|
|
410
|
-
},
|
|
411
|
-
transform(code, id) {
|
|
412
|
-
if (!devtoolsFileId && detectDevtoolsFile(code)) {
|
|
413
|
-
const [filePath] = id.split("?");
|
|
414
|
-
if (filePath) {
|
|
415
|
-
devtoolsFileId = filePath;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return void 0;
|
|
419
|
-
}
|
|
420
|
-
},
|
|
421
|
-
{
|
|
422
|
-
name: "@tanstack/devtools:connection-injection",
|
|
423
|
-
apply(config, { command }) {
|
|
424
|
-
return config.mode === "development" && command === "serve";
|
|
425
|
-
},
|
|
426
|
-
transform(code, id) {
|
|
427
|
-
const hasPlaceholder = code.includes("__TANSTACK_DEVTOOLS_PORT__") || code.includes("__TANSTACK_DEVTOOLS_HOST__") || code.includes("__TANSTACK_DEVTOOLS_PROTOCOL__");
|
|
428
|
-
if (!hasPlaceholder) return;
|
|
429
|
-
if (!id.includes("@tanstack/devtools") && !id.includes("@tanstack/event-bus"))
|
|
430
|
-
return;
|
|
431
|
-
const portValue = devtoolsPort ?? 4206;
|
|
432
|
-
const hostValue = devtoolsHost ?? "localhost";
|
|
433
|
-
const protocolValue = devtoolsProtocol ?? "http";
|
|
434
|
-
let result = code;
|
|
435
|
-
result = result.replace(
|
|
436
|
-
/__TANSTACK_DEVTOOLS_PORT__/g,
|
|
437
|
-
String(portValue)
|
|
438
|
-
);
|
|
439
|
-
result = result.replace(
|
|
440
|
-
/__TANSTACK_DEVTOOLS_HOST__/g,
|
|
441
|
-
JSON.stringify(hostValue)
|
|
442
|
-
);
|
|
443
|
-
result = result.replace(
|
|
444
|
-
/__TANSTACK_DEVTOOLS_PROTOCOL__/g,
|
|
445
|
-
JSON.stringify(protocolValue)
|
|
446
|
-
);
|
|
447
|
-
return result;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
];
|
|
451
|
-
};
|
|
452
|
-
export {
|
|
453
|
-
defineDevtoolsConfig,
|
|
454
|
-
devtools
|
|
9
|
+
import { devtoolsEventClient } from "@tanstack/devtools-client";
|
|
10
|
+
import { ServerEventBus } from "@tanstack/devtools-event-bus/server";
|
|
11
|
+
import { normalizePath } from "vite";
|
|
12
|
+
import chalk from "chalk";
|
|
13
|
+
//#region src/plugin.ts
|
|
14
|
+
var defineDevtoolsConfig = (config) => config;
|
|
15
|
+
var devtools = (args) => {
|
|
16
|
+
let port = 5173;
|
|
17
|
+
const logging = args?.logging ?? true;
|
|
18
|
+
const enhancedLogsConfig = args?.enhancedLogs ?? { enabled: true };
|
|
19
|
+
const injectSourceConfig = args?.injectSource ?? { enabled: true };
|
|
20
|
+
const removeDevtoolsOnBuild = args?.removeDevtoolsOnBuild ?? true;
|
|
21
|
+
const serverBusEnabled = args?.eventBusConfig?.enabled ?? true;
|
|
22
|
+
const consolePipingConfig = args?.consolePiping ?? { enabled: true };
|
|
23
|
+
const consolePipingLevels = consolePipingConfig.levels ?? [
|
|
24
|
+
"log",
|
|
25
|
+
"warn",
|
|
26
|
+
"error",
|
|
27
|
+
"info",
|
|
28
|
+
"debug"
|
|
29
|
+
];
|
|
30
|
+
let devtoolsFileId = null;
|
|
31
|
+
let devtoolsPort = null;
|
|
32
|
+
let devtoolsHost = null;
|
|
33
|
+
let devtoolsProtocol = null;
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
enforce: "pre",
|
|
37
|
+
name: "@tanstack/devtools:inject-source",
|
|
38
|
+
apply(config) {
|
|
39
|
+
return config.mode === "development" && injectSourceConfig.enabled;
|
|
40
|
+
},
|
|
41
|
+
transform: {
|
|
42
|
+
filter: { id: { exclude: [
|
|
43
|
+
/node_modules/,
|
|
44
|
+
/\?raw/,
|
|
45
|
+
/\/dist\//,
|
|
46
|
+
/\/build\//
|
|
47
|
+
] } },
|
|
48
|
+
handler(code, id) {
|
|
49
|
+
return addSourceToJsx(code, id, args?.injectSource?.ignore);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "@tanstack/devtools:config",
|
|
55
|
+
enforce: "pre",
|
|
56
|
+
config(_, { command }) {
|
|
57
|
+
if (command !== "serve") return;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
enforce: "pre",
|
|
62
|
+
name: "@tanstack/devtools:custom-server",
|
|
63
|
+
apply(config) {
|
|
64
|
+
return config.mode === "development";
|
|
65
|
+
},
|
|
66
|
+
async configureServer(server) {
|
|
67
|
+
if (serverBusEnabled) {
|
|
68
|
+
const preferredPort = args?.eventBusConfig?.port ?? 4206;
|
|
69
|
+
const isHttps = !!server.config.server.https;
|
|
70
|
+
const serverHost = typeof server.config.server.host === "string" ? server.config.server.host : "localhost";
|
|
71
|
+
devtoolsProtocol = isHttps ? "https" : "http";
|
|
72
|
+
devtoolsHost = serverHost;
|
|
73
|
+
devtoolsPort = await new ServerEventBus({
|
|
74
|
+
...args?.eventBusConfig,
|
|
75
|
+
port: preferredPort,
|
|
76
|
+
host: serverHost,
|
|
77
|
+
...isHttps && server.httpServer ? { httpServer: server.httpServer } : {}
|
|
78
|
+
}).start();
|
|
79
|
+
}
|
|
80
|
+
server.middlewares.use((req, _res, next) => {
|
|
81
|
+
if (req.socket.localPort && req.socket.localPort !== port) port = req.socket.localPort;
|
|
82
|
+
next();
|
|
83
|
+
});
|
|
84
|
+
if (server.config.server.port) port = server.config.server.port;
|
|
85
|
+
server.httpServer?.on("listening", () => {
|
|
86
|
+
port = server.config.server.port;
|
|
87
|
+
});
|
|
88
|
+
const editor = args?.editor ?? DEFAULT_EDITOR_CONFIG;
|
|
89
|
+
const openInEditor = async (path, lineNum, columnNum) => {
|
|
90
|
+
if (!path) return;
|
|
91
|
+
await editor.open(path, lineNum, columnNum);
|
|
92
|
+
};
|
|
93
|
+
const originalConsole = Object.fromEntries(consolePipingLevels.map((l) => [l, console[l].bind(console)]));
|
|
94
|
+
const sseClients = [];
|
|
95
|
+
let sseClientId = 0;
|
|
96
|
+
const consolePipingEnabled = consolePipingConfig.enabled ?? true;
|
|
97
|
+
server.middlewares.use((req, res, next) => handleDevToolsViteRequest(req, res, next, {
|
|
98
|
+
onOpenSource: (parsedData) => {
|
|
99
|
+
const { data, routine } = parsedData;
|
|
100
|
+
if (routine === "open-source") return handleOpenSource({
|
|
101
|
+
data: {
|
|
102
|
+
type: data.type,
|
|
103
|
+
data
|
|
104
|
+
},
|
|
105
|
+
openInEditor
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
...consolePipingEnabled ? {
|
|
109
|
+
onConsolePipe: (entries) => {
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
const prefix = chalk.cyan("[Client]");
|
|
112
|
+
(originalConsole[entry.level] ?? originalConsole.log)(prefix, ...stripEnhancedLogPrefix(entry.args, (loc) => chalk.gray(loc)));
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
onConsolePipeSSE: (res, req) => {
|
|
116
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
117
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
118
|
+
res.setHeader("Connection", "keep-alive");
|
|
119
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
120
|
+
res.flushHeaders();
|
|
121
|
+
const clientId = ++sseClientId;
|
|
122
|
+
sseClients.push({
|
|
123
|
+
res,
|
|
124
|
+
id: clientId
|
|
125
|
+
});
|
|
126
|
+
req.on("close", () => {
|
|
127
|
+
const index = sseClients.findIndex((c) => c.id === clientId);
|
|
128
|
+
if (index !== -1) sseClients.splice(index, 1);
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
onServerConsolePipe: (entries) => {
|
|
132
|
+
try {
|
|
133
|
+
const data = JSON.stringify({ entries: entries.map((e) => ({
|
|
134
|
+
level: e.level,
|
|
135
|
+
args: e.args,
|
|
136
|
+
source: "server",
|
|
137
|
+
timestamp: e.timestamp || Date.now()
|
|
138
|
+
})) });
|
|
139
|
+
for (const client of sseClients) client.res.write(`data: ${data}\n\n`);
|
|
140
|
+
} catch {}
|
|
141
|
+
}
|
|
142
|
+
} : {}
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "@tanstack/devtools:remove-devtools-on-build",
|
|
148
|
+
apply(config, { command }) {
|
|
149
|
+
return (command !== "serve" || config.mode === "production") && removeDevtoolsOnBuild;
|
|
150
|
+
},
|
|
151
|
+
enforce: "pre",
|
|
152
|
+
transform(code, id) {
|
|
153
|
+
if (id.includes("node_modules") || id.includes("?raw") || ![
|
|
154
|
+
"@tanstack/react-devtools",
|
|
155
|
+
"@tanstack/preact-devtools",
|
|
156
|
+
"@tanstack/solid-devtools",
|
|
157
|
+
"@tanstack/vue-devtools",
|
|
158
|
+
"@tanstack/devtools"
|
|
159
|
+
].some((pkg) => code.includes(pkg))) return;
|
|
160
|
+
const transform = removeDevtools(code, id);
|
|
161
|
+
if (!transform) return;
|
|
162
|
+
if (logging) console.log(`\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), "")}\n`);
|
|
163
|
+
return transform;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "@tanstack/devtools:event-client-setup",
|
|
168
|
+
apply(config, { command }) {
|
|
169
|
+
if (process.env.CI || process.env.NODE_ENV !== "development" || command !== "serve") return false;
|
|
170
|
+
return config.mode === "development";
|
|
171
|
+
},
|
|
172
|
+
async configureServer() {
|
|
173
|
+
const packageJson = await readPackageJson();
|
|
174
|
+
const outdatedDeps = emitOutdatedDeps().then((deps) => deps);
|
|
175
|
+
devtoolsEventClient.on("install-devtools", async (event) => {
|
|
176
|
+
const result = await installPackage(event.payload.packageName);
|
|
177
|
+
devtoolsEventClient.emit("devtools-installed", {
|
|
178
|
+
packageName: event.payload.packageName,
|
|
179
|
+
success: result.success,
|
|
180
|
+
error: result.error
|
|
181
|
+
});
|
|
182
|
+
if (result.success) {
|
|
183
|
+
const { packageName, pluginName, pluginImport } = event.payload;
|
|
184
|
+
console.log(chalk.blueBright(`[@tanstack/devtools-vite] Auto-adding ${packageName} to devtools...`));
|
|
185
|
+
if (addPluginToDevtools(devtoolsFileId, packageName, pluginName, pluginImport).success) {
|
|
186
|
+
devtoolsEventClient.emit("plugin-added", {
|
|
187
|
+
packageName,
|
|
188
|
+
success: true
|
|
189
|
+
});
|
|
190
|
+
const updatedPackageJson = await readPackageJson();
|
|
191
|
+
devtoolsEventClient.emit("package-json-read", { packageJson: updatedPackageJson });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
devtoolsEventClient.on("add-plugin-to-devtools", (event) => {
|
|
196
|
+
const { packageName, pluginName, pluginImport } = event.payload;
|
|
197
|
+
console.log(chalk.blueBright(`[@tanstack/devtools-vite] Adding ${packageName} to devtools...`));
|
|
198
|
+
const result = addPluginToDevtools(devtoolsFileId, packageName, pluginName, pluginImport);
|
|
199
|
+
devtoolsEventClient.emit("plugin-added", {
|
|
200
|
+
packageName,
|
|
201
|
+
success: result.success,
|
|
202
|
+
error: result.error
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
devtoolsEventClient.on("bump-package-version", async (event) => {
|
|
206
|
+
const { packageName, devtoolsPackage, pluginName, minVersion, pluginImport } = event.payload;
|
|
207
|
+
console.log(chalk.blueBright(`[@tanstack/devtools-vite] Bumping ${packageName} to version ${minVersion}...`));
|
|
208
|
+
const result = await installPackage(minVersion ? `${packageName}@^${minVersion}` : packageName);
|
|
209
|
+
if (!result.success) {
|
|
210
|
+
console.log(chalk.redBright(`[@tanstack/devtools-vite] Failed to bump ${packageName}: ${result.error}`));
|
|
211
|
+
devtoolsEventClient.emit("devtools-installed", {
|
|
212
|
+
packageName: devtoolsPackage,
|
|
213
|
+
success: false,
|
|
214
|
+
error: result.error
|
|
215
|
+
});
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
console.log(chalk.greenBright(`[@tanstack/devtools-vite] Successfully bumped ${packageName} to ${minVersion}!`));
|
|
219
|
+
if (!devtoolsFileId) {
|
|
220
|
+
console.log(chalk.yellowBright(`[@tanstack/devtools-vite] Devtools file not found. Skipping auto-injection.`));
|
|
221
|
+
devtoolsEventClient.emit("devtools-installed", {
|
|
222
|
+
packageName: devtoolsPackage,
|
|
223
|
+
success: true
|
|
224
|
+
});
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
console.log(chalk.blueBright(`[@tanstack/devtools-vite] Adding ${devtoolsPackage} to devtools...`));
|
|
228
|
+
const injectResult = injectPluginIntoFile(devtoolsFileId, {
|
|
229
|
+
packageName: devtoolsPackage,
|
|
230
|
+
pluginName,
|
|
231
|
+
pluginImport
|
|
232
|
+
});
|
|
233
|
+
if (injectResult.success) {
|
|
234
|
+
console.log(chalk.greenBright(`[@tanstack/devtools-vite] Successfully added ${devtoolsPackage} to devtools!`));
|
|
235
|
+
devtoolsEventClient.emit("plugin-added", {
|
|
236
|
+
packageName: devtoolsPackage,
|
|
237
|
+
success: true
|
|
238
|
+
});
|
|
239
|
+
const updatedPackageJson = await readPackageJson();
|
|
240
|
+
devtoolsEventClient.emit("package-json-read", { packageJson: updatedPackageJson });
|
|
241
|
+
} else {
|
|
242
|
+
console.log(chalk.redBright(`[@tanstack/devtools-vite] Failed to add ${devtoolsPackage} to devtools: ${injectResult.error}`));
|
|
243
|
+
devtoolsEventClient.emit("plugin-added", {
|
|
244
|
+
packageName: devtoolsPackage,
|
|
245
|
+
success: false,
|
|
246
|
+
error: injectResult.error
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
devtoolsEventClient.on("mounted", async () => {
|
|
251
|
+
devtoolsEventClient.emit("outdated-deps-read", { outdatedDeps: await outdatedDeps });
|
|
252
|
+
devtoolsEventClient.emit("package-json-read", { packageJson });
|
|
253
|
+
});
|
|
254
|
+
},
|
|
255
|
+
async handleHotUpdate({ file }) {
|
|
256
|
+
if (file.endsWith("package.json")) {
|
|
257
|
+
const newPackageJson = await readPackageJson();
|
|
258
|
+
devtoolsEventClient.emit("package-json-read", { packageJson: newPackageJson });
|
|
259
|
+
emitOutdatedDeps();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "@tanstack/devtools:console-pipe-transform",
|
|
265
|
+
enforce: "pre",
|
|
266
|
+
apply(config, { command }) {
|
|
267
|
+
return config.mode === "development" && command === "serve" && (consolePipingConfig.enabled ?? true);
|
|
268
|
+
},
|
|
269
|
+
transform: {
|
|
270
|
+
filter: {
|
|
271
|
+
id: {
|
|
272
|
+
include: /\.(tsx?|jsx?)$/,
|
|
273
|
+
exclude: [
|
|
274
|
+
/node_modules/,
|
|
275
|
+
/\/dist\//,
|
|
276
|
+
/\?/
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
code: { exclude: /__tsdConsolePipe/ }
|
|
280
|
+
},
|
|
281
|
+
handler(code) {
|
|
282
|
+
if (/<html[\s>]/i.test(code) || code.includes("StartClient") || code.includes("hydrateRoot") || code.includes("createRoot") || code.includes("solid-js/web") && code.includes("render(")) return `${generateConsolePipeCode(consolePipingLevels, `http://localhost:${port}`)}\n${code}`;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "@tanstack/devtools:better-console-logs",
|
|
288
|
+
enforce: "pre",
|
|
289
|
+
apply(config) {
|
|
290
|
+
return config.mode === "development" && enhancedLogsConfig.enabled;
|
|
291
|
+
},
|
|
292
|
+
transform: {
|
|
293
|
+
filter: {
|
|
294
|
+
id: { exclude: [
|
|
295
|
+
/node_modules/,
|
|
296
|
+
/\?raw/,
|
|
297
|
+
/\/dist\//,
|
|
298
|
+
/\/build\//
|
|
299
|
+
] },
|
|
300
|
+
code: { include: "console." }
|
|
301
|
+
},
|
|
302
|
+
handler(code, id) {
|
|
303
|
+
return enhanceConsoleLog(code, id, port);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
name: "@tanstack/devtools:inject-plugin",
|
|
309
|
+
apply(config, { command }) {
|
|
310
|
+
return config.mode === "development" && command === "serve";
|
|
311
|
+
},
|
|
312
|
+
transform(code, id) {
|
|
313
|
+
if (!devtoolsFileId && detectDevtoolsFile(code)) {
|
|
314
|
+
const [filePath] = id.split("?");
|
|
315
|
+
if (filePath) devtoolsFileId = filePath;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "@tanstack/devtools:connection-injection",
|
|
321
|
+
apply(config, { command }) {
|
|
322
|
+
return config.mode === "development" && command === "serve";
|
|
323
|
+
},
|
|
324
|
+
transform(code, id) {
|
|
325
|
+
if (!(code.includes("__TANSTACK_DEVTOOLS_PORT__") || code.includes("__TANSTACK_DEVTOOLS_HOST__") || code.includes("__TANSTACK_DEVTOOLS_PROTOCOL__"))) return;
|
|
326
|
+
if (!id.includes("@tanstack/devtools") && !id.includes("@tanstack/event-bus")) return;
|
|
327
|
+
const portValue = devtoolsPort ?? 4206;
|
|
328
|
+
const hostValue = devtoolsHost ?? "localhost";
|
|
329
|
+
const protocolValue = devtoolsProtocol ?? "http";
|
|
330
|
+
let result = code;
|
|
331
|
+
result = result.replace(/__TANSTACK_DEVTOOLS_PORT__/g, String(portValue));
|
|
332
|
+
result = result.replace(/__TANSTACK_DEVTOOLS_HOST__/g, JSON.stringify(hostValue));
|
|
333
|
+
result = result.replace(/__TANSTACK_DEVTOOLS_PROTOCOL__/g, JSON.stringify(protocolValue));
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
];
|
|
455
338
|
};
|
|
456
|
-
//#
|
|
339
|
+
//#endregion
|
|
340
|
+
export { defineDevtoolsConfig, devtools };
|
|
341
|
+
|
|
342
|
+
//# sourceMappingURL=plugin.js.map
|