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

chore: add exports fields #12944

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

chore: add exports fields #12944

wants to merge 3 commits into from

Conversation

tolking
Copy link
Contributor

@tolking tolking commented Jun 17, 2024

Before submitting a pull request, please read the contributing guide.

在提交 pull request 之前,请阅读 贡献指南

fix vant-nuxt#31

unimport 中解析 vant 的目录大致为 ../../../node_modules/.pnpm/[email protected][email protected]/node_modules/vant/lib/vant.cjs,这使得自动导入的方法没有类型提示

增加导入后解析的目录变为 ../../../node_modules/.pnpm/[email protected][email protected]/node_modules/vant 类型提示正常

@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.62%. Comparing base (13e5464) to head (4df81cc).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12944      +/-   ##
==========================================
- Coverage   89.65%   89.62%   -0.03%     
==========================================
  Files         257      257              
  Lines        6977     6979       +2     
  Branches     1718     1719       +1     
==========================================
  Hits         6255     6255              
- Misses        383      386       +3     
+ Partials      339      338       -1     

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

@chenjiahan
Copy link
Member

添加 exports field 会导致无法引用子目录,比如 vant/lib/* 或者 vant/es/*,而且 exports field 对于批量导出的支持比较差,所以我们在之前的某个版本里移除了 exports field。

"require": "./lib/*.js",
"types": "./lib/*.d.ts"
},
"./es/*.mjs": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es/*.mjs 只能导出 lib 下面一级的文件,但是没法导出 es/button/style/index.mjs 这种多级目录的文件

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考 #10348

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是可以导出多级目录的。node 文档

  • maps expose nested subpaths as it is a string replacement syntax only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

咦,还真是。。

那当时是另一个问题了,原来允许忽略 index.mjs,加上 exports 以后不行了

比如 import 'vant/es/button/style':

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在没有后缀的地址会增加 /index.m?js

这样会出现一个问题

vant/es/button/Button -> vant/es/button/Button/index.mjs

只有 vant/es/button/Button.mjs -> vant/es/button/Button.mjs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,添加 exports fields 还是会有潜在的 breaking 风险,通常来说放在大版本里发布比较合适,我们可以先看一下 Nuxt 全局方法的类型问题有没有其他解决方法。。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, 我先看看官方提供的增加类型可以用不

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.

3 participants