fix: update getDirname function to support both ESM and CJS contexts

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