| 176 | } |
| 177 | |
| 178 | function resolveEntrypoint(): string { |
| 179 | const argvPath = process.argv[1]; |
| 180 | if (argvPath) { |
| 181 | try { |
| 182 | return fs.realpathSync(argvPath); |
| 183 | } catch { |
| 184 | // fall through to import.meta.url |
| 185 | } |
| 186 | } |
| 187 | // import.meta.url is the real file:// URL of the running module, which |
| 188 | // already points inside node_modules for a global install. |
| 189 | if (typeof import.meta.url === "string" && import.meta.url) { |
| 190 | return import.meta.url; |
| 191 | } |
| 192 | return ""; |
| 193 | } |
| 194 | |
| 195 | /** Best-effort: run `npm root -g` so we can show the install location. */ |
| 196 | export async function getGlobalInstallRoot(): Promise<string | null> { |