-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Fix/Windows路径解析问题 #18335
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
base: main
Are you sure you want to change the base?
Fix/Windows路径解析问题 #18335
Conversation
Walkthrough在 packages/taro-platform-h5/src/program.ts 中,modifyWebpackConfig 的默认分支在 useHtmlComponents 为 true 时,对插入到 loaderMeta.extraImportForWeb 的导入代码增加了 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. ✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: 0
🧹 Nitpick comments (2)
packages/taro-platform-h5/src/program.ts (2)
143-146: 将路径规范化移动到统一出口,避免只覆盖这一处目前仅对这段新增的 import 片段做
.replace(/\\/g, '/'),而在同一函数内更早追加到extraImportForWeb的内容(如 Line 128、133)未被规范化,存在行为不一致的风险;同时 Vite 分支未做同样处理。建议在返回前对整段loaderMeta.extraImportForWeb做一次统一规范化,并同步到 Vite 插件,保证 webpack/vite 一致。建议修改如下:
default: if (this.useHtmlComponents) { - args[0].loaderMeta.extraImportForWeb += `import '@tarojs/components-react/dist/index.css'\nimport { PullDownRefresh } from '@tarojs/components'\n`.replace(/\\/g, '/') + args[0].loaderMeta.extraImportForWeb += `import '@tarojs/components-react/dist/index.css'\nimport { PullDownRefresh } from '@tarojs/components'\n` args[0].loaderMeta.execBeforeCreateWebApp += `config.PullDownRefresh = PullDownRefresh\n` } } + // 统一归一化,覆盖所有之前追加的片段 + args[0].loaderMeta.extraImportForWeb = + (args[0].loaderMeta.extraImportForWeb || '').replace(/\\/g, '/') return argsVite 分支对应位置(
injectLoaderMeta内)也建议追加一行统一处理:default: if (that.useHtmlComponents) { viteCompilerContext.loaderMeta.extraImportForWeb += `import { PullDownRefresh } from '@tarojs/components'\n` viteCompilerContext.loaderMeta.execBeforeCreateWebApp += `config.PullDownRefresh = PullDownRefresh\n` } } + // 统一归一化,保持与 webpack 行为一致 + viteCompilerContext.loaderMeta.extraImportForWeb = + (viteCompilerContext.loaderMeta.extraImportForWeb || '').replace(/\\/g, '/')验证点:
- 请在 Windows 下构建一次,检查最终注入到虚拟入口/编译产物中的 import 语句是否完全使用正斜杠。
143-146: 如需更稳妥,限定只替换 import 源中的反斜杠若将来注入代码包含字符串/正则字面量中的反斜杠,整串替换可能“误伤”。可以仅替换
import ... from '...'/import '...'源部分。可选替代实现(示意):
args[0].loaderMeta.extraImportForWeb = (args[0].loaderMeta.extraImportForWeb || '').replace( /(import\s+(?:['"][^'"]+['"]|[\s\S]*?\sfrom\s+['"])([^'"]+)(['"]))/g, (_, p1, spec, p3) => p1.replace(spec, spec.replace(/\\/g, '/')) )同理应用于 Vite 分支。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/taro-platform-h5/src/program.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。
Learnt from: ianzone
PR: NervJS/taro#18150
File: packages/taro-platform-harmony-hybrid/package.json:43-45
Timestamp: 2025-09-05T18:40:45.775Z
Learning: 在 tarojs/plugin-platform-harmony-hybrid 包中,tarojs/components-library-react、tarojs/components-library-solid 和 tarojs/components-library-vue3 必须作为直接依赖(dependencies)而不能作为 peer 依赖,因为插件源码中有对这些包的直接引用,包括 componentAdapter* getter 方法和 webpack 别名配置。
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18335 +/- ##
==========================================
+ Coverage 54.98% 55.05% +0.07%
==========================================
Files 417 416 -1
Lines 21693 21560 -133
Branches 5352 5267 -85
==========================================
- Hits 11928 11870 -58
+ Misses 8245 8038 -207
- Partials 1520 1652 +132
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
| default: | ||
| if (this.useHtmlComponents) { | ||
| args[0].loaderMeta.extraImportForWeb += `import '@tarojs/components-react/dist/index.css'\nimport { PullDownRefresh } from '@tarojs/components'\n` | ||
| args[0].loaderMeta.extraImportForWeb += `import '@tarojs/components-react/dist/index.css'\nimport { PullDownRefresh } from '@tarojs/components'\n`.replace(/\\/g, '/') |
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.
模版里好像也没有反斜杠呢
这个 PR 做了什么? (简要描述所做更改)
修改了
program.ts文件,在extraImportForWeb字符串末尾添加了 .replace(/\/g, '/') 方法调用,确保字符串中的反斜杠被替换为正斜杠,从而解决Windows环境下的路径兼容性问题。这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit