Skip to content

Commit c20ef2f

Browse files
committed
Merge branch 'feat/remove-from-rpod' of https://github.com/TanStack/devtools into feat/remove-from-rpod
2 parents 5e4968e + 9c396ee commit c20ef2f

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

examples/react/basic/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Inspect from 'vite-plugin-inspect'
77
export default defineConfig({
88
plugins: [
99
devtools({
10-
removeDevtoolsOnBuild: true
10+
removeDevtoolsOnBuild: true,
1111
}),
1212
Inspect(),
1313
react({

packages/devtools-vite/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
128128
apply(_, { command }) {
129129
return command === 'build' && removeDevtoolsOnBuild
130130
},
131-
enforce: "pre",
131+
enforce: 'pre',
132132
transform(code, id) {
133133
if (
134134
id.includes('node_modules') ||

packages/devtools-vite/src/remove-devtools.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { describe, expect, test } from "vitest";
2-
import { removeDevtools } from "./remove-devtools";
1+
import { describe, expect, test } from 'vitest'
2+
import { removeDevtools } from './remove-devtools'
33

44
const removeEmptySpace = (str: string) => {
55
return str.replace(/\s/g, '').trim()
66
}
77

8-
describe("remove-devtools", () => {
9-
test("it removes devtools if Imported directly", () => {
8+
describe('remove-devtools', () => {
9+
test('it removes devtools if Imported directly', () => {
1010
const output = removeEmptySpace(
1111
removeDevtools(
1212
`
@@ -78,7 +78,7 @@ export default function DevtoolsExample() {
7878
7979
`),
8080
)
81-
});
81+
})
8282

8383
test("it removes devtools if Imported and renamed with 'as' ", () => {
8484
const output = removeEmptySpace(
@@ -152,9 +152,9 @@ export default function DevtoolsExample() {
152152
153153
`),
154154
)
155-
});
155+
})
156156

157-
test("it removes devtools if Imported as * then used as a subcomponent ", () => {
157+
test('it removes devtools if Imported as * then used as a subcomponent ', () => {
158158
const output = removeEmptySpace(
159159
removeDevtools(
160160
`
@@ -226,5 +226,5 @@ export default function DevtoolsExample() {
226226
227227
`),
228228
)
229-
});
230-
})
229+
})
230+
})

packages/devtools-vite/src/remove-devtools.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
21
import { gen, parse, trav } from './babel'
3-
import type { t } from './babel';
4-
import type { types as Babel, } from '@babel/core'
2+
import type { t } from './babel'
3+
import type { types as Babel } from '@babel/core'
54
import type { ParseResult } from '@babel/parser'
65

76
const isTanStackDevtoolsImport = (source: string) =>
8-
source === '@tanstack/react-devtools' || source === "@tanstack/devtools" || source === "@tanstack/solid-devtools"
7+
source === '@tanstack/react-devtools' ||
8+
source === '@tanstack/devtools' ||
9+
source === '@tanstack/solid-devtools'
910

1011
const getImportedNames = (importDecl: t.ImportDeclaration) => {
1112
return importDecl.specifiers.map((spec) => spec.local.name)
1213
}
1314

14-
const transform = (ast: ParseResult<Babel.File>,) => {
15+
const transform = (ast: ParseResult<Babel.File>) => {
1516
let didTransform = false
1617
const devtoolsComponentNames = new Set()
1718

1819
trav(ast, {
1920
ImportDeclaration(path) {
2021
const importSource = path.node.source.value
2122
if (isTanStackDevtoolsImport(importSource)) {
22-
getImportedNames(path.node).forEach((name) => devtoolsComponentNames.add(name))
23+
getImportedNames(path.node).forEach((name) =>
24+
devtoolsComponentNames.add(name),
25+
)
2326
path.remove()
2427
didTransform = true
2528
}
@@ -34,14 +37,15 @@ const transform = (ast: ParseResult<Babel.File>,) => {
3437
didTransform = true
3538
}
3639

37-
if (opening.name.type === 'JSXMemberExpression' &&
40+
if (
41+
opening.name.type === 'JSXMemberExpression' &&
3842
opening.name.object.type === 'JSXIdentifier' &&
3943
devtoolsComponentNames.has(opening.name.object.name)
4044
) {
4145
path.remove()
4246
didTransform = true
4347
}
44-
}
48+
},
4549
})
4650

4751
return didTransform
@@ -55,7 +59,7 @@ export function removeDevtools(code: string, id: string) {
5559
sourceType: 'module',
5660
plugins: ['jsx', 'typescript'],
5761
})
58-
const didTransform = transform(ast,)
62+
const didTransform = transform(ast)
5963
if (!didTransform) {
6064
return { code }
6165
}

0 commit comments

Comments
 (0)