@agenticmail/enterprise 0.5.7 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,39 +57,45 @@ async function ensureDbDriver(dbType: string, ora: any, chalk: any): Promise<voi
57
57
  const packages = DB_DRIVER_MAP[dbType];
58
58
  if (!packages?.length) return;
59
59
 
60
- // Resolve the enterprise package's own directory for installing drivers
61
- const __filename = fileURLToPath(import.meta.url);
62
- const pkgDir = join(dirname(__filename), '..');
63
-
60
+ // Check if any packages are missing
64
61
  const missing: string[] = [];
65
62
  for (const pkg of packages) {
66
- try {
67
- // Check if resolvable from the package directory
68
- const require = createRequire(join(pkgDir, 'node_modules', '.package-lock.json'));
69
- require.resolve(pkg);
70
- } catch {
71
- // Also try dynamic import as fallback
63
+ let found = false;
64
+ // Try ESM import
65
+ try { await import(pkg); found = true; } catch {}
66
+ // Try CJS require from cwd
67
+ if (!found) {
68
+ try {
69
+ const req = createRequire(join(process.cwd(), 'index.js'));
70
+ req.resolve(pkg);
71
+ found = true;
72
+ } catch {}
73
+ }
74
+ // Try CJS require from global
75
+ if (!found) {
72
76
  try {
73
- await import(pkg);
74
- } catch {
75
- missing.push(pkg);
76
- }
77
+ const globalPrefix = execSync('npm prefix -g', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
78
+ const req = createRequire(join(globalPrefix, 'lib', 'node_modules', '.package-lock.json'));
79
+ req.resolve(pkg);
80
+ found = true;
81
+ } catch {}
77
82
  }
83
+ if (!found) missing.push(pkg);
78
84
  }
79
85
  if (!missing.length) return;
80
86
 
81
87
  const spinner = ora(`Installing database driver: ${missing.join(', ')}...`).start();
82
88
  try {
83
- // Install into the enterprise package's node_modules so dynamic imports find them
89
+ // Install in cwd so createRequire(cwd) can find it
84
90
  execSync(`npm install --no-save ${missing.join(' ')}`, {
85
91
  stdio: 'pipe',
86
92
  timeout: 120_000,
87
- cwd: pkgDir,
93
+ cwd: process.cwd(),
88
94
  });
89
95
  spinner.succeed(`Database driver installed: ${missing.join(', ')}`);
90
96
  } catch (err: any) {
91
97
  spinner.fail(`Failed to install ${missing.join(', ')}`);
92
- console.error(chalk.red(`\n Run manually: cd ${pkgDir} && npm install ${missing.join(' ')}\n`));
98
+ console.error(chalk.red(`\n Run manually: npm install ${missing.join(' ')}\n`));
93
99
  process.exit(1);
94
100
  }
95
101
  }