@tanstack/devtools-vite 0.6.1 → 0.7.1
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 +1 -1
- package/dist/esm/editor.js.map +1 -1
- package/dist/esm/enhance-logs.d.ts +4 -1
- package/dist/esm/enhance-logs.js +35 -36
- package/dist/esm/enhance-logs.js.map +1 -1
- package/dist/esm/inject-plugin.d.ts +5 -4
- package/dist/esm/inject-plugin.js +114 -103
- package/dist/esm/inject-plugin.js.map +1 -1
- package/dist/esm/inject-source.d.ts +4 -1
- package/dist/esm/inject-source.js +92 -93
- package/dist/esm/inject-source.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/plugin.js +23 -28
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/remove-devtools.d.ts +4 -1
- package/dist/esm/remove-devtools.js +79 -86
- package/dist/esm/remove-devtools.js.map +1 -1
- package/package.json +3 -9
- 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/editor.ts +1 -1
- 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 +26 -28
- package/src/remove-devtools.test.ts +76 -57
- package/src/remove-devtools.ts +160 -168
- package/dist/esm/babel.d.ts +0 -18
- package/dist/esm/babel.js +0 -11
- package/dist/esm/babel.js.map +0 -1
- package/src/babel.ts +0 -18
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node } from 'oxc-parser';
|
|
2
|
+
/**
|
|
3
|
+
* Iterate over the direct child nodes of an AST node.
|
|
4
|
+
* Uses a per-type cache of which keys hold child nodes to avoid
|
|
5
|
+
* allocating Object.entries() arrays on every call.
|
|
6
|
+
*/
|
|
7
|
+
export declare function forEachChild(node: Node, callback: (child: Node) => void): void;
|
|
8
|
+
/**
|
|
9
|
+
* Recursively walk AST nodes, calling `visitor` for each node with a `type`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function walk(node: Node, visitor: (node: Node) => void): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/ast-utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Cache of keys that hold child nodes (objects/arrays) per AST node type.
|
|
4
|
+
* Since oxc-parser produces AST via JSON.parse, every instance of a given
|
|
5
|
+
* node type has the same set of keys, so we only need to discover them once.
|
|
6
|
+
*/
|
|
7
|
+
var childKeysCache = /* @__PURE__ */ new Map();
|
|
8
|
+
function getChildKeys(node) {
|
|
9
|
+
let keys = childKeysCache.get(node.type);
|
|
10
|
+
if (keys) return keys;
|
|
11
|
+
keys = [];
|
|
12
|
+
for (const key in node) {
|
|
13
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
14
|
+
if (typeof node[key] === "object") keys.push(key);
|
|
15
|
+
}
|
|
16
|
+
childKeysCache.set(node.type, keys);
|
|
17
|
+
return keys;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Iterate over the direct child nodes of an AST node.
|
|
21
|
+
* Uses a per-type cache of which keys hold child nodes to avoid
|
|
22
|
+
* allocating Object.entries() arrays on every call.
|
|
23
|
+
*/
|
|
24
|
+
function forEachChild(node, callback) {
|
|
25
|
+
const keys = getChildKeys(node);
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
const value = node[key];
|
|
28
|
+
if (value === null) continue;
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
for (const item of value) if (typeof item === "object" && item !== null && "type" in item) callback(item);
|
|
31
|
+
} else if ("type" in value) callback(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Recursively walk AST nodes, calling `visitor` for each node with a `type`.
|
|
36
|
+
*/
|
|
37
|
+
function walk(node, visitor) {
|
|
38
|
+
visitor(node);
|
|
39
|
+
forEachChild(node, (child) => walk(child, visitor));
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { forEachChild, walk };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=ast-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-utils.js","names":[],"sources":["../../src/ast-utils.ts"],"sourcesContent":["import type { Node } from 'oxc-parser'\n\n/**\n * Cache of keys that hold child nodes (objects/arrays) per AST node type.\n * Since oxc-parser produces AST via JSON.parse, every instance of a given\n * node type has the same set of keys, so we only need to discover them once.\n */\nconst childKeysCache = new Map<string, Array<string>>()\n\nfunction getChildKeys(node: Node): Array<string> {\n let keys = childKeysCache.get(node.type)\n if (keys) return keys\n\n keys = []\n for (const key in node) {\n if (key === 'type' || key === 'start' || key === 'end') continue\n // typeof null === 'object', so nullable node fields get cached too\n if (typeof (node as any)[key] === 'object') {\n keys.push(key)\n }\n }\n childKeysCache.set(node.type, keys)\n return keys\n}\n\n/**\n * Iterate over the direct child nodes of an AST node.\n * Uses a per-type cache of which keys hold child nodes to avoid\n * allocating Object.entries() arrays on every call.\n */\nexport function forEachChild(node: Node, callback: (child: Node) => void) {\n const keys = getChildKeys(node)\n for (const key of keys) {\n const value = (node as any)[key]\n if (value === null) continue\n if (Array.isArray(value)) {\n for (const item of value) {\n if (typeof item === 'object' && item !== null && 'type' in item) {\n callback(item)\n }\n }\n } else if ('type' in value) {\n callback(value as Node)\n }\n }\n}\n\n/**\n * Recursively walk AST nodes, calling `visitor` for each node with a `type`.\n */\nexport function walk(node: Node, visitor: (node: Node) => void) {\n visitor(node)\n forEachChild(node, (child) => walk(child, visitor))\n}\n"],"mappings":";;;;;;AAOA,IAAM,iCAAiB,IAAI,KAA4B;AAEvD,SAAS,aAAa,MAA2B;CAC/C,IAAI,OAAO,eAAe,IAAI,KAAK,KAAK;CACxC,IAAI,MAAM,OAAO;CAEjB,OAAO,EAAE;CACT,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,QAAQ,UAAU,QAAQ,WAAW,QAAQ,OAAO;EAExD,IAAI,OAAQ,KAAa,SAAS,UAChC,KAAK,KAAK,IAAI;;CAGlB,eAAe,IAAI,KAAK,MAAM,KAAK;CACnC,OAAO;;;;;;;AAQT,SAAgB,aAAa,MAAY,UAAiC;CACxE,MAAM,OAAO,aAAa,KAAK;CAC/B,KAAK,MAAM,OAAO,MAAM;EACtB,MAAM,QAAS,KAAa;EAC5B,IAAI,UAAU,MAAM;EACpB,IAAI,MAAM,QAAQ,MAAM;QACjB,MAAM,QAAQ,OACjB,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,UAAU,MACzD,SAAS,KAAK;SAGb,IAAI,UAAU,OACnB,SAAS,MAAc;;;;;;AAQ7B,SAAgB,KAAK,MAAY,SAA+B;CAC9D,QAAQ,KAAK;CACb,aAAa,OAAO,UAAU,KAAK,OAAO,QAAQ,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const TANSTACK_DEVTOOLS_PACKAGES: readonly ["@tanstack/react-devtools", "@tanstack/preact-devtools", "@tanstack/solid-devtools", "@tanstack/vue-devtools", "@tanstack/svelte-devtools", "@tanstack/angular-devtools", "@tanstack/devtools"];
|
|
2
|
+
export declare const isTanStackDevtoolsImport: (source: string) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/devtools-packages.ts
|
|
2
|
+
var TANSTACK_DEVTOOLS_PACKAGES = [
|
|
3
|
+
"@tanstack/react-devtools",
|
|
4
|
+
"@tanstack/preact-devtools",
|
|
5
|
+
"@tanstack/solid-devtools",
|
|
6
|
+
"@tanstack/vue-devtools",
|
|
7
|
+
"@tanstack/svelte-devtools",
|
|
8
|
+
"@tanstack/angular-devtools",
|
|
9
|
+
"@tanstack/devtools"
|
|
10
|
+
];
|
|
11
|
+
var isTanStackDevtoolsImport = (source) => TANSTACK_DEVTOOLS_PACKAGES.includes(source);
|
|
12
|
+
//#endregion
|
|
13
|
+
export { TANSTACK_DEVTOOLS_PACKAGES, isTanStackDevtoolsImport };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=devtools-packages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools-packages.js","names":[],"sources":["../../src/devtools-packages.ts"],"sourcesContent":["export const TANSTACK_DEVTOOLS_PACKAGES = [\n '@tanstack/react-devtools',\n '@tanstack/preact-devtools',\n '@tanstack/solid-devtools',\n '@tanstack/vue-devtools',\n '@tanstack/svelte-devtools',\n '@tanstack/angular-devtools',\n '@tanstack/devtools',\n] as const\n\nexport const isTanStackDevtoolsImport = (source: string): boolean =>\n (TANSTACK_DEVTOOLS_PACKAGES as ReadonlyArray<string>).includes(source)\n"],"mappings":";AAAA,IAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,IAAa,4BAA4B,WACtC,2BAAqD,SAAS,OAAO"}
|
package/dist/esm/editor.js
CHANGED
|
@@ -3,7 +3,7 @@ var DEFAULT_EDITOR_CONFIG = {
|
|
|
3
3
|
name: "VSCode",
|
|
4
4
|
open: async (path, lineNumber, columnNumber) => {
|
|
5
5
|
const launch = (await import("launch-editor")).default;
|
|
6
|
-
launch(`${path
|
|
6
|
+
launch(`${path}${lineNumber ? `:${lineNumber}` : ""}${columnNumber ? `:${columnNumber}` : ""}`, void 0, (filename, err) => {
|
|
7
7
|
console.warn(`Failed to open ${filename} in editor: ${err}`);
|
|
8
8
|
});
|
|
9
9
|
}
|
package/dist/esm/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.js","names":[],"sources":["../../src/editor.ts"],"sourcesContent":["type OpenSourceData = {\n type: 'open-source'\n data: {\n /** The source file to open */\n source?: string\n /** The react router route ID, usually discovered via the hook useMatches */\n routeID?: string\n /** The line number in the source file */\n line?: number\n /** The column number in the source file */\n column?: number\n }\n}\n\nexport type EditorConfig = {\n /** The name of the editor, used for debugging purposes */\n name: string\n /** Callback to open a file in the editor */\n open: (\n path: string,\n lineNumber: string | undefined,\n columnNumber?: string,\n ) => Promise<void>\n}\n\nexport const DEFAULT_EDITOR_CONFIG: EditorConfig = {\n name: 'VSCode',\n open: async (path, lineNumber, columnNumber) => {\n const launch = (await import('launch-editor')).default\n launch(\n `${path
|
|
1
|
+
{"version":3,"file":"editor.js","names":[],"sources":["../../src/editor.ts"],"sourcesContent":["type OpenSourceData = {\n type: 'open-source'\n data: {\n /** The source file to open */\n source?: string\n /** The react router route ID, usually discovered via the hook useMatches */\n routeID?: string\n /** The line number in the source file */\n line?: number\n /** The column number in the source file */\n column?: number\n }\n}\n\nexport type EditorConfig = {\n /** The name of the editor, used for debugging purposes */\n name: string\n /** Callback to open a file in the editor */\n open: (\n path: string,\n lineNumber: string | undefined,\n columnNumber?: string,\n ) => Promise<void>\n}\n\nexport const DEFAULT_EDITOR_CONFIG: EditorConfig = {\n name: 'VSCode',\n open: async (path, lineNumber, columnNumber) => {\n const launch = (await import('launch-editor')).default\n launch(\n `${path}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}`,\n undefined,\n (filename, err) => {\n console.warn(`Failed to open ${filename} in editor: ${err}`)\n },\n )\n },\n}\n\nexport const handleOpenSource = async ({\n data,\n openInEditor,\n}: {\n data: OpenSourceData\n openInEditor: EditorConfig['open']\n}) => {\n const { source, line, column } = data.data\n const lineNum = line ? `${line}` : undefined\n const columnNum = column ? `${column}` : undefined\n if (source) {\n return openInEditor(source, lineNum, columnNum)\n }\n}\n"],"mappings":";AAyBA,IAAa,wBAAsC;CACjD,MAAM;CACN,MAAM,OAAO,MAAM,YAAY,iBAAiB;EAC9C,MAAM,UAAU,MAAM,OAAO,kBAAkB;EAC/C,OACE,GAAG,OAAO,aAAa,IAAI,eAAe,KAAK,eAAe,IAAI,iBAAiB,MACnF,KAAA,IACC,UAAU,QAAQ;GACjB,QAAQ,KAAK,kBAAkB,SAAS,cAAc,MAAM;IAE/D;;CAEJ;AAED,IAAa,mBAAmB,OAAO,EACrC,MACA,mBAII;CACJ,MAAM,EAAE,QAAQ,MAAM,WAAW,KAAK;CACtC,MAAM,UAAU,OAAO,GAAG,SAAS,KAAA;CACnC,MAAM,YAAY,SAAS,GAAG,WAAW,KAAA;CACzC,IAAI,QACF,OAAO,aAAa,QAAQ,SAAS,UAAU"}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export declare function enhanceConsoleLog(code: string, id: string, port: number):
|
|
1
|
+
export declare function enhanceConsoleLog(code: string, id: string, port: number): {
|
|
2
|
+
code: string;
|
|
3
|
+
map: import('magic-string').SourceMap;
|
|
4
|
+
} | undefined;
|
package/dist/esm/enhance-logs.js
CHANGED
|
@@ -1,47 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { walk } from "./ast-utils.js";
|
|
2
|
+
import { createLocMapper } from "./offset-to-loc.js";
|
|
2
3
|
import { normalizePath } from "vite";
|
|
3
4
|
import chalk from "chalk";
|
|
5
|
+
import MagicString from "magic-string";
|
|
6
|
+
import { parseSync } from "oxc-parser";
|
|
4
7
|
//#region src/enhance-logs.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const callee = path.node.callee;
|
|
9
|
-
if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "console" && callee.property.type === "Identifier" && (callee.property.name === "log" || callee.property.name === "error")) {
|
|
10
|
-
const location = path.node.loc;
|
|
11
|
-
if (!location) return;
|
|
12
|
-
const [lineNumber, column] = [location.start.line, location.start.column];
|
|
13
|
-
const finalPath = `${filePath}:${lineNumber}:${column + 1}`;
|
|
14
|
-
const logMessage = `${chalk.magenta("LOG")} ${chalk.blueBright(`${finalPath}`)}\n → `;
|
|
15
|
-
const serverLogMessage = t.arrayExpression([t.stringLiteral(logMessage)]);
|
|
16
|
-
const browserLogMessage = t.arrayExpression([
|
|
17
|
-
t.stringLiteral(`%cLOG%c %c${`Go to Source: http://localhost:${port}/__tsd/open-source?source=${encodeURIComponent(finalPath)}`}%c \n → `),
|
|
18
|
-
t.stringLiteral("color:#A0A"),
|
|
19
|
-
t.stringLiteral("color:#FFF"),
|
|
20
|
-
t.stringLiteral("color:#55F"),
|
|
21
|
-
t.stringLiteral("color:#FFF")
|
|
22
|
-
]);
|
|
23
|
-
const checkServerCondition = t.binaryExpression("===", t.unaryExpression("typeof", t.identifier("window")), t.stringLiteral("undefined"));
|
|
24
|
-
path.node.arguments.unshift(t.spreadElement(t.conditionalExpression(checkServerCondition, serverLogMessage, browserLogMessage)));
|
|
25
|
-
didTransform = true;
|
|
26
|
-
}
|
|
27
|
-
} });
|
|
28
|
-
return didTransform;
|
|
29
|
-
};
|
|
8
|
+
function escapeForStringLiteral(str) {
|
|
9
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n");
|
|
10
|
+
}
|
|
30
11
|
function enhanceConsoleLog(code, id, port) {
|
|
31
|
-
const
|
|
32
|
-
const location = filePath
|
|
12
|
+
const filePath = id.split("?")[0];
|
|
13
|
+
const location = filePath.replace(normalizePath(process.cwd()), "");
|
|
33
14
|
try {
|
|
34
|
-
const
|
|
15
|
+
const result = parseSync(filePath, code, {
|
|
35
16
|
sourceType: "module",
|
|
36
|
-
|
|
17
|
+
lang: "tsx"
|
|
37
18
|
});
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
if (result.errors.length > 0) return;
|
|
20
|
+
const offsetToLoc = createLocMapper(code);
|
|
21
|
+
const s = new MagicString(code);
|
|
22
|
+
walk(result.program, (node) => {
|
|
23
|
+
if (node.type !== "CallExpression") return;
|
|
24
|
+
const callee = node.callee;
|
|
25
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.object.name === "console" && callee.property.type === "Identifier" && (callee.property.name === "log" || callee.property.name === "error")) {
|
|
26
|
+
const loc = offsetToLoc(node.start);
|
|
27
|
+
const [lineNumber, column] = [loc.line, loc.column];
|
|
28
|
+
const finalPath = `${location}:${lineNumber}:${column + 1}`;
|
|
29
|
+
const spreadStr = `...(typeof window === "undefined" ? ${`["${escapeForStringLiteral(`${chalk.magenta("LOG")} ${chalk.blueBright(`${finalPath}`)}\n → `)}"]`} : ${`["%cLOG%c %c${`Go to Source: http://localhost:${port}/__tsd/open-source?source=${encodeURIComponent(finalPath)}`}%c \\n \\u2192 ","color:#A0A","color:#FFF","color:#55F","color:#FFF"]`}), `;
|
|
30
|
+
let parenOffset = callee.end;
|
|
31
|
+
while (parenOffset < code.length && code[parenOffset] !== "(") parenOffset++;
|
|
32
|
+
s.appendRight(parenOffset + 1, spreadStr);
|
|
33
|
+
}
|
|
44
34
|
});
|
|
35
|
+
if (!s.hasChanged()) return;
|
|
36
|
+
return {
|
|
37
|
+
code: s.toString(),
|
|
38
|
+
map: s.generateMap({
|
|
39
|
+
source: filePath,
|
|
40
|
+
file: id,
|
|
41
|
+
includeContent: true
|
|
42
|
+
})
|
|
43
|
+
};
|
|
45
44
|
} catch (e) {
|
|
46
45
|
return;
|
|
47
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhance-logs.js","names":[],"sources":["../../src/enhance-logs.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { normalizePath } from 'vite'\nimport
|
|
1
|
+
{"version":3,"file":"enhance-logs.js","names":[],"sources":["../../src/enhance-logs.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { normalizePath } from 'vite'\nimport MagicString from 'magic-string'\nimport { parseSync } from 'oxc-parser'\nimport { createLocMapper } from './offset-to-loc'\nimport { walk } from './ast-utils'\n\nfunction escapeForStringLiteral(str: string): string {\n return str.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"').replace(/\\n/g, '\\\\n')\n}\n\nexport function enhanceConsoleLog(code: string, id: string, port: number) {\n const filePath = id.split('?')[0]!\n const location = filePath.replace(normalizePath(process.cwd()), '')\n\n try {\n const result = parseSync(filePath, code, {\n sourceType: 'module',\n lang: 'tsx',\n })\n if (result.errors.length > 0) return\n\n const offsetToLoc = createLocMapper(code)\n const s = new MagicString(code)\n\n walk(result.program, (node) => {\n if (node.type !== 'CallExpression') return\n\n const callee = node.callee\n if (\n callee.type === 'MemberExpression' &&\n !callee.computed &&\n callee.object.type === 'Identifier' &&\n callee.object.name === 'console' &&\n callee.property.type === 'Identifier' &&\n (callee.property.name === 'log' || callee.property.name === 'error')\n ) {\n const loc = offsetToLoc(node.start)\n const [lineNumber, column] = [loc.line, loc.column]\n const finalPath = `${location}:${lineNumber}:${column + 1}`\n const logMessage = `${chalk.magenta('LOG')} ${chalk.blueBright(`${finalPath}`)}\\n → `\n\n const serverLogMessage = `[\"${escapeForStringLiteral(logMessage)}\"]`\n const browserLogMessage = `[\"%c${'LOG'}%c %c${`Go to Source: http://localhost:${port}/__tsd/open-source?source=${encodeURIComponent(finalPath)}`}%c \\\\n \\\\u2192 \",\"color:#A0A\",\"color:#FFF\",\"color:#55F\",\"color:#FFF\"]`\n\n const spreadStr = `...(typeof window === \"undefined\" ? ${serverLogMessage} : ${browserLogMessage}), `\n\n // Find the opening '(' of the call by scanning forward from callee end\n let parenOffset = callee.end\n while (parenOffset < code.length && code[parenOffset] !== '(') {\n parenOffset++\n }\n // Insert right after '('\n s.appendRight(parenOffset + 1, spreadStr)\n }\n })\n\n if (!s.hasChanged()) return\n\n return {\n code: s.toString(),\n map: s.generateMap({\n source: filePath,\n file: id,\n includeContent: true,\n }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F,IAAI,CAAC,EAAE,YAAY,EAAE;EAErB,OAAO;GACL,MAAM,EAAE,UAAU;GAClB,KAAK,EAAE,YAAY;IACjB,QAAQ;IACR,MAAM;IACN,gBAAgB;IACjB,CAAC;GACH;UACM,GAAG;EACV"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { PluginInjection } from '@tanstack/devtools-client';
|
|
2
|
-
import { types as Babel } from '@babel/core';
|
|
3
|
-
import { ParseResult } from '@babel/parser';
|
|
4
2
|
/**
|
|
5
3
|
* Finds the TanStackDevtools component name in the file
|
|
6
4
|
* Handles renamed imports and namespace imports
|
|
7
5
|
*/
|
|
8
|
-
export declare const findDevtoolsComponentName: (
|
|
9
|
-
export declare const transformAndInject: (
|
|
6
|
+
export declare const findDevtoolsComponentName: (code: string) => string | null;
|
|
7
|
+
export declare const transformAndInject: (code: string, injection: PluginInjection, devtoolsComponentName: string) => {
|
|
8
|
+
code: string;
|
|
9
|
+
transformed: boolean;
|
|
10
|
+
} | null;
|
|
10
11
|
/**
|
|
11
12
|
* Detects if a file contains TanStack devtools import
|
|
12
13
|
*/
|
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
2
5
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
6
|
//#region src/inject-plugin.ts
|
|
4
7
|
/**
|
|
5
8
|
* Detects if a file imports TanStack devtools packages
|
|
6
|
-
* Handles: import X from '@tanstack/react-devtools'
|
|
7
|
-
* import * as X from '@tanstack/react-devtools'
|
|
8
|
-
* import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
9
9
|
*/
|
|
10
10
|
var detectDevtoolsImport = (code) => {
|
|
11
|
-
const devtoolsPackages = [
|
|
12
|
-
"@tanstack/react-devtools",
|
|
13
|
-
"@tanstack/solid-devtools",
|
|
14
|
-
"@tanstack/vue-devtools",
|
|
15
|
-
"@tanstack/svelte-devtools",
|
|
16
|
-
"@tanstack/angular-devtools"
|
|
17
|
-
];
|
|
18
11
|
try {
|
|
19
|
-
const
|
|
12
|
+
const result = parseSync("input.tsx", code, {
|
|
20
13
|
sourceType: "module",
|
|
21
|
-
|
|
14
|
+
lang: "tsx"
|
|
22
15
|
});
|
|
16
|
+
if (result.errors.length > 0) return false;
|
|
23
17
|
let hasDevtoolsImport = false;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
path.stop();
|
|
29
|
-
}
|
|
30
|
-
} });
|
|
18
|
+
walk(result.program, (node) => {
|
|
19
|
+
if (hasDevtoolsImport) return;
|
|
20
|
+
if (node.type === "ImportDeclaration" && isTanStackDevtoolsImport(node.source.value)) hasDevtoolsImport = true;
|
|
21
|
+
});
|
|
31
22
|
return hasDevtoolsImport;
|
|
32
23
|
} catch (e) {
|
|
33
24
|
return false;
|
|
@@ -37,92 +28,117 @@ var detectDevtoolsImport = (code) => {
|
|
|
37
28
|
* Finds the TanStackDevtools component name in the file
|
|
38
29
|
* Handles renamed imports and namespace imports
|
|
39
30
|
*/
|
|
40
|
-
var findDevtoolsComponentName = (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
path.stop();
|
|
62
|
-
return;
|
|
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
|
+
}
|
|
63
52
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
});
|
|
54
|
+
return componentName;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
67
58
|
};
|
|
68
|
-
|
|
69
|
-
|
|
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) => {
|
|
70
80
|
const importName = injection.pluginImport?.importName;
|
|
71
81
|
const pluginType = injection.pluginImport?.type || "jsx";
|
|
72
82
|
const displayName = injection.pluginName;
|
|
73
|
-
if (!importName) return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
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") {
|
|
85
102
|
const expression = pluginsProp.value.expression;
|
|
86
|
-
if (
|
|
87
|
-
if (!expression
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return t.isStringLiteral(prop.value) && prop.value.value === displayName;
|
|
94
|
-
});
|
|
95
|
-
})) {
|
|
96
|
-
if (pluginType === "function") expression.elements.push(t.callExpression(t.identifier(importName), []));
|
|
97
|
-
else {
|
|
98
|
-
const renderValue = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(importName), [], true), null, [], true);
|
|
99
|
-
expression.elements.push(t.objectExpression([t.objectProperty(t.identifier("name"), t.stringLiteral(displayName)), t.objectProperty(t.identifier("render"), renderValue)]));
|
|
100
|
-
}
|
|
101
|
-
didTransform = true;
|
|
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);
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
113
|
} else {
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
else
|
|
109
|
-
const renderValue = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(importName), [], true), null, [], true);
|
|
110
|
-
pluginElement = t.objectExpression([t.objectProperty(t.identifier("name"), t.stringLiteral(displayName)), t.objectProperty(t.identifier("render"), renderValue)]);
|
|
111
|
-
}
|
|
112
|
-
path.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("plugins"), t.jsxExpressionContainer(t.arrayExpression([pluginElement]))));
|
|
113
|
-
didTransform = true;
|
|
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);
|
|
114
117
|
}
|
|
115
|
-
}
|
|
116
|
-
} });
|
|
117
|
-
if (didTransform) {
|
|
118
|
-
const importDeclaration = t.importDeclaration([t.importSpecifier(t.identifier(importName), t.identifier(importName))], t.stringLiteral(injection.packageName));
|
|
119
|
-
let lastImportIndex = -1;
|
|
120
|
-
ast.program.body.forEach((node, index) => {
|
|
121
|
-
if (t.isImportDeclaration(node)) lastImportIndex = index;
|
|
122
118
|
});
|
|
123
|
-
|
|
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;
|
|
124
141
|
}
|
|
125
|
-
return didTransform;
|
|
126
142
|
};
|
|
127
143
|
/**
|
|
128
144
|
* Detects if a file contains TanStack devtools import
|
|
@@ -136,23 +152,18 @@ function detectDevtoolsFile(code) {
|
|
|
136
152
|
*/
|
|
137
153
|
function injectPluginIntoFile(filePath, injection) {
|
|
138
154
|
try {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
plugins: ["jsx", "typescript"]
|
|
142
|
-
});
|
|
143
|
-
const devtoolsComponentName = findDevtoolsComponentName(ast);
|
|
155
|
+
const code = readFileSync(filePath, "utf-8");
|
|
156
|
+
const devtoolsComponentName = findDevtoolsComponentName(code);
|
|
144
157
|
if (!devtoolsComponentName) return {
|
|
145
158
|
success: false,
|
|
146
159
|
error: "Could not find TanStackDevtools import"
|
|
147
160
|
};
|
|
148
|
-
|
|
161
|
+
const result = transformAndInject(code, injection, devtoolsComponentName);
|
|
162
|
+
if (!result?.transformed) return {
|
|
149
163
|
success: false,
|
|
150
164
|
error: "Plugin already exists or no TanStackDevtools component found"
|
|
151
165
|
};
|
|
152
|
-
writeFileSync(filePath,
|
|
153
|
-
sourceMaps: false,
|
|
154
|
-
retainLines: false
|
|
155
|
-
}).code, "utf-8");
|
|
166
|
+
writeFileSync(filePath, result.code, "utf-8");
|
|
156
167
|
return { success: true };
|
|
157
168
|
} catch (e) {
|
|
158
169
|
console.error("Error injecting plugin:", e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-plugin.js","names":[],"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"],"mappings":";;;;;;;;;AAYA,IAAM,wBAAwB,SAA0B;CACtD,MAAM,mBAAmB;EACvB;EACA;EACA;EACA;EACA;EACD;CAED,IAAI;EACF,MAAM,MAAM,MAAM,MAAM;GACtB,YAAY;GACZ,SAAS,CAAC,OAAO,aAAa;GAC/B,CAAC;EAEF,IAAI,oBAAoB;EAExB,KAAK,KAAK,EACR,kBAAkB,MAAM;GACtB,MAAM,eAAe,KAAK,KAAK,OAAO;GACtC,IAAI,iBAAiB,SAAS,aAAa,EAAE;IAC3C,oBAAoB;IACpB,KAAK,MAAM;;KAGhB,CAAC;EAEF,OAAO;UACA,GAAG;EACV,OAAO;;;;;;;AAQX,IAAa,6BACX,QACkB;CAClB,IAAI,gBAA+B;CACnC,MAAM,mBAAmB;EACvB;EACA;EACA;EACA;EACA;EACD;CAED,KAAK,KAAK,EACR,kBAAkB,MAAM;EACtB,MAAM,eAAe,KAAK,KAAK,OAAO;EACtC,IAAI,iBAAiB,SAAS,aAAa,EAAE;GAE3C,MAAM,cAAc,KAAK,KAAK,WAAW,MACtC,SACC,EAAE,kBAAkB,KAAK,IACzB,EAAE,aAAa,KAAK,SAAS,IAC7B,KAAK,SAAS,SAAS,mBAC1B;GACD,IAAI,eAAe,EAAE,kBAAkB,YAAY,EAAE;IACnD,g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ACF;IAED,eAAe;;;IAItB,CAAC;CAIF,IAAI,cAAc;EAChB,MAAM,oBAAoB,EAAE,kBAC1B,CAAC,EAAE,gBAAgB,EAAE,WAAW,WAAW,EAAE,EAAE,WAAW,WAAW,CAAC,CAAC,EACvE,EAAE,cAAc,UAAU,YAAY,CACvC;EAGD,IAAI,kBAAkB;EACtB,IAAI,QAAQ,KAAK,SAAS,MAAM,UAAU;GACxC,IAAI,EAAE,oBAAoB,KAAK,EAC7B,kBAAkB;IAEpB;EAGF,IAAI,QAAQ,KAAK,OAAO,kBAAkB,GAAG,GAAG,kBAAkB;;CAGpE,OAAO;;;;;AAMT,SAAgB,mBAAmB,MAAuB;CACxD,OAAO,qBAAqB,KAAK;;;;;;AAOnC,SAAgB,qBACd,UACA,WACsC;CACtC,IAAI;EAKF,MAAM,MAAM,MAHC,aAAa,UAAU,QAGlB,EAAM;GACtB,YAAY;GACZ,SAAS,CAAC,OAAO,aAAa;GAC/B,CAAC;EAGF,MAAM,wBAAwB,0BAA0B,IAAI;EAC5D,IAAI,CAAC,uBACH,OAAO;GACL,SAAS;GACT,OAAO;GACR;EAUH,IAAI,CANiB,mBACnB,KACA,WACA,sBAGG,EACH,OAAO;GACL,SAAS;GACT,OAAO;GACR;EAUH,cAAc,UANC,IAAI,KAAK;GACtB,YAAY;GACZ,aAAa;GACd,CAGuB,CAAO,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
|
+
{"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,OAAO;EAErC,IAAI,oBAAoB;EAExB,KAAK,OAAO,UAAU,SAAS;GAC7B,IAAI,mBAAmB;GACvB,IACE,KAAK,SAAS,uBACd,yBAAyB,KAAK,OAAO,MAAM,EAE3C,oBAAoB;IAEtB;EAEF,OAAO;UACA,GAAG;EACV,OAAO;;;;;;;AAQX,IAAa,6BAA6B,SAAgC;CACxE,IAAI;EACF,MAAM,SAAS,UAAU,aAAa,MAAM;GAC1C,YAAY;GACZ,MAAM;GACP,CAAC;EACF,IAAI,OAAO,OAAO,SAAS,GAAG,OAAO;EAErC,IAAI,gBAA+B;EAEnC,KAAK,OAAO,UAAU,SAAS;GAC7B,IAAI,eAAe;GACnB,IAAI,KAAK,SAAS,qBAAqB;GACvC,IAAI,CAAC,yBAAyB,KAAK,OAAO,MAAM,EAAE;GAElD,KAAK,MAAM,QAAQ,KAAK,YAAY;IAElC,IACE,KAAK,SAAS,qBACd,KAAK,SAAS,SAAS,gBACvB,KAAK,SAAS,SAAS,oBACvB;KACA,gBAAgB,KAAK,MAAM;KAC3B;;IAGF,IAAI,KAAK,SAAS,4BAA4B;KAC5C,gBAAgB,GAAG,KAAK,MAAM,KAAK;KACnC;;;IAGJ;EAEF,OAAO;UACA,GAAG;EACV,OAAO;;;;;;AAOX,SAAS,aACP,MACA,MACA,YACA,aACA,YACS;CACT,IAAI,KAAK,SAAS,mBAAmB,OAAO;CAE5C,KAAK,MAAM,WAAW,KAAK,UAAU;EACnC,IAAI,CAAC,SAAS;EAEd,IAAI,eAAe;OAEf,QAAQ,SAAS,oBACjB,QAAQ,OAAO,S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;CACxD,OAAO,qBAAqB,KAAK;;;;;;AAOnC,SAAgB,qBACd,UACA,WACsC;CACtC,IAAI;EACF,MAAM,OAAO,aAAa,UAAU,QAAQ;EAE5C,MAAM,wBAAwB,0BAA0B,KAAK;EAC7D,IAAI,CAAC,uBACH,OAAO;GACL,SAAS;GACT,OAAO;GACR;EAGH,MAAM,SAAS,mBAAmB,MAAM,WAAW,sBAAsB;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;
|