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

Collecting father doctor rules #608

Open
PeachScript opened this issue Jul 7, 2022 · 11 comments
Open

Collecting father doctor rules #608

PeachScript opened this issue Jul 7, 2022 · 11 comments
Labels
help wanted Extra attention is needed

Comments

@PeachScript
Copy link
Member

PeachScript commented Jul 7, 2022

有提案也欢迎按照追加评论,不需要写 key

收集 father doctor 命令计划考虑的 rules,持续更新:

Error Level

  1. PACK_FILES_MISSING: 没把产物及源码中引入的目录配置到 files 字段中
  2. EFFECTS_IN_SIDE_EFFECTS: sideEffects 配置有误,例如产物里有引入 css 却配置了 false,或 rollup 不兼容的 *.css 配法
  3. PHANTOM_DEPS: 使用了某个依赖但却没在 dependencies 中声明,导致幽灵依赖
  4. NOT_OWNER: 不是当前包的 owner,没有发布权限(未登录时不检查)(取消,只检查项目自身的问题)
  5. CASE_SENSITIVE_PATHS: 引入路径的文件大小写与磁盘上的大小写不符,作用于默认大小写不敏感的操作系统(比如 Windows 和 macOS)
  6. CJS_IMPORT_ESM: 在 cjs 产物中引入了 esm 依赖,这会导致发包实际运行时出现 ERR_REQUIRE_ESM 报错

Warning Level

  1. PREFER_PACK_FILES: 建议指定 files 字段、减小 NPM 产物体积
  2. PREFER_NO_CSS_MODULES: 不建议使用 CSS Modules,使用者难以覆写样式,且会增加额外的编译成本
  3. PREFER_BABEL_RUNTIME: 建议安装 @babel/runtmedependencies,以节省产物大小(仅 babel transformer 下检查)
  4. DUP_IN_PEER_DEPS: peerDependenciesdependencies 里有相同依赖
  5. MISSING_REGISTRY: 检查 registry 是否符合预期(还没想好,有私有 npm 工具的存在不好实现)
  6. PREFER_PEER_DEPS: 有多实例风险的依赖应该放入 peerDependencies,比如 reactantd
@PeachScript PeachScript added the help wanted Extra attention is needed label Jul 7, 2022
@xiaohuoni
Copy link
Member

有没有发包权限,算不算?

@ahwgs
Copy link

ahwgs commented Jul 7, 2022

1、发包 registry 地址是否符合预期
2、发包前先检查下npm 是否包名重复?哈哈哈

@siyi98
Copy link

siyi98 commented Jul 7, 2022

PREFER_PACK_DEP_DUP: 检查 peerDependenciesdependencies 是否声明了相同依赖

@xierenyuan
Copy link
Member

xierenyuan commented Jul 7, 2022

npm scope 是不是配置了
"publishConfig": { "access": "public" }

私有包是否指定了 registry
"publishConfig": { "registry": "https://npm.private.com" }

@ahwgs
Copy link

ahwgs commented Jul 7, 2022

之前有一个场景,一个类create-xxx cli工具
模版目录下有一个packages.json 发包的时候模版目录下的packages.json files 会与主项目packages.json files 冲突,导致发包的文件丢失。需要将模版目录下的packages.json 改名

这种场景 doctor 能监测吗

@txp1035
Copy link
Member

txp1035 commented Jul 7, 2022

之前有一个场景,一个类create-xxx cli工具 模版目录下有一个packages.json 发包的时候模版目录下的packages.json files 会与主项目packages.json files 冲突,导致发包的文件丢失。需要将模版目录下的packages.json 改名

这种场景 doctor 能监测吗
我试了下两个package.json可以发布的,如果是打包移动文件把文件弄掉了那得去看打包流程

image

@PeachScript
Copy link
Member Author

借鉴 https://publint.dev 的规则并转换成 father doctor 的 rule,源码:https://github.com/bluwy/publint/blob/master/pkg/src/message.js#L13

@PeachScript PeachScript transferred this issue from umijs/father-next Mar 28, 2023
@PeachScript PeachScript pinned this issue Apr 3, 2023
@fz6m
Copy link
Member

fz6m commented Apr 4, 2023

针对 exports.types 有一个专门的网站来检测兼容性,比较复杂。

https://github.com/arethetypeswrong/arethetypeswrong.github.io

@PeachScript
Copy link
Member Author

针对 exports.types 有一个专门的网站来检测兼容性,比较复杂

是指 CJS_IMPORT_ESM 这条规则吗,目前只打算覆盖引入了 pure esm 依赖但又输出了 cjs 产物的情况,避免实际运行时报错,所以实现上比较简单,在这个 PR 里 #623

@fz6m
Copy link
Member

fz6m commented Apr 6, 2023

这个 arethetypeswrong.github.io 是用来检测用户开发库时, exports 是否正确配置的。

背景

现在 TS 5 的 moduleResolution: 'bundler' / 'nodenext' 越来越流行,这个选项是专门为业务项目设计的,他会改变 TS 的类型读取行为,改为从 package.json#exports.types 读取(实际中还可能是更细致的条件入口,但类型都会从 exports.xxx.types 下面读),而不会从 package.json#types 读取 。

因为这个行为的改变,社区很多库都类型爆炸失效了,参考 这条 反馈,这是因为人们并不知道真正规范的 exports 是怎么配置的。

问题

关于 exports 的广泛性,现在绝大部分浏览器包都会有这个配置了,专门为现代打包工具使用(webpack5 、esbuild 等),但问题出在很多人都把他配错了。

如何解这个问题:

  1. 用 publint 可以检测到 exports 的配置错误。

  2. arethetypeswrong.github.io 可以检测 exports.types 是否正确配置,这是 publint 做不到的,而且是很关键的,因为一旦配错了,用户在 TS 里用这个库会类型完全爆炸。

综上,描述了 arethetypeswrong.github.io 的必要性,这个检测应该存在于用户开发时,配置了 package.json#exports 的场景。

@PeachScript
Copy link
Member Author

描述了 arethetypeswrong.github.io 的必要性

👍 get,感觉可以参考它拆一些 doctor 规则出来

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
Projects
None yet
Development

No branches or pull requests

7 participants