openpetswithchatandmcp/website/prune-imports.ts
OpenPets Dev 65ac83849e Add 'website/' from commit '966aea480ffe1c340553aa878def30131d2af827'
git-subtree-dir: website
git-subtree-mainline: 8d3849caea
git-subtree-split: 966aea480f
2026-06-17 20:48:39 +00:00

47 lines
1.5 KiB
TypeScript
Executable file

import { Project } from 'ts-morph';
console.log("Starting unused import pruning for runboard-route-logic.tsx...");
const project = new Project({
tsConfigFilePath: 'C:/ScriptoriumAI/scriptoriumai-ui/tsconfig.json'
});
const sourceFile = project.getSourceFileOrThrow('C:/ScriptoriumAI/scriptoriumai-ui/src/utils/runboard-route-logic.tsx');
let removedCount = 0;
const importDeclarations = sourceFile.getImportDeclarations();
for (const importDecl of importDeclarations) {
const defaultImport = importDecl.getDefaultImport();
const namedImports = importDecl.getNamedImports();
let keepAny = false;
if (defaultImport) {
const refs = defaultImport.findReferencesAsNodes();
if (refs.length > 0) keepAny = true;
}
const unreferencedNamed = [];
for (const named of namedImports) {
const refs = named.getNameNode().findReferencesAsNodes();
// refs inherently contains the declaration itself, so length > 1 means it's used elsewhere
if (refs.length <= 1) {
unreferencedNamed.push(named);
removedCount++;
} else {
keepAny = true;
}
}
// Process removal precisely
for(const named of unreferencedNamed) {
named.remove();
}
if (!keepAny && namedImports.length === unreferencedNamed.length && !defaultImport) {
importDecl.remove();
}
}
sourceFile.saveSync();
console.log(`Pruned roughly ${removedCount} unused named imports.`);