* Find the package root (the dir containing `bin/`). The built bundle lives in * `dist/`, so the package root is one level up; but be robust to either layout * by checking `./bin` and `../bin` relative to the module dir.
()
| 69 | * by checking `./bin` and `../bin` relative to the module dir. |
| 70 | */ |
| 71 | function packageBinDir(): string { |
| 72 | const here = moduleDir(); |
| 73 | const candidates = [ |
| 74 | join(here, "bin"), // module sits at package root (unbundled / tests) |
| 75 | join(here, "..", "bin"), // module sits in dist/ (the published bundle) |
| 76 | join(here, "..", "..", "bin"), |
| 77 | ]; |
| 78 | for (const c of candidates) { |
| 79 | if (existsSync(c)) return c; |
| 80 | } |
| 81 | // Default to the dist/.. layout even if the dir does not yet exist, so the |
| 82 | // error below names a sensible path. |
| 83 | return join(here, "..", "bin"); |
| 84 | } |
| 85 | |
| 86 | export function locateBinary(): string { |
| 87 | const override = process.env.CMDOP_CORE_BINARY; |
no test coverage detected