()
| 27 | } |
| 28 | |
| 29 | export function getPackageRoot(): string { |
| 30 | if (cachedPackageRoot) { |
| 31 | return cachedPackageRoot; |
| 32 | } |
| 33 | |
| 34 | const candidates: string[] = []; |
| 35 | const importMetaUrl = typeof import.meta.url === 'string' ? import.meta.url : null; |
| 36 | if (importMetaUrl) { |
| 37 | candidates.push(path.dirname(fileURLToPath(importMetaUrl))); |
| 38 | } |
| 39 | candidates.push(process.cwd()); |
| 40 | const entry = process.argv[1]; |
| 41 | if (entry) { |
| 42 | candidates.push(path.dirname(entry)); |
| 43 | } |
| 44 | |
| 45 | for (const candidate of candidates) { |
| 46 | const found = findPackageRootFrom(candidate); |
| 47 | if (found) { |
| 48 | cachedPackageRoot = found; |
| 49 | return found; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | throw new Error('Could not find package root (no package.json found in parent directories)'); |
| 54 | } |
| 55 | |
| 56 | function getExecutableResourceRoot(): string | null { |
| 57 | const execPath = process.execPath; |
no test coverage detected