Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support check only files for libraries #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
13 changes: 11 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const parseFile = (
path,
readFileSync(path, { encoding: 'utf8' }),
ts.ScriptTarget.ES2015,
/*setParentNodes */ true,
/* setParentNodes */ true,
),
baseUrl,
paths,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface TsConfig {
baseUrl: string;
paths?: TsConfigPaths;
files: string[];
checkOnlyFiles?: string[];
}

export interface ExtraCommandLineOptions {
Expand All @@ -59,6 +60,7 @@ export interface ExtraCommandLineOptions {
showLineNumber?: boolean;
silent?: boolean;
findCompletelyUnusedFiles?: boolean;
onlyCheckInputFiles?: boolean;
}

export interface ExtraOptionsForPresentation {
Expand Down