Skip to content

Commit 96d337e

Browse files
committed
Add more core node_modules folders
1 parent 4e993a2 commit 96d337e

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

scripts/delete-temp-files.cjs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function printUsageAndExit(code = 0) {
3030
);
3131
console.info(' --core Delete Electron and core caches (Electron, dev-appdata)');
3232
console.info(' --ext Delete extension builds (dist, src/temp-build)');
33-
console.info(' --npm Delete extension package-lock.json and both node_modules');
33+
console.info(' --npm Delete extension package-lock.json and all node_modules');
3434
console.info(' --test Delete extension test/lint-related files');
3535
console.info(' --yalc Delete core yalc-related files');
3636
console.info(' --all Delete all of the above');
@@ -53,8 +53,12 @@ const shouldDeleteYalc = hasAllFlag || hasYalcFlag;
5353

5454
// Define directory lists
5555

56-
let electronParent = '';
56+
const CORE_DIRS = [path.join(__dirname, '..', '..', 'paranext-core', 'dev-appdata')];
57+
5758
if (shouldDeleteCore) {
59+
// Determine Electron cache directory based on platform and add to `CORE_DIRS`
60+
let electronParent = '';
61+
5862
/* eslint-disable no-nested-ternary */
5963
electronParent =
6064
process.platform === 'win32'
@@ -71,24 +75,47 @@ if (shouldDeleteCore) {
7175
: '';
7276
}
7377
/* eslint-enable no-nested-ternary */
74-
}
7578

76-
const CORE_DIRS = [
77-
electronParent ? path.join(electronParent, 'Electron') : '',
78-
path.join(__dirname, '..', '..', 'paranext-core', 'dev-appdata'),
79-
];
79+
if (electronParent) {
80+
CORE_DIRS.push(path.join(electronParent, 'Electron Cache'));
81+
}
82+
}
8083

8184
const EXT_DIRS = [
8285
path.join(__dirname, '..', 'dist'),
8386
path.join(__dirname, '..', 'src', 'temp-build'),
8487
];
8588

8689
const NPM_PATHS = [
87-
path.join(__dirname, '..', '..', 'paranext-core', 'node_modules'),
8890
path.join(__dirname, '..', 'node_modules'),
8991
path.join(__dirname, '..', 'package-lock.json'),
9092
];
9193

94+
if (shouldDeleteNpm) {
95+
// Recursively find `node_modules` folders in `paranext-core/` and add them to `NPM_PATHS`
96+
const corePath = path.join(__dirname, '..', '..', 'paranext-core');
97+
const SKIP_DIRS = new Set(['dev-appdata', 'dev-packages']);
98+
const findNodeModules = (dir) => {
99+
let entries;
100+
try {
101+
entries = fs.readdirSync(dir, { withFileTypes: true });
102+
} catch {
103+
return;
104+
}
105+
entries
106+
.filter((entry) => entry.isDirectory() && !SKIP_DIRS.has(entry.name))
107+
.forEach((entry) => {
108+
const fullPath = path.join(dir, entry.name);
109+
if (entry.name === 'node_modules') {
110+
NPM_PATHS.push(fullPath);
111+
} else {
112+
findNodeModules(fullPath);
113+
}
114+
});
115+
};
116+
findNodeModules(corePath);
117+
}
118+
92119
const TEST_PATHS = [
93120
path.join(__dirname, '..', 'coverage'),
94121
path.join(__dirname, '..', '.eslintcache'),

0 commit comments

Comments
 (0)