Skip to content

Commit

Permalink
fix: optimize ts config resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jul 7, 2023
1 parent 1b62741 commit 57a6ce1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/rules/requireExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ const endsWith = (subject: string, needles: string[]) => {
});
};

const createTSConfigFinder = () => {
const cache: Record<string, TSConfig | null> = {};

return (fileName: string) => {
if (cache[fileName] !== undefined) {
return cache[fileName];
}

const tsconfig: TSConfig = JSON.parse(readFileSync(fileName, 'utf8'));

cache[fileName] = tsconfig;

return tsconfig;
};
};

const findTSConfig = createTSConfigFinder();

export default createRule<Options, MessageIds>({
create: (context) => {
return {
Expand Down Expand Up @@ -139,7 +157,7 @@ export default createRule<Options, MessageIds>({
return;
}

const tsconfig: TSConfig = JSON.parse(readFileSync(project, 'utf8'));
const tsconfig = findTSConfig(project);

const paths = tsconfig?.compilerOptions?.paths;

Expand Down

0 comments on commit 57a6ce1

Please sign in to comment.