refactor(auth): move clearRequireCache to utils and update import

Remove the local clearRequireCache function from database.js and import it from
utils/native-module-helper.js. Update the function call to pass require.cache
as the second parameter for proper cache clearing.
This commit is contained in:
jgor20
2026-01-05 01:13:55 +00:00
parent 2d4693b4c6
commit 69b7e130a0

View File

@@ -13,7 +13,7 @@
import { createRequire } from 'module';
import { ANTIGRAVITY_DB_PATH } from '../constants.js';
import { isModuleVersionError, attemptAutoRebuild } from '../utils/native-module-helper.js';
import { isModuleVersionError, attemptAutoRebuild, clearRequireCache } from '../utils/native-module-helper.js';
import { logger } from '../utils/logger.js';
const require = createRequire(import.meta.url);
@@ -47,7 +47,7 @@ function loadDatabaseModule() {
try {
const resolvedPath = require.resolve('better-sqlite3');
// Clear the module and all its dependencies from cache
clearRequireCache(resolvedPath);
clearRequireCache(resolvedPath, require.cache);
Database = require('better-sqlite3');
logger.success('[Database] Module reloaded successfully after rebuild');
@@ -76,33 +76,6 @@ function loadDatabaseModule() {
}
}
/**
* Clear a module and its dependencies from the require cache
* @param {string} modulePath - Resolved path to the module
*/
function clearRequireCache(modulePath) {
const mod = require.cache[modulePath];
if (!mod) return;
// Recursively clear children first
if (mod.children) {
for (const child of mod.children) {
clearRequireCache(child.id);
}
}
// Remove from parent's children
if (mod.parent && mod.parent.children) {
const idx = mod.parent.children.indexOf(mod);
if (idx !== -1) {
mod.parent.children.splice(idx, 1);
}
}
// Delete from cache
delete require.cache[modulePath];
}
/**
* Query Antigravity database for authentication status
* @param {string} [dbPath] - Optional custom database path