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

bug: 使用 Zod 时声明文件没有根据依赖及时生成 #733

Open
ninesunsabiu opened this issue Nov 28, 2023 · 2 comments
Open

bug: 使用 Zod 时声明文件没有根据依赖及时生成 #733

ninesunsabiu opened this issue Nov 28, 2023 · 2 comments
Labels
help wanted Extra attention is needed PR Welcome

Comments

@ninesunsabiu
Copy link

Version

4.3.7

OS Version

macOS 14.1.1 (23B81)

Node.js Version

v18.12.1

Link to minimal reproduction

https://github.com/ninesunsabiu/father-with-zod

Steps to reproduce

  1. clone the minimal reproduction
  2. install the dependency
  3. run "dev"
  4. change the A.ts
diff --git a/src/A.ts b/src/A.ts
index d08b85e..5345cd5 100644
--- a/src/A.ts
+++ b/src/A.ts
@@ -2,7 +2,7 @@ import * as Z from "zod"
 
 export const schemaEntity = Z.lazy(() => {
     return Z.object({
-        id: Z.number(),
+        id: Z.string(),
         name: Z.string(),
     })
 })

What is expected?

A.d.tsB.d.ts 都可以得到正确的更新

What is actually happening?

只有 A.d.ts 按照 A.ts 进行了重新的生成,但是 B.d.ts 没有任何的更新 造成了不正确

Any additional comments? (optional)

使用了 tsc --watch 进行了对比, tsc 的 watch 是能根据 B => A 的关系,也把 B.d.ts 进行更新的

image
@PeachScript
Copy link
Member

father 的 bundless 不会记录模块间的关系,看来 d.ts 的 watch 还是得交给 ts program 来做

@PeachScript PeachScript added help wanted Extra attention is needed PR Welcome labels Nov 30, 2023
@ninesunsabiu
Copy link
Author

我浏览了 dts 的代码
是否因为 这里的输出 output 被限制成了只跟输入 inputFiles 有关

// only collect dts for input files, to avoid output error in watch mode
// ref: https://github.com/umijs/father-next/issues/43
if (inputFiles.includes(sourceFile)) {
const index = output.findIndex(
(out) => out.file === ret.file && out.sourceFile === ret.sourceFile,
);
if (index > -1) {
output.splice(index, 1, ret);
} else {
output.push(ret);
}
}

// use cache first
inputFiles.forEach((file) => {
const cacheRet = cache.getSync(cacheKeys[file], '');
if (cacheRet) {
output.push(...cacheRet);
}
});

所以其实 ts program 有正确的得出 A.d.tsB.d.ts (没有运行调试过不太确定)
注释中指向了一个 umijs/father-next#43 ,如果放开对于 inputFiles 的限制,会不会对它有影响?

ninesunsabiu added a commit to ninesunsabiu/father that referenced this issue Feb 24, 2024
ninesunsabiu added a commit to ninesunsabiu/father that referenced this issue Feb 29, 2024
在 cjs/esm 同时存在的情况下,会因为 ts 的增量编译而跳过
如果仅用 inputFiles 作为缓存初始值 可能存在某个 bundless 输出不全的问题
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed PR Welcome
Projects
None yet
Development

No branches or pull requests

2 participants