|
1 | 1 | import { types as resolveTypes } from "@es-joy/resolve.exports"; |
2 | | -import { goTry } from "go-go-try"; |
3 | 2 | import type { NormalizedPackageJson } from "read-pkg"; |
4 | 3 |
|
5 | 4 | /** `GetPackageTypesOptions` contains the options for calling {@link getPackageTypes}. */ |
@@ -31,18 +30,20 @@ function getExportsMapTypes({ |
31 | 30 | pkgJson, |
32 | 31 | subpath, |
33 | 32 | }: Required<GetPackageTypesOptions>): string | undefined { |
34 | | - // Try to resolve the `exports` map in `package.json` |
35 | | - // with conditions `import` and `types` enabled to find |
36 | | - // a valid TypeScript type definitions file. |
37 | | - const [err, entries = []] = goTry(() => resolveTypes(pkgJson, subpath)); |
| 33 | + try { |
| 34 | + // Try to resolve the `exports` map in `package.json` |
| 35 | + // with conditions `import` and `types` enabled to find |
| 36 | + // a valid TypeScript type definitions file. |
| 37 | + const entries = resolveTypes(pkgJson, subpath) ?? []; |
38 | 38 |
|
39 | | - // The package may not have an `exports` map. |
40 | | - if (err !== undefined) return undefined; |
41 | | - |
42 | | - // Return first entry, if valid. |
43 | | - const entry = entries.at(0); |
44 | | - if (!entry || !isTypesFile(entry)) return undefined; |
45 | | - return entry; |
| 39 | + // Return first entry, if valid. |
| 40 | + const entry = entries.at(0); |
| 41 | + if (!entry || !isTypesFile(entry)) return undefined; |
| 42 | + return entry; |
| 43 | + } catch { |
| 44 | + // The package may not have an `exports` map. |
| 45 | + return undefined; |
| 46 | + } |
46 | 47 | } |
47 | 48 |
|
48 | 49 | function getTypesOrTypings({ |
|
0 commit comments