gebeya-dala-error-fixer
Version:
Automatic runtime error detection and fix suggestions for Next.js applications with config-based setup
68 lines (67 loc) • 2.23 kB
JavaScript
export const defaultConfig = {
enabled: true,
autoShow: true,
position: 'top-right',
environment: 'development',
customPatterns: [],
excludePatterns: [],
showStackTrace: true,
enableConsoleOverride: true,
enableUnhandledRejection: true,
enableErrorBoundary: true,
theme: 'dark',
fixItButton: {
enabled: true
}
};
export function loadConfig() {
// Try to load from multiple config file locations
const configPaths = [
'error-detector.config.js',
'error-detector.config.json',
'next.config.js' // For Next.js projects
];
// Check if running in browser
if (typeof window !== 'undefined') {
// In browser, try to get config from global variable
const globalConfig = window.__ERROR_DETECTOR_CONFIG__;
if (globalConfig) {
return { ...defaultConfig, ...globalConfig };
}
}
// For Node.js environment, try to load config files
if (typeof require !== 'undefined') {
for (const configPath of configPaths) {
try {
const config = require(configPath);
if (config.errorDetector) {
return { ...defaultConfig, ...config.errorDetector };
}
if (configPath.includes('error-detector.config')) {
return { ...defaultConfig, ...config };
}
}
catch (e) {
// Config file not found, continue
}
}
}
// Return default config if no config found
return defaultConfig;
}
export function validateConfig(config) {
const validatedConfig = { ...defaultConfig, ...config };
// Validate environment
if (!['development', 'production', 'all'].includes(validatedConfig.environment)) {
validatedConfig.environment = 'development';
}
// Validate position
if (!['top-right', 'top-left', 'bottom-right', 'bottom-left'].includes(validatedConfig.position)) {
validatedConfig.position = 'top-right';
}
// Validate theme
if (!['dark', 'light'].includes(validatedConfig.theme)) {
validatedConfig.theme = 'dark';
}
return validatedConfig;
}