-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(vite-runner): 修正vite 选项 fs.allow 的默认值
#18291
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在 H5 Vite 配置中,引入了 Changes
Sequence Diagram(s)sequenceDiagram
participant App as H5 Runner
participant Config as H5 Config Builder
participant Vite as Vite Dev Server
App->>Config: 构建 Vite 配置
note over Config: 默认 fs.allow = [searchForWorkspaceRoot(process.cwd())]
alt 用户提供 serverOption.fs.allow
Config->>Config: 使用用户值覆盖默认
else 未提供
Config->>Config: 使用默认工作区根目录
end
Config->>Vite: 传入最终 server.fs.allow
Vite-->>App: 启动 Dev Server(基于允许的文件系统路径)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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-vite-runner/src/h5/config.ts (2)
7-7: 统一引号风格,修复 ESLint 报错本行使用了双引号,项目其余 import 基本为单引号,且 ESLint 已报 quotes 错误。建议改为单引号以通过 lint。
-import { searchForWorkspaceRoot } from "vite" +import { searchForWorkspaceRoot } from 'vite'
145-148: 建议用 appPath 提升一致性与可移植性此处使用
process.cwd()在某些集成场景(例如从非项目根目录启动、脚本切换 cwd、IDE 运行配置)可能与实际应用路径不一致。建议改为使用已从上下文解构的appPath,更贴近 Taro/RN 内部约定并与下方build.outDir等配置保持一致。- let fsAllow: string[] = [searchForWorkspaceRoot(process.cwd())] + let fsAllow: string[] = [searchForWorkspaceRoot(appPath)]如需进一步稳妥,也可在用户自定义
allow时追加而非完全覆盖(与 Vite 语义不同,需谨慎评估),以避免误配置导致再次“拒绝服务”:- if (serverOption.fs && Array.isArray(serverOption.fs.allow)) { - fsAllow = serverOption.fs.allow - } + if (serverOption.fs && Array.isArray(serverOption.fs.allow)) { + fsAllow = serverOption.fs.allow + // 可选:若希望兼容默认工作区根目录,避免覆盖导致误拒绝 + // fsAllow = Array.from(new Set([...serverOption.fs.allow, searchForWorkspaceRoot(appPath)])) + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/taro-vite-runner/src/h5/config.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/taro-vite-runner/src/h5/config.ts (1)
packages/taro-vite-runner/src/utils/compiler/base.ts (1)
process(49-53)
🪛 ESLint
packages/taro-vite-runner/src/h5/config.ts
[error] 7-7: Strings must use singlequote.
(quotes)
🔇 Additional comments (2)
packages/taro-vite-runner/src/h5/config.ts (2)
145-148: 修复点准确:默认 allow 与 Vite 行为对齐,解决 “outside of Vite serving allow list”将默认值从
[]改为[searchForWorkspaceRoot(...)]能恢复 Vite 的默认允许路径,解决 4.1.6 后 dev 启动报错问题,且仍允许用户通过serverOption.fs.allow显式覆盖,符合预期。
7-7: 确认searchForWorkspaceRoot已在 Vite 4.x 导出
packages/taro-vite-runner/package.json中声明了vite依赖范围为^4,Vite 4.x 内置searchForWorkspaceRootAPI(示例见 Vite 4 配置文档),无需额外变更。 (v4.vite.dev)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18291 +/- ##
=======================================
Coverage 55.05% 55.05%
=======================================
Files 416 416
Lines 21560 21560
Branches 5256 5284 +28
=======================================
Hits 11870 11870
+ Misses 8042 8034 -8
- Partials 1648 1656 +8
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
fs.allowfs.allow 的默认值
这个 PR 做了什么? (简要描述所做更改)
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
修复 #18152 中的错误: 更新 4.1.6 后启动开发服务器报错:
原因为新增的默认值中,
fs.allow被错误的设置为[], 此时 Vite 会拒绝为任何文件提供服务本PR将默认值改为
[searchForWorkspaceRoot()], 以对齐 Vite 默认行为参考: https://cn.vite.dev/config/server-options.html#server-fs-allow
Summary by CodeRabbit
新功能
缺陷修复