-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(taro-platform-h5): 修复生成definition.json api为空,导致Taro.xxx未能被转换 #17543
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
Conversation
Walkthrough此次更改更新了 Changes
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This reverts commit 8256f13.
ada3c68
to
1218941
Compare
我还是先revert吧,看着还有snap文件的变动之类的 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
packages/babel-plugin-transform-taroapi/__tests__/__snapshots__/index.spec.ts.snap
is excluded by!**/*.snap
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (13)
.github/workflows/nodejs.yml
(2 hunks)packages/taro-h5/package.json
(2 hunks)packages/taro-h5/rollup.config.mts
(2 hunks)packages/taro-h5/tsconfig.json
(1 hunks)packages/taro-platform-h5/build/definition-json/parser.ts
(1 hunks)packages/taro-platform-harmony-hybrid/package.json
(1 hunks)packages/taro-platform-harmony-hybrid/rollup.config.ts
(4 hunks)packages/taro-platform-harmony-hybrid/tsconfig.json
(1 hunks)packages/taro-platform-harmony/package.json
(1 hunks)packages/taro-platform-harmony/rollup.config.ts
(6 hunks)packages/taro-router/package.json
(1 hunks)packages/taro-runtime/package.json
(2 hunks)packages/taro-runtime/rollup.config.ts
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/taro-platform-h5/build/definition-json/parser.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/taro-platform-harmony-hybrid/rollup.config.ts (1)
packages/taro-framework-vue3/rollup.config.js (1)
cwd
(8-8)
packages/taro-platform-harmony/rollup.config.ts (1)
packages/taro-framework-vue3/rollup.config.js (1)
cwd
(8-8)
🪛 actionlint (1.7.4)
.github/workflows/nodejs.yml
121-121: input "move_coverage_to_trash" is not defined in action "codecov/codecov-action@v4". available inputs are "codecov_yml_path", "commit_parent", "directory", "disable_file_fixes", "disable_safe_directory", "disable_search", "dry_run", "env_vars", "exclude", "fail_ci_if_error", "file", "files", "flags", "git_service", "handle_no_reports_found", "job_code", "name", "network_filter", "network_prefix", "os", "override_branch", "override_build", "override_build_url", "override_commit", "override_pr", "plugin", "plugins", "report_code", "root_dir", "slug", "token", "url", "use_legacy_upload_endpoint", "use_oidc", "verbose", "version", "working-directory"
(action)
129-129: input "move_coverage_to_trash" is not defined in action "codecov/codecov-action@v4". available inputs are "codecov_yml_path", "commit_parent", "directory", "disable_file_fixes", "disable_safe_directory", "disable_search", "dry_run", "env_vars", "exclude", "fail_ci_if_error", "file", "files", "flags", "git_service", "handle_no_reports_found", "job_code", "name", "network_filter", "network_prefix", "os", "override_branch", "override_build", "override_build_url", "override_commit", "override_pr", "plugin", "plugins", "report_code", "root_dir", "slug", "token", "url", "use_legacy_upload_endpoint", "use_oidc", "verbose", "version", "working-directory"
(action)
137-137: input "move_coverage_to_trash" is not defined in action "codecov/codecov-action@v4". available inputs are "codecov_yml_path", "commit_parent", "directory", "disable_file_fixes", "disable_safe_directory", "disable_search", "dry_run", "env_vars", "exclude", "fail_ci_if_error", "file", "files", "flags", "git_service", "handle_no_reports_found", "job_code", "name", "network_filter", "network_prefix", "os", "override_branch", "override_build", "override_build_url", "override_commit", "override_pr", "plugin", "plugins", "report_code", "root_dir", "slug", "token", "url", "use_legacy_upload_endpoint", "use_oidc", "verbose", "version", "working-directory"
(action)
145-145: input "move_coverage_to_trash" is not defined in action "codecov/codecov-action@v4". available inputs are "codecov_yml_path", "commit_parent", "directory", "disable_file_fixes", "disable_safe_directory", "disable_search", "dry_run", "env_vars", "exclude", "fail_ci_if_error", "file", "files", "flags", "git_service", "handle_no_reports_found", "job_code", "name", "network_filter", "network_prefix", "os", "override_branch", "override_build", "override_build_url", "override_commit", "override_pr", "plugin", "plugins", "report_code", "root_dir", "slug", "token", "url", "use_legacy_upload_endpoint", "use_oidc", "verbose", "version", "working-directory"
(action)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
🔇 Additional comments (26)
packages/taro-platform-harmony-hybrid/tsconfig.json (1)
9-9
: 保留调试选项及简化配置
此处明确配置"sourceMap": true
保留了调试信息,同时移除了不再需要的"declaration"
和"outDir"
配置。请确认这一更改符合整体构建和发布策略。packages/taro-h5/tsconfig.json (2)
8-8
: 关闭 sourceMap 生成
将"sourceMap"
修改为false
意味着不生成 source map 文件,请确保这不会影响 H5 调试和错误追踪。
10-10
: 更新 Rollup 配置文件路径
"include"
数组中将rollup.config.ts
替换为rollup.config.mts
,确保构建流程加载的是新的模块格式配置文件。packages/taro-router/package.json (1)
11-11
: 更新声明文件属性
将原先的"types": "dist/index.d.ts"
替换为"typings": "dist/index.esm.d.ts"
,这有助于保持与 ECMAScript 模块格式的一致性。请确认对外接口引用时使用正确的声明文件。packages/taro-platform-harmony/package.json (1)
50-50
: 切换 Rollup TypeScript 插件
使用"rollup-plugin-ts": "^3.4.5"
替换旧版的插件配置,有助于改进 TypeScript 的构建流程。建议确认该插件的配置与整个构建系统保持一致。packages/taro-platform-harmony-hybrid/package.json (2)
63-63
: 降级 @rollup/plugin-typescript 版本
将"@rollup/plugin-typescript"
版本从之前的较高版本调整为^11.1.0
,此调整可能是为了提高构建稳定性,请核实新版插件在所有构建场景下均能正常工作。
70-70
: 新增 rollup-plugin-ts 依赖
添加"rollup-plugin-ts": "^3.4.5"
以与其他包保持一致,帮助优化 TypeScript 文件的 Rollup 构建流程。packages/taro-h5/package.json (3)
26-26
: 变更 Rollup 配置文件格式将 Rollup 配置从
.ts
更改为.mts
并添加了--bundleConfigAsCjs
标志。这个更改使得配置文件采用 ES 模块格式,同时确保输出兼容 CommonJS。这是一个正向的改进,更符合现代 JavaScript 模块化标准。
27-27
: 更新测试脚本路径将测试命令从简单的
jest
更改为直接引用node_modules/jest/bin/jest.js
。这种做法可以确保使用当前项目依赖中的 Jest 版本,避免全局安装的 Jest 可能带来的版本不一致问题。
73-73
: 更换 TypeScript 插件将
@rollup/plugin-typescript
替换为rollup-plugin-ts
。这个变更是整个 PR 中一系列插件更换的一部分,目的可能是为了更好的 TypeScript 支持或构建性能。这个改动应该与第 26 行的 Rollup 配置文件变更保持一致,确保插件能够正确加载和使用。
packages/taro-runtime/rollup.config.ts (2)
4-4
: 更新 TypeScript 插件导入将
@rollup/plugin-typescript
替换为rollup-plugin-ts
。这与 package.json 中的依赖变更保持一致,是整个项目构建系统更新的一部分。
16-16
: 简化 TypeScript 插件配置移除了原有 TypeScript 插件的配置选项,使用更简洁的方式初始化 ts 插件。这表明
rollup-plugin-ts
可能具有更好的默认配置,减少了样板代码,简化了维护工作。.github/workflows/nodejs.yml (1)
121-121
:❓ Verification inconclusive
检查 Codecov 行为的参数有效性
添加了
move_coverage_to_trash: true
参数到 Codecov 行为中。虽然这个参数的目的可能是清理已处理的覆盖率文件以避免工作空间混乱,但静态分析显示move_coverage_to_trash
不是codecov/codecov-action@v4
的定义输入。这可能导致工作流运行时出现问题。建议验证此参数的有效性,或者检查 Codecov 文档以找到正确的参数名称。
Also applies to: 129-129, 137-137, 145-145
🏁 Script executed:
#!/bin/bash # 查询 codecov-action 的最新文档,验证参数有效性 curl -s https://raw.githubusercontent.com/codecov/codecov-action/master/action.yml | grep -A 2 "move_coverage_to_trash"Length of output: 119
验证 Codecov Action 输入参数
move_coverage_to_trash
的有效性目前通过自动查询 Codecov Action 的定义文件未能检索到
move_coverage_to_trash
参数,建议您手动查阅 Codecov 官方文档确认该参数是否被支持。如果确认该参数不再有效或未被定义,请在工作流程配置中删除或修正对应设置,以免影响 workflow 的正常运行。
- 涉及文件:
.github/workflows/nodejs.yml
- 相关行:121, 129, 137, 145
🧰 Tools
🪛 actionlint (1.7.4)
121-121: input "move_coverage_to_trash" is not defined in action "codecov/codecov-action@v4". available inputs are "codecov_yml_path", "commit_parent", "directory", "disable_file_fixes", "disable_safe_directory", "disable_search", "dry_run", "env_vars", "exclude", "fail_ci_if_error", "file", "files", "flags", "git_service", "handle_no_reports_found", "job_code", "name", "network_filter", "network_prefix", "os", "override_branch", "override_build", "override_build_url", "override_commit", "override_pr", "plugin", "plugins", "report_code", "root_dir", "slug", "token", "url", "use_legacy_upload_endpoint", "use_oidc", "verbose", "version", "working-directory"
(action)
packages/taro-runtime/package.json (2)
22-22
: 指定 Rollup 配置插件保留了
.ts
扩展名的 Rollup 配置文件,但明确指定了--configPlugin typescript
。这确保了使用正确的插件来处理配置文件,与项目中其他包采用的.mts
方式略有不同,但功能上应该是一致的。
43-43
: 更新 TypeScript 插件依赖将
@rollup/plugin-typescript
替换为rollup-plugin-ts
,与 rollup 配置文件中的导入保持一致。这是整个项目构建系统更新的一部分,目的是使用更现代的 TypeScript 处理方式。确保这个变更在所有相关文件中都保持一致,以避免构建过程中的兼容性问题。
packages/taro-h5/rollup.config.mts (2)
7-7
: 改进了依赖项管理从
@rollup/plugin-typescript
切换到rollup-plugin-ts
是一项很好的改进,这与PR中其他文件的更改保持一致。rollup-plugin-ts
提供了更好的TypeScript支持和更灵活的配置选项。
27-30
:✅ Verification successful
配置优化,启用了源映射
通过添加
tsconfig
函数并设置sourceMap: true
,改进了TypeScript编译配置。这将有助于调试,并且可能与修复API定义问题有间接关系,因为更好的类型处理可能会影响最终生成的定义文件。
🏁 Script executed:
#!/bin/bash # 检查TypeScript相关包的版本和依赖关系 grep -r "rollup-plugin-ts\|@rollup/plugin-typescript" --include="package.json" .Length of output: 2547
配置优化验证通过:已正确启用 SourceMap
在
packages/taro-h5/rollup.config.mts
中,通过如下配置:tsconfig: (e) => ({ ...e, sourceMap: true, }),实现了合并原有 tsconfig 设置并启用 sourceMap,从而提高了调试体验,并可能间接改善 API 定义问题。同时,根据检查依赖包版本的信息,
rollup-plugin-ts
与@rollup/plugin-typescript
均处于符合要求的版本范围。packages/taro-platform-harmony-hybrid/rollup.config.ts (5)
1-2
: 添加了必要的路径模块和更新了TS插件添加了
path
模块导入并更换了TypeScript插件,这是一个合理的改进。使用rollup-plugin-ts
可以提供更强大的TypeScript处理能力,这可能与修复API定义问题有关。Also applies to: 9-9
15-16
: 添加了当前工作目录常量添加
cwd
常量用于后续路径解析是一个良好的实践,这样可以确保无论从哪里执行构建脚本,路径都能正确解析。这与其他文件中的做法保持一致。
37-43
: 改进了TypeScript编译配置通过使用
tsconfig
函数并启用declaration
和sourceMap
选项,改进了TypeScript编译配置。设置declaration: true
对于生成类型声明文件很重要,这可能与修复API定义问题直接相关,因为API定义可能依赖于这些生成的声明文件。
91-91
: 使用动态路径解析导出插件为
rollup-plugin-export-name-only.js
使用动态路径是个好习惯,提高了代码的可维护性。这个插件可能与处理API导出名称有关,可能与修复API定义问题相关。
80-80
:✅ Verification successful
使用动态路径解析
使用
path.join(cwd, 'src/runtime/apis/index.ts')
替代硬编码路径,提高了代码的可维护性和跨平台兼容性。这个文件看起来与Taro API转换直接相关,注释中提到"供 babel-plugin-transform-taroapi 使用",这可能是修复PR中提到的API问题的关键部分。
🏁 Script executed:
#!/bin/bash # 检查taroApis.js的输出和相关配置 grep -r "babel-plugin-transform-taroapi" --include="*.json" --include="*.js" --include="*.ts" .Length of output: 1747
确认动态路径解析实现符合要求
经过验证,项目中与babel-plugin-transform-taroapi
相关的多个模块都已正确使用动态路径解析方式(例如在packages/taro-platform-harmony-hybrid/rollup.config.ts
第80行),此改动有效提升了代码的可维护性和跨平台兼容性,同时确保了 tree-shaking 功能不受影响。此次修改也验证了 PR 中对 API 问题修复的有效性,请继续关注相关测试,以确保整体稳定性。packages/taro-platform-harmony/rollup.config.ts (4)
1-2
: 添加了路径模块和更新了TS插件添加了
join
函数导入,切换到rollup-plugin-ts
插件,并定义了cwd
常量。这些更改与其他文件保持一致,是对构建配置的良好改进。使用当前目录作为基础路径可以确保跨平台构建的一致性。Also applies to: 8-9, 10-10
23-29
: 优化了TypeScript编译配置通过配置
declaration: true
和sourceMap: true
,改进了TypeScript编译设置。生成声明文件对于正确构建API定义非常重要,这可能是修复PR中描述的API问题的关键部分。
37-38
: 统一使用动态路径解析将所有输入和输出路径替换为使用
join(cwd, ...)
的形式,提高了代码的可维护性和跨平台兼容性。这是一个很好的改进,确保无论在哪个环境中构建项目,路径都能正确解析。Also applies to: 39-40, 62-63, 64-65, 73-74, 75-76, 84-85, 86-87
91-96
: 保持配置一致性对
otherConfig
中的TypeScript配置采用了相同的函数式配置方法,但保留了declaration: false
,这是合理的,因为这些组件文件可能不需要生成声明文件。这保持了整个配置的一致性和可维护性。
@@ -28,7 +28,7 @@ jobs: | |||
name: Build Rust WASM | |||
uses: ./.github/workflows/build-rust-wasm.yml | |||
|
|||
nodejs-testing: | |||
nodejs-tesing: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修复 Job 名称拼写错误
当前的 Job 名称 nodejs-tesing
缺少一个字母 't',应该是 nodejs-testing
。这个拼写错误应该被更正,以保持命名一致性。
- nodejs-tesing:
+ nodejs-testing:
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
nodejs-tesing: | |
nodejs-testing: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #17543 +/- ##
==========================================
+ Coverage 57.70% 58.37% +0.67%
==========================================
Files 469 469
Lines 26551 27231 +680
Branches 5872 6000 +128
==========================================
+ Hits 15321 15896 +575
- Misses 9768 9805 +37
- Partials 1462 1530 +68
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This reverts commit b8f0e34.
ref: #17480 (comment)
这个 PR 做了什么? (简要描述所做更改)
修复了
Taro.xxx
等api在h5平台undefined。原因是生成的definition.json的api为空,而definition.json的内容会被作为参数传递给babel插件babel-plugin-transform-taroapi
,将Taro.xxx
写法转换为import { xxx } from '@tarojs/taro'
。由于为空,所以无法得到转换,导致调用 Taro.xxx 会报错。这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
Summary by CodeRabbit