Skip to content

Commit

Permalink
add fallback if tsconfig not exist in pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
RikoRodriges committed Oct 7, 2024
1 parent 67edf83 commit 5a27876
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,33 @@ export async function parseDependencyTree(
const fullOptions = normalizeOptions(options);
let resolve = simpleResolver;
if (options.tsconfig) {
const baseCompilerOptions = ts.parseJsonConfigFileContent(
ts.readConfigFile(options.tsconfig, ts.sys.readFile).config,
ts.sys,
path.dirname(options.tsconfig),
).options;

const baseHost = ts.createCompilerHost(baseCompilerOptions);
resolve = async (context, request, extensions) => {
const root = findPackageRoot(context);
if (!compilerOptionsByPkg.has(root)) {
let _compilerOptions = ts.parseJsonConfigFileContent(
ts.readConfigFile(path.join(root, 'tsconfig.json'), ts.sys.readFile)
.config,
ts.sys,
root,
).options;
compilerOptionsByPkg.set(root, {
compilerOptions: _compilerOptions,
host: ts.createCompilerHost(_compilerOptions),
});
const tsconfigPath = path.join(root, 'tsconfig.json');
if (fs.existsSync(tsconfigPath)) {
let _compilerOptions = ts.parseJsonConfigFileContent(
ts.readConfigFile(tsconfigPath, ts.sys.readFile).config,
ts.sys,
root,
).options;
compilerOptionsByPkg.set(root, {
compilerOptions: _compilerOptions,
host: ts.createCompilerHost(_compilerOptions),
});
} else {
compilerOptionsByPkg.set(root, {
compilerOptions: baseCompilerOptions,
host: baseHost,
});
}
}
const { compilerOptions, host } = compilerOptionsByPkg.get(
root,
Expand Down

0 comments on commit 5a27876

Please sign in to comment.