dsherret / dsherret/ts-morph

Provide option to intercept module/file resolution

Open
#1,497 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

I’m using ts-morph to build a dependency tree of js source files and d.ts files. I want both trees, that’s why I create two separate projects with different settings. For resolving the js tree I need to ignore all d.ts files. Ideally there would be an easy way to disable .d.ts file resolution, but unfortunately there is no such compiler option.
I’ve looked at the [resolution host](https://ts-morph.com/setup/#custom-module-resolution) but it only allows to map some paths in a different way. I would need a way to filter them.

Right now I’ve found a solution, but it is quite cumbersome. I’ve used a custom file host which is an instance of `RealFileSystemHost` but overrides `fileExists*` and `dirExists*` methods so I can return false for .d.ts files or `node_modules/@types` imports. This works, but I think it is not a good solution, especially because `RealFileSystemHost` is not exported directly and I need to use `@ts-morph/common`.

Is there any better way to solve this? Maybe adding new methods to the resolution host would be a good approach to filter files and folders.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.