Skip to content

Commit bded93b

Browse files
chore: fix issue with dist and build matching (#354)
* chore: fix issue with dist and build matching * chore: fix path * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 541fc6e commit bded93b

File tree

3 files changed

+58
-58
lines changed

3 files changed

+58
-58
lines changed

.changeset/soft-bats-ask.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 an issue with dist and build matching

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ vite.config.ts.timestamp-*
5858
.angular
5959
.nitro
6060
.sonda
61-
61+
*settings.local.json

packages/devtools-vite/src/plugin.ts

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,15 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
126126
apply(config) {
127127
return config.mode === 'development' && injectSourceConfig.enabled
128128
},
129-
transform(code, id) {
130-
if (
131-
id.includes('node_modules') ||
132-
id.includes('?raw') ||
133-
id.includes('dist') ||
134-
id.includes('build')
135-
)
136-
return
137-
138-
return addSourceToJsx(code, id, args?.injectSource?.ignore)
129+
transform: {
130+
filter: {
131+
id: {
132+
exclude: [/node_modules/, /\?raw/, /\/dist\//, /\/build\//],
133+
},
134+
},
135+
handler(code, id) {
136+
return addSourceToJsx(code, id, args?.injectSource?.ignore)
137+
},
139138
},
140139
},
141140
{
@@ -550,43 +549,39 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
550549
(consolePipingConfig.enabled ?? true)
551550
)
552551
},
553-
transform(code, id) {
554-
// Inject the console pipe code into entry files
555-
if (
556-
id.includes('node_modules') ||
557-
id.includes('dist') ||
558-
id.includes('?') ||
559-
!id.match(/\.(tsx?|jsx?)$/)
560-
) {
561-
return
562-
}
563-
564-
// Only inject once - check if already injected
565-
if (code.includes('__tsdConsolePipe')) {
566-
return
567-
}
568-
569-
// Check if this is a root entry file (with <html> JSX or client entry points)
570-
// In SSR frameworks, this file runs on BOTH server (SSR) and client (hydration)
571-
// so our runtime check (typeof window === 'undefined') handles both environments
572-
const isRootEntry =
573-
/<html[\s>]/i.test(code) ||
574-
code.includes('StartClient') ||
575-
code.includes('hydrateRoot') ||
576-
code.includes('createRoot') ||
577-
(code.includes('solid-js/web') && code.includes('render('))
578-
579-
if (isRootEntry) {
580-
const viteServerUrl = `http://localhost:${port}`
581-
const inlineCode = generateConsolePipeCode(
582-
consolePipingLevels,
583-
viteServerUrl,
584-
)
552+
transform: {
553+
filter: {
554+
id: {
555+
include: /\.(tsx?|jsx?)$/,
556+
exclude: [/node_modules/, /\/dist\//, /\?/],
557+
},
558+
code: {
559+
exclude: /__tsdConsolePipe/, // avoid transforming files that already contain the console pipe code
560+
},
561+
},
562+
handler(code) {
563+
// Check if this is a root entry file (with <html> JSX or client entry points)
564+
// In SSR frameworks, this file runs on BOTH server (SSR) and client (hydration)
565+
// so our runtime check (typeof window === 'undefined') handles both environments
566+
const isRootEntry =
567+
/<html[\s>]/i.test(code) ||
568+
code.includes('StartClient') ||
569+
code.includes('hydrateRoot') ||
570+
code.includes('createRoot') ||
571+
(code.includes('solid-js/web') && code.includes('render('))
572+
573+
if (isRootEntry) {
574+
const viteServerUrl = `http://localhost:${port}`
575+
const inlineCode = generateConsolePipeCode(
576+
consolePipingLevels,
577+
viteServerUrl,
578+
)
585579

586-
return `${inlineCode}\n${code}`
587-
}
580+
return `${inlineCode}\n${code}`
581+
}
588582

589-
return undefined
583+
return undefined
584+
},
590585
},
591586
},
592587
{
@@ -595,18 +590,18 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
595590
apply(config) {
596591
return config.mode === 'development' && enhancedLogsConfig.enabled
597592
},
598-
transform(code, id) {
599-
// Ignore anything external
600-
if (
601-
id.includes('node_modules') ||
602-
id.includes('?raw') ||
603-
id.includes('dist') ||
604-
id.includes('build') ||
605-
!code.includes('console.')
606-
)
607-
return
608-
609-
return enhanceConsoleLog(code, id, port)
593+
transform: {
594+
filter: {
595+
id: {
596+
exclude: [/node_modules/, /\?raw/, /\/dist\//, /\/build\//],
597+
},
598+
code: {
599+
include: 'console.',
600+
},
601+
},
602+
handler(code, id) {
603+
return enhanceConsoleLog(code, id, port)
604+
},
610605
},
611606
},
612607
{

0 commit comments

Comments
 (0)