@@ -68,21 +68,26 @@ jobs:
6868 const config = JSON.parse(fs.readFileSync(".changeset/config.json", "utf8"));
6969 const fixed = new Set((config.fixed || []).flat());
7070 const roots = ["packages", "apps"];
71- const results = [];
71+ const skipDirNames = new Set(["dist", "node_modules", ".git", ".nx"]);
72+ const packagePathByName = new Map();
7273
7374 function walk(dir) {
7475 if (!fs.existsSync(dir)) return;
7576 for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
7677 const fullPath = path.join(dir, entry.name);
7778 if (entry.isDirectory()) {
79+ if (skipDirNames.has(entry.name)) continue;
7880 walk(fullPath);
7981 continue;
8082 }
8183 if (entry.isFile() && entry.name === "package.json") {
8284 const pkgDir = path.dirname(fullPath);
8385 const pkg = JSON.parse(fs.readFileSync(fullPath, "utf8"));
8486 if (fixed.has(pkg.name) && pkg.private !== true) {
85- results.push(pkgDir);
87+ const existing = packagePathByName.get(pkg.name);
88+ if (!existing || pkgDir.length < existing.length) {
89+ packagePathByName.set(pkg.name, pkgDir);
90+ }
8691 }
8792 }
8893 }
9297 walk(root);
9398 }
9499
95- // Deduplicate and sort for stable output.
96- const sorted = Array.from(new Set(results )).sort();
100+ // Deduplicate by package name and sort for stable output.
101+ const sorted = Array.from(packagePathByName.values( )).sort();
97102 process.stdout.write(JSON.stringify(sorted));
98103 ')
99104
0 commit comments