Skip to content

Commit f5aa1f0

Browse files
committed
refactor: use try/catch to remove dependency
1 parent 59b3d22 commit f5aa1f0

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

bun.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"@es-joy/resolve.exports": "^1.2.0",
88
"@microsoft/tsdoc": "^0.15.1",
99
"execa": "^9.6.0",
10-
"go-go-try": "^6.2.0",
1110
"memoize": "^10.2.0",
1211
"natural-orderby": "^5.0.0",
1312
"pathe": "^2.0.3",
@@ -20,6 +19,7 @@
2019
"@total-typescript/shoehorn": "^0.1.2",
2120
"@types/node": "^24.9.2",
2221
"@vitest/coverage-v8": "^4.0.5",
22+
"go-go-try": "^6.2.0",
2323
"np": "^10.2.0",
2424
"prettier-plugin-organize-imports": "^4.3.0",
2525
"ts-dedent": "^2.2.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"@es-joy/resolve.exports": "^1.2.0",
7070
"@microsoft/tsdoc": "^0.15.1",
7171
"execa": "^9.6.0",
72-
"go-go-try": "^6.2.0",
7372
"memoize": "^10.2.0",
7473
"natural-orderby": "^5.0.0",
7574
"pathe": "^2.0.3",
@@ -82,6 +81,7 @@
8281
"@total-typescript/shoehorn": "^0.1.2",
8382
"@types/node": "^24.9.2",
8483
"@vitest/coverage-v8": "^4.0.5",
84+
"go-go-try": "^6.2.0",
8585
"np": "^10.2.0",
8686
"prettier-plugin-organize-imports": "^4.3.0",
8787
"ts-dedent": "^2.2.0",

src/get-package-types.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { types as resolveTypes } from "@es-joy/resolve.exports";
2-
import { goTry } from "go-go-try";
32
import type { NormalizedPackageJson } from "read-pkg";
43

54
/** `GetPackageTypesOptions` contains the options for calling {@link getPackageTypes}. */
@@ -31,18 +30,20 @@ function getExportsMapTypes({
3130
pkgJson,
3231
subpath,
3332
}: 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) ?? [];
3838

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+
}
4647
}
4748

4849
function getTypesOrTypings({

0 commit comments

Comments
 (0)