diff --git a/.changeset/giant-emus-wave.md b/.changeset/giant-emus-wave.md new file mode 100644 index 0000000..fb4acc5 --- /dev/null +++ b/.changeset/giant-emus-wave.md @@ -0,0 +1,5 @@ +--- +"unused-i18n": patch +--- + +fix some bug diff --git a/src/index.ts b/src/index.ts index f6f3a75..a3f3f51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,8 +32,8 @@ export const processTranslations = async ({ let pathUnusedLocalesCount = 0 srcPath.forEach((pathEntry) => { - const ignorePathExists = config.ignorePaths?.some( - (ignorePath) => ignorePath === pathEntry + const ignorePathExists = config.ignorePaths?.some((ignorePath) => + pathEntry.includes(ignorePath) ) if (ignorePathExists) return const files = searchFilesRecursively({ @@ -61,7 +61,10 @@ export const processTranslations = async ({ allExtractedTranslations = [...new Set(allExtractedTranslations)].sort() const localeFilePath = `${localPath}/${localesNames}.${localesExtensions}` - if (fs.existsSync(localeFilePath)) { + const ignorePathExists = config.ignorePaths?.some((ignorePath) => + localeFilePath.includes(ignorePath) + ) + if (fs.existsSync(localeFilePath) && !ignorePathExists) { console.log(`${localeFilePath}...`) const localLines = fs @@ -87,12 +90,14 @@ export const processTranslations = async ({ const message = missingTranslations.length ? `Unused translations in \x1b[33m${localeFilePath}\x1b[0m : \x1b[31m${pathUnusedLocalesCount} \n${formattedMissingTranslations}\x1b[0m` - : `\x1b[32mNo unused translations in \x1b[33m${localeFilePath}\x1b[0m\x1b[0m` + : undefined - unusedLocalesCountByPath.push({ - path: localPath, - messages: message, - }) + if (message) { + unusedLocalesCountByPath.push({ + path: localPath, + messages: message, + }) + } // Remove the unused locale keys action === 'remove' @@ -101,20 +106,19 @@ export const processTranslations = async ({ missingTranslations: missingTranslations, }) : null - } else { - const warningMessage = `\x1b[31mLocale file not found: ${localeFilePath}\x1b[0m` - - unusedLocalesCountByPath.push({ - path: localPath, - warning: warningMessage, - }) } }) const endTime = performance.now() + summary({ unusedLocalesCountByPath, totalUnusedLocales }) console.log( `\x1b[38;2;128;128;128mDuration : ${(endTime - startTime).toFixed( 0 )}ms\x1b[0m` ) + + // Check if totalUnusedLocales is greater than 0 + if (totalUnusedLocales > 0) { + process.exit(1) + } } diff --git a/src/utils/summary.ts b/src/utils/summary.ts index 53af59b..8132e34 100644 --- a/src/utils/summary.ts +++ b/src/utils/summary.ts @@ -1,5 +1,4 @@ import { SummaryArgs } from '../types' -import { exit } from 'process' export const summary = ({ unusedLocalesCountByPath, @@ -13,7 +12,4 @@ export const summary = ({ }) console.log(`Total unused locales: \x1b[33m${totalUnusedLocales}\x1b[0m`) - if (unusedLocalesCountByPath.length === 1) { - exit(1) - } } diff --git a/vite.config.ts b/vite.config.ts index 0044cd1..ff25a88 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -6,7 +6,7 @@ const external = (id: string) => { id.endsWith('fs') || id.endsWith('path') || id.endsWith('perf_hooks') || - id.endsWith('process') || + id.endsWith('process') || id.endsWith('commander') ) { return true