@tanstack/devtools-vite 0.8.1 → 0.8.3

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.
Files changed (81) hide show
  1. package/dist/esm/plugin.d.ts +4 -74
  2. package/dist/esm/plugin.js +2 -12
  3. package/dist/esm/plugin.js.map +1 -1
  4. package/package.json +2 -6
  5. package/src/plugin.ts +25 -97
  6. package/dist/esm/ast-utils.d.ts +0 -11
  7. package/dist/esm/ast-utils.js +0 -44
  8. package/dist/esm/ast-utils.js.map +0 -1
  9. package/dist/esm/ast-utils.test.d.ts +0 -1
  10. package/dist/esm/devtools-packages.d.ts +0 -2
  11. package/dist/esm/devtools-packages.js +0 -15
  12. package/dist/esm/devtools-packages.js.map +0 -1
  13. package/dist/esm/devtools-packages.test.d.ts +0 -1
  14. package/dist/esm/editor.d.ts +0 -25
  15. package/dist/esm/editor.js +0 -20
  16. package/dist/esm/editor.js.map +0 -1
  17. package/dist/esm/editor.test.d.ts +0 -1
  18. package/dist/esm/enhance-logs.d.ts +0 -4
  19. package/dist/esm/enhance-logs.js +0 -51
  20. package/dist/esm/enhance-logs.js.map +0 -1
  21. package/dist/esm/enhance-logs.test.d.ts +0 -1
  22. package/dist/esm/inject-plugin.d.ts +0 -22
  23. package/dist/esm/inject-plugin.js +0 -179
  24. package/dist/esm/inject-plugin.js.map +0 -1
  25. package/dist/esm/inject-plugin.test.d.ts +0 -1
  26. package/dist/esm/inject-source.d.ts +0 -7
  27. package/dist/esm/inject-source.js +0 -114
  28. package/dist/esm/inject-source.js.map +0 -1
  29. package/dist/esm/inject-source.test.d.ts +0 -1
  30. package/dist/esm/matcher.d.ts +0 -1
  31. package/dist/esm/matcher.js +0 -13
  32. package/dist/esm/matcher.js.map +0 -1
  33. package/dist/esm/matcher.test.d.ts +0 -1
  34. package/dist/esm/offset-to-loc.d.ts +0 -14
  35. package/dist/esm/offset-to-loc.js +0 -29
  36. package/dist/esm/offset-to-loc.js.map +0 -1
  37. package/dist/esm/offset-to-loc.test.d.ts +0 -1
  38. package/dist/esm/package-manager.d.ts +0 -16
  39. package/dist/esm/package-manager.js +0 -98
  40. package/dist/esm/package-manager.js.map +0 -1
  41. package/dist/esm/remove-devtools.d.ts +0 -4
  42. package/dist/esm/remove-devtools.js +0 -96
  43. package/dist/esm/remove-devtools.js.map +0 -1
  44. package/dist/esm/remove-devtools.test.d.ts +0 -1
  45. package/dist/esm/runtime-bridge.d.ts +0 -31
  46. package/dist/esm/runtime-bridge.js +0 -75
  47. package/dist/esm/runtime-bridge.js.map +0 -1
  48. package/dist/esm/runtime-bridge.test.d.ts +0 -1
  49. package/dist/esm/utils.d.ts +0 -31
  50. package/dist/esm/utils.js +0 -155
  51. package/dist/esm/utils.js.map +0 -1
  52. package/dist/esm/utils.test.d.ts +0 -1
  53. package/dist/esm/virtual-console.d.ts +0 -19
  54. package/dist/esm/virtual-console.js +0 -336
  55. package/dist/esm/virtual-console.js.map +0 -1
  56. package/dist/esm/virtual-console.test.d.ts +0 -1
  57. package/src/ast-utils.test.ts +0 -109
  58. package/src/ast-utils.ts +0 -58
  59. package/src/devtools-packages.test.ts +0 -58
  60. package/src/devtools-packages.ts +0 -12
  61. package/src/editor.test.ts +0 -75
  62. package/src/editor.ts +0 -53
  63. package/src/enhance-logs.test.ts +0 -132
  64. package/src/enhance-logs.ts +0 -71
  65. package/src/inject-plugin.test.ts +0 -1139
  66. package/src/inject-plugin.ts +0 -300
  67. package/src/inject-source.test.ts +0 -939
  68. package/src/inject-source.ts +0 -235
  69. package/src/matcher.test.ts +0 -33
  70. package/src/matcher.ts +0 -19
  71. package/src/offset-to-loc.test.ts +0 -34
  72. package/src/offset-to-loc.ts +0 -39
  73. package/src/package-manager.ts +0 -181
  74. package/src/remove-devtools.test.ts +0 -607
  75. package/src/remove-devtools.ts +0 -190
  76. package/src/runtime-bridge.test.ts +0 -179
  77. package/src/runtime-bridge.ts +0 -113
  78. package/src/utils.test.ts +0 -184
  79. package/src/utils.ts +0 -247
  80. package/src/virtual-console.test.ts +0 -244
  81. package/src/virtual-console.ts +0 -341
@@ -1 +0,0 @@
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 }),\n }\n } catch (e) {\n return\n }\n}\n"],"mappings":";;;;;;;AAOA,SAAS,uBAAuB,KAAqB;CACnD,OAAO,IAAI,QAAQ,OAAO,OAAO,CAAC,QAAQ,MAAM,OAAM,CAAC,QAAQ,OAAO,MAAM;;AAG9E,SAAgB,kBAAkB,MAAc,IAAY,MAAc;CACxE,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;CAC/B,MAAM,WAAW,SAAS,QAAQ,cAAc,QAAQ,KAAK,CAAC,EAAE,GAAG;CAEnE,IAAI;EACF,MAAM,SAAS,UAAU,UAAU,MAAM;GACvC,YAAY;GACZ,MAAM;GACP,CAAC;EACF,IAAI,OAAO,OAAO,SAAS,GAAG;EAE9B,MAAM,cAAc,gBAAgB,KAAK;EACzC,MAAM,IAAI,IAAI,YAAY,KAAK;EAE/B,KAAK,OAAO,UAAU,SAAS;GAC7B,IAAI,KAAK,SAAS,kBAAkB;GAEpC,MAAM,SAAS,KAAK;GACpB,IACE,OAAO,SAAS,sBAChB,CAAC,OAAO,YACR,OAAO,OAAO,SAAS,gBACvB,OAAO,OAAO,SAAS,aACvB,OAAO,SAAS,SAAS,iBACxB,OAAO,SAAS,SAAS,SAAS,OAAO,SAAS,SAAS,UAC5D;IACA,MAAM,MAAM,YAAY,KAAK,MAAM;IACnC,MAAM,CAAC,YAAY,UAAU,CAAC,IAAI,MAAM,IAAI,OAAO;IACnD,MAAM,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS;IAMxD,MAAM,YAAY,uCAAuC,KAH3B,uBAAuB,GAF/B,MAAM,QAAQ,MAAM,CAAC,GAAG,MAAM,WAAW,GAAG,YAAY,CAAC,OAEf,CAAC,IAGS,KAAK,eAFjC,kCAAkC,KAAK,4BAA4B,mBAAmB,UAAU,GAAG,uEAEhD;IAGjG,IAAI,cAAc,OAAO;IACzB,OAAO,cAAc,KAAK,UAAU,KAAK,iBAAiB,KACxD;IAGF,EAAE,YAAY,cAAc,GAAG,UAAU;;IAE3C;EAEF,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 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import { PluginInjection } from '@tanstack/devtools-client';
2
- /**
3
- * Finds the TanStackDevtools component name in the file
4
- * Handles renamed imports and namespace imports
5
- */
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;
11
- /**
12
- * Detects if a file contains TanStack devtools import
13
- */
14
- export declare function detectDevtoolsFile(code: string): boolean;
15
- /**
16
- * Injects a plugin into the TanStackDevtools component in a file
17
- * Reads the file, transforms it, and writes it back
18
- */
19
- export declare function injectPluginIntoFile(filePath: string, injection: PluginInjection): {
20
- success: boolean;
21
- error?: string;
22
- };
@@ -1,179 +0,0 @@
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";
5
- import { readFileSync, writeFileSync } from "node:fs";
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
- }
26
- };
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
- }
58
- };
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
- }
142
- };
143
- /**
144
- * Detects if a file contains TanStack devtools import
145
- */
146
- function detectDevtoolsFile(code) {
147
- return detectDevtoolsImport(code);
148
- }
149
- /**
150
- * Injects a plugin into the TanStackDevtools component in a file
151
- * Reads the file, transforms it, and writes it back
152
- */
153
- function injectPluginIntoFile(filePath, injection) {
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
- }
175
- }
176
- //#endregion
177
- export { detectDevtoolsFile, injectPluginIntoFile };
178
-
179
- //# sourceMappingURL=inject-plugin.js.map
@@ -1 +0,0 @@
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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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 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- export declare function addSourceToJsx(code: string, id: string, ignore?: {
2
- files?: Array<string | RegExp>;
3
- components?: Array<string | RegExp>;
4
- }): {
5
- code: string;
6
- map: import('magic-string').SourceMap;
7
- } | undefined;
@@ -1,114 +0,0 @@
1
- import { forEachChild } from "./ast-utils.js";
2
- import { createLocMapper } from "./offset-to-loc.js";
3
- import { matcher } from "./matcher.js";
4
- import { normalizePath } from "vite";
5
- import MagicString from "magic-string";
6
- import { parseSync } from "oxc-parser";
7
- //#region src/inject-source.ts
8
- /**
9
- * Extract the props name from a function's first parameter.
10
- * Handles: `(props) => {}`, `({ ...props }) => {}`, `function(props) {}`
11
- */
12
- function getPropsName(params) {
13
- const first = params[0];
14
- if (!first) return null;
15
- if (first.type === "Identifier") return first.name;
16
- if (first.type === "ObjectPattern") {
17
- for (const prop of first.properties) if (prop.type === "RestElement" && prop.argument.type === "Identifier") return prop.argument.name;
18
- }
19
- return null;
20
- }
21
- /**
22
- * Get the display name from a JSX element name node.
23
- */
24
- function getNameOfElement(name) {
25
- if (name.type === "JSXIdentifier") return name.name;
26
- if (name.type === "JSXMemberExpression") return `${getNameOfElement(name.object)}.${name.property.name}`;
27
- return `${name.namespace.name}:${name.name.name}`;
28
- }
29
- /**
30
- * Check whether a JSXOpeningElement should receive `data-tsd-source`.
31
- */
32
- function shouldTransform(node, propsName, ignorePatterns) {
33
- const nameOfElement = getNameOfElement(node.name);
34
- if (nameOfElement === "Fragment" || nameOfElement === "React.Fragment") return false;
35
- if (matcher(ignorePatterns, nameOfElement)) return false;
36
- if (node.attributes.some((a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "data-tsd-source")) return false;
37
- if (node.attributes.some((a) => a.type === "JSXSpreadAttribute" && a.argument.type === "Identifier" && a.argument.name === propsName)) return false;
38
- return true;
39
- }
40
- function isFunctionLike(node) {
41
- return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
42
- }
43
- /**
44
- * Walk a subtree collecting JSXOpeningElements owned by the current function.
45
- * Function-like nodes are traversal boundaries so inner components keep their
46
- * own propsName context and aren't annotated with an outer function's props.
47
- */
48
- function collectJsx(node, out) {
49
- if (node.type === "JSXOpeningElement") {
50
- out.push(node);
51
- return;
52
- }
53
- if (isFunctionLike(node)) return;
54
- forEachChild(node, (child) => collectJsx(child, out));
55
- }
56
- /**
57
- * Walk the AST to find all function-like nodes (in document order).
58
- * For each, extract propsName and collect JSX elements from its body.
59
- */
60
- function visitFunctions(node, annotated, file, ignorePatterns, offsetToLoc, s, code) {
61
- let didTransform = false;
62
- const processFunction = (params, body) => {
63
- const propsName = getPropsName(params);
64
- const jsxNodes = [];
65
- collectJsx(body, jsxNodes);
66
- for (const jsx of jsxNodes) {
67
- if (annotated.has(jsx.start)) continue;
68
- if (!shouldTransform(jsx, propsName, ignorePatterns)) continue;
69
- const loc = offsetToLoc(jsx.start);
70
- const attrStr = ` data-tsd-source="${file}:${loc.line}:${loc.column + 1}"`;
71
- if (jsx.selfClosing) s.appendLeft(jsx.end - 2, attrStr);
72
- else s.appendLeft(jsx.end - 1, attrStr);
73
- annotated.add(jsx.start);
74
- didTransform = true;
75
- }
76
- };
77
- if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression") {
78
- if (node.body) processFunction(node.params, node.body);
79
- } else if (node.type === "ArrowFunctionExpression") processFunction(node.params, node.body);
80
- forEachChild(node, (child) => {
81
- if (visitFunctions(child, annotated, file, ignorePatterns, offsetToLoc, s, code)) didTransform = true;
82
- });
83
- return didTransform;
84
- }
85
- function addSourceToJsx(code, id, ignore = {}) {
86
- const filePath = id.split("?")[0];
87
- const location = filePath.replace(normalizePath(process.cwd()), "");
88
- if (matcher(ignore.files || [], location)) return;
89
- try {
90
- const result = parseSync(filePath, code, {
91
- sourceType: "module",
92
- lang: "tsx"
93
- });
94
- if (result.errors.length > 0) return;
95
- const offsetToLoc = createLocMapper(code);
96
- const s = new MagicString(code);
97
- const annotated = /* @__PURE__ */ new Set();
98
- if (!visitFunctions(result.program, annotated, location, ignore.components || [], offsetToLoc, s, code)) return;
99
- return {
100
- code: s.toString(),
101
- map: s.generateMap({
102
- source: filePath,
103
- file: id,
104
- includeContent: true
105
- })
106
- };
107
- } catch (e) {
108
- return;
109
- }
110
- }
111
- //#endregion
112
- export { addSourceToJsx };
113
-
114
- //# sourceMappingURL=inject-source.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inject-source.js","names":[],"sources":["../../src/inject-source.ts"],"sourcesContent":["import { normalizePath } from 'vite'\nimport MagicString from 'magic-string'\nimport { parseSync } from 'oxc-parser'\nimport { createLocMapper } from './offset-to-loc'\nimport { matcher } from './matcher'\nimport { forEachChild } from './ast-utils'\nimport type {\n JSXElementName,\n JSXOpeningElement,\n Node,\n ParamPattern,\n} from 'oxc-parser'\nimport type { Loc } from './offset-to-loc'\n\n/**\n * Extract the props name from a function's first parameter.\n * Handles: `(props) => {}`, `({ ...props }) => {}`, `function(props) {}`\n */\nfunction getPropsName(params: Array<ParamPattern>): string | null {\n const first = params[0]\n if (!first) return null\n\n // (props) => {} or function(props) {}\n if (first.type === 'Identifier') return first.name\n\n // ({ ...rest }) => {} or function({ ...rest }) {}\n if (first.type === 'ObjectPattern') {\n for (const prop of first.properties) {\n if (prop.type === 'RestElement' && prop.argument.type === 'Identifier') {\n return prop.argument.name\n }\n }\n }\n\n return null\n}\n\n/**\n * Get the display name from a JSX element name node.\n */\nfunction getNameOfElement(name: JSXElementName): string {\n if (name.type === 'JSXIdentifier') return name.name\n if (name.type === 'JSXMemberExpression') {\n return `${getNameOfElement(name.object)}.${name.property.name}`\n }\n // JSXNamespacedName\n return `${name.namespace.name}:${name.name.name}`\n}\n\n/**\n * Check whether a JSXOpeningElement should receive `data-tsd-source`.\n */\nfunction shouldTransform(\n node: JSXOpeningElement,\n propsName: string | null,\n ignorePatterns: Array<string | RegExp>,\n): boolean {\n const nameOfElement = getNameOfElement(node.name)\n\n if (nameOfElement === 'Fragment' || nameOfElement === 'React.Fragment') {\n return false\n }\n if (matcher(ignorePatterns, nameOfElement)) return false\n\n // Already annotated?\n if (\n node.attributes.some(\n (a) =>\n a.type === 'JSXAttribute' &&\n a.name.type === 'JSXIdentifier' &&\n a.name.name === 'data-tsd-source',\n )\n ) {\n return false\n }\n\n // Props spread?\n if (\n node.attributes.some(\n (a) =>\n a.type === 'JSXSpreadAttribute' &&\n a.argument.type === 'Identifier' &&\n a.argument.name === propsName,\n )\n ) {\n return false\n }\n\n return true\n}\n\nfunction isFunctionLike(node: Node): boolean {\n return (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n )\n}\n\n/**\n * Walk a subtree collecting JSXOpeningElements owned by the current function.\n * Function-like nodes are traversal boundaries so inner components keep their\n * own propsName context and aren't annotated with an outer function's props.\n */\nfunction collectJsx(node: Node, out: Array<JSXOpeningElement>) {\n if (node.type === 'JSXOpeningElement') {\n out.push(node)\n return\n }\n if (isFunctionLike(node)) return\n forEachChild(node, (child) => collectJsx(child, out))\n}\n\n/**\n * Walk the AST to find all function-like nodes (in document order).\n * For each, extract propsName and collect JSX elements from its body.\n */\nfunction visitFunctions(\n node: Node,\n annotated: Set<number>,\n file: string,\n ignorePatterns: Array<string | RegExp>,\n offsetToLoc: (offset: number) => Loc,\n s: MagicString,\n code: string,\n): boolean {\n let didTransform = false\n\n const processFunction = (params: Array<ParamPattern>, body: Node) => {\n const propsName = getPropsName(params)\n const jsxNodes: Array<JSXOpeningElement> = []\n collectJsx(body, jsxNodes)\n\n for (const jsx of jsxNodes) {\n if (annotated.has(jsx.start)) continue\n if (!shouldTransform(jsx, propsName, ignorePatterns)) continue\n\n const loc = offsetToLoc(jsx.start)\n const attrStr = ` data-tsd-source=\"${file}:${loc.line}:${loc.column + 1}\"`\n\n // Insert before '>' or '/>' at the end of the opening element\n if (jsx.selfClosing) {\n // ends with '/>' — insert before '/>'\n s.appendLeft(jsx.end - 2, attrStr)\n } else {\n // ends with '>' — insert before '>'\n s.appendLeft(jsx.end - 1, attrStr)\n }\n\n annotated.add(jsx.start)\n didTransform = true\n }\n }\n\n // Check if this node is a function-like node. Variable-initialized\n // functions (`const Foo = () => {}`) are handled when forEachChild reaches\n // their init, so VariableDeclaration doesn't need a special case here.\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression'\n ) {\n if (node.body) processFunction(node.params, node.body)\n } else if (node.type === 'ArrowFunctionExpression') {\n processFunction(node.params, node.body)\n }\n\n // Recurse into children to find nested functions\n forEachChild(node, (child) => {\n if (\n visitFunctions(\n child,\n annotated,\n file,\n ignorePatterns,\n offsetToLoc,\n s,\n code,\n )\n ) {\n didTransform = true\n }\n })\n\n return didTransform\n}\n\nexport function addSourceToJsx(\n code: string,\n id: string,\n ignore: {\n files?: Array<string | RegExp>\n components?: Array<string | RegExp>\n } = {},\n) {\n const filePath = id.split('?')[0]!\n const location = filePath.replace(normalizePath(process.cwd()), '')\n\n const fileIgnored = matcher(ignore.files || [], location)\n if (fileIgnored) return\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 const annotated = new Set<number>()\n\n const didTransform = visitFunctions(\n result.program,\n annotated,\n location,\n ignore.components || [],\n offsetToLoc,\n s,\n code,\n )\n\n if (!didTransform) return\n\n return {\n code: s.toString(),\n map: s.generateMap({\n source: filePath,\n file: id,\n includeContent: true,\n }),\n }\n } catch (e) {\n return\n }\n}\n"],"mappings":";;;;;;;;;;;AAkBA,SAAS,aAAa,QAA4C;CAChE,MAAM,QAAQ,OAAO;CACrB,IAAI,CAAC,OAAO,OAAO;CAGnB,IAAI,MAAM,SAAS,cAAc,OAAO,MAAM;CAG9C,IAAI,MAAM,SAAS;OACZ,MAAM,QAAQ,MAAM,YACvB,IAAI,KAAK,SAAS,iBAAiB,KAAK,SAAS,SAAS,cACxD,OAAO,KAAK,SAAS;;CAK3B,OAAO;;;;;AAMT,SAAS,iBAAiB,MAA8B;CACtD,IAAI,KAAK,SAAS,iBAAiB,OAAO,KAAK;CAC/C,IAAI,KAAK,SAAS,uBAChB,OAAO,GAAG,iBAAiB,KAAK,OAAO,CAAC,GAAG,KAAK,SAAS;CAG3D,OAAO,GAAG,KAAK,UAAU,KAAK,GAAG,KAAK,KAAK;;;;;AAM7C,SAAS,gBACP,MACA,WACA,gBACS;CACT,MAAM,gBAAgB,iBAAiB,KAAK,KAAK;CAEjD,IAAI,kBAAkB,cAAc,kBAAkB,kBACpD,OAAO;CAET,IAAI,QAAQ,gBAAgB,cAAc,EAAE,OAAO;CAGnD,IACE,KAAK,WAAW,MACb,MACC,EAAE,SAAS,kBACX,EAAE,KAAK,SAAS,mBAChB,EAAE,KAAK,SAAS,kBACnB,EAED,OAAO;CAIT,IACE,KAAK,WAAW,MACb,MACC,EAAE,SAAS,wBACX,EAAE,SAAS,SAAS,gBACpB,EAAE,SAAS,SAAS,UACvB,EAED,OAAO;CAGT,OAAO;;AAGT,SAAS,eAAe,MAAqB;CAC3C,OACE,KAAK,SAAS,yBACd,KAAK,SAAS,wBACd,KAAK,SAAS;;;;;;;AASlB,SAAS,WAAW,MAAY,KAA+B;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AS,UAAU,UAAU,MAAM;GACvC,YAAY;GACZ,MAAM;GACP,CAAC;EACF,IAAI,OAAO,OAAO,SAAS,GAAG;EAE9B,MAAM,cAAc,gBAAgB,KAAK;EACzC,MAAM,IAAI,IAAI,YAAY,KAAK;EAC/B,MAAM,4BAAY,IAAI,KAAa;EAYnC,IAAI,CAViB,eACnB,OAAO,SACP,WACA,UACA,OAAO,cAAc,EAAE,EACvB,aACA,GACA,KAGG,EAAc;EAEnB,OAAO;GACL,MAAM,EAAE,UAAU;GAClB,KAAK,EAAE,YAAY;IACjB,QAAQ;IACR,MAAM;IACN,gBAAgB;IACjB,CAAC;GACH;UACM,GAAG;EACV"}
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare const matcher: (patterns: Array<string | RegExp>, str: string) => boolean;
@@ -1,13 +0,0 @@
1
- import picomatch from "picomatch";
2
- //#region src/matcher.ts
3
- var matcher = (patterns, str) => {
4
- if (patterns.length === 0) return false;
5
- return patterns.map((pattern) => {
6
- if (typeof pattern === "string") return picomatch(pattern);
7
- else return (s) => pattern.test(s);
8
- }).some((isMatch) => isMatch(str));
9
- };
10
- //#endregion
11
- export { matcher };
12
-
13
- //# sourceMappingURL=matcher.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"matcher.js","names":[],"sources":["../../src/matcher.ts"],"sourcesContent":["import picomatch from 'picomatch'\n\nexport const matcher = (\n patterns: Array<string | RegExp>,\n str: string,\n): boolean => {\n if (patterns.length === 0) {\n return false\n }\n const matchers = patterns.map((pattern) => {\n if (typeof pattern === 'string') {\n return picomatch(pattern)\n } else {\n return (s: string) => pattern.test(s)\n }\n })\n\n return matchers.some((isMatch) => isMatch(str))\n}\n"],"mappings":";;AAEA,IAAa,WACX,UACA,QACY;CACZ,IAAI,SAAS,WAAW,GACtB,OAAO;CAUT,OARiB,SAAS,KAAK,YAAY;EACzC,IAAI,OAAO,YAAY,UACrB,OAAO,UAAU,QAAQ;OAEzB,QAAQ,MAAc,QAAQ,KAAK,EAAE;GAIlC,CAAS,MAAM,YAAY,QAAQ,IAAI,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- export interface Loc {
2
- /** 1-based line number */
3
- line: number;
4
- /** 0-based column offset */
5
- column: number;
6
- }
7
- /**
8
- * Pre-compute line start offsets for fast byte-offset to line/column conversion.
9
- * Returns a function that maps a byte offset to `{ line, column }`.
10
- *
11
- * Build: O(n) single pass over the source string.
12
- * Lookup: O(log n) binary search.
13
- */
14
- export declare function createLocMapper(source: string): (offset: number) => Loc;
@@ -1,29 +0,0 @@
1
- //#region src/offset-to-loc.ts
2
- /**
3
- * Pre-compute line start offsets for fast byte-offset to line/column conversion.
4
- * Returns a function that maps a byte offset to `{ line, column }`.
5
- *
6
- * Build: O(n) single pass over the source string.
7
- * Lookup: O(log n) binary search.
8
- */
9
- function createLocMapper(source) {
10
- const lineStarts = [0];
11
- for (let i = 0; i < source.length; i++) if (source.charCodeAt(i) === 10) lineStarts.push(i + 1);
12
- return (offset) => {
13
- let lo = 0;
14
- let hi = lineStarts.length - 1;
15
- while (lo < hi) {
16
- const mid = lo + hi + 1 >> 1;
17
- if (lineStarts[mid] <= offset) lo = mid;
18
- else hi = mid - 1;
19
- }
20
- return {
21
- line: lo + 1,
22
- column: offset - lineStarts[lo]
23
- };
24
- };
25
- }
26
- //#endregion
27
- export { createLocMapper };
28
-
29
- //# sourceMappingURL=offset-to-loc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"offset-to-loc.js","names":[],"sources":["../../src/offset-to-loc.ts"],"sourcesContent":["export interface Loc {\n /** 1-based line number */\n line: number\n /** 0-based column offset */\n column: number\n}\n\n/**\n * Pre-compute line start offsets for fast byte-offset to line/column conversion.\n * Returns a function that maps a byte offset to `{ line, column }`.\n *\n * Build: O(n) single pass over the source string.\n * Lookup: O(log n) binary search.\n */\nexport function createLocMapper(source: string): (offset: number) => Loc {\n const lineStarts: Array<number> = [0]\n for (let i = 0; i < source.length; i++) {\n if (source.charCodeAt(i) === 10 /* \\n */) {\n lineStarts.push(i + 1)\n }\n }\n\n return (offset: number): Loc => {\n let lo = 0\n let hi = lineStarts.length - 1\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1\n if (lineStarts[mid]! <= offset) {\n lo = mid\n } else {\n hi = mid - 1\n }\n }\n return {\n line: lo + 1,\n column: offset - lineStarts[lo]!,\n }\n }\n}\n"],"mappings":";;;;;;;;AAcA,SAAgB,gBAAgB,QAAyC;CACvE,MAAM,aAA4B,CAAC,EAAE;CACrC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KACjC,IAAI,OAAO,WAAW,EAAE,KAAK,IAC3B,WAAW,KAAK,IAAI,EAAE;CAI1B,QAAQ,WAAwB;EAC9B,IAAI,KAAK;EACT,IAAI,KAAK,WAAW,SAAS;EAC7B,OAAO,KAAK,IAAI;GACd,MAAM,MAAO,KAAK,KAAK,KAAM;GAC7B,IAAI,WAAW,QAAS,QACtB,KAAK;QAEL,KAAK,MAAM;;EAGf,OAAO;GACL,MAAM,KAAK;GACX,QAAQ,SAAS,WAAW;GAC7B"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { OutdatedDeps } from '@tanstack/devtools-client';
2
- /**
3
- * Adds a plugin to the devtools configuration file
4
- */
5
- export declare const addPluginToDevtools: (devtoolsFileId: string | null, packageName: string, pluginName: string, pluginImport?: {
6
- importName: string;
7
- type: "jsx" | "function";
8
- }) => {
9
- success: boolean;
10
- error?: string;
11
- };
12
- export declare const installPackage: (packageName: string) => Promise<{
13
- success: boolean;
14
- error?: string;
15
- }>;
16
- export declare const emitOutdatedDeps: () => Promise<OutdatedDeps | null>;
@@ -1,98 +0,0 @@
1
- import { readPackageJson, tryParseJson } from "./utils.js";
2
- import { injectPluginIntoFile } from "./inject-plugin.js";
3
- import { devtoolsEventClient } from "@tanstack/devtools-client";
4
- import chalk from "chalk";
5
- import { existsSync } from "node:fs";
6
- import { exec } from "node:child_process";
7
- import { join } from "node:path";
8
- //#region src/package-manager.ts
9
- /**
10
- * Gets the outdated command for the detected package manager
11
- */
12
- var getOutdatedCommand = (packageManager) => {
13
- switch (packageManager) {
14
- case "yarn": return "yarn outdated --json";
15
- case "pnpm": return "pnpm outdated --format json";
16
- case "bun": return "bun outdated --json";
17
- default: return "npm outdated --json";
18
- }
19
- };
20
- /**
21
- * Adds a plugin to the devtools configuration file
22
- */
23
- var addPluginToDevtools = (devtoolsFileId, packageName, pluginName, pluginImport) => {
24
- if (!devtoolsFileId) {
25
- const error = "Devtools file not found";
26
- console.log(chalk.yellowBright(`[@tanstack/devtools-vite] Could not add plugin. ${error}.`));
27
- return {
28
- success: false,
29
- error
30
- };
31
- }
32
- const result = injectPluginIntoFile(devtoolsFileId, {
33
- packageName,
34
- pluginName,
35
- pluginImport
36
- });
37
- if (result.success) console.log(chalk.greenBright(`[@tanstack/devtools-vite] Successfully added ${packageName} to devtools!`));
38
- else console.log(chalk.yellowBright(`[@tanstack/devtools-vite] Could not add plugin: ${result.error}`));
39
- return result;
40
- };
41
- /**
42
- * Gets the install command for the detected package manager
43
- */
44
- var getInstallCommand = (packageManager, packageName) => {
45
- switch (packageManager) {
46
- case "yarn": return `yarn add -D ${packageName}`;
47
- case "pnpm": return `pnpm add -D ${packageName}`;
48
- case "bun": return `bun add -D ${packageName}`;
49
- default: return `npm install -D ${packageName}`;
50
- }
51
- };
52
- var installPackage = async (packageName) => {
53
- return new Promise((resolve) => {
54
- const installCommand = getInstallCommand(detectPackageManager(), packageName);
55
- console.log(chalk.blueBright(`[@tanstack/devtools-vite] Installing ${packageName}...`));
56
- exec(installCommand, async (installError) => {
57
- if (installError) {
58
- console.error(chalk.redBright(`[@tanstack/devtools-vite] Failed to install ${packageName}:`), installError.message);
59
- resolve({
60
- success: false,
61
- error: installError.message
62
- });
63
- return;
64
- }
65
- console.log(chalk.greenBright(`[@tanstack/devtools-vite] Successfully installed ${packageName}`));
66
- const updatedPackageJson = await readPackageJson();
67
- devtoolsEventClient.emit("package-json-updated", { packageJson: updatedPackageJson });
68
- resolve({ success: true });
69
- });
70
- });
71
- };
72
- /**
73
- * Detects the package manager used in the project by checking for lock files
74
- */
75
- var detectPackageManager = () => {
76
- const cwd = process.cwd();
77
- if (existsSync(join(cwd, "bun.lockb")) || existsSync(join(cwd, "bun.lock"))) return "bun";
78
- if (existsSync(join(cwd, "pnpm-lock.yaml"))) return "pnpm";
79
- if (existsSync(join(cwd, "yarn.lock"))) return "yarn";
80
- if (existsSync(join(cwd, "package-lock.json"))) return "npm";
81
- return "pnpm";
82
- };
83
- var emitOutdatedDeps = async () => {
84
- return await new Promise((resolve) => {
85
- exec(getOutdatedCommand(detectPackageManager()), (_, stdout) => {
86
- if (stdout) {
87
- const newOutdatedDeps = tryParseJson(stdout);
88
- if (!newOutdatedDeps) return;
89
- devtoolsEventClient.emit("outdated-deps-read", { outdatedDeps: newOutdatedDeps });
90
- resolve(newOutdatedDeps);
91
- }
92
- });
93
- });
94
- };
95
- //#endregion
96
- export { addPluginToDevtools, emitOutdatedDeps, installPackage };
97
-
98
- //# sourceMappingURL=package-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-manager.js","names":[],"sources":["../../src/package-manager.ts"],"sourcesContent":["import { exec } from 'node:child_process'\nimport { existsSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { devtoolsEventClient } from '@tanstack/devtools-client'\nimport chalk from 'chalk'\nimport { readPackageJson, tryParseJson } from './utils'\nimport { injectPluginIntoFile } from './inject-plugin'\nimport type { OutdatedDeps } from '@tanstack/devtools-client'\n\n/**\n * Gets the outdated command for the detected package manager\n */\nconst getOutdatedCommand = (packageManager: string): string => {\n switch (packageManager) {\n case 'yarn':\n return 'yarn outdated --json'\n case 'pnpm':\n return 'pnpm outdated --format json'\n case 'bun':\n return 'bun outdated --json'\n case 'npm':\n default:\n return 'npm outdated --json'\n }\n}\n\n/**\n * Adds a plugin to the devtools configuration file\n */\nexport const addPluginToDevtools = (\n devtoolsFileId: string | null,\n packageName: string,\n pluginName: string,\n pluginImport?: { importName: string; type: 'jsx' | 'function' },\n): { success: boolean; error?: string } => {\n // Check if we found the devtools file\n if (!devtoolsFileId) {\n const error = 'Devtools file not found'\n console.log(\n chalk.yellowBright(\n `[@tanstack/devtools-vite] Could not add plugin. ${error}.`,\n ),\n )\n return { success: false, error }\n }\n\n // Inject the plugin into the file\n const result = injectPluginIntoFile(devtoolsFileId, {\n packageName,\n pluginName,\n pluginImport,\n })\n\n if (result.success) {\n console.log(\n chalk.greenBright(\n `[@tanstack/devtools-vite] Successfully added ${packageName} to devtools!`,\n ),\n )\n } else {\n console.log(\n chalk.yellowBright(\n `[@tanstack/devtools-vite] Could not add plugin: ${result.error}`,\n ),\n )\n }\n\n return result\n}\n/**\n * Gets the install command for the detected package manager\n */\nconst getInstallCommand = (\n packageManager: string,\n packageName: string,\n): string => {\n switch (packageManager) {\n case 'yarn':\n return `yarn add -D ${packageName}`\n case 'pnpm':\n return `pnpm add -D ${packageName}`\n case 'bun':\n return `bun add -D ${packageName}`\n case 'npm':\n default:\n return `npm install -D ${packageName}`\n }\n}\n\nexport const installPackage = async (\n packageName: string,\n): Promise<{\n success: boolean\n error?: string\n}> => {\n return new Promise((resolve) => {\n const packageManager = detectPackageManager()\n const installCommand = getInstallCommand(packageManager, packageName)\n\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Installing ${packageName}...`,\n ),\n )\n\n exec(installCommand, async (installError) => {\n if (installError) {\n console.error(\n chalk.redBright(\n `[@tanstack/devtools-vite] Failed to install ${packageName}:`,\n ),\n installError.message,\n )\n resolve({\n success: false,\n error: installError.message,\n })\n return\n }\n\n console.log(\n chalk.greenBright(\n `[@tanstack/devtools-vite] Successfully installed ${packageName}`,\n ),\n )\n\n // Read the updated package.json and emit the event\n const updatedPackageJson = await readPackageJson()\n devtoolsEventClient.emit('package-json-updated', {\n packageJson: updatedPackageJson,\n })\n\n resolve({ success: true })\n })\n })\n}\n\n/**\n * Detects the package manager used in the project by checking for lock files\n */\nconst detectPackageManager = (): 'npm' | 'yarn' | 'pnpm' | 'bun' => {\n const cwd = process.cwd()\n\n // Check for lock files in order of specificity\n if (existsSync(join(cwd, 'bun.lockb')) || existsSync(join(cwd, 'bun.lock'))) {\n return 'bun'\n }\n if (existsSync(join(cwd, 'pnpm-lock.yaml'))) {\n return 'pnpm'\n }\n if (existsSync(join(cwd, 'yarn.lock'))) {\n return 'yarn'\n }\n if (existsSync(join(cwd, 'package-lock.json'))) {\n return 'npm'\n }\n\n // Default to pnpm if no lock file is found\n return 'pnpm'\n}\n\nexport const emitOutdatedDeps = async () => {\n return await new Promise<OutdatedDeps | null>((resolve) => {\n const packageManager = detectPackageManager()\n const outdatedCommand = getOutdatedCommand(packageManager)\n\n exec(outdatedCommand, (_, stdout) => {\n // outdated commands exit with code 1 if there are outdated packages, but still output valid JSON\n if (stdout) {\n const newOutdatedDeps = tryParseJson<OutdatedDeps>(stdout)\n if (!newOutdatedDeps) {\n return\n }\n devtoolsEventClient.emit('outdated-deps-read', {\n outdatedDeps: newOutdatedDeps,\n })\n resolve(newOutdatedDeps)\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;AAYA,IAAM,sBAAsB,mBAAmC;CAC7D,QAAQ,gBAAR;EACE,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,OACH,OAAO;EAET,SACE,OAAO;;;;;;AAOb,IAAa,uBACX,gBACA,aACA,YACA,iBACyC;CAEzC,IAAI,CAAC,gBAAgB;EACnB,MAAM,QAAQ;EACd,QAAQ,IACN,MAAM,aACJ,mDAAmD,MAAM,GAC1D,CACF;EACD,OAAO;GAAE,SAAS;GAAO;GAAO;;CAIlC,MAAM,SAAS,qBAAqB,gBAAgB;EAClD;EACA;EACA;EACD,CAAC;CAEF,IAAI,OAAO,SACT,QAAQ,IACN,MAAM,YACJ,gDAAgD,YAAY,eAC7D,CACF;MAED,QAAQ,IACN,MAAM,aACJ,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2B,OAAO;IAC1D,IAAI,CAAC,iBACH;IAEF,oBAAoB,KAAK,sBAAsB,EAC7C,cAAc,iBACf,CAAC;IACF,QAAQ,gBAAgB;;IAE1B;GACF"}
@@ -1,4 +0,0 @@
1
- export declare function removeDevtools(code: string, id: string): {
2
- code: string;
3
- map: import('magic-string').SourceMap;
4
- } | undefined;