fix: tsconfig paths has type error if out of cwd #715
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
修复超出 cwd 的 tsconfig
paths
会出现模块找不到的类型错误的问题。背景是 father 会在 d.ts 生成的时候自动替换 cwd 内的
paths
为相对路径,确保 d.ts 产物中的路径是可以被 resolve 的;但同时又会保留 cwd 之外的paths
,因为 monorepo 场景下会引用其他的子包,不能用相对路径去 resolve。问题原因是之前 father 排除 cwd 之外的方式是把 tsconfig 中的部分
paths
删掉后再给 ts compiler,最后由 ts 插件来转换,但这其实会引起paths
对应模块找不到的错误,而之前没报错是因为 4.3.2 之前有很多错误没抛出,ref: #701 。解决方案是 father 保留原始的 tsconfig
paths
给 ts compiler 确保编译过程中的类型完整,但对 ts 插件消费的paths
做特殊处理,排除掉 cwd 之外的 paths。