Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: d.ts may lost if tsconfig changed #702

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

PeachScript
Copy link
Member

修复在 tsconfig 变更后,d.ts 文件可能丢失的问题,引发该问题的上下文如下:

  1. father 4.2 使用了 tsc 的 incremental 模式做增量编译,部分 tsconfig 的修改可能会被 tsc 判定为不需要重新编译
  2. father 构建前默认清空输出目录,而上一条 tsc 又可能不会重新输出文件,所以 father 利用持久缓存做了文件补齐,参考 fix: dts lost when rebuild with incremental cache #649 fix: dts lost when esm and cjs has different ignores #656
  3. father 持久缓存的 key 由文件 path、contenthash 和 tsconfig 组成,这意味着只要 tsconfig 发生变更这份缓存就失效了,也就无法为 1 做文件不齐,导致 d.ts 文件丢失

解决方案:将 father 持久缓存 key 中的 tsconfig 去掉,缓存失效与否以 path 和 contenthash 为准;另外手动让 tsc 缓存失效,避免用户更新依赖但未删除 node_modules/.cache 的时候出现异常情况

这里无需担心缓存错乱的问题,几种带缓存构建的情况:

  1. 文件未变 + tsconfig 变,tsc 就会重新编译输出新的产物,father 也会用这份新的结果覆盖旧的缓存
  2. 文件变 + tsconfig 变,tsc 会重新编译输出新的产物,father 也会建立新的缓存
  3. 文件未变 + tsconfig 未变,tsc 不会输出产物,father 会用持久缓存补齐产物

Close #698

@PeachScript PeachScript changed the title fix: dts may lost if tsconfig changed fix: d.ts may lost if tsconfig changed Aug 31, 2023
@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (2150873) 93.81% compared to head (b9c92bb) 93.81%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #702   +/-   ##
=======================================
  Coverage   93.81%   93.81%           
=======================================
  Files          54       54           
  Lines        1537     1537           
  Branches      365      365           
=======================================
  Hits         1442     1442           
- Misses         90       95    +5     
+ Partials        5        0    -5     
Files Changed Coverage Δ
src/builder/bundless/dts/index.ts 91.89% <ø> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@PeachScript PeachScript merged commit 5fa24e8 into master Aug 31, 2023
9 checks passed
@delete-merged-branch delete-merged-branch bot deleted the hotfix/dts-lost-if-tsconfig-changed branch August 31, 2023 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v4.3.1 生成 cjs 代码时没有 index.d.ts,esm 看概率出现 index.d.ts
1 participant