From 39ade83ea366f803036841bdc42cd59378e64cd5 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Thu, 14 May 2026 14:39:33 -0400 Subject: [PATCH 1/5] Add yalc-files to the delete script --- package.json | 2 +- scripts/delete-temp-files.cjs | 36 +++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 578bbd8f..e92f2e84 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "core:start": "npm --prefix ../paranext-core start", "core:stop": "npm --prefix ../paranext-core stop", "core:reset": "npm run core:stop && node ./scripts/delete-temp-files.cjs --core --ext", - "core:reinstall": "npm run core:reset && node ./scripts/delete-temp-files.cjs --npm && npm run core:update && npm i", + "core:reinstall": "npm run core:stop && node ./scripts/delete-temp-files.cjs --all && npm run core:update && npm i", "core:install": "npm --prefix ../paranext-core install", "core:pull": "git -C ../paranext-core pull --ff-only", "core:update": "npm run core:pull && npm run core:install" diff --git a/scripts/delete-temp-files.cjs b/scripts/delete-temp-files.cjs index f88cfb63..9b880d69 100644 --- a/scripts/delete-temp-files.cjs +++ b/scripts/delete-temp-files.cjs @@ -9,26 +9,39 @@ const path = require('path'); * * - The `Electron` cache folder, which affect any other Electron apps * - `paranext-core/dev-appdata/`, which includes `installed-extensions/` + * + * Warning: The `--yalc` flag deletion includes: + * + * - `paranext-core/dev-packages/`, which makes the core re-install last minutes longer */ // Check command-line arguments +const hasAllFlag = process.argv.includes('--all'); const hasCoreFlag = process.argv.includes('--core'); const hasExtFlag = process.argv.includes('--ext'); const hasNpmFlag = process.argv.includes('--npm'); +const hasYalcFlag = process.argv.includes('--yalc'); -if (!hasCoreFlag && !hasExtFlag && !hasNpmFlag) { - console.error('Usage: node delete-temp-files.cjs [--core] [--ext] [--npm]'); +if (!hasAllFlag && !hasCoreFlag && !hasExtFlag && !hasNpmFlag && !hasYalcFlag) { + console.error('Usage: node delete-temp-files.cjs [--all] [--core] [--ext] [--npm] [--yalc]'); console.error(' --core Delete Electron and core caches (Electron, dev-appdata)'); console.error(' --ext Delete extension directories (coverage, dist, src/temp-build)'); console.error(' --npm Delete both node_modules and extension package-lock.json'); + console.error(' --yalc Delete core yalc-related files'); + console.error(' --all Delete all of the above'); process.exit(1); } +const shouldDeleteCore = hasAllFlag || hasCoreFlag; +const shouldDeleteExt = hasAllFlag || hasExtFlag; +const shouldDeleteNpm = hasAllFlag || hasNpmFlag; +const shouldDeleteYalc = hasAllFlag || hasYalcFlag; + // Define directory lists let electronParent = ''; -if (hasCoreFlag) { +if (shouldDeleteCore) { /* eslint-disable no-nested-ternary */ electronParent = process.platform === 'win32' @@ -64,6 +77,12 @@ const NPM_PATHS = [ path.join(__dirname, '..', 'package-lock.json'), ]; +const YALC_PATHS = [ + path.join(__dirname, '..', '..', 'paranext-core', '.yalc'), + path.join(__dirname, '..', '..', 'paranext-core', 'dev-packages'), + path.join(__dirname, '..', '..', 'paranext-core', 'yalc.lock'), +]; + /** * Delete a path if it exists * @@ -90,21 +109,26 @@ function deletePath(pathToDelete) { // Delete paths based on command-line flags try { - if (hasCoreFlag) { + if (shouldDeleteCore) { console.log('Deleting core cache directories...'); CORE_DIRS.forEach(deletePath); } - if (hasExtFlag) { + if (shouldDeleteExt) { console.log('Deleting extension directories...'); EXT_DIRS.forEach(deletePath); } - if (hasNpmFlag) { + if (shouldDeleteNpm) { console.log('Deleting node_modules and package-lock.json...'); NPM_PATHS.forEach(deletePath); } + if (shouldDeleteYalc) { + console.log('Deleting core yalc-related files...'); + YALC_PATHS.forEach(deletePath); + } + console.log('Complete!'); process.exit(0); } catch (error) { From 4e993a28136637a421e729f8c373aeb75df8faa4 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Fri, 15 May 2026 10:11:04 -0400 Subject: [PATCH 2/5] Update script --- scripts/delete-temp-files.cjs | 42 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/scripts/delete-temp-files.cjs b/scripts/delete-temp-files.cjs index 9b880d69..b8bebc6e 100644 --- a/scripts/delete-temp-files.cjs +++ b/scripts/delete-temp-files.cjs @@ -21,21 +21,34 @@ const hasAllFlag = process.argv.includes('--all'); const hasCoreFlag = process.argv.includes('--core'); const hasExtFlag = process.argv.includes('--ext'); const hasNpmFlag = process.argv.includes('--npm'); +const hasTestFlag = process.argv.includes('--test'); const hasYalcFlag = process.argv.includes('--yalc'); -if (!hasAllFlag && !hasCoreFlag && !hasExtFlag && !hasNpmFlag && !hasYalcFlag) { - console.error('Usage: node delete-temp-files.cjs [--all] [--core] [--ext] [--npm] [--yalc]'); - console.error(' --core Delete Electron and core caches (Electron, dev-appdata)'); - console.error(' --ext Delete extension directories (coverage, dist, src/temp-build)'); - console.error(' --npm Delete both node_modules and extension package-lock.json'); - console.error(' --yalc Delete core yalc-related files'); - console.error(' --all Delete all of the above'); - process.exit(1); +function printUsageAndExit(code = 0) { + console.info( + 'Usage: node delete-temp-files.cjs [--all] [--core] [--ext] [--npm] [--test] [--yalc]', + ); + console.info(' --core Delete Electron and core caches (Electron, dev-appdata)'); + console.info(' --ext Delete extension builds (dist, src/temp-build)'); + console.info(' --npm Delete extension package-lock.json and both node_modules'); + console.info(' --test Delete extension test/lint-related files'); + console.info(' --yalc Delete core yalc-related files'); + console.info(' --all Delete all of the above'); + process.exit(code); +} + +if (process.argv.length <= 2 || process.argv.includes('--help') || process.argv.includes('-h')) { + printUsageAndExit(); +} + +if (!hasAllFlag && !hasCoreFlag && !hasExtFlag && !hasNpmFlag && !hasTestFlag && !hasYalcFlag) { + printUsageAndExit(1); } const shouldDeleteCore = hasAllFlag || hasCoreFlag; const shouldDeleteExt = hasAllFlag || hasExtFlag; const shouldDeleteNpm = hasAllFlag || hasNpmFlag; +const shouldDeleteTest = hasAllFlag || hasTestFlag; const shouldDeleteYalc = hasAllFlag || hasYalcFlag; // Define directory lists @@ -66,7 +79,6 @@ const CORE_DIRS = [ ]; const EXT_DIRS = [ - path.join(__dirname, '..', 'coverage'), path.join(__dirname, '..', 'dist'), path.join(__dirname, '..', 'src', 'temp-build'), ]; @@ -77,6 +89,11 @@ const NPM_PATHS = [ path.join(__dirname, '..', 'package-lock.json'), ]; +const TEST_PATHS = [ + path.join(__dirname, '..', 'coverage'), + path.join(__dirname, '..', '.eslintcache'), +]; + const YALC_PATHS = [ path.join(__dirname, '..', '..', 'paranext-core', '.yalc'), path.join(__dirname, '..', '..', 'paranext-core', 'dev-packages'), @@ -97,7 +114,7 @@ function deletePath(pathToDelete) { try { if (fs.existsSync(pathToDelete)) { fs.rmSync(pathToDelete, { recursive: true, force: true }); - console.log(`✓ Deleted ${pathToDelete}`); + console.log(`✓ ${pathToDelete} deleted`); } else { console.log(`⊘ ${pathToDelete} does not exist`); } @@ -124,6 +141,11 @@ try { NPM_PATHS.forEach(deletePath); } + if (shouldDeleteTest) { + console.log('Deleting extension test- and lint-related files...'); + TEST_PATHS.forEach(deletePath); + } + if (shouldDeleteYalc) { console.log('Deleting core yalc-related files...'); YALC_PATHS.forEach(deletePath); From 96d337ea25892df0a239b24524b0d32f3d42e68d Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Fri, 15 May 2026 15:42:12 -0400 Subject: [PATCH 3/5] Add more core node_modules folders --- scripts/delete-temp-files.cjs | 43 ++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/scripts/delete-temp-files.cjs b/scripts/delete-temp-files.cjs index b8bebc6e..1924ffb9 100644 --- a/scripts/delete-temp-files.cjs +++ b/scripts/delete-temp-files.cjs @@ -30,7 +30,7 @@ function printUsageAndExit(code = 0) { ); console.info(' --core Delete Electron and core caches (Electron, dev-appdata)'); console.info(' --ext Delete extension builds (dist, src/temp-build)'); - console.info(' --npm Delete extension package-lock.json and both node_modules'); + console.info(' --npm Delete extension package-lock.json and all node_modules'); console.info(' --test Delete extension test/lint-related files'); console.info(' --yalc Delete core yalc-related files'); console.info(' --all Delete all of the above'); @@ -53,8 +53,12 @@ const shouldDeleteYalc = hasAllFlag || hasYalcFlag; // Define directory lists -let electronParent = ''; +const CORE_DIRS = [path.join(__dirname, '..', '..', 'paranext-core', 'dev-appdata')]; + if (shouldDeleteCore) { + // Determine Electron cache directory based on platform and add to `CORE_DIRS` + let electronParent = ''; + /* eslint-disable no-nested-ternary */ electronParent = process.platform === 'win32' @@ -71,12 +75,11 @@ if (shouldDeleteCore) { : ''; } /* eslint-enable no-nested-ternary */ -} -const CORE_DIRS = [ - electronParent ? path.join(electronParent, 'Electron') : '', - path.join(__dirname, '..', '..', 'paranext-core', 'dev-appdata'), -]; + if (electronParent) { + CORE_DIRS.push(path.join(electronParent, 'Electron Cache')); + } +} const EXT_DIRS = [ path.join(__dirname, '..', 'dist'), @@ -84,11 +87,35 @@ const EXT_DIRS = [ ]; const NPM_PATHS = [ - path.join(__dirname, '..', '..', 'paranext-core', 'node_modules'), path.join(__dirname, '..', 'node_modules'), path.join(__dirname, '..', 'package-lock.json'), ]; +if (shouldDeleteNpm) { + // Recursively find `node_modules` folders in `paranext-core/` and add them to `NPM_PATHS` + const corePath = path.join(__dirname, '..', '..', 'paranext-core'); + const SKIP_DIRS = new Set(['dev-appdata', 'dev-packages']); + const findNodeModules = (dir) => { + let entries; + try { + entries = fs.readdirSync(dir, { withFileTypes: true }); + } catch { + return; + } + entries + .filter((entry) => entry.isDirectory() && !SKIP_DIRS.has(entry.name)) + .forEach((entry) => { + const fullPath = path.join(dir, entry.name); + if (entry.name === 'node_modules') { + NPM_PATHS.push(fullPath); + } else { + findNodeModules(fullPath); + } + }); + }; + findNodeModules(corePath); +} + const TEST_PATHS = [ path.join(__dirname, '..', 'coverage'), path.join(__dirname, '..', '.eslintcache'), From f2fffc3aca8413a3a6cadebabad281cf7905e4b7 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Fri, 15 May 2026 16:23:35 -0400 Subject: [PATCH 4/5] Delete temp build paths --- scripts/delete-temp-files.cjs | 129 +++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 55 deletions(-) diff --git a/scripts/delete-temp-files.cjs b/scripts/delete-temp-files.cjs index 1924ffb9..d3d9cd67 100644 --- a/scripts/delete-temp-files.cjs +++ b/scripts/delete-temp-files.cjs @@ -5,6 +5,10 @@ const path = require('path'); * Cross-platform script to delete temporary and cache paths. Run this if Platform.Bible is holding * on to outdated resources, such as localization strings, project data, or WebView ids. * + * Warning: The `--build` flag deletes: + * + * - All core extension builds, which makes the next core:start last minutes longer + * * Warning: The `--core` flag deletes: * * - The `Electron` cache folder, which affect any other Electron apps @@ -12,22 +16,24 @@ const path = require('path'); * * Warning: The `--yalc` flag deletion includes: * - * - `paranext-core/dev-packages/`, which makes the core re-install last minutes longer + * - `paranext-core/dev-packages/`, which makes the next core:install last minutes longer */ // Check command-line arguments -const hasAllFlag = process.argv.includes('--all'); -const hasCoreFlag = process.argv.includes('--core'); -const hasExtFlag = process.argv.includes('--ext'); -const hasNpmFlag = process.argv.includes('--npm'); -const hasTestFlag = process.argv.includes('--test'); -const hasYalcFlag = process.argv.includes('--yalc'); +const allFlag = process.argv.includes('--all'); +const buildFlag = process.argv.includes('--build'); +const coreFlag = process.argv.includes('--core'); +const extFlag = process.argv.includes('--ext'); +const npmFlag = process.argv.includes('--npm'); +const testFlag = process.argv.includes('--test'); +const yalcFlag = process.argv.includes('--yalc'); function printUsageAndExit(code = 0) { console.info( - 'Usage: node delete-temp-files.cjs [--all] [--core] [--ext] [--npm] [--test] [--yalc]', + 'Usage: node delete-temp-files.cjs [--all] [--build] [--core] [--ext] [--npm] [--test] [--yalc]', ); + console.info(' --build Delete core build files'); console.info(' --core Delete Electron and core caches (Electron, dev-appdata)'); console.info(' --ext Delete extension builds (dist, src/temp-build)'); console.info(' --npm Delete extension package-lock.json and all node_modules'); @@ -41,22 +47,33 @@ if (process.argv.length <= 2 || process.argv.includes('--help') || process.argv. printUsageAndExit(); } -if (!hasAllFlag && !hasCoreFlag && !hasExtFlag && !hasNpmFlag && !hasTestFlag && !hasYalcFlag) { +if (!allFlag && !buildFlag && !coreFlag && !extFlag && !npmFlag && !testFlag && !yalcFlag) { printUsageAndExit(1); } -const shouldDeleteCore = hasAllFlag || hasCoreFlag; -const shouldDeleteExt = hasAllFlag || hasExtFlag; -const shouldDeleteNpm = hasAllFlag || hasNpmFlag; -const shouldDeleteTest = hasAllFlag || hasTestFlag; -const shouldDeleteYalc = hasAllFlag || hasYalcFlag; +const shouldDeleteBuild = allFlag || buildFlag; +const shouldDeleteCore = allFlag || coreFlag; +const shouldDeleteExt = allFlag || extFlag; +const shouldDeleteNpm = allFlag || npmFlag; +const shouldDeleteTest = allFlag || testFlag; +const shouldDeleteYalc = allFlag || yalcFlag; // Define directory lists -const CORE_DIRS = [path.join(__dirname, '..', '..', 'paranext-core', 'dev-appdata')]; +const EXT_DIR_PATH = path.join(__dirname, '..'); +const CORE_DIR_PATH = path.join(EXT_DIR_PATH, '..', 'paranext-core'); +const SKIP_DIRS = new Set(['.yalc', 'dev-appdata', 'dev-packages', 'lib']); +const BUILD_PATHS = []; +if (shouldDeleteBuild) { + // Add core build output subdirectories to `BUILD_PATHS` + BUILD_PATHS.push(...findDirsNamed(CORE_DIR_PATH, 'dist', SKIP_DIRS)); + BUILD_PATHS.push(...findDirsNamed(CORE_DIR_PATH, 'temp-build', SKIP_DIRS)); +} + +const CORE_PATHS = [path.join(CORE_DIR_PATH, 'dev-appdata')]; if (shouldDeleteCore) { - // Determine Electron cache directory based on platform and add to `CORE_DIRS` + // Determine Electron cache directory based on platform and add to `CORE_PATHS` let electronParent = ''; /* eslint-disable no-nested-ternary */ @@ -77,56 +94,53 @@ if (shouldDeleteCore) { /* eslint-enable no-nested-ternary */ if (electronParent) { - CORE_DIRS.push(path.join(electronParent, 'Electron Cache')); + CORE_PATHS.push(path.join(electronParent, 'Electron Cache')); } } -const EXT_DIRS = [ - path.join(__dirname, '..', 'dist'), - path.join(__dirname, '..', 'src', 'temp-build'), -]; +const EXT_PATHS = [path.join(EXT_DIR_PATH, 'dist'), path.join(EXT_DIR_PATH, 'src', 'temp-build')]; const NPM_PATHS = [ - path.join(__dirname, '..', 'node_modules'), - path.join(__dirname, '..', 'package-lock.json'), + path.join(EXT_DIR_PATH, 'node_modules'), + path.join(EXT_DIR_PATH, 'package-lock.json'), ]; - if (shouldDeleteNpm) { - // Recursively find `node_modules` folders in `paranext-core/` and add them to `NPM_PATHS` - const corePath = path.join(__dirname, '..', '..', 'paranext-core'); - const SKIP_DIRS = new Set(['dev-appdata', 'dev-packages']); - const findNodeModules = (dir) => { - let entries; - try { - entries = fs.readdirSync(dir, { withFileTypes: true }); - } catch { - return; - } - entries - .filter((entry) => entry.isDirectory() && !SKIP_DIRS.has(entry.name)) - .forEach((entry) => { - const fullPath = path.join(dir, entry.name); - if (entry.name === 'node_modules') { - NPM_PATHS.push(fullPath); - } else { - findNodeModules(fullPath); - } - }); - }; - findNodeModules(corePath); + // Find core `node_modules` subdirectories and add them to `NPM_PATHS` + NPM_PATHS.push(...findDirsNamed(CORE_DIR_PATH, 'node_modules', SKIP_DIRS)); } -const TEST_PATHS = [ - path.join(__dirname, '..', 'coverage'), - path.join(__dirname, '..', '.eslintcache'), -]; +const TEST_PATHS = [path.join(EXT_DIR_PATH, 'coverage'), path.join(EXT_DIR_PATH, '.eslintcache')]; const YALC_PATHS = [ - path.join(__dirname, '..', '..', 'paranext-core', '.yalc'), - path.join(__dirname, '..', '..', 'paranext-core', 'dev-packages'), - path.join(__dirname, '..', '..', 'paranext-core', 'yalc.lock'), + path.join(CORE_DIR_PATH, '.yalc'), + path.join(CORE_DIR_PATH, 'dev-packages'), + path.join(CORE_DIR_PATH, 'yalc.lock'), ]; +/** + * Recursively find all subdirectories named `targetDir` inside `corePath`, skipping `skipDirs`. + * + * @param {string} corePath - Root directory to search + * @param {string} targetDir - Directory name to collect + * @param {Set} skipDirs - Directory names to skip entirely + * @returns {string[]} Absolute paths of every matching directory found + */ +function findDirsNamed(corePath, targetDir, skipDirs) { + let entries; + try { + entries = fs.readdirSync(corePath, { withFileTypes: true }); + } catch { + return []; + } + return entries + .filter((entry) => entry.isDirectory() && !skipDirs.has(entry.name)) + .flatMap((entry) => { + const fullPath = path.join(corePath, entry.name); + if (entry.name === targetDir) return [fullPath]; + return findDirsNamed(fullPath, targetDir, skipDirs); + }); +} + /** * Delete a path if it exists * @@ -153,14 +167,19 @@ function deletePath(pathToDelete) { // Delete paths based on command-line flags try { + if (shouldDeleteBuild) { + console.log('Deleting core build directories...'); + BUILD_PATHS.forEach(deletePath); + } + if (shouldDeleteCore) { console.log('Deleting core cache directories...'); - CORE_DIRS.forEach(deletePath); + CORE_PATHS.forEach(deletePath); } if (shouldDeleteExt) { console.log('Deleting extension directories...'); - EXT_DIRS.forEach(deletePath); + EXT_PATHS.forEach(deletePath); } if (shouldDeleteNpm) { From 0f21254ef4c1f26723f3379d784351a1a1c55dae Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Thu, 21 May 2026 10:14:28 -0400 Subject: [PATCH 5/5] Prevent node_modules diving --- scripts/delete-temp-files.cjs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/delete-temp-files.cjs b/scripts/delete-temp-files.cjs index d3d9cd67..e14ba263 100644 --- a/scripts/delete-temp-files.cjs +++ b/scripts/delete-temp-files.cjs @@ -62,13 +62,13 @@ const shouldDeleteYalc = allFlag || yalcFlag; const EXT_DIR_PATH = path.join(__dirname, '..'); const CORE_DIR_PATH = path.join(EXT_DIR_PATH, '..', 'paranext-core'); -const SKIP_DIRS = new Set(['.yalc', 'dev-appdata', 'dev-packages', 'lib']); +const SKIP_DIRS = new Set(['.yalc', 'dev-appdata', 'dev-packages', 'lib', 'node_modules']); const BUILD_PATHS = []; if (shouldDeleteBuild) { // Add core build output subdirectories to `BUILD_PATHS` - BUILD_PATHS.push(...findDirsNamed(CORE_DIR_PATH, 'dist', SKIP_DIRS)); - BUILD_PATHS.push(...findDirsNamed(CORE_DIR_PATH, 'temp-build', SKIP_DIRS)); + BUILD_PATHS.push(...findNamed(CORE_DIR_PATH, 'dist', SKIP_DIRS)); + BUILD_PATHS.push(...findNamed(CORE_DIR_PATH, 'temp-build', SKIP_DIRS)); } const CORE_PATHS = [path.join(CORE_DIR_PATH, 'dev-appdata')]; @@ -106,7 +106,7 @@ const NPM_PATHS = [ ]; if (shouldDeleteNpm) { // Find core `node_modules` subdirectories and add them to `NPM_PATHS` - NPM_PATHS.push(...findDirsNamed(CORE_DIR_PATH, 'node_modules', SKIP_DIRS)); + NPM_PATHS.push(...findNamed(CORE_DIR_PATH, 'node_modules', SKIP_DIRS)); } const TEST_PATHS = [path.join(EXT_DIR_PATH, 'coverage'), path.join(EXT_DIR_PATH, '.eslintcache')]; @@ -125,7 +125,7 @@ const YALC_PATHS = [ * @param {Set} skipDirs - Directory names to skip entirely * @returns {string[]} Absolute paths of every matching directory found */ -function findDirsNamed(corePath, targetDir, skipDirs) { +function findNamed(corePath, target, skipDirs) { let entries; try { entries = fs.readdirSync(corePath, { withFileTypes: true }); @@ -133,11 +133,10 @@ function findDirsNamed(corePath, targetDir, skipDirs) { return []; } return entries - .filter((entry) => entry.isDirectory() && !skipDirs.has(entry.name)) + .filter((entry) => entry.name === target || (entry.isDirectory() && !skipDirs.has(entry.name))) .flatMap((entry) => { const fullPath = path.join(corePath, entry.name); - if (entry.name === targetDir) return [fullPath]; - return findDirsNamed(fullPath, targetDir, skipDirs); + return entry.name === target ? [fullPath] : findNamed(fullPath, target, skipDirs); }); }