From 996069a9d980b26dfa9152f99bfa674365a44964 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Thu, 3 Jul 2025 17:10:01 -0400 Subject: [PATCH] fix: correct SUPPORTED_LANGUAGES import in translate-modal.js --- src/translate-modal.js | 3 +- validate_exports.js | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 validate_exports.js diff --git a/src/translate-modal.js b/src/translate-modal.js index 7f1cf40..055459d 100644 --- a/src/translate-modal.js +++ b/src/translate-modal.js @@ -2,8 +2,7 @@ import { initializeChunkFiveFont } from "./ui-themes.js"; import { getUIText } from "./ui-translations.js"; import { extractWebpageContent } from "./content.js"; -import { handleTranslation } from "./translation.js"; -import { SUPPORTED_LANGUAGES } from "./languages/index.js"; +import { translateCurrentPage, translateText, SUPPORTED_LANGUAGES } from "./translation.js"; // Get USE_CUSTOM_STYLING from window or default const USE_CUSTOM_STYLING = window.UNCLOSEAI_CUSTOM_STYLING !== false; diff --git a/validate_exports.js b/validate_exports.js new file mode 100644 index 0000000..4deac78 --- /dev/null +++ b/validate_exports.js @@ -0,0 +1,69 @@ +// Quick validation script to check if imports match exports +import { promises as fs } from 'fs'; +import path from 'path'; + +const srcDir = './src'; + +async function validateExports() { + const files = await fs.readdir(srcDir); + const jsFiles = files.filter(f => f.endsWith('.js')); + + console.log('šŸ” Validating exports/imports...\n'); + + const exportMap = new Map(); + const importMap = new Map(); + + // Extract exports and imports + for (const file of jsFiles) { + const content = await fs.readFile(path.join(srcDir, file), 'utf-8'); + + // Extract exports + const exportMatches = content.match(/export\s+(?:async\s+)?(?:function|const|let|var|class)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g); + if (exportMatches) { + const exports = exportMatches.map(match => { + const parts = match.split(/\s+/); + return parts[parts.length - 1]; + }); + exportMap.set(file, exports); + } + + // Extract imports + const importMatches = content.match(/import\s+{([^}]+)}\s+from\s+["']\.\/([^"']+)["']/g); + if (importMatches) { + importMatches.forEach(match => { + const parts = match.match(/import\s+{([^}]+)}\s+from\s+["']\.\/([^"']+)["']/); + if (parts) { + const imports = parts[1].split(',').map(s => s.trim()); + const fromFile = parts[2]; + if (!importMap.has(file)) importMap.set(file, []); + importMap.get(file).push({ imports, fromFile }); + } + }); + } + } + + // Validate + let errors = 0; + for (const [file, importData] of importMap) { + for (const { imports, fromFile } of importData) { + const targetFile = fromFile.endsWith('.js') ? fromFile : fromFile + '.js'; + const exports = exportMap.get(targetFile) || []; + + for (const importName of imports) { + if (!exports.includes(importName)) { + console.log(`āŒ ${file}: imports '${importName}' from ${targetFile}, but it's not exported`); + console.log(` Available exports: ${exports.join(', ') || 'none'}`); + errors++; + } + } + } + } + + if (errors === 0) { + console.log('āœ… All imports match their exports!'); + } else { + console.log(`\nšŸ’„ Found ${errors} import/export mismatches`); + } +} + +validateExports().catch(console.error); \ No newline at end of file