-
Notifications
You must be signed in to change notification settings - Fork 16
/
unused.js
50 lines (44 loc) · 1011 Bytes
/
unused.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//@ts-check
import { execSync } from "child_process";
const args = process.argv.slice(2);
const update = args.includes("--update");
/**
* @typedef {{name: string, version: string, path: string, private:boolean}} Package
*/
/**
* @type {Package[]}
*/
const packages = JSON.parse(
execSync("pnpm ls -r --depth -1 --json", {
encoding: "utf-8",
})
);
for (const pkg of packages) {
checkPackage(pkg);
}
/**
* @param {Package} pkg
*/
function checkPackage(pkg) {
if (pkg.name === "@starbeam-workspace/root") {
console.log("Skipping root");
return;
}
console.group("Checking package", pkg.name);
try {
execSync(
`npm-check ${update ? "-u" : ""} -i rollup --specials eslint,babel`,
{
cwd: pkg.path,
stdio: "inherit",
}
);
} catch (e) {
console.log();
console.error("Unused dependencies in package", pkg.name);
console.log("Please fix them and then continue");
process.exit(1);
} finally {
console.groupEnd();
}
}