From 17451ae61cdc50b95e96910b4b21d05ddab9a987 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Fri, 19 Sep 2025 14:05:23 +0200 Subject: [PATCH 1/8] chore: fix issues with sourcemaps --- .gitignore | 1 + docs/vite-plugin.md | 16 ++++ examples/react/basic/package.json | 3 +- examples/react/basic/vite.config.ts | 5 + .../devtools-vite/src/enhance-logs.test.ts | 16 ++-- packages/devtools-vite/src/enhance-logs.ts | 4 +- .../devtools-vite/src/inject-source.test.ts | 96 +++++++++---------- packages/devtools-vite/src/inject-source.ts | 4 +- packages/devtools-vite/src/plugin.ts | 30 ++++-- .../devtools-vite/src/remove-devtools.test.ts | 20 ++-- packages/devtools-vite/src/remove-devtools.ts | 4 +- pnpm-lock.yaml | 15 +++ 12 files changed, 131 insertions(+), 83 deletions(-) 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..3a8349ff 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" }, @@ -40,4 +41,4 @@ "last 1 safari version" ] } -} +} \ No newline at end of file diff --git a/examples/react/basic/vite.config.ts b/examples/react/basic/vite.config.ts index 5ea9c49a..61d94aa6 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..65bad701 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( @@ -33,7 +33,7 @@ describe('remove-devtools', () => { `, 'test.jsx', 3000, - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -50,7 +50,7 @@ describe('remove-devtools', () => { `, 'test.jsx', 3000, - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -69,7 +69,7 @@ describe('remove-devtools', () => { `, 'test.jsx', 3000, - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -88,7 +88,7 @@ describe('remove-devtools', () => { `, 'test.jsx', 3000, - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -107,7 +107,7 @@ describe('remove-devtools', () => { `, 'test.jsx', 3000, - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -126,7 +126,7 @@ describe('remove-devtools', () => { `, 'test.jsx', 3000, - ).code, + )!.code, ) console.log('output', output) expect( @@ -146,7 +146,7 @@ describe('remove-devtools', () => { `, 'test.jsx', 3000, - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` 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..6c484ef1 100644 --- a/packages/devtools-vite/src/inject-source.test.ts +++ b/packages/devtools-vite/src/inject-source.test.ts @@ -15,7 +15,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -35,7 +35,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -54,7 +54,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -74,7 +74,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -94,7 +94,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -114,7 +114,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -134,7 +134,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -154,7 +154,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -176,7 +176,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -196,7 +196,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -216,7 +216,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -236,7 +236,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -256,7 +256,7 @@ describe('inject source', () => { }) `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -280,7 +280,7 @@ describe('inject source', () => { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -305,7 +305,7 @@ function test({...props }) { } `, 'test.tsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -325,7 +325,7 @@ function test({...props }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -345,7 +345,7 @@ function test(props) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -367,7 +367,7 @@ function test(props) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -391,7 +391,7 @@ function test(props) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -415,7 +415,7 @@ function test({...props}) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -437,7 +437,7 @@ function test({...rest}) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -457,7 +457,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -477,7 +477,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -497,7 +497,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -517,7 +517,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -537,7 +537,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -558,7 +558,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -578,7 +578,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -600,7 +600,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -624,7 +624,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -648,7 +648,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -670,7 +670,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -690,7 +690,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -710,7 +710,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -730,7 +730,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -750,7 +750,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -770,7 +770,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -791,7 +791,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -811,7 +811,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -833,7 +833,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -857,7 +857,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -881,7 +881,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -903,7 +903,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -923,7 +923,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -943,7 +943,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -963,7 +963,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -983,7 +983,7 @@ function test({ children, ...rest }) { } `, 'test.jsx', - ).code, + )!.code, ) expect(output).toBe( removeEmptySpace(` @@ -1003,7 +1003,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..6b40a986 100644 --- a/packages/devtools-vite/src/plugin.ts +++ b/packages/devtools-vite/src/plugin.ts @@ -6,7 +6,8 @@ import { addSourceToJsx } from './inject-source' import { enhanceConsoleLog } from './enhance-logs' import type { EditorConfig } from './editor' import type { ServerEventBusConfig } from '@tanstack/devtools-event-bus/server' -import type { Plugin } from 'vite' +import { normalizePath, type Plugin } from 'vite' +import chalk from 'chalk' export type TanStackDevtoolsViteConfig = { /** @@ -32,6 +33,12 @@ export type TanStackDevtoolsViteConfig = { * @default true */ removeDevtoolsOnBuild?: boolean + + /** + * Whether to log information to the console. + * @default true + */ + logging?: boolean /** * Configuration for source injection. */ @@ -68,7 +75,7 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array => { id.includes('dist') || id.includes('build') ) - return code + return return addSourceToJsx(code, id) }, @@ -135,9 +142,13 @@ 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 (args?.logging) { + console.log(`\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), '')}\n`); + } + return transform; }, }, { @@ -152,13 +163,12 @@ 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: From 49515bdf6a2bf73aa06dea9f62ada044a14df7c3 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Fri, 19 Sep 2025 14:05:53 +0200 Subject: [PATCH 2/8] chore: fix issues with sourcemaps --- .changeset/stupid-doors-open.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/stupid-doors-open.md 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 From 7e1426c0f61b6a0e83e28144754428d9f453ee40 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 19 Sep 2025 12:06:29 +0000 Subject: [PATCH 3/8] ci: apply automated fixes --- examples/react/basic/package.json | 2 +- examples/react/basic/vite.config.ts | 4 ++-- packages/devtools-vite/src/plugin.ts | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/react/basic/package.json b/examples/react/basic/package.json index 3a8349ff..bda592ed 100644 --- a/examples/react/basic/package.json +++ b/examples/react/basic/package.json @@ -41,4 +41,4 @@ "last 1 safari version" ] } -} \ No newline at end of file +} diff --git a/examples/react/basic/vite.config.ts b/examples/react/basic/vite.config.ts index 61d94aa6..f4d37d0d 100644 --- a/examples/react/basic/vite.config.ts +++ b/examples/react/basic/vite.config.ts @@ -2,7 +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"; +import sonda from 'sonda/vite' // https://vite.dev/config/ export default defineConfig({ @@ -20,5 +20,5 @@ export default defineConfig({ ], build: { sourcemap: true, - } + }, }) diff --git a/packages/devtools-vite/src/plugin.ts b/packages/devtools-vite/src/plugin.ts index 6b40a986..536782be 100644 --- a/packages/devtools-vite/src/plugin.ts +++ b/packages/devtools-vite/src/plugin.ts @@ -146,9 +146,11 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array => { const transform = removeDevtools(code, id) if (!transform) return if (args?.logging) { - console.log(`\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), '')}\n`); + console.log( + `\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), '')}\n`, + ) } - return transform; + return transform }, }, { @@ -168,7 +170,6 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array => { ) return - return enhanceConsoleLog(code, id, port) }, }, From 0f5955db84ac0f5b14f1f67ce2877e72d15a976c Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Fri, 19 Sep 2025 14:11:20 +0200 Subject: [PATCH 4/8] fix lint --- packages/devtools-vite/src/plugin.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/devtools-vite/src/plugin.ts b/packages/devtools-vite/src/plugin.ts index 536782be..6a5a6ca2 100644 --- a/packages/devtools-vite/src/plugin.ts +++ b/packages/devtools-vite/src/plugin.ts @@ -1,13 +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 { normalizePath, type Plugin } from 'vite' -import chalk from 'chalk' export type TanStackDevtoolsViteConfig = { /** From c8b4c7e1e02c6f315b4ea0897346b4847fe560d7 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 19 Sep 2025 12:11:52 +0000 Subject: [PATCH 5/8] ci: apply automated fixes --- packages/devtools-vite/src/plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/devtools-vite/src/plugin.ts b/packages/devtools-vite/src/plugin.ts index 6a5a6ca2..9edd3aa6 100644 --- a/packages/devtools-vite/src/plugin.ts +++ b/packages/devtools-vite/src/plugin.ts @@ -1,12 +1,12 @@ import { ServerEventBus } from '@tanstack/devtools-event-bus/server' -import { normalizePath } from 'vite' +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 { Plugin } from 'vite' import type { EditorConfig } from './editor' import type { ServerEventBusConfig } from '@tanstack/devtools-event-bus/server' From 058c07e9e9ec8ed4ca2444324e0a3e627251aed3 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Fri, 19 Sep 2025 14:45:16 +0200 Subject: [PATCH 6/8] fix tests --- .../devtools-vite/src/enhance-logs.test.ts | 89 ++---- .../devtools-vite/src/inject-source.test.ts | 288 +++++------------- 2 files changed, 110 insertions(+), 267 deletions(-) diff --git a/packages/devtools-vite/src/enhance-logs.test.ts b/packages/devtools-vite/src/enhance-logs.test.ts index 65bad701..fe114069 100644 --- a/packages/devtools-vite/src/enhance-logs.test.ts +++ b/packages/devtools-vite/src/enhance-logs.test.ts @@ -26,95 +26,71 @@ 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, + 'test.jsx', + 3000, ) expect(output).toBe( - removeEmptySpace(` - console.log - `), + 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, + 'test.jsx', + 3000, ) expect(output).toBe( - removeEmptySpace(` - // console.log('This is a log') - `), + 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, + 'test.jsx', + 3000, ) expect(output).toBe( - removeEmptySpace(` - /* - console.log('This is a log') - */ - `), + 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, + 'test.jsx', + 3000, ) expect(output).toBe( - removeEmptySpace(` - // console.error('This is a log') - `), + 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, + 'test.jsx', + 3000, ) expect(output).toBe( - removeEmptySpace(` - /* - console.error('This is a log') - */ - `), + undefined ) }) @@ -139,19 +115,14 @@ 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, + 'test.jsx', + 3000, ) expect(output).toBe( - removeEmptySpace(` - console.log - `), - ) + undefined) }) }) diff --git a/packages/devtools-vite/src/inject-source.test.ts b/packages/devtools-vite/src/inject-source.test.ts index 6c484ef1..83d23be7 100644 --- a/packages/devtools-vite/src/inject-source.test.ts +++ b/packages/devtools-vite/src/inject-source.test.ts @@ -7,61 +7,43 @@ 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: function() { return <>Hello World }, - }) - `), + 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: function() { return Hello World }, - }) - `), + 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: function() { return Hello World }, - }) - `), + undefined ) }) describe('FunctionExpression', () => { @@ -86,62 +68,44 @@ 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: function(props) { return
Hello World
}, - }) - `), + 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: function({...props}) { return
Hello World
}, - }) - `), + 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: function({...rest}) { return
Hello World
}, - }) - `), + undefined ) }) @@ -188,62 +152,44 @@ 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: (props) =>
Hello World
, - }) - `), + 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: ({...props}) =>
Hello World
, - }) - `), + 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, + 'test.jsx', ) expect(output).toBe( - removeEmptySpace(` - export const Route = createFileRoute("/test")({ - component: ({...rest}) =>
Hello World
, - }) - `), + undefined ) }) @@ -337,22 +283,16 @@ 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