Skip to content

Commit

Permalink
fix: update getTSConfigCompilerOptions to handle TypeScript >= 5.4, r…
Browse files Browse the repository at this point in the history
…esolves issue introduced by #40

This commit updates the getTSConfigCompilerOptions function to handle TypeScript versions 5.4 and above. It introduces a conditional check to determine the TypeScript version and uses the appropriate parsing method accordingly. For TypeScript versions 5.4 and above, it reads the tsconfig file, parses the JSON config, and retrieves the compiler options. It also adds a log grouping to display the parsed compiler options when the TypeScript version is 5.4 or above.
  • Loading branch information
steven-pribilinskiy committed Oct 14, 2024
1 parent d2b0449 commit 767c771
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/compileTypes/helpers/getTSConfigCompilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ export function getTSConfigCompilerOptions(
process.exit(1);
}

const tsconfigJsonFile = ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile);
const parsedConfig = ts.parseJsonSourceFileConfigFileContent(
tsconfigJsonFile,
ts.sys,
path.dirname(tsconfigPath),
);
if (ts.version.match(/^[5-9]\.([4-9]|[1-9]\d)/)) {
const tsconfigJsonFile = ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile);
const parsedConfig = ts.parseJsonSourceFileConfigFileContent(
tsconfigJsonFile,
ts.sys,
path.dirname(tsconfigPath),
);

return parsedConfig.options;
logger.groupCollapsed(
`Parsed tsconfig compiler options for TypeScript >= 5.4 (current version: ${ts.version})`,
);
logger.log(parsedConfig.options);
logger.groupEnd();

return parsedConfig.options;
}

return require(tsconfigPath).compilerOptions;
}

0 comments on commit 767c771

Please sign in to comment.