@tanstack/devtools-vite 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,7 +79,7 @@ describe('inject source', () => {
79
79
  expect(output).toBe(
80
80
  removeEmptySpace(`
81
81
  export const Route = createFileRoute("/test")({
82
- component: function() { return <div data-tsd-source="test.jsx:3:37">Hello World</div>; }
82
+ component: function() { return <div data-tsd-source="test.jsx:3:38">Hello World</div>; }
83
83
  });
84
84
  `),
85
85
  )
@@ -159,7 +159,7 @@ describe('inject source', () => {
159
159
  expect(output).toBe(
160
160
  removeEmptySpace(`
161
161
  export const Route = createFileRoute("/test")({
162
- component: function({...rest}) { return <div data-tsd-source="test.jsx:3:46"><div {...rest}>Hello World</div></div>; }
162
+ component: function({...rest}) { return <div data-tsd-source="test.jsx:3:47"><div {...rest}>Hello World</div></div>; }
163
163
  });
164
164
  `),
165
165
  )
@@ -181,7 +181,7 @@ describe('inject source', () => {
181
181
  expect(output).toBe(
182
182
  removeEmptySpace(`
183
183
  export const Route = createFileRoute("/test")({
184
- component: () => <div data-tsd-source="test.jsx:3:23">Hello World</div>
184
+ component: () => <div data-tsd-source="test.jsx:3:24">Hello World</div>
185
185
  });
186
186
  `),
187
187
  )
@@ -261,7 +261,7 @@ describe('inject source', () => {
261
261
  expect(output).toBe(
262
262
  removeEmptySpace(`
263
263
  export const Route = createFileRoute("/test")({
264
- component: ({...rest}) => <div data-tsd-source="test.jsx:3:32"><div {...rest}>Hello World</div></div>
264
+ component: ({...rest}) => <div data-tsd-source="test.jsx:3:33"><div {...rest}>Hello World</div></div>
265
265
  });
266
266
  `),
267
267
  )
@@ -286,7 +286,7 @@ describe('inject source', () => {
286
286
  removeEmptySpace(`
287
287
  function Parent({ ...props }) {
288
288
  function Child({ ...props }) {
289
- return <div data-tsd-source="test.jsx:4:17" />;
289
+ return <div data-tsd-source="test.jsx:4:18" />;
290
290
  }
291
291
  return <Child {...props} />;
292
292
  }
@@ -312,7 +312,7 @@ function test({...props }) {
312
312
  import Custom from "external";
313
313
 
314
314
  function test({...props }) {
315
- return <Custom children={props.children} data-tsd-source="test.tsx:6:9" />;
315
+ return <Custom children={props.children} data-tsd-source="test.tsx:6:10" />;
316
316
  }`),
317
317
  )
318
318
  })
@@ -330,7 +330,7 @@ function test({...props }) {
330
330
  expect(output).toBe(
331
331
  removeEmptySpace(`
332
332
  function test(props) {
333
- return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
333
+ return <button children={props.children} data-tsd-source="test.jsx:3:16" />;
334
334
  }
335
335
  `),
336
336
  )
@@ -372,7 +372,7 @@ function test(props) {
372
372
  expect(output).toBe(
373
373
  removeEmptySpace(`
374
374
  function test(props) {
375
- return <div data-tsd-source="test.jsx:3:16">
375
+ return <div data-tsd-source="test.jsx:3:17">
376
376
  <button {...props} />
377
377
  </div>;
378
378
  }
@@ -396,7 +396,7 @@ function test(props) {
396
396
  expect(output).toBe(
397
397
  removeEmptySpace(`
398
398
  function test({...props}) {
399
- return <div data-tsd-source="test.jsx:3:16">
399
+ return <div data-tsd-source="test.jsx:3:17">
400
400
  <button {...props} />
401
401
  </div>;
402
402
  }
@@ -420,7 +420,7 @@ function test({...props}) {
420
420
  expect(output).toBe(
421
421
  removeEmptySpace(`
422
422
  function test({...rest}) {
423
- return <div data-tsd-source="test.jsx:3:16">
423
+ return <div data-tsd-source="test.jsx:3:17">
424
424
  <button {...rest} />
425
425
  </div>;
426
426
  }
@@ -462,7 +462,7 @@ function test({ children, ...rest }) {
462
462
  expect(output).toBe(
463
463
  removeEmptySpace(`
464
464
  function test({ ...props }) {
465
- return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
465
+ return <button children={props.children} data-tsd-source="test.jsx:3:16" />;
466
466
  }
467
467
  `),
468
468
  )
@@ -502,7 +502,7 @@ function test({ children, ...rest }) {
502
502
  expect(output).toBe(
503
503
  removeEmptySpace(`
504
504
  function test({ ...props }) {
505
- return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
505
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:16" />;
506
506
  }
507
507
  `),
508
508
  )
@@ -542,7 +542,7 @@ function test({ children, ...rest }) {
542
542
  expect(output).toBe(
543
543
  removeEmptySpace(`
544
544
  function test({ ...props }) {
545
- return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
545
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:16" />;
546
546
  }
547
547
  `),
548
548
  )
@@ -563,7 +563,7 @@ function test({ children, ...rest }) {
563
563
  expect(output).toBe(
564
564
  removeEmptySpace(`
565
565
  const ButtonWithProps = function test(props) {
566
- return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
566
+ return <button children={props.children} data-tsd-source="test.jsx:3:16" />;
567
567
  };
568
568
  `),
569
569
  )
@@ -605,7 +605,7 @@ function test({ children, ...rest }) {
605
605
  expect(output).toBe(
606
606
  removeEmptySpace(`
607
607
  const ButtonWithProps = function test(props) {
608
- return <div data-tsd-source="test.jsx:3:16">
608
+ return <div data-tsd-source="test.jsx:3:17">
609
609
  <button {...props} />
610
610
  </div>;
611
611
  };
@@ -629,7 +629,7 @@ function test({ children, ...rest }) {
629
629
  expect(output).toBe(
630
630
  removeEmptySpace(`
631
631
  const ButtonWithProps = function test({...props}) {
632
- return <div data-tsd-source="test.jsx:3:16">
632
+ return <div data-tsd-source="test.jsx:3:17">
633
633
  <button {...props} />
634
634
  </div>;
635
635
  };
@@ -653,7 +653,7 @@ function test({ children, ...rest }) {
653
653
  expect(output).toBe(
654
654
  removeEmptySpace(`
655
655
  const ButtonWithProps = function test({...rest}) {
656
- return <div data-tsd-source="test.jsx:3:16">
656
+ return <div data-tsd-source="test.jsx:3:17">
657
657
  <button {...rest} />
658
658
  </div>;
659
659
  };
@@ -695,7 +695,7 @@ function test({ children, ...rest }) {
695
695
  expect(output).toBe(
696
696
  removeEmptySpace(`
697
697
  const ButtonWithProps = function test({ ...props }) {
698
- return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
698
+ return <button children={props.children} data-tsd-source="test.jsx:3:16" />;
699
699
  };
700
700
  `),
701
701
  )
@@ -735,7 +735,7 @@ function test({ children, ...rest }) {
735
735
  expect(output).toBe(
736
736
  removeEmptySpace(`
737
737
  const ButtonWithProps = function test({ ...props }) {
738
- return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
738
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:16" />;
739
739
  };
740
740
  `),
741
741
  )
@@ -775,7 +775,7 @@ function test({ children, ...rest }) {
775
775
  expect(output).toBe(
776
776
  removeEmptySpace(`
777
777
  export const ButtonWithProps = function test({ ...props }) {
778
- return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
778
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:16" />;
779
779
  };
780
780
  `),
781
781
  )
@@ -795,8 +795,8 @@ function test({ children, ...rest }) {
795
795
  )
796
796
  expect(output).toBe(
797
797
  removeEmptySpace(`
798
- const ButtonWithProps = props => {
799
- return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
798
+ const ButtonWithProps = (props) => {
799
+ return <button children={props.children} data-tsd-source="test.jsx:3:16" />;
800
800
  };
801
801
  `),
802
802
  )
@@ -837,8 +837,8 @@ function test({ children, ...rest }) {
837
837
  )
838
838
  expect(output).toBe(
839
839
  removeEmptySpace(`
840
- const ButtonWithProps = props => {
841
- return <div data-tsd-source="test.jsx:3:16">
840
+ const ButtonWithProps = (props) => {
841
+ return <div data-tsd-source="test.jsx:3:17">
842
842
  <button {...props} />
843
843
  </div>;
844
844
  };
@@ -862,7 +862,7 @@ function test({ children, ...rest }) {
862
862
  expect(output).toBe(
863
863
  removeEmptySpace(`
864
864
  const ButtonWithProps = ({...props}) => {
865
- return <div data-tsd-source="test.jsx:3:16">
865
+ return <div data-tsd-source="test.jsx:3:17">
866
866
  <button {...props} />
867
867
  </div>;
868
868
  };
@@ -886,7 +886,7 @@ function test({ children, ...rest }) {
886
886
  expect(output).toBe(
887
887
  removeEmptySpace(`
888
888
  const ButtonWithProps = ({...rest}) => {
889
- return <div data-tsd-source= "test.jsx:3:16">
889
+ return <div data-tsd-source= "test.jsx:3:17">
890
890
  <button {...rest} />
891
891
  </div>;
892
892
  };
@@ -908,7 +908,7 @@ function test({ children, ...rest }) {
908
908
  expect(output).toBe(
909
909
  removeEmptySpace(`
910
910
  const ButtonWithProps = ({ children, ...rest }) => {
911
- return <button children={children} data-tsd-source="test.jsx:3:15" />;
911
+ return <button children={children} data-tsd-source="test.jsx:3:16" />;
912
912
  };
913
913
  `),
914
914
  )
@@ -928,7 +928,7 @@ function test({ children, ...rest }) {
928
928
  expect(output).toBe(
929
929
  removeEmptySpace(`
930
930
  const ButtonWithProps = ({ ...props }) => {
931
- return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
931
+ return <button children={props.children} data-tsd-source="test.jsx:3:16" />;
932
932
  };
933
933
  `),
934
934
  )
@@ -968,7 +968,7 @@ function test({ children, ...rest }) {
968
968
  expect(output).toBe(
969
969
  removeEmptySpace(`
970
970
  const ButtonWithProps = ({ ...props }) => {
971
- return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
971
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:16" />;
972
972
  };
973
973
  `),
974
974
  )
@@ -1008,7 +1008,7 @@ function test({ children, ...rest }) {
1008
1008
  expect(output).toBe(
1009
1009
  removeEmptySpace(`
1010
1010
  export const ButtonWithProps = ({ ...props }) => {
1011
- return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
1011
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:16" />;
1012
1012
  };
1013
1013
  `),
1014
1014
  )
@@ -144,7 +144,7 @@ const transformJSX = (
144
144
  element.node.attributes.push(
145
145
  t.jsxAttribute(
146
146
  t.jsxIdentifier('data-tsd-source'),
147
- t.stringLiteral(`${file}:${line}:${column}`),
147
+ t.stringLiteral(`${file}:${line}:${column + 1}`),
148
148
  ),
149
149
  )
150
150
 
@@ -232,6 +232,7 @@ export function addSourceToJsx(code: string, id: string) {
232
232
  }
233
233
  return gen(ast, {
234
234
  sourceMaps: true,
235
+ retainLines: true,
235
236
  filename: id,
236
237
  sourceFileName: filePath,
237
238
  })
package/src/plugin.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { normalizePath } from 'vite'
2
- import chalk from 'chalk'
3
1
  import { ServerEventBus } from '@tanstack/devtools-event-bus/server'
4
2
  import { handleDevToolsViteRequest } from './utils'
5
3
  import { DEFAULT_EDITOR_CONFIG, handleOpenSource } from './editor'
6
4
  import { removeDevtools } from './remove-devtools'
7
5
  import { addSourceToJsx } from './inject-source'
6
+ import { enhanceConsoleLog } from './enhance-logs'
8
7
  import type { EditorConfig } from './editor'
9
8
  import type { ServerEventBusConfig } from '@tanstack/devtools-event-bus/server'
10
9
  import type { Plugin } from 'vite'
@@ -160,38 +159,7 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
160
159
  if (!code.includes('console.')) {
161
160
  return code
162
161
  }
163
- const lines = code.split('\n')
164
- return lines
165
- .map((line, lineNumber) => {
166
- if (
167
- line.trim().startsWith('//') ||
168
- line.trim().startsWith('/**') ||
169
- line.trim().startsWith('*')
170
- ) {
171
- return line
172
- }
173
- // Do not add for arrow functions or return statements
174
- if (
175
- line.replaceAll(' ', '').includes('=>console.') ||
176
- line.includes('return console.')
177
- ) {
178
- return line
179
- }
180
-
181
- const column = line.indexOf('console.')
182
- const location = `${id.replace(normalizePath(process.cwd()), '')}:${lineNumber + 1}:${column + 1}`
183
- const logMessage = `'${chalk.magenta('LOG')} ${chalk.blueBright(`${location} - http://localhost:${port}/__tsd/open-source?source=${encodeURIComponent(id.replace(normalizePath(process.cwd()), ''))}&line=${lineNumber + 1}&column=${column + 1}`)}\\n → '`
184
- if (line.includes('console.log(')) {
185
- const newLine = `console.log(${logMessage},`
186
- return line.replace('console.log(', newLine)
187
- }
188
- if (line.includes('console.error(')) {
189
- const newLine = `console.error(${logMessage},`
190
- return line.replace('console.error(', newLine)
191
- }
192
- return line
193
- })
194
- .join('\n')
162
+ return enhanceConsoleLog(code, id, port)
195
163
  },
196
164
  },
197
165
  ]