fix: make frontend-vite Cloudflare peer optional - #731
Conversation
|
Warning Review limit reached
More reviews will be available in 47 minutes and 3 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesCloudflare 플러그인 선택적 peer dependency 전환
Sequence Diagram(s)sequenceDiagram
participant Consumer as 소비자 코드
participant Plugin as crocoVitePlugin()
participant Loader as loadCloudflarePlugin()
participant CFPlugin as `@cloudflare/vite-plugin`
Consumer->>Plugin: crocoVitePlugin({ cloudflare: true, ssr })
Plugin->>Loader: loadCloudflarePlugin({ ssr })
Loader->>CFPlugin: dynamic import("`@cloudflare/vite-plugin`")
alt 모듈 존재
CFPlugin-->>Loader: { cloudflare } 반환
Loader-->>Plugin: PluginOption[] 반환
Plugin-->>Consumer: PluginOption[] 반환
else 모듈 누락 (ERR_MODULE_NOT_FOUND)
CFPlugin-->>Loader: ModuleNotFoundError 던지기
Loader-->>Plugin: MissingCloudflareVitePluginProblem 던지기
Plugin-->>Consumer: 설치 안내 오류 전파
end
Consumer->>Plugin: crocoVitePlugin({ cloudflare: false })
Plugin-->>Consumer: [] 즉시 반환
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 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 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 |
📊 Benchmark Results❌ Some benchmarks failed
Updated: 2026-06-14T19:07:42.354Z · Commit: 971a4d6 |
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 `@packages/frontend-vite/src/libs/crocoVitePlugin.ts`:
- Around line 20-25: The crocoVitePlugin function is throwing a generic Error
instead of a Problem subclass, which violates the RFC 7807 Problem-based error
handling guidelines. Replace the thrown Error with an appropriate Problem
subclass (such as MissingDependencyProblem or a similar existing Problem class
that represents missing peer dependencies) to align with the coding standards
for error handling.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 03106def-6a05-4477-90f3-7e4ed36e2f20
📒 Files selected for processing (7)
.changeset/frontend-vite-cloudflare-contract.mdpackages/frontend-vite/README.mdpackages/frontend-vite/package.jsonpackages/frontend-vite/src/libs/crocoVitePlugin.tspackages/frontend-vite/src/libs/types.tspackages/frontend-vite/src/tests/crocoVitePlugin.spec.tsscripts/package-entrypoint-smoke.mts
f697ff5 to
a239c5e
Compare
a239c5e to
3828434
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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
`@packages/frontend-vite/src/libs/problems/MissingCloudflareVitePluginProblem.ts`:
- Around line 8-17: The MissingCloudflareVitePluginProblem class constructor is
currently using ProblemCategory.InternalServerError, which represents runtime
server errors (500), but missing optional peer dependencies are
build/configuration-time issues rather than runtime errors. Replace
ProblemCategory.InternalServerError with a more semantically appropriate
category such as BadRequest (400 for build configuration errors),
ValidationError (422 for build setting validation failures), or NotImplemented
(501 for unavailable plugins), depending on which best reflects the nature of
the missing Cloudflare Vite plugin in your system's problem categorization
scheme.
In `@packages/frontend-vite/src/tests/crocoVitePlugin.spec.ts`:
- Around line 77-100: The collectPlugins function does not await Promises within
nested arrays, which could leave unresolved Promises if Vite's PluginOption
contains nested Promise structures. In the collectPlugins function, when
handling the array case (the for loop that iterates through pluginOption array
elements), modify the code to await each nestedPluginOption before passing it to
the recursive collectPlugins call, ensuring all Promise values are resolved
regardless of nesting depth. This will make the helper robust for handling any
combination of nested arrays and Promises that Vite's PluginOption type allows.
- Around line 57-74: The test "should preserve nested module resolution errors
from the cloudflare plugin" currently relies on a module reset happening in a
previous afterEach hook, making it fragile to test execution order or parallel
runs. Add an explicit vi.resetModules() call at the very beginning of this test
function, before the vi.doMock call, to ensure the test has a clean and
independent module state regardless of how tests are ordered or executed.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: cd315ea5-dc22-47cd-b7cd-c8e12e4afc9c
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
.changeset/frontend-vite-cloudflare-contract.mdpackages/frontend-vite/README.mdpackages/frontend-vite/package.jsonpackages/frontend-vite/src/index.tspackages/frontend-vite/src/libs/crocoVitePlugin.tspackages/frontend-vite/src/libs/problems/MissingCloudflareVitePluginProblem.tspackages/frontend-vite/src/libs/types.tspackages/frontend-vite/src/tests/crocoVitePlugin.spec.tsscripts/package-entrypoint-smoke.mts
Addressed by follow-up commits; all automated review threads are resolved, and the latest review rerun is blocked by prepaid credits.
Summary
@croco/frontend-vitenow treats@cloudflare/vite-pluginas an optional peer that is loaded only when Cloudflare integration is enabled, so consumers can import the root package and usecrocoVitePlugin({ cloudflare: false })without installing the Cloudflare plugin. The default Cloudflare path now emits a clear install diagnostic when the optional peer is absent.Fixes #636
변경 사항
@cloudflare/vite-pluginruntime import and lazy-load it only for the Cloudflare-enabled path.@cloudflare/vite-pluginas an optional peer dependency and documented the install contract.CrocoViteConfig/crocoVitePlugin()to use VitePluginOption[], which supports the lazy async plugin path.cloudflare: false, nested Cloudflare plugin resolution errors, and the copied-dist package entrypoint smoke fixture.@croco/frontend-vite.Verification
pnpm --filter @croco/frontend-vite test- 2 files, 9 tests passed.pnpm --filter @croco/frontend-vite typecheck- passed.pnpm --filter @croco/frontend-vite build- passed.pnpm check- passed.pnpm package-entrypoints:smoke- framework-context CJS/ESM, frontend-vite CJS/ESM, and nested-error smoke passed.pnpm install --lockfile-only --frozen-lockfile- passed.pnpm exec changeset status --since origin/trunk- patch bump reported for@croco/frontend-vite.auto-changeset, fulltest(195 tasks), and fulltypecheck(194 tasks) passed.Self-review
cloudflare: falsework without the Cloudflare plugin; the default path reports the missing optional peer; and installed Cloudflare plugin nested resolution failures are preserved instead of rewritten.--frozen-lockfile, and the return type is broadened to Vite's supportedPluginOption[]for async plugin loading. A patch changeset covers the public package behavior change.Risk
Low. Consumers with explicit
Plugin[]annotations aroundcrocoVitePlugin()may need to accept Vite'sPluginOption[], matching Vite's config contract and enabling the optional lazy load.Summary by CodeRabbit
릴리스 노트
새로운 기능
crocoVitePlugin({ cloudflare: false })설정 시 관련 의존성 설치 없이 사용 가능합니다.버그 수정
문서/타입
crocoVitePlugin및 설정의 플러그인 타입이PluginOption기준으로 정리되었습니다.기타