@tanstack/devtools-vite 0.6.0 → 0.7.0

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 (55) hide show
  1. package/dist/esm/ast-utils.d.ts +11 -0
  2. package/dist/esm/ast-utils.js +44 -0
  3. package/dist/esm/ast-utils.js.map +1 -0
  4. package/dist/esm/devtools-packages.d.ts +2 -0
  5. package/dist/esm/devtools-packages.js +15 -0
  6. package/dist/esm/devtools-packages.js.map +1 -0
  7. package/dist/esm/editor.js +18 -27
  8. package/dist/esm/editor.js.map +1 -1
  9. package/dist/esm/enhance-logs.d.ts +4 -1
  10. package/dist/esm/enhance-logs.js +48 -81
  11. package/dist/esm/enhance-logs.js.map +1 -1
  12. package/dist/esm/index.js +1 -5
  13. package/dist/esm/inject-plugin.d.ts +5 -4
  14. package/dist/esm/inject-plugin.js +171 -220
  15. package/dist/esm/inject-plugin.js.map +1 -1
  16. package/dist/esm/inject-source.d.ts +4 -1
  17. package/dist/esm/inject-source.js +111 -205
  18. package/dist/esm/inject-source.js.map +1 -1
  19. package/dist/esm/matcher.js +11 -16
  20. package/dist/esm/matcher.js.map +1 -1
  21. package/dist/esm/offset-to-loc.d.ts +14 -0
  22. package/dist/esm/offset-to-loc.js +29 -0
  23. package/dist/esm/offset-to-loc.js.map +1 -0
  24. package/dist/esm/package-manager.js +90 -131
  25. package/dist/esm/package-manager.js.map +1 -1
  26. package/dist/esm/plugin.js +329 -448
  27. package/dist/esm/plugin.js.map +1 -1
  28. package/dist/esm/remove-devtools.d.ts +4 -1
  29. package/dist/esm/remove-devtools.js +93 -134
  30. package/dist/esm/remove-devtools.js.map +1 -1
  31. package/dist/esm/utils.js +149 -162
  32. package/dist/esm/utils.js.map +1 -1
  33. package/dist/esm/virtual-console.js +170 -14
  34. package/dist/esm/virtual-console.js.map +1 -1
  35. package/package.json +4 -10
  36. package/skills/devtools-vite-plugin/SKILL.md +7 -7
  37. package/skills/devtools-vite-plugin/references/vite-options.md +2 -2
  38. package/src/ast-utils.ts +54 -0
  39. package/src/devtools-packages.ts +12 -0
  40. package/src/enhance-logs.ts +48 -78
  41. package/src/inject-plugin.test.ts +200 -147
  42. package/src/inject-plugin.ts +195 -238
  43. package/src/inject-source.test.ts +165 -115
  44. package/src/inject-source.ts +183 -231
  45. package/src/offset-to-loc.ts +39 -0
  46. package/src/plugin.ts +35 -29
  47. package/src/remove-devtools.test.ts +76 -57
  48. package/src/remove-devtools.ts +160 -168
  49. package/src/virtual-console.test.ts +172 -1
  50. package/src/virtual-console.ts +146 -7
  51. package/dist/esm/babel.d.ts +0 -18
  52. package/dist/esm/babel.js +0 -19
  53. package/dist/esm/babel.js.map +0 -1
  54. package/dist/esm/index.js.map +0 -1
  55. package/src/babel.ts +0 -18
@@ -4,7 +4,6 @@ import {
4
4
  findDevtoolsComponentName,
5
5
  transformAndInject,
6
6
  } from './inject-plugin'
7
- import { gen, parse } from './babel'
8
7
 
9
8
  const removeEmptySpace = (str: string) => {
10
9
  return str.replace(/\s/g, '').trim()
@@ -20,27 +19,21 @@ const testTransform = (
20
19
  type: 'jsx' | 'function'
21
20
  },
22
21
  ) => {
23
- const ast = parse(code, {
24
- sourceType: 'module',
25
- plugins: ['jsx', 'typescript'],
26
- })
27
-
28
- const devtoolsComponentName = findDevtoolsComponentName(ast)
22
+ const devtoolsComponentName = findDevtoolsComponentName(code)
29
23
  if (!devtoolsComponentName) {
30
24
  return { transformed: false, code }
31
25
  }
32
26
 
33
- const didTransform = transformAndInject(
34
- ast,
27
+ const result = transformAndInject(
28
+ code,
35
29
  { packageName, pluginName, pluginImport },
36
30
  devtoolsComponentName,
37
31
  )
38
32
 
39
- if (!didTransform) {
33
+ if (!result?.transformed) {
40
34
  return { transformed: false, code }
41
35
  }
42
36
 
43
- const result = gen(ast, { sourceMaps: false, retainLines: false })
44
37
  return { transformed: true, code: result.code }
45
38
  }
46
39
 
@@ -103,7 +96,7 @@ describe('inject-plugin', () => {
103
96
  test('should add plugin to existing empty plugins array', () => {
104
97
  const code = `
105
98
  import { TanStackDevtools } from '@tanstack/react-devtools'
106
-
99
+
107
100
  function App() {
108
101
  return <TanStackDevtools plugins={[]} />
109
102
  }
@@ -122,14 +115,14 @@ describe('inject-plugin', () => {
122
115
  expect(result.transformed).toBe(true)
123
116
  expect(removeEmptySpace(result.code)).toBe(
124
117
  removeEmptySpace(`
125
- import { TanStackDevtools } from '@tanstack/react-devtools';
118
+ import { TanStackDevtools } from '@tanstack/react-devtools'
126
119
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
127
-
120
+
128
121
  function App() {
129
122
  return <TanStackDevtools plugins={[{
130
123
  name: "TanStack Query",
131
124
  render: <ReactQueryDevtoolsPanel />
132
- }]} />;
125
+ }]} />
133
126
  }
134
127
  `),
135
128
  )
@@ -139,7 +132,7 @@ describe('inject-plugin', () => {
139
132
  const code = `
140
133
  import { TanStackDevtools } from '@tanstack/react-devtools'
141
134
  import { OtherPlugin } from '@tanstack/other-plugin'
142
-
135
+
143
136
  function App() {
144
137
  return <TanStackDevtools plugins={[
145
138
  { name: 'other', render: <OtherPlugin /> }
@@ -160,10 +153,10 @@ describe('inject-plugin', () => {
160
153
  expect(result.transformed).toBe(true)
161
154
  expect(removeEmptySpace(result.code)).toBe(
162
155
  removeEmptySpace(`
163
- import { TanStackDevtools } from '@tanstack/react-devtools';
164
- import { OtherPlugin } from '@tanstack/other-plugin';
156
+ import { TanStackDevtools } from '@tanstack/react-devtools'
157
+ import { OtherPlugin } from '@tanstack/other-plugin'
165
158
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
166
-
159
+
167
160
  function App() {
168
161
  return <TanStackDevtools plugins={[
169
162
  { name: 'other', render: <OtherPlugin /> },
@@ -171,7 +164,7 @@ describe('inject-plugin', () => {
171
164
  name: "TanStack Query",
172
165
  render: <ReactQueryDevtoolsPanel />
173
166
  }
174
- ]} />;
167
+ ]} />
175
168
  }
176
169
  `),
177
170
  )
@@ -180,7 +173,7 @@ describe('inject-plugin', () => {
180
173
  test('should create plugins prop if it does not exist', () => {
181
174
  const code = `
182
175
  import { TanStackDevtools } from '@tanstack/react-devtools'
183
-
176
+
184
177
  function App() {
185
178
  return <TanStackDevtools />
186
179
  }
@@ -199,14 +192,14 @@ describe('inject-plugin', () => {
199
192
  expect(result.transformed).toBe(true)
200
193
  expect(removeEmptySpace(result.code)).toBe(
201
194
  removeEmptySpace(`
202
- import { TanStackDevtools } from '@tanstack/react-devtools';
195
+ import { TanStackDevtools } from '@tanstack/react-devtools'
203
196
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
204
-
197
+
205
198
  function App() {
206
199
  return <TanStackDevtools plugins={[{
207
200
  name: "TanStack Query",
208
201
  render: <ReactQueryDevtoolsPanel />
209
- }]} />;
202
+ }]} />
210
203
  }
211
204
  `),
212
205
  )
@@ -215,7 +208,7 @@ describe('inject-plugin', () => {
215
208
  test('should create plugins prop with other existing props', () => {
216
209
  const code = `
217
210
  import { TanStackDevtools } from '@tanstack/react-devtools'
218
-
211
+
219
212
  function App() {
220
213
  return <TanStackDevtools position="bottom-right" />
221
214
  }
@@ -234,14 +227,14 @@ describe('inject-plugin', () => {
234
227
  expect(result.transformed).toBe(true)
235
228
  expect(removeEmptySpace(result.code)).toBe(
236
229
  removeEmptySpace(`
237
- import { TanStackDevtools } from '@tanstack/react-devtools';
230
+ import { TanStackDevtools } from '@tanstack/react-devtools'
238
231
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
239
-
232
+
240
233
  function App() {
241
234
  return <TanStackDevtools position="bottom-right" plugins={[{
242
235
  name: "TanStack Query",
243
236
  render: <ReactQueryDevtoolsPanel />
244
- }]} />;
237
+ }]} />
245
238
  }
246
239
  `),
247
240
  )
@@ -251,7 +244,7 @@ describe('inject-plugin', () => {
251
244
  const code = `
252
245
  import { TanStackDevtools } from '@tanstack/react-devtools'
253
246
  import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
254
-
247
+
255
248
  function App() {
256
249
  return <TanStackDevtools plugins={[
257
250
  { name: 'TanStack Query', render: <ReactQueryDevtoolsPanel /> }
@@ -277,7 +270,7 @@ describe('inject-plugin', () => {
277
270
  test('should handle renamed named import', () => {
278
271
  const code = `
279
272
  import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools'
280
-
273
+
281
274
  function App() {
282
275
  return <DevtoolsPanel plugins={[]} />
283
276
  }
@@ -296,14 +289,14 @@ describe('inject-plugin', () => {
296
289
  expect(result.transformed).toBe(true)
297
290
  expect(removeEmptySpace(result.code)).toBe(
298
291
  removeEmptySpace(`
299
- import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools';
292
+ import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools'
300
293
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
301
-
294
+
302
295
  function App() {
303
296
  return <DevtoolsPanel plugins={[{
304
297
  name: "TanStack Query",
305
298
  render: <ReactQueryDevtoolsPanel />
306
- }]} />;
299
+ }]} />
307
300
  }
308
301
  `),
309
302
  )
@@ -312,7 +305,7 @@ describe('inject-plugin', () => {
312
305
  test('should handle renamed import without plugins prop', () => {
313
306
  const code = `
314
307
  import { TanStackDevtools as MyDevtools } from '@tanstack/solid-devtools'
315
-
308
+
316
309
  function App() {
317
310
  return <MyDevtools />
318
311
  }
@@ -331,14 +324,14 @@ describe('inject-plugin', () => {
331
324
  expect(result.transformed).toBe(true)
332
325
  expect(removeEmptySpace(result.code)).toBe(
333
326
  removeEmptySpace(`
334
- import { TanStackDevtools as MyDevtools } from '@tanstack/solid-devtools';
327
+ import { TanStackDevtools as MyDevtools } from '@tanstack/solid-devtools'
335
328
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
336
-
329
+
337
330
  function App() {
338
331
  return <MyDevtools plugins={[{
339
332
  name: "TanStack Query",
340
333
  render: <ReactQueryDevtoolsPanel />
341
- }]} />;
334
+ }]} />
342
335
  }
343
336
  `),
344
337
  )
@@ -349,7 +342,7 @@ describe('inject-plugin', () => {
349
342
  test('should handle namespace import', () => {
350
343
  const code = `
351
344
  import * as DevtoolsModule from '@tanstack/react-devtools'
352
-
345
+
353
346
  function App() {
354
347
  return <DevtoolsModule.TanStackDevtools plugins={[]} />
355
348
  }
@@ -368,14 +361,14 @@ describe('inject-plugin', () => {
368
361
  expect(result.transformed).toBe(true)
369
362
  expect(removeEmptySpace(result.code)).toBe(
370
363
  removeEmptySpace(`
371
- import * as DevtoolsModule from '@tanstack/react-devtools';
364
+ import * as DevtoolsModule from '@tanstack/react-devtools'
372
365
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
373
-
366
+
374
367
  function App() {
375
368
  return <DevtoolsModule.TanStackDevtools plugins={[{
376
369
  name: "TanStack Query",
377
370
  render: <ReactQueryDevtoolsPanel />
378
- }]} />;
371
+ }]} />
379
372
  }
380
373
  `),
381
374
  )
@@ -384,7 +377,7 @@ describe('inject-plugin', () => {
384
377
  test('should handle namespace import without plugins prop', () => {
385
378
  const code = `
386
379
  import * as TSD from '@tanstack/solid-devtools'
387
-
380
+
388
381
  function App() {
389
382
  return <TSD.TanStackDevtools />
390
383
  }
@@ -403,14 +396,14 @@ describe('inject-plugin', () => {
403
396
  expect(result.transformed).toBe(true)
404
397
  expect(removeEmptySpace(result.code)).toBe(
405
398
  removeEmptySpace(`
406
- import * as TSD from '@tanstack/solid-devtools';
399
+ import * as TSD from '@tanstack/solid-devtools'
407
400
  import { SolidRouterDevtoolsPanel } from "@tanstack/solid-router-devtools";
408
-
401
+
409
402
  function App() {
410
403
  return <TSD.TanStackDevtools plugins={[{
411
404
  name: "TanStack Router",
412
405
  render: <SolidRouterDevtoolsPanel />
413
- }]} />;
406
+ }]} />
414
407
  }
415
408
  `),
416
409
  )
@@ -421,7 +414,7 @@ describe('inject-plugin', () => {
421
414
  test('should handle router devtools', () => {
422
415
  const code = `
423
416
  import { TanStackDevtools } from '@tanstack/react-devtools'
424
-
417
+
425
418
  function App() {
426
419
  return <TanStackDevtools plugins={[]} />
427
420
  }
@@ -440,14 +433,14 @@ describe('inject-plugin', () => {
440
433
  expect(result.transformed).toBe(true)
441
434
  expect(removeEmptySpace(result.code)).toBe(
442
435
  removeEmptySpace(`
443
- import { TanStackDevtools } from '@tanstack/react-devtools';
436
+ import { TanStackDevtools } from '@tanstack/react-devtools'
444
437
  import { ReactRouterDevtoolsPanel } from "@tanstack/react-router-devtools";
445
-
438
+
446
439
  function App() {
447
440
  return <TanStackDevtools plugins={[{
448
441
  name: "TanStack Router",
449
442
  render: <ReactRouterDevtoolsPanel />
450
- }]} />;
443
+ }]} />
451
444
  }
452
445
  `),
453
446
  )
@@ -456,7 +449,7 @@ describe('inject-plugin', () => {
456
449
  test('should handle form devtools', () => {
457
450
  const code = `
458
451
  import { TanStackDevtools } from '@tanstack/solid-devtools'
459
-
452
+
460
453
  function App() {
461
454
  return <TanStackDevtools />
462
455
  }
@@ -475,14 +468,14 @@ describe('inject-plugin', () => {
475
468
  expect(result.transformed).toBe(true)
476
469
  expect(removeEmptySpace(result.code)).toBe(
477
470
  removeEmptySpace(`
478
- import { TanStackDevtools } from '@tanstack/solid-devtools';
471
+ import { TanStackDevtools } from '@tanstack/solid-devtools'
479
472
  import { ReactFormDevtoolsPanel } from "@tanstack/react-form-devtools";
480
-
473
+
481
474
  function App() {
482
475
  return <TanStackDevtools plugins={[{
483
476
  name: "TanStack Form",
484
477
  render: <ReactFormDevtoolsPanel />
485
- }]} />;
478
+ }]} />
486
479
  }
487
480
  `),
488
481
  )
@@ -491,7 +484,7 @@ describe('inject-plugin', () => {
491
484
  test('should handle query devtools', () => {
492
485
  const code = `
493
486
  import { TanStackDevtools } from '@tanstack/vue-devtools'
494
-
487
+
495
488
  function App() {
496
489
  return <TanStackDevtools plugins={[]} />
497
490
  }
@@ -510,14 +503,14 @@ describe('inject-plugin', () => {
510
503
  expect(result.transformed).toBe(true)
511
504
  expect(removeEmptySpace(result.code)).toBe(
512
505
  removeEmptySpace(`
513
- import { TanStackDevtools } from '@tanstack/vue-devtools';
506
+ import { TanStackDevtools } from '@tanstack/vue-devtools'
514
507
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
515
-
508
+
516
509
  function App() {
517
510
  return <TanStackDevtools plugins={[{
518
511
  name: "TanStack Query",
519
512
  render: <ReactQueryDevtoolsPanel />
520
- }]} />;
513
+ }]} />
521
514
  }
522
515
  `),
523
516
  )
@@ -528,7 +521,7 @@ describe('inject-plugin', () => {
528
521
  test('should not transform files without TanStackDevtools component', () => {
529
522
  const code = `
530
523
  import { TanStackDevtools } from '@tanstack/react-devtools'
531
-
524
+
532
525
  function App() {
533
526
  return <div>Hello World</div>
534
527
  }
@@ -550,7 +543,7 @@ describe('inject-plugin', () => {
550
543
  test('should handle TanStackDevtools with children', () => {
551
544
  const code = `
552
545
  import { TanStackDevtools } from '@tanstack/react-devtools'
553
-
546
+
554
547
  function App() {
555
548
  return (
556
549
  <TanStackDevtools plugins={[]}>
@@ -573,16 +566,18 @@ describe('inject-plugin', () => {
573
566
  expect(result.transformed).toBe(true)
574
567
  expect(removeEmptySpace(result.code)).toBe(
575
568
  removeEmptySpace(`
576
- import { TanStackDevtools } from '@tanstack/react-devtools';
569
+ import { TanStackDevtools } from '@tanstack/react-devtools'
577
570
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
578
-
571
+
579
572
  function App() {
580
- return <TanStackDevtools plugins={[{
581
- name: "TanStack Query",
582
- render: <ReactQueryDevtoolsPanel />
583
- }]}>
584
- <div>Custom content</div>
585
- </TanStackDevtools>;
573
+ return (
574
+ <TanStackDevtools plugins={[{
575
+ name: "TanStack Query",
576
+ render: <ReactQueryDevtoolsPanel />
577
+ }]}>
578
+ <div>Custom content</div>
579
+ </TanStackDevtools>
580
+ )
586
581
  }
587
582
  `),
588
583
  )
@@ -591,7 +586,7 @@ describe('inject-plugin', () => {
591
586
  test('should handle multiple TanStackDevtools in same file', () => {
592
587
  const code = `
593
588
  import { TanStackDevtools } from '@tanstack/react-devtools'
594
-
589
+
595
590
  function App() {
596
591
  return (
597
592
  <>
@@ -615,20 +610,22 @@ describe('inject-plugin', () => {
615
610
  expect(result.transformed).toBe(true)
616
611
  expect(removeEmptySpace(result.code)).toBe(
617
612
  removeEmptySpace(`
618
- import { TanStackDevtools } from '@tanstack/react-devtools';
613
+ import { TanStackDevtools } from '@tanstack/react-devtools'
619
614
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
620
-
615
+
621
616
  function App() {
622
- return <>
623
- <TanStackDevtools plugins={[{
624
- name: "TanStack Query",
625
- render: <ReactQueryDevtoolsPanel />
626
- }]} />
627
- <TanStackDevtools plugins={[{
628
- name: "TanStack Query",
629
- render: <ReactQueryDevtoolsPanel />
630
- }]} />
631
- </>;
617
+ return (
618
+ <>
619
+ <TanStackDevtools plugins={[{
620
+ name: "TanStack Query",
621
+ render: <ReactQueryDevtoolsPanel />
622
+ }]} />
623
+ <TanStackDevtools plugins={[{
624
+ name: "TanStack Query",
625
+ render: <ReactQueryDevtoolsPanel />
626
+ }]} />
627
+ </>
628
+ )
632
629
  }
633
630
  `),
634
631
  )
@@ -637,7 +634,7 @@ describe('inject-plugin', () => {
637
634
  test('should handle TanStackDevtools deeply nested', () => {
638
635
  const code = `
639
636
  import { TanStackDevtools } from '@tanstack/react-devtools'
640
-
637
+
641
638
  function App() {
642
639
  return (
643
640
  <div>
@@ -664,20 +661,22 @@ describe('inject-plugin', () => {
664
661
  expect(result.transformed).toBe(true)
665
662
  expect(removeEmptySpace(result.code)).toBe(
666
663
  removeEmptySpace(`
667
- import { TanStackDevtools } from '@tanstack/react-devtools';
664
+ import { TanStackDevtools } from '@tanstack/react-devtools'
668
665
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
669
-
666
+
670
667
  function App() {
671
- return <div>
672
- <header>
673
- <nav>
674
- <TanStackDevtools plugins={[{
675
- name: "TanStack Query",
676
- render: <ReactQueryDevtoolsPanel />
677
- }]} />
678
- </nav>
679
- </header>
680
- </div>;
668
+ return (
669
+ <div>
670
+ <header>
671
+ <nav>
672
+ <TanStackDevtools plugins={[{
673
+ name: "TanStack Query",
674
+ render: <ReactQueryDevtoolsPanel />
675
+ }]} />
676
+ </nav>
677
+ </header>
678
+ </div>
679
+ )
681
680
  }
682
681
  `),
683
682
  )
@@ -687,10 +686,10 @@ describe('inject-plugin', () => {
687
686
  const code = `
688
687
  import { TanStackDevtools } from '@tanstack/react-devtools'
689
688
  import { useState } from 'react'
690
-
689
+
691
690
  function App() {
692
691
  const [count, setCount] = useState(0)
693
-
692
+
694
693
  return (
695
694
  <div>
696
695
  <button onClick={() => setCount(count + 1)}>
@@ -715,21 +714,23 @@ describe('inject-plugin', () => {
715
714
  expect(result.transformed).toBe(true)
716
715
  expect(removeEmptySpace(result.code)).toBe(
717
716
  removeEmptySpace(`
718
- import { TanStackDevtools } from '@tanstack/react-devtools';
719
- import { useState } from 'react';
717
+ import { TanStackDevtools } from '@tanstack/react-devtools'
718
+ import { useState } from 'react'
720
719
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
721
-
720
+
722
721
  function App() {
723
- const [count, setCount] = useState(0);
724
- return <div>
725
- <button onClick={() => setCount(count + 1)}>
726
- Count: {count}
727
- </button>
728
- <TanStackDevtools plugins={[{
729
- name: "TanStack Query",
730
- render: <ReactQueryDevtoolsPanel />
731
- }]} />
732
- </div>;
722
+ const [count, setCount] = useState(0)
723
+ return (
724
+ <div>
725
+ <button onClick={() => setCount(count + 1)}>
726
+ Count: {count}
727
+ </button>
728
+ <TanStackDevtools plugins={[{
729
+ name: "TanStack Query",
730
+ render: <ReactQueryDevtoolsPanel />
731
+ }]} />
732
+ </div>
733
+ )
733
734
  }
734
735
  `),
735
736
  )
@@ -739,7 +740,7 @@ describe('inject-plugin', () => {
739
740
  const code = `
740
741
  import { TanStackDevtools } from '@tanstack/react-devtools'
741
742
  import type { FC } from 'react'
742
-
743
+
743
744
  const App: FC = () => {
744
745
  return <TanStackDevtools plugins={[]} />
745
746
  }
@@ -758,16 +759,16 @@ describe('inject-plugin', () => {
758
759
  expect(result.transformed).toBe(true)
759
760
  expect(removeEmptySpace(result.code)).toBe(
760
761
  removeEmptySpace(`
761
- import { TanStackDevtools } from '@tanstack/react-devtools';
762
- import type { FC } from 'react';
762
+ import { TanStackDevtools } from '@tanstack/react-devtools'
763
+ import type { FC } from 'react'
763
764
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
764
-
765
+
765
766
  const App: FC = () => {
766
767
  return <TanStackDevtools plugins={[{
767
768
  name: "TanStack Query",
768
769
  render: <ReactQueryDevtoolsPanel />
769
- }]} />;
770
- };
770
+ }]} />
771
+ }
771
772
  `),
772
773
  )
773
774
  })
@@ -775,7 +776,7 @@ describe('inject-plugin', () => {
775
776
  test('should handle plugins array with trailing comma', () => {
776
777
  const code = `
777
778
  import { TanStackDevtools } from '@tanstack/react-devtools'
778
-
779
+
779
780
  function App() {
780
781
  return <TanStackDevtools plugins={[
781
782
  { name: 'other', render: <OtherPlugin /> },
@@ -796,9 +797,9 @@ describe('inject-plugin', () => {
796
797
  expect(result.transformed).toBe(true)
797
798
  expect(removeEmptySpace(result.code)).toBe(
798
799
  removeEmptySpace(`
799
- import { TanStackDevtools } from '@tanstack/react-devtools';
800
+ import { TanStackDevtools } from '@tanstack/react-devtools'
800
801
  import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
801
-
802
+
802
803
  function App() {
803
804
  return <TanStackDevtools plugins={[
804
805
  { name: 'other', render: <OtherPlugin /> },
@@ -806,7 +807,7 @@ describe('inject-plugin', () => {
806
807
  name: "TanStack Query",
807
808
  render: <ReactQueryDevtoolsPanel />
808
809
  }
809
- ]} />;
810
+ ]} />
810
811
  }
811
812
  `),
812
813
  )
@@ -815,7 +816,7 @@ describe('inject-plugin', () => {
815
816
  test('should not transform if devtools import not found', () => {
816
817
  const code = `
817
818
  import { SomeOtherComponent } from 'some-package'
818
-
819
+
819
820
  function App() {
820
821
  return <SomeOtherComponent />
821
822
  }
@@ -839,7 +840,7 @@ describe('inject-plugin', () => {
839
840
  test('should add function plugin to empty plugins array', () => {
840
841
  const code = `
841
842
  import { TanStackDevtools } from '@tanstack/react-devtools'
842
-
843
+
843
844
  function App() {
844
845
  return <TanStackDevtools plugins={[]} />
845
846
  }
@@ -858,11 +859,11 @@ describe('inject-plugin', () => {
858
859
  expect(result.transformed).toBe(true)
859
860
  expect(removeEmptySpace(result.code)).toBe(
860
861
  removeEmptySpace(`
861
- import { TanStackDevtools } from '@tanstack/react-devtools';
862
+ import { TanStackDevtools } from '@tanstack/react-devtools'
862
863
  import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
863
-
864
+
864
865
  function App() {
865
- return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />;
866
+ return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />
866
867
  }
867
868
  `),
868
869
  )
@@ -872,7 +873,7 @@ describe('inject-plugin', () => {
872
873
  const code = `
873
874
  import { TanStackDevtools } from '@tanstack/react-devtools'
874
875
  import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
875
-
876
+
876
877
  function App() {
877
878
  return <TanStackDevtools plugins={[
878
879
  { name: 'TanStack Query', render: <ReactQueryDevtoolsPanel /> }
@@ -893,15 +894,15 @@ describe('inject-plugin', () => {
893
894
  expect(result.transformed).toBe(true)
894
895
  expect(removeEmptySpace(result.code)).toBe(
895
896
  removeEmptySpace(`
896
- import { TanStackDevtools } from '@tanstack/react-devtools';
897
- import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools';
897
+ import { TanStackDevtools } from '@tanstack/react-devtools'
898
+ import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
898
899
  import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
899
-
900
+
900
901
  function App() {
901
902
  return <TanStackDevtools plugins={[
902
903
  { name: 'TanStack Query', render: <ReactQueryDevtoolsPanel /> },
903
904
  FormDevtoolsPlugin()
904
- ]} />;
905
+ ]} />
905
906
  }
906
907
  `),
907
908
  )
@@ -910,7 +911,7 @@ describe('inject-plugin', () => {
910
911
  test('should create plugins prop with function plugin when it does not exist', () => {
911
912
  const code = `
912
913
  import { TanStackDevtools } from '@tanstack/react-devtools'
913
-
914
+
914
915
  function App() {
915
916
  return <TanStackDevtools />
916
917
  }
@@ -929,11 +930,11 @@ describe('inject-plugin', () => {
929
930
  expect(result.transformed).toBe(true)
930
931
  expect(removeEmptySpace(result.code)).toBe(
931
932
  removeEmptySpace(`
932
- import { TanStackDevtools } from '@tanstack/react-devtools';
933
+ import { TanStackDevtools } from '@tanstack/react-devtools'
933
934
  import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
934
-
935
+
935
936
  function App() {
936
- return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />;
937
+ return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />
937
938
  }
938
939
  `),
939
940
  )
@@ -943,7 +944,7 @@ describe('inject-plugin', () => {
943
944
  const code = `
944
945
  import { TanStackDevtools } from '@tanstack/react-devtools'
945
946
  import { FormDevtoolsPlugin } from '@tanstack/react-form-devtools'
946
-
947
+
947
948
  function App() {
948
949
  return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />
949
950
  }
@@ -965,7 +966,7 @@ describe('inject-plugin', () => {
965
966
  test('should handle function plugin with renamed devtools import', () => {
966
967
  const code = `
967
968
  import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools'
968
-
969
+
969
970
  function App() {
970
971
  return <DevtoolsPanel plugins={[]} />
971
972
  }
@@ -984,11 +985,11 @@ describe('inject-plugin', () => {
984
985
  expect(result.transformed).toBe(true)
985
986
  expect(removeEmptySpace(result.code)).toBe(
986
987
  removeEmptySpace(`
987
- import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools';
988
+ import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools'
988
989
  import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
989
-
990
+
990
991
  function App() {
991
- return <DevtoolsPanel plugins={[FormDevtoolsPlugin()]} />;
992
+ return <DevtoolsPanel plugins={[FormDevtoolsPlugin()]} />
992
993
  }
993
994
  `),
994
995
  )
@@ -997,7 +998,7 @@ describe('inject-plugin', () => {
997
998
  test('should handle function plugin with namespace import', () => {
998
999
  const code = `
999
1000
  import * as DevtoolsModule from '@tanstack/solid-devtools'
1000
-
1001
+
1001
1002
  function App() {
1002
1003
  return <DevtoolsModule.TanStackDevtools plugins={[]} />
1003
1004
  }
@@ -1016,11 +1017,11 @@ describe('inject-plugin', () => {
1016
1017
  expect(result.transformed).toBe(true)
1017
1018
  expect(removeEmptySpace(result.code)).toBe(
1018
1019
  removeEmptySpace(`
1019
- import * as DevtoolsModule from '@tanstack/solid-devtools';
1020
+ import * as DevtoolsModule from '@tanstack/solid-devtools'
1020
1021
  import { FormDevtoolsPlugin } from "@tanstack/solid-form-devtools";
1021
-
1022
+
1022
1023
  function App() {
1023
- return <DevtoolsModule.TanStackDevtools plugins={[FormDevtoolsPlugin()]} />;
1024
+ return <DevtoolsModule.TanStackDevtools plugins={[FormDevtoolsPlugin()]} />
1024
1025
  }
1025
1026
  `),
1026
1027
  )
@@ -1030,7 +1031,7 @@ describe('inject-plugin', () => {
1030
1031
  const code = `
1031
1032
  import { TanStackDevtools } from '@tanstack/react-devtools'
1032
1033
  import { FormDevtoolsPlugin } from '@tanstack/react-form-devtools'
1033
-
1034
+
1034
1035
  function App() {
1035
1036
  return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />
1036
1037
  }
@@ -1049,12 +1050,12 @@ describe('inject-plugin', () => {
1049
1050
  expect(result.transformed).toBe(true)
1050
1051
  expect(removeEmptySpace(result.code)).toBe(
1051
1052
  removeEmptySpace(`
1052
- import { TanStackDevtools } from '@tanstack/react-devtools';
1053
- import { FormDevtoolsPlugin } from '@tanstack/react-form-devtools';
1053
+ import { TanStackDevtools } from '@tanstack/react-devtools'
1054
+ import { FormDevtoolsPlugin } from '@tanstack/react-form-devtools'
1054
1055
  import { RouterDevtoolsPlugin } from "@tanstack/react-router-devtools";
1055
-
1056
+
1056
1057
  function App() {
1057
- return <TanStackDevtools plugins={[FormDevtoolsPlugin(), RouterDevtoolsPlugin()]} />;
1058
+ return <TanStackDevtools plugins={[FormDevtoolsPlugin(), RouterDevtoolsPlugin()]} />
1058
1059
  }
1059
1060
  `),
1060
1061
  )
@@ -1063,7 +1064,7 @@ describe('inject-plugin', () => {
1063
1064
  test('should not transform when pluginImport is not provided', () => {
1064
1065
  const code = `
1065
1066
  import { TanStackDevtools } from '@tanstack/react-devtools'
1066
-
1067
+
1067
1068
  function App() {
1068
1069
  return <TanStackDevtools plugins={[]} />
1069
1070
  }
@@ -1083,4 +1084,56 @@ describe('inject-plugin', () => {
1083
1084
  expect(result.transformed).toBe(false)
1084
1085
  })
1085
1086
  })
1087
+
1088
+ describe('safe code generation', () => {
1089
+ test('escapes quotes/backslashes in displayName when emitting JSX object', () => {
1090
+ const code = `
1091
+ import { TanStackDevtools } from '@tanstack/react-devtools'
1092
+
1093
+ function App() {
1094
+ return <TanStackDevtools />
1095
+ }
1096
+ `
1097
+ const result = testTransform(
1098
+ code,
1099
+ '@example/plugin',
1100
+ 'has "quotes" and \\backslash',
1101
+ { importName: 'ExamplePlugin', type: 'jsx' },
1102
+ )
1103
+
1104
+ expect(result.transformed).toBe(true)
1105
+ // displayName must be serialized via JSON.stringify so embedded quotes
1106
+ // and backslashes don't break the generated source.
1107
+ expect(result.code).toContain(
1108
+ 'name: "has \\"quotes\\" and \\\\backslash"',
1109
+ )
1110
+ // and the package name in the appended import is also a JSON literal
1111
+ expect(result.code).toContain(
1112
+ 'import { ExamplePlugin } from "@example/plugin"',
1113
+ )
1114
+ })
1115
+
1116
+ test('does not re-add an existing import when the plugin component is already imported', () => {
1117
+ const code = `
1118
+ import { TanStackDevtools } from '@tanstack/react-devtools'
1119
+ import { ExamplePlugin } from '@example/plugin'
1120
+
1121
+ function App() {
1122
+ return <TanStackDevtools />
1123
+ }
1124
+ `
1125
+ const result = testTransform(code, '@example/plugin', 'Example', {
1126
+ importName: 'ExamplePlugin',
1127
+ type: 'jsx',
1128
+ })
1129
+
1130
+ expect(result.transformed).toBe(true)
1131
+ // Exactly one import for ExamplePlugin from @example/plugin should remain.
1132
+ const importMatches = result.code.match(
1133
+ /import\s*\{\s*ExamplePlugin\s*\}\s*from\s*['"]@example\/plugin['"]/g,
1134
+ )
1135
+ expect(importMatches).not.toBeNull()
1136
+ expect(importMatches!.length).toBe(1)
1137
+ })
1138
+ })
1086
1139
  })