Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions scripts/check-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ function extractImports(src) {

return imports;
}

// Helper to parse JSON files with comments and trailing commas (JSONC) commonly found in tsconfig.json
function parseJsonc(content) {
const clean = content
.replace(/\/\*[\s\S]*?\*\//g, "")
.replace(/(^|[^:])\/\/.*$/gm, "$1")
.replace(/,\s*([\]}])/g, "$1");
return JSON.parse(clean);
}

function loadConfigWithExtends(configPath) {
const config = JSON.parse(
const config = parseJsonc(
fs.readFileSync(configPath, "utf8")
);

Expand Down Expand Up @@ -98,6 +108,7 @@ function loadConfigWithExtends(configPath) {
},
};
}

function loadInternalAliases(rootDir) {
const aliases = ["@/", "~/", "src/"];

Expand Down Expand Up @@ -128,6 +139,7 @@ function loadInternalAliases(rootDir) {

return aliases;
}

function isValidPackageSubpath(pkgName, mod, cwd) {
try {
let pkgJson;
Expand Down Expand Up @@ -158,18 +170,38 @@ function isValidPackageSubpath(pkgName, mod, cwd) {
const exportKey =
"." + (subpath.startsWith("/") ? subpath : "/" + subpath);

if (typeof exportsField === "string") {
if (typeof exportsField === "string" || Array.isArray(exportsField)) {
return exportKey === ".";
}

const keys = Object.keys(exportsField);

// Check if it's a root conditional export mapping (no keys start with ".")
const isRootConditional = keys.length > 0 && keys.every(k => !k.startsWith("."));
if (isRootConditional) {
return exportKey === ".";
}

return (
exportKey in exportsField ||
"./*" in exportsField
);
if (exportKey in exportsField || "./*" in exportsField) {
return true;
}

// Resolve advanced wildcard exports (e.g., "./features/*")
for (const key of keys) {
if (key.endsWith("/*")) {
const prefix = key.slice(0, -2);
if (exportKey.startsWith(prefix + "/")) {
return true;
}
}
}

return false;
} catch {
return true;
}
}

function collectMissingDeps(files, allDeps, cwd = process.cwd()) {
const missing = new Map(); // pkgName β†’ Set of files
// Load Aliases
Expand Down Expand Up @@ -212,7 +244,7 @@ function collectMissingDeps(files, allDeps, cwd = process.cwd()) {
}

continue;
}
}

if (!missing.has(pkgName)) missing.set(pkgName, new Set());
missing.get(pkgName).add(rel);
Expand Down
Loading