Refactor getDirname function to only return __dirname for CJS context

This commit is contained in:
Alex Newman
2025-10-23 23:00:34 -04:00
parent c04e5c571c
commit 15362d1aed
11 changed files with 73 additions and 78 deletions
+2 -7
View File
@@ -4,14 +4,9 @@ import { existsSync, mkdirSync } from 'fs';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
// Get __dirname that works in both ESM (hooks) and CJS (worker) contexts
// Get __dirname that works in CJS context
function getDirname(): string {
// CJS context - __dirname exists
if (typeof __dirname !== 'undefined') {
return __dirname;
}
// ESM context - use import.meta.url
return dirname(fileURLToPath(import.meta.url));
return __dirname;
}
const _dirname = getDirname();