-
Notifications
You must be signed in to change notification settings - Fork 0
/
prune_deps.cjs
46 lines (42 loc) · 1.14 KB
/
prune_deps.cjs
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
const fs = require('fs');
const path = require('path');
const REMOVE_DEPENDENCIES = [
'@types',
'c8',
'cssnano',
'commitlint',
'eslint',
'husky',
'jsdom',
'lint-staged',
'playwright',
'pre-commit',
'prettier',
'safaridriver',
'testing-library',
'tslib',
'typescript',
'vitest',
'webdriverio',
];
const PRESERVE_DEPENDENCIES = ['vite-node@', 'vite@'];
const pnpmStoreFolderPath = path.resolve(__dirname, 'node_modules/.pnpm');
let removeFolders = [];
const dirents = fs.readdirSync(pnpmStoreFolderPath, { withFileTypes: true });
for (const dirent of dirents) {
if (dirent.isDirectory()) {
REMOVE_DEPENDENCIES.forEach((removeName) => {
if (
dirent.name.includes(removeName) &&
!PRESERVE_DEPENDENCIES.some((keepDepName) => dirent.name.includes(keepDepName))
) {
const folderPath = path.resolve(pnpmStoreFolderPath, dirent.name);
removeFolders.push(folderPath);
}
});
}
}
removeFolders = [...new Set(removeFolders)];
removeFolders.forEach((dir) => fs.rmSync(dir, { recursive: true }));
console.log(`${removeFolders.length} total folders were removed:\n`);
removeFolders.forEach((dir) => console.log(`\t- ${dir}`));