diff --git a/.changeset/ripe-olives-decide.md b/.changeset/ripe-olives-decide.md new file mode 100644 index 00000000..d1d3a3a6 --- /dev/null +++ b/.changeset/ripe-olives-decide.md @@ -0,0 +1,5 @@ +--- +'@tanstack/devtools-vite': patch +--- + +improve open-source by using a 3rd party package diff --git a/docs/vite-plugin.md b/docs/vite-plugin.md index 092fa840..cc248e27 100644 --- a/docs/vite-plugin.md +++ b/docs/vite-plugin.md @@ -71,8 +71,7 @@ export default { ### editor -> [!IMPORTANT] `editor` is only needed for editors that are NOT VS Code, by default this works OOTB with VS Code. If you don't have `code` available in your terminal you need to set it up though, if you don't know how to do that you can follow this guide: https://stackoverflow.com/questions/29955500/code-is-not-working-in-on-the-command-line-for-visual-studio-code-on-os-x-ma - +> [!IMPORTANT] `editor` is used as an escape hatch to implement your own go-to-source functionality if your system/editor does not work OOTB. We use `launch-editor` under the hood which supports a lot of editors but not all. If your editor is not supported you can implement your own version here. Here is the list of supported editors: https://github.com/yyx990803/launch-editor?tab=readme-ov-file#supported-editors The open in editor configuration which has two fields, `name` and `open`, `name` is the name of your editor, and `open` is a function that opens the editor with the given file and line number. You can implement your version for your editor as follows: diff --git a/packages/devtools-vite/package.json b/packages/devtools-vite/package.json index 5c90b56e..a45e3748 100644 --- a/packages/devtools-vite/package.json +++ b/packages/devtools-vite/package.json @@ -57,7 +57,8 @@ "@babel/traverse": "^7.28.3", "@babel/types": "^7.28.2", "@tanstack/devtools-event-bus": "workspace:*", - "chalk": "^5.6.0" + "chalk": "^5.6.0", + "launch-editor": "^2.11.1" }, "devDependencies": { "@types/babel__core": "^7.20.5", diff --git a/packages/devtools-vite/src/editor.ts b/packages/devtools-vite/src/editor.ts index 17ac6800..c7eee57d 100644 --- a/packages/devtools-vite/src/editor.ts +++ b/packages/devtools-vite/src/editor.ts @@ -26,9 +26,13 @@ export type EditorConfig = { export const DEFAULT_EDITOR_CONFIG: EditorConfig = { name: 'VSCode', open: async (path, lineNumber, columnNumber) => { - const { exec } = await import('node:child_process') - exec( - `code -g "${path.replaceAll('$', '\\$')}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}"`, + const launch = (await import('launch-editor')).default + launch( + `${path.replaceAll('$', '\\$')}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}`, + undefined, + (filename, err) => { + console.warn(`Failed to open ${filename} in editor: ${err}`) + }, ) }, } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 35f9ff3f..d806bcd7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -359,6 +359,8 @@ importers: specifier: ^4.2.4 version: 4.2.4 + examples/react/start/generated/prisma: {} + examples/react/time-travel: dependencies: '@tanstack/devtools-event-client': @@ -524,6 +526,9 @@ importers: chalk: specifier: ^5.6.0 version: 5.6.0 + launch-editor: + specifier: ^2.11.1 + version: 2.11.1 vite: specifier: ^7.0.0 version: 7.0.6(@types/node@22.15.2)(jiti@2.5.1)(lightningcss@1.30.1)(terser@5.43.1)(tsx@4.20.3)(yaml@2.8.0) @@ -5193,6 +5198,9 @@ packages: engines: {node: '>=8'} hasBin: true + launch-editor@2.11.1: + resolution: {integrity: sha512-SEET7oNfgSaB6Ym0jufAdCeo3meJVeCaaDyzRygy0xsp2BFKCprcfHljTq4QkzTLUxEKkFK6OK4811YM2oSrRg==} + lazystream@1.0.1: resolution: {integrity: sha512-b94GiNHQNy6JNTrt5w6zNyffMrNkXZb3KTkCZJb2V1xaEGCk093vkZ2jk3tpaeP33/OiXC+WvK9AxUebnf5nbw==} engines: {node: '>= 0.6.3'} @@ -6347,6 +6355,10 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} + shell-quote@1.8.3: + resolution: {integrity: sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==} + engines: {node: '>= 0.4'} + sherif-darwin-arm64@1.5.0: resolution: {integrity: sha512-4BYYCEXVJ8+xqfnntxnyGcwgByjrHSeKOitPYdBPMB3aauptC4GUMeVqXRXf5JNbx3lRKg8bZdoq0QPnbsr6BQ==} cpu: [arm64] @@ -12832,6 +12844,11 @@ snapshots: dotenv: 16.6.1 winston: 3.17.0 + launch-editor@2.11.1: + dependencies: + picocolors: 1.1.1 + shell-quote: 1.8.3 + lazystream@1.0.1: dependencies: readable-stream: 2.3.8 @@ -14181,6 +14198,8 @@ snapshots: shebang-regex@3.0.0: {} + shell-quote@1.8.3: {} + sherif-darwin-arm64@1.5.0: optional: true