(moduleEntry: string)
| 3 | import { createRequire } from "module"; |
| 4 | |
| 5 | export const getModuleDir = (moduleEntry: string) => { |
| 6 | const packageName = moduleEntry.includes("/") |
| 7 | ? moduleEntry.startsWith("@") |
| 8 | ? moduleEntry.split("/").slice(0, 2).join("/") |
| 9 | : moduleEntry.split("/")[0] |
| 10 | : moduleEntry; |
| 11 | const require = createRequire(import.meta.url); |
| 12 | const lookupPaths = require.resolve |
| 13 | .paths(moduleEntry)! |
| 14 | .map((p) => path.join(p, packageName)); |
| 15 | return lookupPaths.find((p) => fs.existsSync(p)); |
| 16 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected