From 8ef263d607f862ce5bd1755497988af176240190 Mon Sep 17 00:00:00 2001 From: Aaron Friedlander Date: Thu, 20 Feb 2025 20:51:35 -0500 Subject: [PATCH] Support check only files for libraries --- src/analyzer.ts | 5 ++++- src/app.ts | 13 +++++++++++-- src/parser/index.ts | 2 +- src/types.ts | 2 ++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/analyzer.ts b/src/analyzer.ts index 5a7fb25..953f358 100644 --- a/src/analyzer.ts +++ b/src/analyzer.ts @@ -268,13 +268,16 @@ const makeExportStarRelativeForPresentation = ( export default ( files: File[], + checkOnlyFiles: File[], extraOptions?: ExtraCommandLineOptions & ExtraOptionsForPresentation, ): Analysis => { const filteredFiles = filterFiles(files, extraOptions); const exportMap = getExportMap(filteredFiles); expandExportFromStar(filteredFiles, exportMap); - filteredFiles.forEach((file) => processImports(file, exportMap)); + [...filteredFiles, ...checkOnlyFiles].forEach((file) => + processImports(file, exportMap), + ); const analysis: Analysis = { unusedExports: {} }; const unusedFiles: string[] = []; diff --git a/src/app.ts b/src/app.ts index bd1d395..ec7bb38 100644 --- a/src/app.ts +++ b/src/app.ts @@ -61,11 +61,20 @@ export const analyzeTsConfig = ( files?: string[], ): Analysis => { const args = extractOptionsFromFiles(files); - const tsConfig = loadTsConfig(tsconfigPath, args.tsFiles); + const tsConfig = loadTsConfig( + tsconfigPath, + args.options?.onlyCheckInputFiles ? args.tsFiles : [], + ); + + const normalFiles = parseFiles(tsConfig, args.options); + + const checkOnlyFiles = args.options?.onlyCheckInputFiles + ? parseFiles({ ...tsConfig, files: args.tsFiles ?? [] }, args.options) + : []; const options = { ...args.options, baseUrl: tsConfig.baseUrl, }; - return analyze(parseFiles(tsConfig, args.options), options); + return analyze(normalFiles, checkOnlyFiles, options); }; diff --git a/src/parser/index.ts b/src/parser/index.ts index cc54e1a..6f5e87a 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -110,7 +110,7 @@ const parseFile = ( path, readFileSync(path, { encoding: 'utf8' }), ts.ScriptTarget.ES2015, - /*setParentNodes */ true, + /* setParentNodes */ true, ), baseUrl, paths, diff --git a/src/types.ts b/src/types.ts index 4cfa653..e3de373 100644 --- a/src/types.ts +++ b/src/types.ts @@ -43,6 +43,7 @@ export interface TsConfig { baseUrl: string; paths?: TsConfigPaths; files: string[]; + checkOnlyFiles?: string[]; } export interface ExtraCommandLineOptions { @@ -59,6 +60,7 @@ export interface ExtraCommandLineOptions { showLineNumber?: boolean; silent?: boolean; findCompletelyUnusedFiles?: boolean; + onlyCheckInputFiles?: boolean; } export interface ExtraOptionsForPresentation {