vite-plugin-source-locator 1.1.2 → 1.1.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.
- package/README.md +7 -5
- package/dist/vite/editor-cli.d.ts +4 -0
- package/dist/vite/editor-cli.js +47 -0
- package/dist/vite/editors.js +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -149,7 +149,7 @@ By default, `ides` includes `'auto'` as the first entry. In `auto` mode, the plu
|
|
|
149
149
|
2. Running editor process (VS Code, Cursor, WebStorm, etc.)
|
|
150
150
|
3. `VISUAL` / `EDITOR` environment variable
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
The plugin resolves known app-bundle CLI paths automatically (e.g. VS Code on macOS). If detection still fails, install the editor shell command or set `LAUNCH_EDITOR` to the full CLI path.
|
|
153
153
|
|
|
154
154
|
```typescript
|
|
155
155
|
// auto-detect open IDE (default)
|
|
@@ -166,7 +166,7 @@ The first entry in `ides` is the default. Shift+L cycles through the list in mem
|
|
|
166
166
|
|
|
167
167
|
### Explicit editor
|
|
168
168
|
|
|
169
|
-
When not using `auto`, the
|
|
169
|
+
When not using `auto`, the plugin resolves common install paths first, then falls back to the CLI name on `PATH`:
|
|
170
170
|
|
|
171
171
|
| IDE | CLI command |
|
|
172
172
|
|-----|-------------|
|
|
@@ -174,10 +174,12 @@ When not using `auto`, the editor CLI should be on your `PATH`:
|
|
|
174
174
|
| VS Code | `code` |
|
|
175
175
|
| WebStorm | `webstorm` |
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
If opening fails with `ENOENT`, install the shell command in your editor (VS Code: **Shell Command: Install 'code' command in PATH**) or set a full path:
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
```
|
|
180
|
+
LAUNCH_EDITOR=/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code
|
|
181
|
+
REACT_EDITOR=/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code
|
|
182
|
+
```
|
|
181
183
|
|
|
182
184
|
## Adding a New IDE
|
|
183
185
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import guessEditor from 'launch-editor/guess.js';
|
|
3
|
+
const IDE_LAUNCH_NAMES = {
|
|
4
|
+
vscode: 'code',
|
|
5
|
+
cursor: 'cursor',
|
|
6
|
+
webstorm: 'webstorm',
|
|
7
|
+
};
|
|
8
|
+
function buildCliCandidates() {
|
|
9
|
+
if (process.platform === 'win32') {
|
|
10
|
+
const localAppData = process.env.LOCALAPPDATA ?? '';
|
|
11
|
+
const programFiles = process.env.ProgramFiles ?? 'C:\\Program Files';
|
|
12
|
+
return {
|
|
13
|
+
code: [
|
|
14
|
+
`${localAppData}\\Programs\\Microsoft VS Code\\bin\\code.cmd`,
|
|
15
|
+
`${programFiles}\\Microsoft VS Code\\bin\\code.cmd`,
|
|
16
|
+
'code',
|
|
17
|
+
],
|
|
18
|
+
cursor: [`${localAppData}\\Programs\\cursor\\Cursor.exe`, 'cursor'],
|
|
19
|
+
webstorm: [`${programFiles}\\JetBrains\\WebStorm\\bin\\webstorm64.exe`, 'webstorm'],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
code: ['/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code', 'code'],
|
|
24
|
+
cursor: ['/Applications/Cursor.app/Contents/Resources/app/bin/cursor', 'cursor'],
|
|
25
|
+
webstorm: ['/Applications/WebStorm.app/Contents/MacOS/webstorm', 'webstorm'],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const CLI_CANDIDATES = buildCliCandidates();
|
|
29
|
+
export function toLaunchEditorName(ide) {
|
|
30
|
+
return IDE_LAUNCH_NAMES[ide];
|
|
31
|
+
}
|
|
32
|
+
export function resolveCliPath(command) {
|
|
33
|
+
if ((command.includes('/') || command.includes('\\')) && existsSync(command)) {
|
|
34
|
+
return command;
|
|
35
|
+
}
|
|
36
|
+
const candidates = CLI_CANDIDATES[command] ?? [command];
|
|
37
|
+
const bundlePath = candidates.find((path) => (path.includes('/') || path.includes('\\')) && existsSync(path));
|
|
38
|
+
if (bundlePath)
|
|
39
|
+
return bundlePath;
|
|
40
|
+
return command;
|
|
41
|
+
}
|
|
42
|
+
export function resolveAutoEditor() {
|
|
43
|
+
const [editor] = guessEditor();
|
|
44
|
+
if (!editor)
|
|
45
|
+
return null;
|
|
46
|
+
return resolveCliPath(editor);
|
|
47
|
+
}
|
package/dist/vite/editors.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import launch from 'launch-editor';
|
|
2
2
|
import { resolveIde } from '../shared/index.js';
|
|
3
|
+
import { resolveAutoEditor, resolveCliPath, toLaunchEditorName } from './editor-cli.js';
|
|
3
4
|
export function openInEditor(loc, ideParam, allowed) {
|
|
4
5
|
const ide = resolveIde(ideParam, allowed);
|
|
5
6
|
const spec = `${loc.file}:${loc.line}:${loc.col}`;
|
|
6
7
|
if (ide === 'auto') {
|
|
8
|
+
const resolved = resolveAutoEditor();
|
|
9
|
+
if (resolved) {
|
|
10
|
+
launch(spec, resolved);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
7
13
|
launch(spec);
|
|
8
14
|
return;
|
|
9
15
|
}
|
|
10
|
-
|
|
16
|
+
const command = resolveCliPath(toLaunchEditorName(ide));
|
|
17
|
+
launch(spec, command);
|
|
11
18
|
}
|