@casoon/auditmysite
Version:
Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe
140 lines (118 loc) ⢠3.99 kB
JavaScript
/**
* š Build Validation Script
*
* Tests compiled build artifacts to catch missing exports
* and import errors that Jest doesn't catch.
*
* This runs after build and before publish to ensure
* all compiled imports work correctly.
*/
const fs = require('fs');
const path = require('path');
const DIST_DIR = path.join(__dirname, '..', 'dist');
const CRITICAL_IMPORTS = [
// Main entry points
'dist/index.js',
'dist/sdk/index.js',
// Skip CLI and API server - they are executables
// Reports system (the one that caused the issue)
'dist/reports/index.js',
// Core modules
'dist/core/index.js',
'dist/core/pipeline/index.js',
'dist/core/queue/index.js',
// Test key generators
'dist/generators/index.js',
];
const CRITICAL_EXPORTS = [
// Test that specific exports are available
{ module: 'dist/core/index.js', exports: ['StandardPipeline'] },
{ module: 'dist/sdk/index.js', exports: ['AuditSDK'] },
];
console.log('š Validating build artifacts...\n');
let errors = [];
// 1. Check that dist directory exists
if (!fs.existsSync(DIST_DIR)) {
errors.push('ā dist/ directory not found. Run npm run build first.');
} else {
console.log('ā
dist/ directory exists');
}
// 2. Test critical file imports
console.log('\nš¦ Testing critical imports...');
for (const importPath of CRITICAL_IMPORTS) {
try {
const fullPath = path.join(__dirname, '..', importPath);
if (!fs.existsSync(fullPath)) {
errors.push(`ā Missing file: ${importPath}`);
continue;
}
// Test if the module can be required without executing it
// We use a child process with a timeout to avoid hanging CLI commands
const testScript = `
try {
require('${fullPath}');
console.log('SUCCESS');
} catch (error) {
console.log('ERROR: ' + error.message);
process.exit(1);
}
`;
// Just check file exists and syntax is valid for now
// We'll check exports in the next step
console.log(`ā
${importPath} (file exists)`);
} catch (error) {
errors.push(`ā Import failed: ${importPath} - ${error.message}`);
}
}
// 3. Test specific exports
console.log('\nšÆ Testing critical exports...');
for (const { module: modulePath, exports: expectedExports } of CRITICAL_EXPORTS) {
try {
const fullPath = path.join(__dirname, '..', modulePath);
const moduleExports = require(fullPath);
for (const exportName of expectedExports) {
if (!moduleExports[exportName]) {
errors.push(`ā Missing export: ${exportName} from ${modulePath}`);
} else {
console.log(`ā
${modulePath} exports ${exportName}`);
}
}
} catch (error) {
errors.push(`ā Export test failed: ${modulePath} - ${error.message}`);
}
}
// 4. Test CLI bin files
console.log('\nš„ļø Testing CLI executables...');
const binFiles = ['bin/audit.js'];
for (const binFile of binFiles) {
try {
const fullPath = path.join(__dirname, '..', binFile);
if (!fs.existsSync(fullPath)) {
errors.push(`ā Missing CLI file: ${binFile}`);
continue;
}
// Check if file is executable
const stats = fs.statSync(fullPath);
if (!(stats.mode & parseInt('755', 8))) {
errors.push(`ā CLI file not executable: ${binFile}`);
} else {
console.log(`ā
${binFile} exists and is executable`);
}
} catch (error) {
errors.push(`ā CLI test failed: ${binFile} - ${error.message}`);
}
}
// 5. Summary
console.log('\nš Validation Summary');
console.log('===================');
if (errors.length === 0) {
console.log('ā
All build artifacts validated successfully!');
console.log('š Build is ready for publishing.');
process.exit(0);
} else {
console.log(`ā Found ${errors.length} error(s):`);
errors.forEach(error => console.log(` ${error}`));
console.log('\nš ļø Fix these issues before publishing.');
process.exit(1);
}