@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
|
@@ -1,228 +1,179 @@
|
|
|
1
|
+
import { walk } from "./ast-utils.js";
|
|
2
|
+
import { isTanStackDevtoolsImport } from "./devtools-packages.js";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
import { parseSync } from "oxc-parser";
|
|
1
5
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (devtoolsPackages.includes(importSource)) {
|
|
23
|
-
hasDevtoolsImport = true;
|
|
24
|
-
path.stop();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return hasDevtoolsImport;
|
|
29
|
-
} catch (e) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
6
|
+
//#region src/inject-plugin.ts
|
|
7
|
+
/**
|
|
8
|
+
* Detects if a file imports TanStack devtools packages
|
|
9
|
+
*/
|
|
10
|
+
var detectDevtoolsImport = (code) => {
|
|
11
|
+
try {
|
|
12
|
+
const result = parseSync("input.tsx", code, {
|
|
13
|
+
sourceType: "module",
|
|
14
|
+
lang: "tsx"
|
|
15
|
+
});
|
|
16
|
+
if (result.errors.length > 0) return false;
|
|
17
|
+
let hasDevtoolsImport = false;
|
|
18
|
+
walk(result.program, (node) => {
|
|
19
|
+
if (hasDevtoolsImport) return;
|
|
20
|
+
if (node.type === "ImportDeclaration" && isTanStackDevtoolsImport(node.source.value)) hasDevtoolsImport = true;
|
|
21
|
+
});
|
|
22
|
+
return hasDevtoolsImport;
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
32
26
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
return componentName;
|
|
27
|
+
/**
|
|
28
|
+
* Finds the TanStackDevtools component name in the file
|
|
29
|
+
* Handles renamed imports and namespace imports
|
|
30
|
+
*/
|
|
31
|
+
var findDevtoolsComponentName = (code) => {
|
|
32
|
+
try {
|
|
33
|
+
const result = parseSync("input.tsx", code, {
|
|
34
|
+
sourceType: "module",
|
|
35
|
+
lang: "tsx"
|
|
36
|
+
});
|
|
37
|
+
if (result.errors.length > 0) return null;
|
|
38
|
+
let componentName = null;
|
|
39
|
+
walk(result.program, (node) => {
|
|
40
|
+
if (componentName) return;
|
|
41
|
+
if (node.type !== "ImportDeclaration") return;
|
|
42
|
+
if (!isTanStackDevtoolsImport(node.source.value)) return;
|
|
43
|
+
for (const spec of node.specifiers) {
|
|
44
|
+
if (spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && spec.imported.name === "TanStackDevtools") {
|
|
45
|
+
componentName = spec.local.name;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (spec.type === "ImportNamespaceSpecifier") {
|
|
49
|
+
componentName = `${spec.local.name}.TanStackDevtools`;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return componentName;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
66
58
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
),
|
|
151
|
-
t.objectProperty(t.identifier("render"), renderValue)
|
|
152
|
-
]);
|
|
153
|
-
}
|
|
154
|
-
path.node.attributes.push(
|
|
155
|
-
t.jsxAttribute(
|
|
156
|
-
t.jsxIdentifier("plugins"),
|
|
157
|
-
t.jsxExpressionContainer(t.arrayExpression([pluginElement]))
|
|
158
|
-
)
|
|
159
|
-
);
|
|
160
|
-
didTransform = true;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
if (didTransform) {
|
|
166
|
-
const importDeclaration = t.importDeclaration(
|
|
167
|
-
[t.importSpecifier(t.identifier(importName), t.identifier(importName))],
|
|
168
|
-
t.stringLiteral(injection.packageName)
|
|
169
|
-
);
|
|
170
|
-
let lastImportIndex = -1;
|
|
171
|
-
ast.program.body.forEach((node, index) => {
|
|
172
|
-
if (t.isImportDeclaration(node)) {
|
|
173
|
-
lastImportIndex = index;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
ast.program.body.splice(lastImportIndex + 1, 0, importDeclaration);
|
|
177
|
-
}
|
|
178
|
-
return didTransform;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a plugin already exists in the array expression
|
|
61
|
+
*/
|
|
62
|
+
function pluginExists(code, node, importName, displayName, pluginType) {
|
|
63
|
+
if (node.type !== "ArrayExpression") return false;
|
|
64
|
+
for (const element of node.elements) {
|
|
65
|
+
if (!element) continue;
|
|
66
|
+
if (pluginType === "function") {
|
|
67
|
+
if (element.type === "CallExpression" && element.callee.type === "Identifier" && element.callee.name === importName) return true;
|
|
68
|
+
} else {
|
|
69
|
+
if (element.type !== "ObjectExpression") continue;
|
|
70
|
+
for (const prop of element.properties) if (prop.type === "Property" && prop.key.type === "Identifier" && prop.key.name === "name" && prop.value.type === "Literal" && code.slice(prop.value.start + 1, prop.value.end - 1) === displayName) return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
function buildPluginString(importName, displayName, pluginType) {
|
|
76
|
+
if (pluginType === "function") return `${importName}()`;
|
|
77
|
+
return `{ name: ${JSON.stringify(displayName)}, render: <${importName} /> }`;
|
|
78
|
+
}
|
|
79
|
+
var transformAndInject = (code, injection, devtoolsComponentName) => {
|
|
80
|
+
const importName = injection.pluginImport?.importName;
|
|
81
|
+
const pluginType = injection.pluginImport?.type || "jsx";
|
|
82
|
+
const displayName = injection.pluginName;
|
|
83
|
+
if (!importName) return null;
|
|
84
|
+
try {
|
|
85
|
+
const result = parseSync("input.tsx", code, {
|
|
86
|
+
sourceType: "module",
|
|
87
|
+
lang: "tsx"
|
|
88
|
+
});
|
|
89
|
+
if (result.errors.length > 0) return null;
|
|
90
|
+
const s = new MagicString(code);
|
|
91
|
+
const isNamespaceImport = devtoolsComponentName.includes(".");
|
|
92
|
+
walk(result.program, (node) => {
|
|
93
|
+
if (node.type !== "JSXOpeningElement") return;
|
|
94
|
+
let matches = false;
|
|
95
|
+
if (isNamespaceImport) {
|
|
96
|
+
if (node.name.type === "JSXMemberExpression") matches = `${node.name.object.type === "JSXIdentifier" ? node.name.object.name : ""}.${node.name.property.name}` === devtoolsComponentName;
|
|
97
|
+
} else matches = node.name.type === "JSXIdentifier" && node.name.name === devtoolsComponentName;
|
|
98
|
+
if (!matches) return;
|
|
99
|
+
const pluginsProp = node.attributes.find((attr) => attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "plugins");
|
|
100
|
+
if (pluginsProp && pluginsProp.type === "JSXAttribute") {
|
|
101
|
+
if (pluginsProp.value && pluginsProp.value.type === "JSXExpressionContainer") {
|
|
102
|
+
const expression = pluginsProp.value.expression;
|
|
103
|
+
if (expression.type === "ArrayExpression") {
|
|
104
|
+
if (!pluginExists(code, expression, importName, displayName, pluginType)) {
|
|
105
|
+
const pluginStr = buildPluginString(importName, displayName, pluginType);
|
|
106
|
+
const arrayEnd = expression.end - 1;
|
|
107
|
+
let prefix = "";
|
|
108
|
+
if (expression.elements.length > 0) prefix = code.slice(expression.start + 1, arrayEnd).trimEnd().endsWith(",") ? " " : ", ";
|
|
109
|
+
s.appendLeft(arrayEnd, prefix + pluginStr);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
const attrStr = ` plugins={[${buildPluginString(importName, displayName, pluginType)}]}`;
|
|
115
|
+
if (node.selfClosing) s.appendLeft(node.end - 2, attrStr);
|
|
116
|
+
else s.appendLeft(node.end - 1, attrStr);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
if (s.hasChanged()) {
|
|
120
|
+
const state = {
|
|
121
|
+
lastImportEnd: 0,
|
|
122
|
+
alreadyImported: false
|
|
123
|
+
};
|
|
124
|
+
walk(result.program, (n) => {
|
|
125
|
+
if (n.type !== "ImportDeclaration") return;
|
|
126
|
+
if (n.end > state.lastImportEnd) state.lastImportEnd = n.end;
|
|
127
|
+
if (n.source.value !== injection.packageName) return;
|
|
128
|
+
for (const spec of n.specifiers) if (spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && spec.imported.name === importName) state.alreadyImported = true;
|
|
129
|
+
});
|
|
130
|
+
if (!state.alreadyImported) {
|
|
131
|
+
const importStr = `\nimport { ${importName} } from ${JSON.stringify(injection.packageName)};`;
|
|
132
|
+
s.appendRight(state.lastImportEnd, importStr);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
code: s.toString(),
|
|
137
|
+
transformed: s.hasChanged()
|
|
138
|
+
};
|
|
139
|
+
} catch (e) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
179
142
|
};
|
|
143
|
+
/**
|
|
144
|
+
* Detects if a file contains TanStack devtools import
|
|
145
|
+
*/
|
|
180
146
|
function detectDevtoolsFile(code) {
|
|
181
|
-
|
|
147
|
+
return detectDevtoolsImport(code);
|
|
182
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Injects a plugin into the TanStackDevtools component in a file
|
|
151
|
+
* Reads the file, transforms it, and writes it back
|
|
152
|
+
*/
|
|
183
153
|
function injectPluginIntoFile(filePath, injection) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
error: "Plugin already exists or no TanStackDevtools component found"
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
const result = gen(ast, {
|
|
209
|
-
sourceMaps: false,
|
|
210
|
-
retainLines: false
|
|
211
|
-
});
|
|
212
|
-
writeFileSync(filePath, result.code, "utf-8");
|
|
213
|
-
return { success: true };
|
|
214
|
-
} catch (e) {
|
|
215
|
-
console.error("Error injecting plugin:", e);
|
|
216
|
-
return {
|
|
217
|
-
success: false,
|
|
218
|
-
error: e instanceof Error ? e.message : "Unknown error"
|
|
219
|
-
};
|
|
220
|
-
}
|
|
154
|
+
try {
|
|
155
|
+
const code = readFileSync(filePath, "utf-8");
|
|
156
|
+
const devtoolsComponentName = findDevtoolsComponentName(code);
|
|
157
|
+
if (!devtoolsComponentName) return {
|
|
158
|
+
success: false,
|
|
159
|
+
error: "Could not find TanStackDevtools import"
|
|
160
|
+
};
|
|
161
|
+
const result = transformAndInject(code, injection, devtoolsComponentName);
|
|
162
|
+
if (!result?.transformed) return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: "Plugin already exists or no TanStackDevtools component found"
|
|
165
|
+
};
|
|
166
|
+
writeFileSync(filePath, result.code, "utf-8");
|
|
167
|
+
return { success: true };
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.error("Error injecting plugin:", e);
|
|
170
|
+
return {
|
|
171
|
+
success: false,
|
|
172
|
+
error: e instanceof Error ? e.message : "Unknown error"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
221
175
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
transformAndInject
|
|
227
|
-
};
|
|
228
|
-
//# sourceMappingURL=inject-plugin.js.map
|
|
176
|
+
//#endregion
|
|
177
|
+
export { detectDevtoolsFile, injectPluginIntoFile };
|
|
178
|
+
|
|
179
|
+
//# sourceMappingURL=inject-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-plugin.js","sources":["../../src/inject-plugin.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs'\nimport { gen, parse, t, trav } from './babel'\nimport type { PluginInjection } from '@tanstack/devtools-client'\nimport type { types as Babel } from '@babel/core'\nimport type { ParseResult } from '@babel/parser'\n\n/**\n * Detects if a file imports TanStack devtools packages\n * Handles: import X from '@tanstack/react-devtools'\n * import * as X from '@tanstack/react-devtools'\n * import { TanStackDevtools } from '@tanstack/react-devtools'\n */\nconst detectDevtoolsImport = (code: string): boolean => {\n const devtoolsPackages = [\n '@tanstack/react-devtools',\n '@tanstack/solid-devtools',\n '@tanstack/vue-devtools',\n '@tanstack/svelte-devtools',\n '@tanstack/angular-devtools',\n ]\n\n try {\n const ast = parse(code, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n })\n\n let hasDevtoolsImport = false\n\n trav(ast, {\n ImportDeclaration(path) {\n const importSource = path.node.source.value\n if (devtoolsPackages.includes(importSource)) {\n hasDevtoolsImport = true\n path.stop()\n }\n },\n })\n\n return hasDevtoolsImport\n } catch (e) {\n return false\n }\n}\n\n/**\n * Finds the TanStackDevtools component name in the file\n * Handles renamed imports and namespace imports\n */\nexport const findDevtoolsComponentName = (\n ast: ParseResult<Babel.File>,\n): string | null => {\n let componentName: string | null = null\n const devtoolsPackages = [\n '@tanstack/react-devtools',\n '@tanstack/solid-devtools',\n '@tanstack/vue-devtools',\n '@tanstack/svelte-devtools',\n '@tanstack/angular-devtools',\n ]\n\n trav(ast, {\n ImportDeclaration(path) {\n const importSource = path.node.source.value\n if (devtoolsPackages.includes(importSource)) {\n // Check for: import { TanStackDevtools } from '@tanstack/...'\n const namedImport = path.node.specifiers.find(\n (spec) =>\n t.isImportSpecifier(spec) &&\n t.isIdentifier(spec.imported) &&\n spec.imported.name === 'TanStackDevtools',\n )\n if (namedImport && t.isImportSpecifier(namedImport)) {\n componentName = namedImport.local.name\n path.stop()\n return\n }\n\n // Check for: import * as DevtoolsName from '@tanstack/...'\n const namespaceImport = path.node.specifiers.find((spec) =>\n t.isImportNamespaceSpecifier(spec),\n )\n if (namespaceImport && t.isImportNamespaceSpecifier(namespaceImport)) {\n // For namespace imports, we need to look for DevtoolsName.TanStackDevtools\n componentName = `${namespaceImport.local.name}.TanStackDevtools`\n path.stop()\n return\n }\n }\n },\n })\n\n return componentName\n}\n\nexport const transformAndInject = (\n ast: ParseResult<Babel.File>,\n injection: PluginInjection,\n devtoolsComponentName: string,\n) => {\n let didTransform = false\n\n // Use pluginImport if provided, otherwise generate from package name\n const importName = injection.pluginImport?.importName\n const pluginType = injection.pluginImport?.type || 'jsx'\n const displayName = injection.pluginName\n\n if (!importName) {\n return false\n }\n // Handle namespace imports like DevtoolsModule.TanStackDevtools\n const isNamespaceImport = devtoolsComponentName.includes('.')\n\n // Find and modify the TanStackDevtools JSX element\n trav(ast, {\n JSXOpeningElement(path) {\n const elementName = path.node.name\n let matches = false\n\n if (isNamespaceImport) {\n // Handle <DevtoolsModule.TanStackDevtools />\n if (t.isJSXMemberExpression(elementName)) {\n const fullName = `${t.isJSXIdentifier(elementName.object) ? elementName.object.name : ''}.${t.isJSXIdentifier(elementName.property) ? elementName.property.name : ''}`\n matches = fullName === devtoolsComponentName\n }\n } else {\n // Handle <TanStackDevtools /> or <RenamedDevtools />\n matches =\n t.isJSXIdentifier(elementName) &&\n elementName.name === devtoolsComponentName\n }\n\n if (matches) {\n // Find the plugins prop\n const pluginsProp = path.node.attributes.find(\n (attr) =>\n t.isJSXAttribute(attr) &&\n t.isJSXIdentifier(attr.name) &&\n attr.name.name === 'plugins',\n )\n // plugins found\n if (pluginsProp && t.isJSXAttribute(pluginsProp)) {\n // Check if plugins prop has a value\n if (\n pluginsProp.value &&\n t.isJSXExpressionContainer(pluginsProp.value)\n ) {\n const expression = pluginsProp.value.expression\n\n // If it's an array expression, add our plugin to it\n if (t.isArrayExpression(expression)) {\n // Check if plugin already exists\n const pluginExists = expression.elements.some((element) => {\n if (!element) return false\n\n // For function-based plugins, check if the function call exists\n if (pluginType === 'function') {\n return (\n t.isCallExpression(element) &&\n t.isIdentifier(element.callee) &&\n element.callee.name === importName\n )\n }\n\n // For JSX plugins, check object with name property\n if (!t.isObjectExpression(element)) return false\n\n return element.properties.some((prop) => {\n if (\n !t.isObjectProperty(prop) ||\n !t.isIdentifier(prop.key) ||\n prop.key.name !== 'name'\n ) {\n return false\n }\n\n return (\n t.isStringLiteral(prop.value) &&\n prop.value.value === displayName\n )\n })\n })\n\n if (!pluginExists) {\n // For function-based plugins, add them directly as function calls\n // For JSX plugins, wrap them in objects with name and render\n if (pluginType === 'function') {\n // Add directly: FormDevtoolsPlugin()\n expression.elements.push(\n t.callExpression(t.identifier(importName), []),\n )\n } else {\n // Add as object: { name: \"...\", render: <Component /> }\n const renderValue = t.jsxElement(\n t.jsxOpeningElement(t.jsxIdentifier(importName), [], true),\n null,\n [],\n true,\n )\n\n expression.elements.push(\n t.objectExpression([\n t.objectProperty(\n t.identifier('name'),\n t.stringLiteral(displayName),\n ),\n t.objectProperty(t.identifier('render'), renderValue),\n ]),\n )\n }\n\n didTransform = true\n }\n }\n }\n } else {\n // No plugins prop exists, create one with our plugin\n // For function-based plugins, add them directly as function calls\n // For JSX plugins, wrap them in objects with name and render\n let pluginElement\n if (pluginType === 'function') {\n // Add directly: plugins={[FormDevtoolsPlugin()]}\n pluginElement = t.callExpression(t.identifier(importName), [])\n } else {\n // Add as object: plugins={[{ name: \"...\", render: <Component /> }]}\n const renderValue = t.jsxElement(\n t.jsxOpeningElement(t.jsxIdentifier(importName), [], true),\n null,\n [],\n true,\n )\n\n pluginElement = t.objectExpression([\n t.objectProperty(\n t.identifier('name'),\n t.stringLiteral(displayName),\n ),\n t.objectProperty(t.identifier('render'), renderValue),\n ])\n }\n\n path.node.attributes.push(\n t.jsxAttribute(\n t.jsxIdentifier('plugins'),\n t.jsxExpressionContainer(t.arrayExpression([pluginElement])),\n ),\n )\n\n didTransform = true\n }\n }\n },\n })\n\n // Add import at the top of the file if transform happened\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (didTransform) {\n const importDeclaration = t.importDeclaration(\n [t.importSpecifier(t.identifier(importName), t.identifier(importName))],\n t.stringLiteral(injection.packageName),\n )\n\n // Find the last import declaration\n let lastImportIndex = -1\n ast.program.body.forEach((node, index) => {\n if (t.isImportDeclaration(node)) {\n lastImportIndex = index\n }\n })\n\n // Insert after the last import or at the beginning\n ast.program.body.splice(lastImportIndex + 1, 0, importDeclaration)\n }\n\n return didTransform\n}\n\n/**\n * Detects if a file contains TanStack devtools import\n */\nexport function detectDevtoolsFile(code: string): boolean {\n return detectDevtoolsImport(code)\n}\n\n/**\n * Injects a plugin into the TanStackDevtools component in a file\n * Reads the file, transforms it, and writes it back\n */\nexport function injectPluginIntoFile(\n filePath: string,\n injection: PluginInjection,\n): { success: boolean; error?: string } {\n try {\n // Read the file\n const code = readFileSync(filePath, 'utf-8')\n\n // Parse the code\n const ast = parse(code, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n })\n\n // Find the devtools component name (handles renamed imports)\n const devtoolsComponentName = findDevtoolsComponentName(ast)\n if (!devtoolsComponentName) {\n return {\n success: false,\n error: 'Could not find TanStackDevtools import',\n }\n }\n\n // Transform and inject\n const didTransform = transformAndInject(\n ast,\n injection,\n devtoolsComponentName,\n )\n\n if (!didTransform) {\n return {\n success: false,\n error: 'Plugin already exists or no TanStackDevtools component found',\n }\n }\n\n // Generate the new code\n const result = gen(ast, {\n sourceMaps: false,\n retainLines: false,\n })\n\n // Write back to file\n writeFileSync(filePath, result.code, 'utf-8')\n\n return { success: true }\n } catch (e) {\n console.error('Error injecting plugin:', e)\n return {\n success: false,\n error: e instanceof Error ? e.message : 'Unknown error',\n }\n }\n}\n"],"names":[],"mappings":";;;;AAYA,MAAM,uBAAuB,CAAC,SAA0B;AACtD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,MAAI;AACF,UAAM,MAAM,MAAM,MAAM;AAAA,MACtB,YAAY;AAAA,MACZ,SAAS,CAAC,OAAO,YAAY;AAAA,IAAA,CAC9B;AAED,QAAI,oBAAoB;AAExB,SAAK,KAAK;AAAA,MACR,kBAAkB,MAAM;AACtB,cAAM,eAAe,KAAK,KAAK,OAAO;AACtC,YAAI,iBAAiB,SAAS,YAAY,GAAG;AAC3C,8BAAoB;AACpB,eAAK,KAAA;AAAA,QACP;AAAA,MACF;AAAA,IAAA,CACD;AAED,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAMO,MAAM,4BAA4B,CACvC,QACkB;AAClB,MAAI,gBAA+B;AACnC,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,OAAK,KAAK;AAAA,IACR,kBAAkB,MAAM;AACtB,YAAM,eAAe,KAAK,KAAK,OAAO;AACtC,UAAI,iBAAiB,SAAS,YAAY,GAAG;AAE3C,cAAM,cAAc,KAAK,KAAK,WAAW;AAAA,UACvC,CAAC,SACC,EAAE,kBAAkB,IAAI,KACxB,EAAE,aAAa,KAAK,QAAQ,KAC5B,KAAK,SAAS,SAAS;AAAA,QAAA;AAE3B,YAAI,eAAe,EAAE,kBAAkB,WAAW,GAAG;AACnD,0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;AAEF,UAAM,OAAO,aAAa,UAAU,OAAO;AAG3C,UAAM,MAAM,MAAM,MAAM;AAAA,MACtB,YAAY;AAAA,MACZ,SAAS,CAAC,OAAO,YAAY;AAAA,IAAA,CAC9B;AAGD,UAAM,wBAAwB,0BAA0B,GAAG;AAC3D,QAAI,CAAC,uBAAuB;AAC1B,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO;AAAA,MAAA;AAAA,IAEX;AAGA,UAAM,eAAe;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAGF,QAAI,CAAC,cAAc;AACjB,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO;AAAA,MAAA;AAAA,IAEX;AAGA,UAAM,SAAS,IAAI,KAAK;AAAA,MACtB,YAAY;AAAA,MACZ,aAAa;AAAA,IAAA,CACd;AAGD,kBAAc,UAAU,OAAO,MAAM,OAAO;AAE5C,WAAO,EAAE,SAAS,KAAA;AAAA,EACpB,SAAS,GAAG;AACV,YAAQ,MAAM,2BAA2B,CAAC;AAC1C,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO,aAAa,QAAQ,EAAE,UAAU;AAAA,IAAA;AAAA,EAE5C;AACF;"}
|
|
1
|
+
{"version":3,"file":"inject-plugin.js","names":[],"sources":["../../src/inject-plugin.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs'\nimport MagicString from 'magic-string'\nimport { parseSync } from 'oxc-parser'\nimport { walk } from './ast-utils'\nimport { isTanStackDevtoolsImport } from './devtools-packages'\nimport type { Node } from 'oxc-parser'\nimport type { PluginInjection } from '@tanstack/devtools-client'\n\n/**\n * Detects if a file imports TanStack devtools packages\n */\nconst detectDevtoolsImport = (code: string): boolean => {\n try {\n const result = parseSync('input.tsx', code, {\n sourceType: 'module',\n lang: 'tsx',\n })\n if (result.errors.length > 0) return false\n\n let hasDevtoolsImport = false\n\n walk(result.program, (node) => {\n if (hasDevtoolsImport) return\n if (\n node.type === 'ImportDeclaration' &&\n isTanStackDevtoolsImport(node.source.value)\n ) {\n hasDevtoolsImport = true\n }\n })\n\n return hasDevtoolsImport\n } catch (e) {\n return false\n }\n}\n\n/**\n * Finds the TanStackDevtools component name in the file\n * Handles renamed imports and namespace imports\n */\nexport const findDevtoolsComponentName = (code: string): string | null => {\n try {\n const result = parseSync('input.tsx', code, {\n sourceType: 'module',\n lang: 'tsx',\n })\n if (result.errors.length > 0) return null\n\n let componentName: string | null = null\n\n walk(result.program, (node) => {\n if (componentName) return\n if (node.type !== 'ImportDeclaration') return\n if (!isTanStackDevtoolsImport(node.source.value)) return\n\n for (const spec of node.specifiers) {\n // import { TanStackDevtools } or import { TanStackDevtools as X }\n if (\n spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'TanStackDevtools'\n ) {\n componentName = spec.local.name\n return\n }\n // import * as X from '...'\n if (spec.type === 'ImportNamespaceSpecifier') {\n componentName = `${spec.local.name}.TanStackDevtools`\n return\n }\n }\n })\n\n return componentName\n } catch (e) {\n return null\n }\n}\n\n/**\n * Check if a plugin already exists in the array expression\n */\nfunction pluginExists(\n code: string,\n node: Node,\n importName: string,\n displayName: string,\n pluginType: string,\n): boolean {\n if (node.type !== 'ArrayExpression') return false\n\n for (const element of node.elements) {\n if (!element) continue\n\n if (pluginType === 'function') {\n if (\n element.type === 'CallExpression' &&\n element.callee.type === 'Identifier' &&\n element.callee.name === importName\n ) {\n return true\n }\n } else {\n if (element.type !== 'ObjectExpression') continue\n for (const prop of element.properties) {\n if (\n prop.type === 'Property' &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'name' &&\n prop.value.type === 'Literal' &&\n code.slice(prop.value.start + 1, prop.value.end - 1) === displayName\n ) {\n return true\n }\n }\n }\n }\n\n return false\n}\n\nfunction buildPluginString(\n importName: string,\n displayName: string,\n pluginType: string,\n): string {\n if (pluginType === 'function') {\n return `${importName}()`\n }\n return `{ name: ${JSON.stringify(displayName)}, render: <${importName} /> }`\n}\n\nexport const transformAndInject = (\n code: string,\n injection: PluginInjection,\n devtoolsComponentName: string,\n): { code: string; transformed: boolean } | null => {\n const importName = injection.pluginImport?.importName\n const pluginType = injection.pluginImport?.type || 'jsx'\n const displayName = injection.pluginName\n\n if (!importName) {\n return null\n }\n\n try {\n const result = parseSync('input.tsx', code, {\n sourceType: 'module',\n lang: 'tsx',\n })\n if (result.errors.length > 0) return null\n\n const s = new MagicString(code)\n const isNamespaceImport = devtoolsComponentName.includes('.')\n\n walk(result.program, (node) => {\n if (node.type !== 'JSXOpeningElement') return\n\n let matches = false\n if (isNamespaceImport) {\n if (node.name.type === 'JSXMemberExpression') {\n const fullName = `${node.name.object.type === 'JSXIdentifier' ? node.name.object.name : ''}.${node.name.property.name}`\n matches = fullName === devtoolsComponentName\n }\n } else {\n matches =\n node.name.type === 'JSXIdentifier' &&\n node.name.name === devtoolsComponentName\n }\n\n if (!matches) return\n\n // Find the plugins prop\n const pluginsProp = node.attributes.find(\n (attr) =>\n attr.type === 'JSXAttribute' &&\n attr.name.type === 'JSXIdentifier' &&\n attr.name.name === 'plugins',\n )\n\n if (pluginsProp && pluginsProp.type === 'JSXAttribute') {\n if (\n pluginsProp.value &&\n pluginsProp.value.type === 'JSXExpressionContainer'\n ) {\n const expression = pluginsProp.value.expression\n if (expression.type === 'ArrayExpression') {\n if (\n !pluginExists(\n code,\n expression,\n importName,\n displayName,\n pluginType,\n )\n ) {\n const pluginStr = buildPluginString(\n importName,\n displayName,\n pluginType,\n )\n // Insert before closing ']'\n const arrayEnd = expression.end - 1\n let prefix = ''\n if (expression.elements.length > 0) {\n const arrayContent = code.slice(expression.start + 1, arrayEnd)\n prefix = arrayContent.trimEnd().endsWith(',') ? ' ' : ', '\n }\n s.appendLeft(arrayEnd, prefix + pluginStr)\n }\n }\n }\n } else {\n // No plugins prop — create one\n const pluginStr = buildPluginString(importName, displayName, pluginType)\n const attrStr = ` plugins={[${pluginStr}]}`\n if (node.selfClosing) {\n s.appendLeft(node.end - 2, attrStr)\n } else {\n s.appendLeft(node.end - 1, attrStr)\n }\n }\n })\n\n // Add import at the top of the file if transform happened\n if (s.hasChanged()) {\n const state = { lastImportEnd: 0, alreadyImported: false }\n walk(result.program, (n) => {\n if (n.type !== 'ImportDeclaration') return\n if (n.end > state.lastImportEnd) state.lastImportEnd = n.end\n if (n.source.value !== injection.packageName) return\n for (const spec of n.specifiers) {\n if (\n spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === importName\n ) {\n state.alreadyImported = true\n }\n }\n })\n if (!state.alreadyImported) {\n const importStr = `\\nimport { ${importName} } from ${JSON.stringify(injection.packageName)};`\n s.appendRight(state.lastImportEnd, importStr)\n }\n }\n\n return { code: s.toString(), transformed: s.hasChanged() }\n } catch (e) {\n return null\n }\n}\n\n/**\n * Detects if a file contains TanStack devtools import\n */\nexport function detectDevtoolsFile(code: string): boolean {\n return detectDevtoolsImport(code)\n}\n\n/**\n * Injects a plugin into the TanStackDevtools component in a file\n * Reads the file, transforms it, and writes it back\n */\nexport function injectPluginIntoFile(\n filePath: string,\n injection: PluginInjection,\n): { success: boolean; error?: string } {\n try {\n const code = readFileSync(filePath, 'utf-8')\n\n const devtoolsComponentName = findDevtoolsComponentName(code)\n if (!devtoolsComponentName) {\n return {\n success: false,\n error: 'Could not find TanStackDevtools import',\n }\n }\n\n const result = transformAndInject(code, injection, devtoolsComponentName)\n\n if (!result?.transformed) {\n return {\n success: false,\n error: 'Plugin already exists or no TanStackDevtools component found',\n }\n }\n\n writeFileSync(filePath, result.code, 'utf-8')\n\n return { success: true }\n } catch (e) {\n console.error('Error injecting plugin:', e)\n return {\n success: false,\n error: e instanceof Error ? e.message : 'Unknown error',\n }\n }\n}\n"],"mappings":";;;;;;;;;AAWA,IAAM,wBAAwB,SAA0B;CACtD,IAAI;EACF,MAAM,SAAS,UAAU,aAAa,MAAM;GAC1C,YAAY;GACZ,MAAM;GACP,CAAC;EACF,IAAI,OAAO,OAAO,SAAS,GAAG,O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EAEzE,IAAI,CAAC,QAAQ,aACX,OAAO;GACL,SAAS;GACT,OAAO;GACR;EAGH,cAAc,UAAU,OAAO,MAAM,QAAQ;EAE7C,OAAO,EAAE,SAAS,MAAM;UACjB,GAAG;EACV,QAAQ,MAAM,2BAA2B,EAAE;EAC3C,OAAO;GACL,SAAS;GACT,OAAO,aAAa,QAAQ,EAAE,UAAU;GACzC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare function addSourceToJsx(code: string, id: string, ignore?: {
|
|
2
2
|
files?: Array<string | RegExp>;
|
|
3
3
|
components?: Array<string | RegExp>;
|
|
4
|
-
}):
|
|
4
|
+
}): {
|
|
5
|
+
code: string;
|
|
6
|
+
map: import('magic-string').SourceMap;
|
|
7
|
+
} | undefined;
|