refactor(uniapp): 自实现配置解析并补充单测#34
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough本 PR 将 UniApp JSON 条件编译解析移入本地工具:新增 src/utils/uniapp/config.ts(含 manifest/pages 解析、条件指令预处理、布尔表达式求值、注释/逗号清理等),添加 Vitest 配置与测试用例,并更新相关导出、插件导入与开发配置。 UniApp JSON 解析工具提取
总体概览本 PR 将 UniApp JSON 解析功能从外部依赖迁移到内部工具库。新增 src/utils/uniapp/config.ts 模块,提供带条件编译支持的 manifest.json 和 pages.json 解析能力,包含平台特定的指令处理、布尔表达式求值和 JSON 预处理功能。建立 Vitest 测试框架并提供完整的测试覆盖。 变更说明UniApp JSON 解析工具提取
📝 代码审查工作量估计🎯 3 (中等) | ⏱️ ~20 分钟 🐰 诗意庆贺
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/utils/uniapp/config.ts`:
- Around line 41-44: The current check returns an empty object whenever
process.env.UNI_COMPILE_TARGET is truthy, which can hide real missing-manifest
errors; change the logic in the block that checks fs.existsSync(filename) so it
only returns {} for an explicit whitelist of compile targets (e.g.
process.env.UNI_COMPILE_TARGET === 'ext-api' or membership in a small allowed
array) and otherwise throw or re-raise an error for the missing manifest; update
the condition that references process.env.UNI_COMPILE_TARGET and the early
return so only whitelisted targets short-circuit to {} while all other cases
surface the missing-file error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1a655d65-5509-4bfe-a5bc-9b7d13683633
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
.vscode/settings.jsonexamples/vue3+vite+ts/package.jsonpackage.jsonpnpm-workspace.yamlsrc/plugin/subpackages-optimization.tssrc/utils/uniapp/config.test.tssrc/utils/uniapp/config.tssrc/utils/uniapp/index.tsvitest.config.ts
💤 Files with no reviewable changes (2)
- examples/vue3+vite+ts/package.json
- pnpm-workspace.yaml
| if (!fs.existsSync(filename)) { | ||
| // 特殊编译目标可能没有完整项目配置,缺失 manifest 时按空配置处理 | ||
| if (process.env.UNI_COMPILE_TARGET) | ||
| return {} |
There was a problem hiding this comment.
收窄 manifest.json 缺失时的兜底条件,避免误吞配置错误
Line 43 当前只要 UNI_COMPILE_TARGET 有值就返回空对象,范围过大;这会在非特殊目标下把真实配置问题静默掩盖。建议仅对白名单目标(如 ext-api)兜底,其余情况继续抛错。
建议修改
if (!fs.existsSync(filename)) {
// 特殊编译目标可能没有完整项目配置,缺失 manifest 时按空配置处理
- if (process.env.UNI_COMPILE_TARGET)
+ if (process.env.UNI_COMPILE_TARGET === 'ext-api')
return {}
throw new Error(`[bundle-optimizer] manifest.json not found: ${filename}`)
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/utils/uniapp/config.ts` around lines 41 - 44, The current check returns
an empty object whenever process.env.UNI_COMPILE_TARGET is truthy, which can
hide real missing-manifest errors; change the logic in the block that checks
fs.existsSync(filename) so it only returns {} for an explicit whitelist of
compile targets (e.g. process.env.UNI_COMPILE_TARGET === 'ext-api' or membership
in a small allowed array) and otherwise throw or re-raise an error for the
missing manifest; update the condition that references
process.env.UNI_COMPILE_TARGET and the early return so only whitelisted targets
short-circuit to {} while all other cases surface the missing-file error.
Summary by CodeRabbit
发布说明
New Features
Tests
Chores