-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom-path.ts
More file actions
33 lines (29 loc) · 1.24 KB
/
from-path.ts
File metadata and controls
33 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @file `skillspectorFromPath()` — `which skillspector` lookup. Reports
* `source: 'pipx'` when the resolved path lives under a `pipx/venvs/`
* directory (the dev's `pipx install skillspector` path); reports `source:
* 'path'` otherwise (a one-off binary on PATH).
*/
import { which } from '../../bin/which'
import { normalizePath } from '../../paths/normalize'
import type { ResolvedSkillSpector } from './types'
// pipx puts venvs under either:
// ~/.local/pipx/venvs/<pkg>/bin/<entry-point> (linux/macOS)
// ~/.local/share/pipx/venvs/<pkg>/bin/<entry-point> (XDG)
// %USERPROFILE%\pipx\venvs\<pkg>\Scripts\<entry-point> (windows)
// Match against the forward-slash form only — normalizePath drops
// the Windows backslash variant so the regex stays single-shape.
const PIPX_PATH_SEGMENT_RE = /pipx\/venvs\//
export async function skillspectorFromPath(): Promise<
ResolvedSkillSpector | undefined
> {
const resolved = await which('skillspector', { nothrow: true })
if (typeof resolved !== 'string') {
return undefined
}
const normalized = normalizePath(resolved)
if (PIPX_PATH_SEGMENT_RE.test(normalized)) {
return { path: normalized, source: 'pipx' }
}
return { path: normalized, source: 'path' }
}