Skip to content

Commit cf46006

Browse files
Feat/fix sourcemapping issues (#151)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a8e21ef commit cf46006

File tree

13 files changed

+222
-366
lines changed

13 files changed

+222
-366
lines changed

.changeset/stupid-doors-open.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools-vite': patch
3+
---
4+
5+
fix issue with sourcemaps and vite plugin

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ vite.config.ts.timestamp-*
5656

5757
.angular
5858
.nitro
59+
.sonda

docs/vite-plugin.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ export default {
134134
}
135135
```
136136

137+
### logging
138+
Whether to log information to the console. Defaults to true.
139+
140+
```ts
141+
import { devtools } from '@tanstack/devtools-vite'
142+
143+
export default {
144+
plugins: [
145+
devtools({
146+
logging: true
147+
}),
148+
// ... rest of your plugins here
149+
],
150+
}
151+
```
152+
137153
### injectSource
138154

139155
Configuration for source injection. Defaults to enabled.

examples/react/basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@types/react": "^19.1.12",
2626
"@types/react-dom": "^19.1.2",
2727
"@vitejs/plugin-react": "^4.5.2",
28+
"sonda": "0.9.0",
2829
"vite": "^7.0.6",
2930
"vite-plugin-inspect": "11.3.2"
3031
},

examples/react/basic/vite.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import { devtools } from '@tanstack/devtools-vite'
44
import Inspect from 'vite-plugin-inspect'
5+
import sonda from 'sonda/vite'
56

67
// https://vite.dev/config/
78
export default defineConfig({
@@ -10,10 +11,14 @@ export default defineConfig({
1011
removeDevtoolsOnBuild: true,
1112
}),
1213
Inspect(),
14+
sonda(),
1315
react({
1416
// babel: {
1517
// plugins: [['babel-plugin-react-compiler', { target: '19' }]],
1618
// },
1719
}),
1820
],
21+
build: {
22+
sourcemap: true,
23+
},
1924
})

packages/devtools-vite/src/enhance-logs.test.ts

Lines changed: 32 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('remove-devtools', () => {
1414
`,
1515
'test.jsx',
1616
3000,
17-
).code,
17+
)!.code,
1818
)
1919
expect(
2020
output.includes(
@@ -26,96 +26,62 @@ describe('remove-devtools', () => {
2626
})
2727

2828
test('it does not add enhanced console.logs to console.log that is not called', () => {
29-
const output = removeEmptySpace(
30-
enhanceConsoleLog(
31-
`
29+
const output = enhanceConsoleLog(
30+
`
3231
console.log
3332
`,
34-
'test.jsx',
35-
3000,
36-
).code,
37-
)
38-
expect(output).toBe(
39-
removeEmptySpace(`
40-
console.log
41-
`),
33+
'test.jsx',
34+
3000,
4235
)
36+
expect(output).toBe(undefined)
4337
})
4438

4539
test('it does not add enhanced console.logs to console.log that is inside a comment', () => {
46-
const output = removeEmptySpace(
47-
enhanceConsoleLog(
48-
`
40+
const output = enhanceConsoleLog(
41+
`
4942
// console.log('This is a log')
5043
`,
51-
'test.jsx',
52-
3000,
53-
).code,
54-
)
55-
expect(output).toBe(
56-
removeEmptySpace(`
57-
// console.log('This is a log')
58-
`),
44+
'test.jsx',
45+
3000,
5946
)
47+
expect(output).toBe(undefined)
6048
})
6149

6250
test('it does not add enhanced console.logs to console.log that is inside a multiline comment', () => {
63-
const output = removeEmptySpace(
64-
enhanceConsoleLog(
65-
`
51+
const output = enhanceConsoleLog(
52+
`
6653
/*
6754
console.log('This is a log')
6855
*/
6956
`,
70-
'test.jsx',
71-
3000,
72-
).code,
73-
)
74-
expect(output).toBe(
75-
removeEmptySpace(`
76-
/*
77-
console.log('This is a log')
78-
*/
79-
`),
57+
'test.jsx',
58+
3000,
8059
)
60+
expect(output).toBe(undefined)
8161
})
8262

8363
test('it does not add enhanced console.error to console.error that is inside a comment', () => {
84-
const output = removeEmptySpace(
85-
enhanceConsoleLog(
86-
`
64+
const output = enhanceConsoleLog(
65+
`
8766
// console.error('This is a log')
8867
`,
89-
'test.jsx',
90-
3000,
91-
).code,
92-
)
93-
expect(output).toBe(
94-
removeEmptySpace(`
95-
// console.error('This is a log')
96-
`),
68+
'test.jsx',
69+
3000,
9770
)
71+
expect(output).toBe(undefined)
9872
})
9973

10074
test('it does not add enhanced console.error to console.error that is inside a multiline comment', () => {
101-
const output = removeEmptySpace(
102-
enhanceConsoleLog(
103-
`
75+
const output = enhanceConsoleLog(
76+
`
10477
/*
10578
console.error('This is a log')
10679
*/
10780
`,
108-
'test.jsx',
109-
3000,
110-
).code,
111-
)
112-
expect(output).toBe(
113-
removeEmptySpace(`
114-
/*
115-
console.error('This is a log')
116-
*/
117-
`),
81+
'test.jsx',
82+
3000,
11883
)
84+
expect(output).toBe(undefined)
11985
})
12086

12187
test('it adds enhanced console.error to console.error()', () => {
@@ -126,7 +92,7 @@ describe('remove-devtools', () => {
12692
`,
12793
'test.jsx',
12894
3000,
129-
).code,
95+
)!.code,
13096
)
13197
console.log('output', output)
13298
expect(
@@ -139,19 +105,13 @@ describe('remove-devtools', () => {
139105
})
140106

141107
test('it does not add enhanced console.error to console.error that is not called', () => {
142-
const output = removeEmptySpace(
143-
enhanceConsoleLog(
144-
`
108+
const output = enhanceConsoleLog(
109+
`
145110
console.log
146111
`,
147-
'test.jsx',
148-
3000,
149-
).code,
150-
)
151-
expect(output).toBe(
152-
removeEmptySpace(`
153-
console.log
154-
`),
112+
'test.jsx',
113+
3000,
155114
)
115+
expect(output).toBe(undefined)
156116
})
157117
})

packages/devtools-vite/src/enhance-logs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function enhanceConsoleLog(code: string, id: string, port: number) {
5656
})
5757
const didTransform = transform(ast, location, port)
5858
if (!didTransform) {
59-
return { code }
59+
return
6060
}
6161
return gen(ast, {
6262
sourceMaps: true,
@@ -65,6 +65,6 @@ export function enhanceConsoleLog(code: string, id: string, port: number) {
6565
sourceFileName: filePath,
6666
})
6767
} catch (e) {
68-
return { code }
68+
return
6969
}
7070
}

0 commit comments

Comments
 (0)