diff --git a/.changeset/stupid-doors-open.md b/.changeset/stupid-doors-open.md
new file mode 100644
index 00000000..476d28da
--- /dev/null
+++ b/.changeset/stupid-doors-open.md
@@ -0,0 +1,5 @@
+---
+'@tanstack/devtools-vite': patch
+---
+
+fix issue with sourcemaps and vite plugin
diff --git a/.gitignore b/.gitignore
index c161882e..4121b416 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,3 +56,4 @@ vite.config.ts.timestamp-*
.angular
.nitro
+.sonda
\ No newline at end of file
diff --git a/docs/vite-plugin.md b/docs/vite-plugin.md
index 75d22bd2..c41175b2 100644
--- a/docs/vite-plugin.md
+++ b/docs/vite-plugin.md
@@ -134,6 +134,22 @@ export default {
}
```
+### logging
+ Whether to log information to the console. Defaults to true.
+
+```ts
+import { devtools } from '@tanstack/devtools-vite'
+
+export default {
+ plugins: [
+ devtools({
+ logging: true
+ }),
+ // ... rest of your plugins here
+ ],
+}
+```
+
### injectSource
Configuration for source injection. Defaults to enabled.
diff --git a/examples/react/basic/package.json b/examples/react/basic/package.json
index ef495c0c..bda592ed 100644
--- a/examples/react/basic/package.json
+++ b/examples/react/basic/package.json
@@ -25,6 +25,7 @@
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.2",
"@vitejs/plugin-react": "^4.5.2",
+ "sonda": "0.9.0",
"vite": "^7.0.6",
"vite-plugin-inspect": "11.3.2"
},
diff --git a/examples/react/basic/vite.config.ts b/examples/react/basic/vite.config.ts
index 5ea9c49a..f4d37d0d 100644
--- a/examples/react/basic/vite.config.ts
+++ b/examples/react/basic/vite.config.ts
@@ -2,6 +2,7 @@ import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { devtools } from '@tanstack/devtools-vite'
import Inspect from 'vite-plugin-inspect'
+import sonda from 'sonda/vite'
// https://vite.dev/config/
export default defineConfig({
@@ -10,10 +11,14 @@ export default defineConfig({
removeDevtoolsOnBuild: true,
}),
Inspect(),
+ sonda(),
react({
// babel: {
// plugins: [['babel-plugin-react-compiler', { target: '19' }]],
// },
}),
],
+ build: {
+ sourcemap: true,
+ },
})
diff --git a/packages/devtools-vite/src/enhance-logs.test.ts b/packages/devtools-vite/src/enhance-logs.test.ts
index 3aeeb190..4e9be263 100644
--- a/packages/devtools-vite/src/enhance-logs.test.ts
+++ b/packages/devtools-vite/src/enhance-logs.test.ts
@@ -14,7 +14,7 @@ describe('remove-devtools', () => {
`,
'test.jsx',
3000,
- ).code,
+ )!.code,
)
expect(
output.includes(
@@ -26,96 +26,62 @@ describe('remove-devtools', () => {
})
test('it does not add enhanced console.logs to console.log that is not called', () => {
- const output = removeEmptySpace(
- enhanceConsoleLog(
- `
+ const output = enhanceConsoleLog(
+ `
console.log
`,
- 'test.jsx',
- 3000,
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- console.log
- `),
+ 'test.jsx',
+ 3000,
)
+ expect(output).toBe(undefined)
})
test('it does not add enhanced console.logs to console.log that is inside a comment', () => {
- const output = removeEmptySpace(
- enhanceConsoleLog(
- `
+ const output = enhanceConsoleLog(
+ `
// console.log('This is a log')
`,
- 'test.jsx',
- 3000,
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- // console.log('This is a log')
- `),
+ 'test.jsx',
+ 3000,
)
+ expect(output).toBe(undefined)
})
test('it does not add enhanced console.logs to console.log that is inside a multiline comment', () => {
- const output = removeEmptySpace(
- enhanceConsoleLog(
- `
+ const output = enhanceConsoleLog(
+ `
/*
console.log('This is a log')
*/
`,
- 'test.jsx',
- 3000,
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- /*
- console.log('This is a log')
- */
- `),
+ 'test.jsx',
+ 3000,
)
+ expect(output).toBe(undefined)
})
test('it does not add enhanced console.error to console.error that is inside a comment', () => {
- const output = removeEmptySpace(
- enhanceConsoleLog(
- `
+ const output = enhanceConsoleLog(
+ `
// console.error('This is a log')
`,
- 'test.jsx',
- 3000,
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- // console.error('This is a log')
- `),
+ 'test.jsx',
+ 3000,
)
+ expect(output).toBe(undefined)
})
test('it does not add enhanced console.error to console.error that is inside a multiline comment', () => {
- const output = removeEmptySpace(
- enhanceConsoleLog(
- `
+ const output = enhanceConsoleLog(
+ `
/*
console.error('This is a log')
*/
`,
- 'test.jsx',
- 3000,
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- /*
- console.error('This is a log')
- */
- `),
+ 'test.jsx',
+ 3000,
)
+ expect(output).toBe(undefined)
})
test('it adds enhanced console.error to console.error()', () => {
@@ -126,7 +92,7 @@ describe('remove-devtools', () => {
`,
'test.jsx',
3000,
- ).code,
+ )!.code,
)
console.log('output', output)
expect(
@@ -139,19 +105,13 @@ describe('remove-devtools', () => {
})
test('it does not add enhanced console.error to console.error that is not called', () => {
- const output = removeEmptySpace(
- enhanceConsoleLog(
- `
+ const output = enhanceConsoleLog(
+ `
console.log
`,
- 'test.jsx',
- 3000,
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- console.log
- `),
+ 'test.jsx',
+ 3000,
)
+ expect(output).toBe(undefined)
})
})
diff --git a/packages/devtools-vite/src/enhance-logs.ts b/packages/devtools-vite/src/enhance-logs.ts
index 0e30cf73..d0d2aee6 100644
--- a/packages/devtools-vite/src/enhance-logs.ts
+++ b/packages/devtools-vite/src/enhance-logs.ts
@@ -56,7 +56,7 @@ export function enhanceConsoleLog(code: string, id: string, port: number) {
})
const didTransform = transform(ast, location, port)
if (!didTransform) {
- return { code }
+ return
}
return gen(ast, {
sourceMaps: true,
@@ -65,6 +65,6 @@ export function enhanceConsoleLog(code: string, id: string, port: number) {
sourceFileName: filePath,
})
} catch (e) {
- return { code }
+ return
}
}
diff --git a/packages/devtools-vite/src/inject-source.test.ts b/packages/devtools-vite/src/inject-source.test.ts
index fd6134f8..d8c8d55c 100644
--- a/packages/devtools-vite/src/inject-source.test.ts
+++ b/packages/devtools-vite/src/inject-source.test.ts
@@ -7,62 +7,38 @@ const removeEmptySpace = (str: string) => {
describe('inject source', () => {
it("shouldn't augment react fragments", () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: function() { return <>Hello World> },
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: function() { return <>Hello World> },
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it("shouldn't augment react fragments if they start with Fragment ", () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: function() { return Hello World },
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: function() { return Hello World },
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it("shouldn't augment react fragments if they start with React.Fragment ", () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: function() { return Hello World },
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: function() { return Hello World },
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
describe('FunctionExpression', () => {
it('should work with deeply nested custom JSX syntax', () => {
@@ -74,7 +50,7 @@ describe('inject source', () => {
})
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -86,63 +62,39 @@ describe('inject source', () => {
})
it('should work with props not destructured and spread', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: function(props) { return
Hello World
},
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: function(props) { return Hello World
},
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('should work with props destructured and spread', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: function({...props}) { return Hello World
},
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: function({...props}) { return Hello World
},
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('should work with props destructured and spread with a different name', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: function({...rest}) { return Hello World
},
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: function({...rest}) { return Hello World
},
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('should work with props spread and other normal elements', () => {
@@ -154,7 +106,7 @@ describe('inject source', () => {
})
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -176,7 +128,7 @@ describe('inject source', () => {
})
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -188,63 +140,39 @@ describe('inject source', () => {
})
it('should work with props not destructured and spread', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: (props) => Hello World
,
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: (props) => Hello World
,
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('should work with props destructured and spread', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: ({...props}) => Hello World
,
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: ({...props}) => Hello World
,
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('should work with props destructured and spread with a different name', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const Route = createFileRoute("/test")({
component: ({...rest}) => Hello World
,
})
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const Route = createFileRoute("/test")({
- component: ({...rest}) => Hello World
,
- })
- `),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('should work with props spread and other normal elements', () => {
@@ -256,7 +184,7 @@ describe('inject source', () => {
})
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -280,7 +208,7 @@ describe('inject source', () => {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -305,7 +233,7 @@ function test({...props }) {
}
`,
'test.tsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -325,7 +253,7 @@ function test({...props }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -337,23 +265,15 @@ function test(props) {
})
it("doesn't transform when props are spread across the element", () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
function test(props) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
-function test(props) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it("doesn't transform when props are spread across the element but applies to other elements without any props", () => {
@@ -367,7 +287,7 @@ function test(props) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -391,7 +311,7 @@ function test(props) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -415,7 +335,7 @@ function test({...props}) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -429,23 +349,15 @@ function test({...rest}) {
})
it(' props destructured and collected with a different name', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
function test({ children, ...rest }) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
-function test({ children, ...rest }) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it(' props destructured and collected', () => {
@@ -457,7 +369,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -469,23 +381,15 @@ function test({ children, ...rest }) {
})
it('props destructured and collected with a different name even on custom components', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
function test({ children, ...rest }) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
-function test({ children, ...rest }) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('props destructured and collected even on custom components', () => {
@@ -497,7 +401,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -509,23 +413,15 @@ function test({ children, ...rest }) {
})
it('props destructured and collected with a different name even on custom components even if exported', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
function test({ children, ...rest }) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- function test({ children, ...rest }) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('props destructured and collected even on custom components even if exported', () => {
@@ -537,7 +433,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -558,7 +454,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -570,23 +466,15 @@ function test({ children, ...rest }) {
})
it("doesn't transform when props are spread across the element", () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
const ButtonWithProps = function test(props) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- const ButtonWithProps = function test(props) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it("doesn't transform when props are spread across the element but applies to other elements without any props", () => {
@@ -600,7 +488,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -624,7 +512,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -648,7 +536,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -662,23 +550,15 @@ function test({ children, ...rest }) {
})
it(' props destructured and collected with a different name', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
const ButtonWithProps = function test({ children, ...rest }) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- const ButtonWithProps = function test({ children, ...rest }) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it(' props destructured and collected', () => {
@@ -690,7 +570,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -702,23 +582,15 @@ function test({ children, ...rest }) {
})
it('props destructured and collected with a different name even on custom components', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
const ButtonWithProps = function test({ children, ...rest }) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- const ButtonWithProps = function test({ children, ...rest }) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('props destructured and collected even on custom components', () => {
@@ -730,7 +602,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -742,23 +614,15 @@ function test({ children, ...rest }) {
})
it('props destructured and collected with a different name even on custom components even if exported', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const ButtonWithProps = function test({ children, ...rest }) {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const ButtonWithProps = function test({ children, ...rest }) {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('props destructured and collected even on custom components even if exported', () => {
@@ -770,7 +634,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -791,7 +655,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -803,23 +667,15 @@ function test({ children, ...rest }) {
})
it("doesn't transform when props are spread across the element", () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
const ButtonWithProps = (props) => {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- const ButtonWithProps = (props) => {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it("doesn't transform when props are spread across the element but applies to other elements without any props", () => {
@@ -833,7 +689,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -857,7 +713,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -881,7 +737,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -903,7 +759,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -923,7 +779,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -935,23 +791,15 @@ function test({ children, ...rest }) {
})
it('works with arrow function and props destructured and collected with a different name even on custom components', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
const ButtonWithProps = ({ children, ...rest }) => {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- const ButtonWithProps = ({ children, ...rest }) => {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('works with arrow function and props destructured and collected even on custom components', () => {
@@ -963,7 +811,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -975,23 +823,15 @@ function test({ children, ...rest }) {
})
it('works with arrow function and props destructured and collected with a different name even on custom components even if exported', () => {
- const output = removeEmptySpace(
- addSourceToJsx(
- `
+ const output = addSourceToJsx(
+ `
export const ButtonWithProps = ({ children, ...rest }) => {
return
}
`,
- 'test.jsx',
- ).code,
- )
- expect(output).toBe(
- removeEmptySpace(`
- export const ButtonWithProps = ({ children, ...rest }) => {
- return
- }
-`),
+ 'test.jsx',
)
+ expect(output).toBe(undefined)
})
it('works with arrow function and props destructured and collected even on custom components even if exported', () => {
@@ -1003,7 +843,7 @@ function test({ children, ...rest }) {
}
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
diff --git a/packages/devtools-vite/src/inject-source.ts b/packages/devtools-vite/src/inject-source.ts
index cc0e3735..0b4cbe7d 100644
--- a/packages/devtools-vite/src/inject-source.ts
+++ b/packages/devtools-vite/src/inject-source.ts
@@ -228,7 +228,7 @@ export function addSourceToJsx(code: string, id: string) {
})
const didTransform = transform(ast, location)
if (!didTransform) {
- return { code }
+ return
}
return gen(ast, {
sourceMaps: true,
@@ -237,6 +237,6 @@ export function addSourceToJsx(code: string, id: string) {
sourceFileName: filePath,
})
} catch (e) {
- return { code }
+ return
}
}
diff --git a/packages/devtools-vite/src/plugin.ts b/packages/devtools-vite/src/plugin.ts
index c82958d1..8c43c6b2 100644
--- a/packages/devtools-vite/src/plugin.ts
+++ b/packages/devtools-vite/src/plugin.ts
@@ -1,12 +1,14 @@
import { ServerEventBus } from '@tanstack/devtools-event-bus/server'
+import { normalizePath } from 'vite'
+import chalk from 'chalk'
import { handleDevToolsViteRequest } from './utils'
import { DEFAULT_EDITOR_CONFIG, handleOpenSource } from './editor'
import { removeDevtools } from './remove-devtools'
import { addSourceToJsx } from './inject-source'
import { enhanceConsoleLog } from './enhance-logs'
+import type { Plugin } from 'vite'
import type { EditorConfig } from './editor'
import type { ServerEventBusConfig } from '@tanstack/devtools-event-bus/server'
-import type { Plugin } from 'vite'
export type TanStackDevtoolsViteConfig = {
/**
@@ -32,6 +34,12 @@ export type TanStackDevtoolsViteConfig = {
* @default true
*/
removeDevtoolsOnBuild?: boolean
+
+ /**
+ * Whether to log information to the console.
+ * @default true
+ */
+ logging?: boolean
/**
* Configuration for source injection.
*/
@@ -49,6 +57,7 @@ export const defineDevtoolsConfig = (config: TanStackDevtoolsViteConfig) =>
export const devtools = (args?: TanStackDevtoolsViteConfig): Array => {
let port = 5173
+ const logging = args?.logging ?? true
const enhancedLogsConfig = args?.enhancedLogs ?? { enabled: true }
const injectSourceConfig = args?.injectSource ?? { enabled: true }
const removeDevtoolsOnBuild = args?.removeDevtoolsOnBuild ?? true
@@ -68,7 +77,7 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array => {
id.includes('dist') ||
id.includes('build')
)
- return code
+ return
return addSourceToJsx(code, id)
},
@@ -135,9 +144,15 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array => {
id.includes('dist') ||
id.includes('build')
)
- return code
-
- return removeDevtools(code, id)
+ return
+ const transform = removeDevtools(code, id)
+ if (!transform) return
+ if (logging) {
+ console.log(
+ `\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), '')}\n`,
+ )
+ }
+ return transform
},
},
{
@@ -152,13 +167,11 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array => {
id.includes('node_modules') ||
id.includes('?raw') ||
id.includes('dist') ||
- id.includes('build')
+ id.includes('build') ||
+ !code.includes('console.')
)
- return code
+ return
- if (!code.includes('console.')) {
- return code
- }
return enhanceConsoleLog(code, id, port)
},
},
diff --git a/packages/devtools-vite/src/remove-devtools.test.ts b/packages/devtools-vite/src/remove-devtools.test.ts
index 925b0a4f..5fdee0e2 100644
--- a/packages/devtools-vite/src/remove-devtools.test.ts
+++ b/packages/devtools-vite/src/remove-devtools.test.ts
@@ -53,7 +53,7 @@ export default function DevtoolsExample() {
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -125,7 +125,7 @@ export default function DevtoolsExample() {
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -197,7 +197,7 @@ export default function DevtoolsExample() {
`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
removeEmptySpace(`
@@ -268,7 +268,7 @@ export default function DevtoolsExample() {
)
}`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
@@ -325,7 +325,7 @@ export default function DevtoolsExample() {
)
}`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
@@ -372,7 +372,7 @@ export default function DevtoolsExample() {
)
}`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
@@ -416,7 +416,7 @@ export default function DevtoolsExample() {
)
}`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
@@ -458,7 +458,7 @@ export default function DevtoolsExample() {
)
}`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
@@ -500,7 +500,7 @@ export default function DevtoolsExample() {
)
}`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
@@ -542,7 +542,7 @@ export default function DevtoolsExample() {
)
}`,
'test.jsx',
- ).code,
+ )!.code,
)
expect(output).toBe(
diff --git a/packages/devtools-vite/src/remove-devtools.ts b/packages/devtools-vite/src/remove-devtools.ts
index 30c32b4c..6171f47c 100644
--- a/packages/devtools-vite/src/remove-devtools.ts
+++ b/packages/devtools-vite/src/remove-devtools.ts
@@ -180,7 +180,7 @@ export function removeDevtools(code: string, id: string) {
})
const didTransform = transform(ast)
if (!didTransform) {
- return { code }
+ return
}
return gen(ast, {
sourceMaps: true,
@@ -189,6 +189,6 @@ export function removeDevtools(code: string, id: string) {
sourceFileName: filePath,
})
} catch (e) {
- return { code }
+ return
}
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e90bdc98..d90126ae 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -211,6 +211,9 @@ importers:
'@vitejs/plugin-react':
specifier: ^4.5.2
version: 4.7.0(vite@7.0.6(@types/node@22.15.2)(jiti@2.5.1)(lightningcss@1.30.1)(terser@5.43.1)(tsx@4.20.3)(yaml@2.8.0))
+ sonda:
+ specifier: 0.9.0
+ version: 0.9.0
vite:
specifier: ^7.0.6
version: 7.0.6(@types/node@22.15.2)(jiti@2.5.1)(lightningcss@1.30.1)(terser@5.43.1)(tsx@4.20.3)(yaml@2.8.0)
@@ -465,6 +468,8 @@ importers:
specifier: ^4.2.4
version: 4.2.4
+ examples/react/start/generated/prisma: {}
+
examples/react/time-travel:
dependencies:
'@tanstack/devtools-event-client':
@@ -9399,6 +9404,11 @@ packages:
peerDependencies:
solid-js: ^1.7
+ sonda@0.9.0:
+ resolution: {integrity: sha512-abMPj/ki+FdVCKkC2tFahz3dMFQi5vlSyx5X8u9rUB6IMX7vWwBdv6rMj9XjE7iuWcf/OYn/jVOcXkIUmHzXUA==}
+ engines: {node: '>=20.19 || >=22.12'}
+ hasBin: true
+
source-map-js@1.2.1:
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'}
@@ -21382,6 +21392,11 @@ snapshots:
dependencies:
solid-js: 1.9.7
+ sonda@0.9.0:
+ dependencies:
+ '@ampproject/remapping': 2.3.0
+ open: 10.2.0
+
source-map-js@1.2.1: {}
source-map-support@0.5.21: