@tanstack/devtools-vite 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/ast-utils.d.ts +11 -0
- package/dist/esm/ast-utils.js +44 -0
- package/dist/esm/ast-utils.js.map +1 -0
- package/dist/esm/devtools-packages.d.ts +2 -0
- package/dist/esm/devtools-packages.js +15 -0
- package/dist/esm/devtools-packages.js.map +1 -0
- package/dist/esm/editor.js +18 -27
- package/dist/esm/editor.js.map +1 -1
- package/dist/esm/enhance-logs.d.ts +4 -1
- package/dist/esm/enhance-logs.js +48 -81
- package/dist/esm/enhance-logs.js.map +1 -1
- package/dist/esm/index.js +1 -5
- package/dist/esm/inject-plugin.d.ts +5 -4
- package/dist/esm/inject-plugin.js +171 -220
- package/dist/esm/inject-plugin.js.map +1 -1
- package/dist/esm/inject-source.d.ts +4 -1
- package/dist/esm/inject-source.js +111 -205
- package/dist/esm/inject-source.js.map +1 -1
- package/dist/esm/matcher.js +11 -16
- package/dist/esm/matcher.js.map +1 -1
- package/dist/esm/offset-to-loc.d.ts +14 -0
- package/dist/esm/offset-to-loc.js +29 -0
- package/dist/esm/offset-to-loc.js.map +1 -0
- package/dist/esm/package-manager.js +90 -131
- package/dist/esm/package-manager.js.map +1 -1
- package/dist/esm/plugin.js +329 -448
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/remove-devtools.d.ts +4 -1
- package/dist/esm/remove-devtools.js +93 -134
- package/dist/esm/remove-devtools.js.map +1 -1
- package/dist/esm/utils.js +149 -162
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/virtual-console.js +170 -14
- package/dist/esm/virtual-console.js.map +1 -1
- package/package.json +4 -10
- package/skills/devtools-vite-plugin/SKILL.md +7 -7
- package/skills/devtools-vite-plugin/references/vite-options.md +2 -2
- package/src/ast-utils.ts +54 -0
- package/src/devtools-packages.ts +12 -0
- package/src/enhance-logs.ts +48 -78
- package/src/inject-plugin.test.ts +200 -147
- package/src/inject-plugin.ts +195 -238
- package/src/inject-source.test.ts +165 -115
- package/src/inject-source.ts +183 -231
- package/src/offset-to-loc.ts +39 -0
- package/src/plugin.ts +35 -29
- package/src/remove-devtools.test.ts +76 -57
- package/src/remove-devtools.ts +160 -168
- package/src/virtual-console.test.ts +172 -1
- package/src/virtual-console.ts +146 -7
- package/dist/esm/babel.d.ts +0 -18
- package/dist/esm/babel.js +0 -19
- package/dist/esm/babel.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/src/babel.ts +0 -18
package/src/inject-plugin.ts
CHANGED
|
@@ -1,40 +1,32 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
-
import
|
|
2
|
+
import MagicString from 'magic-string'
|
|
3
|
+
import { parseSync } from 'oxc-parser'
|
|
4
|
+
import { walk } from './ast-utils'
|
|
5
|
+
import { isTanStackDevtoolsImport } from './devtools-packages'
|
|
6
|
+
import type { Node } from 'oxc-parser'
|
|
3
7
|
import type { PluginInjection } from '@tanstack/devtools-client'
|
|
4
|
-
import type { types as Babel } from '@babel/core'
|
|
5
|
-
import type { ParseResult } from '@babel/parser'
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Detects if a file imports TanStack devtools packages
|
|
9
|
-
* Handles: import X from '@tanstack/react-devtools'
|
|
10
|
-
* import * as X from '@tanstack/react-devtools'
|
|
11
|
-
* import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
12
11
|
*/
|
|
13
12
|
const detectDevtoolsImport = (code: string): boolean => {
|
|
14
|
-
const devtoolsPackages = [
|
|
15
|
-
'@tanstack/react-devtools',
|
|
16
|
-
'@tanstack/solid-devtools',
|
|
17
|
-
'@tanstack/vue-devtools',
|
|
18
|
-
'@tanstack/svelte-devtools',
|
|
19
|
-
'@tanstack/angular-devtools',
|
|
20
|
-
]
|
|
21
|
-
|
|
22
13
|
try {
|
|
23
|
-
const
|
|
14
|
+
const result = parseSync('input.tsx', code, {
|
|
24
15
|
sourceType: 'module',
|
|
25
|
-
|
|
16
|
+
lang: 'tsx',
|
|
26
17
|
})
|
|
18
|
+
if (result.errors.length > 0) return false
|
|
27
19
|
|
|
28
20
|
let hasDevtoolsImport = false
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
22
|
+
walk(result.program, (node) => {
|
|
23
|
+
if (hasDevtoolsImport) return
|
|
24
|
+
if (
|
|
25
|
+
node.type === 'ImportDeclaration' &&
|
|
26
|
+
isTanStackDevtoolsImport(node.source.value)
|
|
27
|
+
) {
|
|
28
|
+
hasDevtoolsImport = true
|
|
29
|
+
}
|
|
38
30
|
})
|
|
39
31
|
|
|
40
32
|
return hasDevtoolsImport
|
|
@@ -47,232 +39,217 @@ const detectDevtoolsImport = (code: string): boolean => {
|
|
|
47
39
|
* Finds the TanStackDevtools component name in the file
|
|
48
40
|
* Handles renamed imports and namespace imports
|
|
49
41
|
*/
|
|
50
|
-
export const findDevtoolsComponentName = (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (namedImport && t.isImportSpecifier(namedImport)) {
|
|
74
|
-
componentName = namedImport.local.name
|
|
75
|
-
path.stop()
|
|
42
|
+
export const findDevtoolsComponentName = (code: string): string | null => {
|
|
43
|
+
try {
|
|
44
|
+
const result = parseSync('input.tsx', code, {
|
|
45
|
+
sourceType: 'module',
|
|
46
|
+
lang: 'tsx',
|
|
47
|
+
})
|
|
48
|
+
if (result.errors.length > 0) return null
|
|
49
|
+
|
|
50
|
+
let componentName: string | null = null
|
|
51
|
+
|
|
52
|
+
walk(result.program, (node) => {
|
|
53
|
+
if (componentName) return
|
|
54
|
+
if (node.type !== 'ImportDeclaration') return
|
|
55
|
+
if (!isTanStackDevtoolsImport(node.source.value)) return
|
|
56
|
+
|
|
57
|
+
for (const spec of node.specifiers) {
|
|
58
|
+
// import { TanStackDevtools } or import { TanStackDevtools as X }
|
|
59
|
+
if (
|
|
60
|
+
spec.type === 'ImportSpecifier' &&
|
|
61
|
+
spec.imported.type === 'Identifier' &&
|
|
62
|
+
spec.imported.name === 'TanStackDevtools'
|
|
63
|
+
) {
|
|
64
|
+
componentName = spec.local.name
|
|
76
65
|
return
|
|
77
66
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
t.isImportNamespaceSpecifier(spec),
|
|
82
|
-
)
|
|
83
|
-
if (namespaceImport && t.isImportNamespaceSpecifier(namespaceImport)) {
|
|
84
|
-
// For namespace imports, we need to look for DevtoolsName.TanStackDevtools
|
|
85
|
-
componentName = `${namespaceImport.local.name}.TanStackDevtools`
|
|
86
|
-
path.stop()
|
|
67
|
+
// import * as X from '...'
|
|
68
|
+
if (spec.type === 'ImportNamespaceSpecifier') {
|
|
69
|
+
componentName = `${spec.local.name}.TanStackDevtools`
|
|
87
70
|
return
|
|
88
71
|
}
|
|
89
72
|
}
|
|
90
|
-
}
|
|
91
|
-
})
|
|
73
|
+
})
|
|
92
74
|
|
|
93
|
-
|
|
75
|
+
return componentName
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check if a plugin already exists in the array expression
|
|
83
|
+
*/
|
|
84
|
+
function pluginExists(
|
|
85
|
+
code: string,
|
|
86
|
+
node: Node,
|
|
87
|
+
importName: string,
|
|
88
|
+
displayName: string,
|
|
89
|
+
pluginType: string,
|
|
90
|
+
): boolean {
|
|
91
|
+
if (node.type !== 'ArrayExpression') return false
|
|
92
|
+
|
|
93
|
+
for (const element of node.elements) {
|
|
94
|
+
if (!element) continue
|
|
95
|
+
|
|
96
|
+
if (pluginType === 'function') {
|
|
97
|
+
if (
|
|
98
|
+
element.type === 'CallExpression' &&
|
|
99
|
+
element.callee.type === 'Identifier' &&
|
|
100
|
+
element.callee.name === importName
|
|
101
|
+
) {
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
if (element.type !== 'ObjectExpression') continue
|
|
106
|
+
for (const prop of element.properties) {
|
|
107
|
+
if (
|
|
108
|
+
prop.type === 'Property' &&
|
|
109
|
+
prop.key.type === 'Identifier' &&
|
|
110
|
+
prop.key.name === 'name' &&
|
|
111
|
+
prop.value.type === 'Literal' &&
|
|
112
|
+
code.slice(prop.value.start + 1, prop.value.end - 1) === displayName
|
|
113
|
+
) {
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function buildPluginString(
|
|
124
|
+
importName: string,
|
|
125
|
+
displayName: string,
|
|
126
|
+
pluginType: string,
|
|
127
|
+
): string {
|
|
128
|
+
if (pluginType === 'function') {
|
|
129
|
+
return `${importName}()`
|
|
130
|
+
}
|
|
131
|
+
return `{ name: ${JSON.stringify(displayName)}, render: <${importName} /> }`
|
|
94
132
|
}
|
|
95
133
|
|
|
96
134
|
export const transformAndInject = (
|
|
97
|
-
|
|
135
|
+
code: string,
|
|
98
136
|
injection: PluginInjection,
|
|
99
137
|
devtoolsComponentName: string,
|
|
100
|
-
) => {
|
|
101
|
-
let didTransform = false
|
|
102
|
-
|
|
103
|
-
// Use pluginImport if provided, otherwise generate from package name
|
|
138
|
+
): { code: string; transformed: boolean } | null => {
|
|
104
139
|
const importName = injection.pluginImport?.importName
|
|
105
140
|
const pluginType = injection.pluginImport?.type || 'jsx'
|
|
106
141
|
const displayName = injection.pluginName
|
|
107
142
|
|
|
108
143
|
if (!importName) {
|
|
109
|
-
return
|
|
144
|
+
return null
|
|
110
145
|
}
|
|
111
|
-
// Handle namespace imports like DevtoolsModule.TanStackDevtools
|
|
112
|
-
const isNamespaceImport = devtoolsComponentName.includes('.')
|
|
113
146
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
147
|
+
try {
|
|
148
|
+
const result = parseSync('input.tsx', code, {
|
|
149
|
+
sourceType: 'module',
|
|
150
|
+
lang: 'tsx',
|
|
151
|
+
})
|
|
152
|
+
if (result.errors.length > 0) return null
|
|
153
|
+
|
|
154
|
+
const s = new MagicString(code)
|
|
155
|
+
const isNamespaceImport = devtoolsComponentName.includes('.')
|
|
156
|
+
|
|
157
|
+
walk(result.program, (node) => {
|
|
158
|
+
if (node.type !== 'JSXOpeningElement') return
|
|
119
159
|
|
|
160
|
+
let matches = false
|
|
120
161
|
if (isNamespaceImport) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const fullName = `${t.isJSXIdentifier(elementName.object) ? elementName.object.name : ''}.${t.isJSXIdentifier(elementName.property) ? elementName.property.name : ''}`
|
|
162
|
+
if (node.name.type === 'JSXMemberExpression') {
|
|
163
|
+
const fullName = `${node.name.object.type === 'JSXIdentifier' ? node.name.object.name : ''}.${node.name.property.name}`
|
|
124
164
|
matches = fullName === devtoolsComponentName
|
|
125
165
|
}
|
|
126
166
|
} else {
|
|
127
|
-
// Handle <TanStackDevtools /> or <RenamedDevtools />
|
|
128
167
|
matches =
|
|
129
|
-
|
|
130
|
-
|
|
168
|
+
node.name.type === 'JSXIdentifier' &&
|
|
169
|
+
node.name.name === devtoolsComponentName
|
|
131
170
|
}
|
|
132
171
|
|
|
133
|
-
if (matches)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
!t.isObjectProperty(prop) ||
|
|
171
|
-
!t.isIdentifier(prop.key) ||
|
|
172
|
-
prop.key.name !== 'name'
|
|
173
|
-
) {
|
|
174
|
-
return false
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return (
|
|
178
|
-
t.isStringLiteral(prop.value) &&
|
|
179
|
-
prop.value.value === displayName
|
|
180
|
-
)
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
if (!pluginExists) {
|
|
185
|
-
// For function-based plugins, add them directly as function calls
|
|
186
|
-
// For JSX plugins, wrap them in objects with name and render
|
|
187
|
-
if (pluginType === 'function') {
|
|
188
|
-
// Add directly: FormDevtoolsPlugin()
|
|
189
|
-
expression.elements.push(
|
|
190
|
-
t.callExpression(t.identifier(importName), []),
|
|
191
|
-
)
|
|
192
|
-
} else {
|
|
193
|
-
// Add as object: { name: "...", render: <Component /> }
|
|
194
|
-
const renderValue = t.jsxElement(
|
|
195
|
-
t.jsxOpeningElement(t.jsxIdentifier(importName), [], true),
|
|
196
|
-
null,
|
|
197
|
-
[],
|
|
198
|
-
true,
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
expression.elements.push(
|
|
202
|
-
t.objectExpression([
|
|
203
|
-
t.objectProperty(
|
|
204
|
-
t.identifier('name'),
|
|
205
|
-
t.stringLiteral(displayName),
|
|
206
|
-
),
|
|
207
|
-
t.objectProperty(t.identifier('render'), renderValue),
|
|
208
|
-
]),
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
didTransform = true
|
|
172
|
+
if (!matches) return
|
|
173
|
+
|
|
174
|
+
// Find the plugins prop
|
|
175
|
+
const pluginsProp = node.attributes.find(
|
|
176
|
+
(attr) =>
|
|
177
|
+
attr.type === 'JSXAttribute' &&
|
|
178
|
+
attr.name.type === 'JSXIdentifier' &&
|
|
179
|
+
attr.name.name === 'plugins',
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
if (pluginsProp && pluginsProp.type === 'JSXAttribute') {
|
|
183
|
+
if (
|
|
184
|
+
pluginsProp.value &&
|
|
185
|
+
pluginsProp.value.type === 'JSXExpressionContainer'
|
|
186
|
+
) {
|
|
187
|
+
const expression = pluginsProp.value.expression
|
|
188
|
+
if (expression.type === 'ArrayExpression') {
|
|
189
|
+
if (
|
|
190
|
+
!pluginExists(
|
|
191
|
+
code,
|
|
192
|
+
expression,
|
|
193
|
+
importName,
|
|
194
|
+
displayName,
|
|
195
|
+
pluginType,
|
|
196
|
+
)
|
|
197
|
+
) {
|
|
198
|
+
const pluginStr = buildPluginString(
|
|
199
|
+
importName,
|
|
200
|
+
displayName,
|
|
201
|
+
pluginType,
|
|
202
|
+
)
|
|
203
|
+
// Insert before closing ']'
|
|
204
|
+
const arrayEnd = expression.end - 1
|
|
205
|
+
let prefix = ''
|
|
206
|
+
if (expression.elements.length > 0) {
|
|
207
|
+
const arrayContent = code.slice(expression.start + 1, arrayEnd)
|
|
208
|
+
prefix = arrayContent.trimEnd().endsWith(',') ? ' ' : ', '
|
|
213
209
|
}
|
|
210
|
+
s.appendLeft(arrayEnd, prefix + pluginStr)
|
|
214
211
|
}
|
|
215
212
|
}
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
// No plugins prop — create one
|
|
216
|
+
const pluginStr = buildPluginString(importName, displayName, pluginType)
|
|
217
|
+
const attrStr = ` plugins={[${pluginStr}]}`
|
|
218
|
+
if (node.selfClosing) {
|
|
219
|
+
s.appendLeft(node.end - 2, attrStr)
|
|
216
220
|
} else {
|
|
217
|
-
|
|
218
|
-
// For function-based plugins, add them directly as function calls
|
|
219
|
-
// For JSX plugins, wrap them in objects with name and render
|
|
220
|
-
let pluginElement
|
|
221
|
-
if (pluginType === 'function') {
|
|
222
|
-
// Add directly: plugins={[FormDevtoolsPlugin()]}
|
|
223
|
-
pluginElement = t.callExpression(t.identifier(importName), [])
|
|
224
|
-
} else {
|
|
225
|
-
// Add as object: plugins={[{ name: "...", render: <Component /> }]}
|
|
226
|
-
const renderValue = t.jsxElement(
|
|
227
|
-
t.jsxOpeningElement(t.jsxIdentifier(importName), [], true),
|
|
228
|
-
null,
|
|
229
|
-
[],
|
|
230
|
-
true,
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
pluginElement = t.objectExpression([
|
|
234
|
-
t.objectProperty(
|
|
235
|
-
t.identifier('name'),
|
|
236
|
-
t.stringLiteral(displayName),
|
|
237
|
-
),
|
|
238
|
-
t.objectProperty(t.identifier('render'), renderValue),
|
|
239
|
-
])
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
path.node.attributes.push(
|
|
243
|
-
t.jsxAttribute(
|
|
244
|
-
t.jsxIdentifier('plugins'),
|
|
245
|
-
t.jsxExpressionContainer(t.arrayExpression([pluginElement])),
|
|
246
|
-
),
|
|
247
|
-
)
|
|
248
|
-
|
|
249
|
-
didTransform = true
|
|
221
|
+
s.appendLeft(node.end - 1, attrStr)
|
|
250
222
|
}
|
|
251
223
|
}
|
|
252
|
-
},
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
// Add import at the top of the file if transform happened
|
|
256
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
257
|
-
if (didTransform) {
|
|
258
|
-
const importDeclaration = t.importDeclaration(
|
|
259
|
-
[t.importSpecifier(t.identifier(importName), t.identifier(importName))],
|
|
260
|
-
t.stringLiteral(injection.packageName),
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
// Find the last import declaration
|
|
264
|
-
let lastImportIndex = -1
|
|
265
|
-
ast.program.body.forEach((node, index) => {
|
|
266
|
-
if (t.isImportDeclaration(node)) {
|
|
267
|
-
lastImportIndex = index
|
|
268
|
-
}
|
|
269
224
|
})
|
|
270
225
|
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
226
|
+
// Add import at the top of the file if transform happened
|
|
227
|
+
if (s.hasChanged()) {
|
|
228
|
+
const state = { lastImportEnd: 0, alreadyImported: false }
|
|
229
|
+
walk(result.program, (n) => {
|
|
230
|
+
if (n.type !== 'ImportDeclaration') return
|
|
231
|
+
if (n.end > state.lastImportEnd) state.lastImportEnd = n.end
|
|
232
|
+
if (n.source.value !== injection.packageName) return
|
|
233
|
+
for (const spec of n.specifiers) {
|
|
234
|
+
if (
|
|
235
|
+
spec.type === 'ImportSpecifier' &&
|
|
236
|
+
spec.imported.type === 'Identifier' &&
|
|
237
|
+
spec.imported.name === importName
|
|
238
|
+
) {
|
|
239
|
+
state.alreadyImported = true
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
if (!state.alreadyImported) {
|
|
244
|
+
const importStr = `\nimport { ${importName} } from ${JSON.stringify(injection.packageName)};`
|
|
245
|
+
s.appendRight(state.lastImportEnd, importStr)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
274
248
|
|
|
275
|
-
|
|
249
|
+
return { code: s.toString(), transformed: s.hasChanged() }
|
|
250
|
+
} catch (e) {
|
|
251
|
+
return null
|
|
252
|
+
}
|
|
276
253
|
}
|
|
277
254
|
|
|
278
255
|
/**
|
|
@@ -291,17 +268,9 @@ export function injectPluginIntoFile(
|
|
|
291
268
|
injection: PluginInjection,
|
|
292
269
|
): { success: boolean; error?: string } {
|
|
293
270
|
try {
|
|
294
|
-
// Read the file
|
|
295
271
|
const code = readFileSync(filePath, 'utf-8')
|
|
296
272
|
|
|
297
|
-
|
|
298
|
-
const ast = parse(code, {
|
|
299
|
-
sourceType: 'module',
|
|
300
|
-
plugins: ['jsx', 'typescript'],
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
// Find the devtools component name (handles renamed imports)
|
|
304
|
-
const devtoolsComponentName = findDevtoolsComponentName(ast)
|
|
273
|
+
const devtoolsComponentName = findDevtoolsComponentName(code)
|
|
305
274
|
if (!devtoolsComponentName) {
|
|
306
275
|
return {
|
|
307
276
|
success: false,
|
|
@@ -309,27 +278,15 @@ export function injectPluginIntoFile(
|
|
|
309
278
|
}
|
|
310
279
|
}
|
|
311
280
|
|
|
312
|
-
|
|
313
|
-
const didTransform = transformAndInject(
|
|
314
|
-
ast,
|
|
315
|
-
injection,
|
|
316
|
-
devtoolsComponentName,
|
|
317
|
-
)
|
|
281
|
+
const result = transformAndInject(code, injection, devtoolsComponentName)
|
|
318
282
|
|
|
319
|
-
if (!
|
|
283
|
+
if (!result?.transformed) {
|
|
320
284
|
return {
|
|
321
285
|
success: false,
|
|
322
286
|
error: 'Plugin already exists or no TanStackDevtools component found',
|
|
323
287
|
}
|
|
324
288
|
}
|
|
325
289
|
|
|
326
|
-
// Generate the new code
|
|
327
|
-
const result = gen(ast, {
|
|
328
|
-
sourceMaps: false,
|
|
329
|
-
retainLines: false,
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
// Write back to file
|
|
333
290
|
writeFileSync(filePath, result.code, 'utf-8')
|
|
334
291
|
|
|
335
292
|
return { success: true }
|