(
deps: Partial<DetectInstallSourceDeps> = {},
)
| 133 | } |
| 134 | |
| 135 | export async function detectInstallSource( |
| 136 | deps: Partial<DetectInstallSourceDeps> = {}, |
| 137 | ): Promise<InstallSource> { |
| 138 | const platform = deps.platform ?? process.platform; |
| 139 | const resolved: DetectInstallSourceDeps = { |
| 140 | getPackageRoot: deps.getPackageRoot ?? getHostPackageRoot, |
| 141 | getGlobalPrefix: |
| 142 | deps.getGlobalPrefix ?? |
| 143 | (() => execFileText(npmCommand(platform), ['prefix', '-g']).then((text) => text.trim())), |
| 144 | detectNative: deps.detectNative ?? detectNativeInstall, |
| 145 | platform, |
| 146 | }; |
| 147 | |
| 148 | if (resolved.detectNative()) return 'native'; |
| 149 | |
| 150 | const packageRoot = resolved.getPackageRoot(); |
| 151 | const heuristic = classifyByPathHeuristic(packageRoot); |
| 152 | if (heuristic !== null) return heuristic; |
| 153 | |
| 154 | try { |
| 155 | const globalPrefix = await resolved.getGlobalPrefix(); |
| 156 | return classifyInstallSource(packageRoot, globalPrefix, resolved.platform); |
| 157 | } catch { |
| 158 | return 'unsupported'; |
| 159 | } |
| 160 | } |
no test coverage detected