Skip to content

Commit 83dc6f8

Browse files
committed
feat: handle DT package in handlePackage
1 parent fc0d31f commit 83dc6f8

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

lib/handlers/package/handle-package.ts

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Bun, getPackageJson } from "@jsdocs-io/extractor";
1+
import { Bun, getPackageJson, getPackageTypes } from "@jsdocs-io/extractor";
22
import { goTry } from "go-go-try";
33
import { join } from "pathe";
44
import { serverEnv } from "../../server-env";
55
import { checkLicense } from "../../utils/check-license";
6+
import { getDTPackageName, isDTPackage } from "../../utils/definitely-typed";
67
import { packageId } from "../../utils/package-id";
78
import { resolvePackage } from "../../utils/resolve-package";
89
import { tempDir } from "../../utils/temp-dir";
@@ -71,33 +72,49 @@ export async function handlePackage(slug: string) {
7172
};
7273
}
7374

74-
// TODO:
75-
// // Check if the package provides type definitions and if not
76-
// // check if there is an associated DefinitelyTyped (DT) package.
77-
// const typesRes = yield * Effect.either(packageTypes(pkgJson, subpath));
78-
// if (Either.isLeft(typesRes)) {
79-
// const dtPkgName = yield * findDefinitelyTypedPackage({ pkgName, cwd });
80-
// if (!dtPkgName) {
81-
// yield * Effect.logWarning(`no types: ${pkgId}`);
82-
// return {
83-
// status: "no-types" as const,
84-
// pkgId,
85-
// subpath,
86-
// pkgJson,
87-
// generatedAt: generatedAt(),
88-
// generatedIn: generatedIn(start),
89-
// };
90-
// }
91-
// return {
92-
// status: "definitely-typed" as const,
93-
// pkgId,
94-
// subpath,
95-
// pkgJson,
96-
// dtPkgName,
97-
// generatedAt: generatedAt(),
98-
// generatedIn: generatedIn(start),
99-
// };
100-
// }
75+
// Check if the package provides type definitions and if not
76+
// check if there is a corresponding DefinitelyTyped (DT) package.
77+
const types = getPackageTypes({ pkgJson, subpath });
78+
if (!types) {
79+
// A DT package without types is deprecated.
80+
if (isDTPackage(pkgName)) {
81+
log.warn({ warn: "deprecated DT package" });
82+
return {
83+
status: "deprecated-dt-pkg" as const,
84+
pkgId,
85+
subpath,
86+
pkgJson,
87+
generatedAt: generatedAt(),
88+
generatedIn: generatedIn(start),
89+
};
90+
}
91+
92+
// Try to install the corresponding DT package to check if it exists.
93+
const dtPkgName = getDTPackageName(pkgName);
94+
const [bunErr] = await goTry(bun.add(dtPkgName, cwd));
95+
if (bunErr !== undefined) {
96+
log.warn({ warn: "no-dt-pkg" });
97+
return {
98+
status: "no-types" as const,
99+
pkgId,
100+
subpath,
101+
pkgJson,
102+
generatedAt: generatedAt(),
103+
generatedIn: generatedIn(start),
104+
};
105+
}
106+
107+
// A DT package exists.
108+
return {
109+
status: "has-dt-pkg" as const,
110+
pkgId,
111+
subpath,
112+
pkgJson,
113+
dtPkgName,
114+
generatedAt: generatedAt(),
115+
generatedIn: generatedIn(start),
116+
};
117+
}
101118

102119
// // Check if the DB already has the package API.
103120
// const db = yield * Db;

0 commit comments

Comments
 (0)