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: unexpected exports in demo pre-compiling result #1926

Merged
merged 2 commits into from
Oct 7, 2023

Conversation

PeachScript
Copy link
Member

🤔 这个变动的性质是?/ What is the nature of this change?

  • 新特性提交 / New feature
  • bug 修复 / Fix bug
  • 样式优化 / Style optimization
  • 代码风格优化 / Code style optimization
  • 性能优化 / Performance optimization
  • 构建优化 / Build optimization
  • 网站、文档、Demo 改进 / Website, documentation, demo improvements
  • 重构代码或样式 / Refactor code or style
  • 测试相关 / Test related
  • 其他 / Other

🔗 相关 Issue / Related Issue

Close #1920

💡 需求背景和解决方案 / Background or solution

修复 dumi v1 demo 预编译结果中包含非预期 exports 导致编译报错的问题。

大致原因:

  • 虽然 dumi 锁了 babel,但非预打包的方式锁不了间接依赖,由 @babel/plugin-transform-modules-commonjs 间接引用到了更新的 babel 版本,和 @umijs/babel-preset-umi 用到的预打包的 babel 版本对不上
  • 使用 Babel REPL 测试最新版本是正常的(不会出现类似 exports['default'] = function _default() {} 的语句)
  • 所以推测该问题是因为间接使用不同版本的 babel 生态包(7.23.0 与 7.18.6),导致 AST 结果异常
    考虑到 dumi 1 已经不再迭代,精力有限上述猜想就不继续验证了

解决方案:

  • 本质解是 Umi 3 的 @umijs/deps 把 dumi 需要的 @babel/plugin-transform-modules-commonjs 一起预打包,这样间接依赖也被打进去了,但 Umi 3 做预打包的改动风险比较高,预打包脚本很久没有维护了,加上对 Umi 3 的项目造成的影响是未知的,收益又不算高,只影响 dumi 1(Bigfish 3 组件库)应用,所以放弃本质解
  • 平衡解是 dumi 1 对 exports['default'] = function _default() {} 也做转换,目前只转了 exports['default'] = _default,该方案的好处是代码改动量很小,加上 Babel 8 已经进入 alpha 阶段,v7 未来再出现类似影响的概率较小,所以选择平衡解

📝 更新日志 / Changelog

Language Changelog
🇺🇸 English Fix unexpected exports in demo pre-compiling result
🇨🇳 Chinese 修复 demo 预编译结果中意外出现 exports 的问题

@vercel
Copy link

vercel bot commented Oct 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dumi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 7, 2023 8:05am

@codecov
Copy link

codecov bot commented Oct 7, 2023

Codecov Report

All modified lines are covered by tests ✅

❗ No coverage uploaded for pull request base (1.x@5cb6003). Click here to learn what that means.

Additional details and impacted files
@@          Coverage Diff           @@
##             1.x    #1926   +/-   ##
======================================
  Coverage       ?   94.69%           
======================================
  Files          ?      119           
  Lines          ?     2960           
  Branches       ?      985           
======================================
  Hits           ?     2803           
  Misses         ?      153           
  Partials       ?        4           

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

@PeachScript PeachScript merged commit abc4aec into 1.x Oct 7, 2023
9 checks passed
@PeachScript PeachScript deleted the hotfix/wrong-demo-ast branch October 7, 2023 09:15
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.

1 participant