mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-07-03 12:27:41 +08:00
Dissolve the by-kind @shared/config junk drawer per shared-layer governance: route each member by shape and actual consumer process — cross-process slices into types//utils//ai/, single-process code back into main/renderer (Invariant 1.1). Confirm each item's real consumer process rather than trusting the directional plan (API_SERVER_DEFAULTS is renderer-only, MIN_WINDOW_* is cross-process, providers.ts is renderer-only), and drop dead consts (ZOOM_LEVELS/ZOOM_OPTIONS, bookExts, thirdPartyApplicationExts). Purge runtime logic from types/ so the bucket holds only declarations: move serializeError + AI-SDK error guards to utils/error.ts, the FileHandle factories/guards to utils/file/handle.ts, isSerializable + SerializableSchema to utils/serializable.ts, and the tab-instance guard/normalizer to utils/tabInstanceMetadata.ts. Tests follow the logic to utils/__tests__; the type-level ipc contract test is retired (its invariants kept as a breadcrumb for the future IpcApi Zod schema). types/ is now logic-free and test-free. Also: remove the dead @shared mock from the packages/ui code-editor test so packages/ui no longer references production code; fix the data-classify preference generator prompts import and the update-languages output path to the relocated modules. Update shared-layer-architecture (3.1 type/util test rule, 5/6 config dissolution) and renderer-architecture cross-references.
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { codeLangExts, customTextExts } from '../src/shared/utils/file/fileExtensions'
|
||
|
||
console.log('Running sanity check for custom extensions...')
|
||
|
||
// Create a Set for efficient lookup of extensions from the linguist database.
|
||
const linguistExtsSet = new Set(codeLangExts)
|
||
|
||
const overlappingExtsByCategory = new Map<string, string[]>()
|
||
let totalOverlaps = 0
|
||
|
||
// Iterate over each category and its extensions in our custom map.
|
||
for (const [category, exts] of customTextExts.entries()) {
|
||
const categoryOverlaps = exts.filter((ext) => linguistExtsSet.has(ext))
|
||
|
||
if (categoryOverlaps.length > 0) {
|
||
overlappingExtsByCategory.set(category, categoryOverlaps.sort())
|
||
totalOverlaps += categoryOverlaps.length
|
||
}
|
||
}
|
||
|
||
// Report the results.
|
||
if (totalOverlaps === 0) {
|
||
console.log('\n✅ Check passed!')
|
||
console.log('The `customTextExts` map contains no extensions that are already in `codeLangExts`.')
|
||
console.log('\nCustom extensions checked:')
|
||
for (const [category, exts] of customTextExts.entries()) {
|
||
console.log(` - Category '${category}' (${exts.length}):`)
|
||
console.log(` ${exts.sort().join(', ')}`)
|
||
}
|
||
console.log('\n')
|
||
} else {
|
||
console.error('\n⚠️ Check failed: Overlapping extensions found!')
|
||
console.error(
|
||
'The following extensions in `customTextExts` are already present in `codeLangExts` (from languages.ts).'
|
||
)
|
||
console.error(
|
||
'Please remove them from `customTextExts` in `src/shared/utils/file/fileExtensions.ts` to avoid redundancy.'
|
||
)
|
||
console.error(`\nFound ${totalOverlaps} overlapping extensions in ${overlappingExtsByCategory.size} categories:`)
|
||
|
||
for (const [category, exts] of overlappingExtsByCategory.entries()) {
|
||
console.error(` - Category '${category}': ${exts.join(', ')}`)
|
||
}
|
||
|
||
console.error('\n')
|
||
process.exit(1) // Exit with an error code for CI/CD purposes.
|
||
}
|