scripts/check-type-dependencies: work around exports resolution

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-09-01 00:53:53 +02:00
parent 24b06ff92b
commit 6fb165fbd4
+12 -1
View File
@@ -136,10 +136,21 @@ function findTypesPackage(dep, pkg) {
return undefined;
} catch {
try {
// Finally check if it's just a .d.ts file
// Check if it's just a .d.ts file
require.resolve(`${dep}.d.ts`, { paths: [pkg.dir] });
return undefined;
} catch {
// And finally a naive lookup of the file directly, in case `require.resolve` fails us due to "exports"
if (fs.existsSync(resolvePath(pkg.dir, `node_modules/${dep}.d.ts`))) {
return undefined;
}
if (
fs.existsSync(
resolvePath(pkg.dir, `../../node_modules/${dep}.d.ts`),
)
) {
return undefined;
}
throw mkErr('MissingDepError', `No types for ${dep}`, { dep });
}
}