@@ -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+
5758if ( 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
8184const EXT_DIRS = [
8285 path . join ( __dirname , '..' , 'dist' ) ,
8386 path . join ( __dirname , '..' , 'src' , 'temp-build' ) ,
8487] ;
8588
8689const 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+
92119const TEST_PATHS = [
93120 path . join ( __dirname , '..' , 'coverage' ) ,
94121 path . join ( __dirname , '..' , '.eslintcache' ) ,
0 commit comments