From ebdf64c0b905c146669d0d1c7ecf741699d0c398 Mon Sep 17 00:00:00 2001 From: rhyme Date: Tue, 23 Dec 2025 15:33:29 +0800 Subject: [PATCH] fix(core): replace require() with ESM imports in cache-manager Remove CommonJS require() calls that caused \"require is not defined\" errors when scanning .workflow directories in ESM context. Changes: - Add unlinkSync and readdirSync to fs import statement - Replace require('fs').unlinkSync() with direct unlinkSync() call - Replace require('fs').readdirSync() with direct readdirSync() call Fixes: Cannot scan directory .workflow/active: require is not defined File: ccw/src/core/cache-manager.ts --- ccw/src/core/cache-manager.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ccw/src/core/cache-manager.ts b/ccw/src/core/cache-manager.ts index 9ed55005..8c7a9907 100644 --- a/ccw/src/core/cache-manager.ts +++ b/ccw/src/core/cache-manager.ts @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync } from 'fs'; +import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync, unlinkSync, readdirSync } from 'fs'; import { join, dirname } from 'path'; import { StoragePaths, ensureStorageDir } from '../config/storage-paths.js'; @@ -118,8 +118,7 @@ export class CacheManager { invalidate(): void { try { if (existsSync(this.cacheFile)) { - const fs = require('fs'); - fs.unlinkSync(this.cacheFile); + unlinkSync(this.cacheFile); } } catch (err) { console.warn(`Cache invalidation error for ${this.cacheFile}:`, (err as Error).message); @@ -180,8 +179,7 @@ export class CacheManager { if (depth > 3) return; // Limit recursion depth try { - const fs = require('fs'); - const entries = fs.readdirSync(dirPath, { withFileTypes: true }); + const entries = readdirSync(dirPath, { withFileTypes: true }); for (const entry of entries) { const fullPath = join(dirPath, entry.name);