Skip to content

Commit ca08a50

Browse files
authored
Merge pull request #245 from arethetypeswrong/bug/no-proxy-dirs-in-vendor
Do not detect proxy directories inside vendor directories as entrypoints
2 parents ed8ea33 + a4dc8a6 commit ca08a50

File tree

4 files changed

+575
-12
lines changed

4 files changed

+575
-12
lines changed

.changeset/cold-wasps-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/core": patch
3+
---
4+
5+
Do not detect proxy directories inside vendor directories as entrypoints

packages/core/src/internal/getEntrypointInfo.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function getEntrypoints(fs: Package, exportsObject: unknown, options: CheckPacka
5353
});
5454
});
5555
}
56+
5657
function formatEntrypointString(path: string, packageName: string) {
5758
return (
5859
path === "." || path.startsWith("./")
@@ -64,6 +65,7 @@ function formatEntrypointString(path: string, packageName: string) {
6465
: `./${path}`
6566
).trim();
6667
}
68+
6769
function getSubpaths(exportsObject: any): string[] {
6870
if (!exportsObject || typeof exportsObject !== "object" || Array.isArray(exportsObject)) {
6971
return [];
@@ -74,22 +76,41 @@ function getSubpaths(exportsObject: any): string[] {
7476
}
7577
return keys.flatMap((key) => getSubpaths(exportsObject[key]));
7678
}
79+
7780
function getProxyDirectories(rootDir: string, fs: Package) {
78-
return fs
79-
.listFiles()
80-
.filter((f) => f.startsWith(rootDir) && f.endsWith("package.json"))
81-
.filter((f) => {
81+
const vendorDirectories = new Set<string>();
82+
const proxyDirectories: string[] = [];
83+
const files = fs.listFiles().sort((a, b) => a.length - b.length);
84+
for (const file of files) {
85+
if (file.startsWith(rootDir) && file.endsWith("/package.json")) {
8286
try {
83-
const packageJson = JSON.parse(fs.readFile(f));
84-
return "main" in packageJson && (!packageJson.name || packageJson.name.startsWith(fs.packageName));
85-
} catch {
86-
return false;
87+
const packageJson = JSON.parse(fs.readFile(file));
88+
if (packageJson.name && !packageJson.name.startsWith(fs.packageName)) {
89+
// Name unrelated to the root package, this is a vendored package
90+
const vendorDir = file.slice(0, file.lastIndexOf("/"));
91+
vendorDirectories.add(vendorDir);
92+
} else if ("main" in packageJson && !isInsideVendorDirectory(file)) {
93+
// No name or name starting with root package name, this is intended to be an entrypoint
94+
const proxyDir = "." + file.slice(rootDir.length, file.lastIndexOf("/"));
95+
proxyDirectories.push(proxyDir);
96+
}
97+
} catch {}
98+
}
99+
}
100+
101+
return proxyDirectories.sort((a, b) => {
102+
return ts.comparePathsCaseInsensitive(a, b);
103+
});
104+
105+
function isInsideVendorDirectory(file: string) {
106+
return !!ts.forEachAncestorDirectory(file, (dir) => {
107+
if (vendorDirectories.has(dir)) {
108+
return true;
87109
}
88-
})
89-
.map((f) => "." + f.slice(rootDir.length).slice(0, -`/package.json`.length))
90-
.filter((f) => f !== "./")
91-
.sort();
110+
});
111+
}
92112
}
113+
93114
export function getEntrypointInfo(
94115
packageName: string,
95116
fs: Package,
2.63 MB
Binary file not shown.

0 commit comments

Comments
 (0)