Skip to content

Commit aaad3d7

Browse files
author
Dev Optimizer Bot
committed
feat: Add --force-refresh flag to bypass npm cache
- Added forceRefresh option to CLI - When flag is set, npm outdated/audit cache is ignored - Useful when you know dependencies changed - All 72 tests passing
1 parent 8122306 commit aaad3d7

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/analyzers/DepsAnalyzer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface DepsAnalyzerOptions {
1919
mode?: 'quick' | 'full' | 'deep';
2020
runNpmOutdated?: boolean;
2121
runNpmAudit?: boolean;
22+
forceRefresh?: boolean;
2223
}
2324

2425
interface KnipResult {
@@ -826,8 +827,8 @@ export class DepsAnalyzer implements Analyzer {
826827
// Ignore errors
827828
}
828829

829-
// Check cache first (24h TTL)
830-
let outdated: Record<string, any> | null = getCachedOutdated(projectPath);
830+
// Check cache first (24h TTL), skip if forceRefresh
831+
let outdated: Record<string, any> | null = this.options.forceRefresh ? null : getCachedOutdated(projectPath);
831832

832833
// Run npm outdated if no cache
833834
if (!outdated) {
@@ -923,8 +924,8 @@ export class DepsAnalyzer implements Analyzer {
923924

924925
const findings: Finding[] = [];
925926

926-
// Check cache first (6h TTL)
927-
let audit: any = getCachedAudit(projectPath);
927+
// Check cache first (6h TTL), skip if forceRefresh
928+
let audit: any = this.options.forceRefresh ? null : getCachedAudit(projectPath);
928929

929930
// Run npm audit if no cache
930931
if (!audit) {

src/commands/analyze.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface AnalyzeOptions {
2424
top: number;
2525
quick?: boolean;
2626
deep?: boolean;
27+
forceRefresh?: boolean;
2728
verbose?: boolean;
2829
quiet?: boolean;
2930
}
@@ -60,7 +61,7 @@ export async function analyzeCommand(options: AnalyzeOptions): Promise<void> {
6061
// Initialize analyzers - pass mode based on quick option
6162
const analyzerMode = options.quick ? 'quick' : 'full';
6263
const dockerAnalyzer = new DockerAnalyzer({ mode: analyzerMode });
63-
const depsAnalyzer = new DepsAnalyzer({ mode: analyzerMode });
64+
const depsAnalyzer = new DepsAnalyzer({ mode: analyzerMode, forceRefresh: options.forceRefresh });
6465
const ciAnalyzer = new CiAnalyzer();
6566

6667
const allFindings: Finding[] = [];

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ program
2525
.option('--top <n>', 'Show top N findings', '5')
2626
.option('--quick', 'Quick mode - fast analysis without npm commands', false)
2727
.option('--deep', 'Deep mode - thorough analysis with size estimates', false)
28+
.option('--force-refresh', 'Force refresh - ignore npm cache', false)
2829
.option('--verbose', 'Verbose output - show more details', false)
2930
.option('--quiet', 'Quiet mode - minimal output', false)
3031
.action(analyzeCommand);

0 commit comments

Comments
 (0)