55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Circular Dependency Verification Script
|
|
*
|
|
* This script verifies that the NestJS application can be imported without
|
|
* circular dependency errors. It imports AppModule without bootstrapping,
|
|
* which is faster than a full startup and catches circular deps early.
|
|
*
|
|
* Usage: node scripts/verify-circular-deps.mjs
|
|
* Exit codes: 0 = success, 1 = circular dependency detected
|
|
*/
|
|
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
import { existsSync } from 'fs';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const distPath = join(__dirname, '..', 'dist');
|
|
|
|
async function verify() {
|
|
console.log('🔍 Verifying circular dependencies...\n');
|
|
|
|
// Check if dist exists
|
|
if (!existsSync(distPath)) {
|
|
console.error('❌ dist/ directory not found. Run `pnpm build` first.');
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
// Import AppModule - this will fail if there are circular deps
|
|
const appModulePath = join(distPath, 'app.module.js');
|
|
const { AppModule } = await import(appModulePath);
|
|
|
|
if (!AppModule) {
|
|
throw new Error('AppModule not exported');
|
|
}
|
|
|
|
console.log('✅ No circular dependencies detected');
|
|
console.log('✅ AppModule loaded successfully');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('❌ Circular dependency detected!\n');
|
|
console.error(error.message);
|
|
|
|
if (error.stack) {
|
|
console.error('\nStack trace:');
|
|
console.error(error.stack);
|
|
}
|
|
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
verify();
|