fix: support Nitro 2 and 3 server runtimes - #844
Conversation
|
@onmax is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
2b82982 to
346d651
Compare
346d651 to
5886d49
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe module adds Nitro v2 and Nitro v3 runtime compatibility setup. Server files now use project-local H3 and Nitro aliases. Runtime configuration access no longer passes request events. Tests, proxy-alias fixtures, Vitest aliases, and a Nitro 3 CI job validate the integration. Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/script/src/module.ts (1)
521-530: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winFail fast when a Nitro runtime helper cannot be resolved.
At Line [524],
resolveNuxtPath()can return a normalized input when resolution fails.pathToFileURL()can then create afile:URL for a nonexistent path. Validate each resolved file before registering the imports. The@nuxt/kitresolver documents this fallback behavior. (nuxt.com)Proposed validation
- const resolveNitroImport = async (id: string) => pathToFileURL(await resolveNuxtPath(id, { cwd: nitroDir })).href + const resolveNitroImport = async (id: string) => { + const resolved = await resolveNuxtPath(id, { cwd: nitroDir }) + if (!existsSync(resolved)) + throw new Error(`[nuxt-scripts] Could not resolve Nitro runtime helper "${id}" from "${nitroDir}".`) + return pathToFileURL(resolved).href + }🤖 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 `@packages/script/src/module.ts` around lines 521 - 530, Update the Nitro import setup in the Nuxt version branch, especially resolveNitroImport, to verify each resolved helper file exists before converting it with pathToFileURL or registering it through addServerImports. Fail immediately when resolution returns a nonexistent fallback path, and preserve registration only for valid Nitro runtime helpers..github/workflows/ci.yml (1)
173-174: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winRun the unknown-alias security test in the Nitro 3 job.
Line [174] skips the
rejects an unknown alias segmenttest intest/e2e/proxy-alias.test.tsat Lines [24] through [27]. An allowlist regression can therefore pass the Nitro 3 job. Addrejectsto the filter or run the complete proxy-alias test file.Proposed CI change
- run: pnpm vitest run --project e2e test/e2e/proxy-alias.test.ts -t 'auto-injects|resolves' + run: pnpm vitest run --project e2e test/e2e/proxy-alias.test.ts -t 'auto-injects|rejects|resolves'🤖 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 @.github/workflows/ci.yml around lines 173 - 174, Update the “Run Nitro 3 compatibility tests” step to include the `rejects` test pattern in its Vitest filter, or run the complete test/e2e/proxy-alias.test.ts file, so the unknown-alias rejection coverage executes alongside the existing auto-injects and resolves tests.
🤖 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 `@test/e2e/proxy-alias.test.ts`:
- Line 41: Remove the status assertion from the live-upstream test so a valid
alias is not rejected when Plausible returns an uncontrolled HTTP 500; cover
local Nitro runtime failures separately with a controlled upstream fixture or
unit test.
---
Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 173-174: Update the “Run Nitro 3 compatibility tests” step to
include the `rejects` test pattern in its Vitest filter, or run the complete
test/e2e/proxy-alias.test.ts file, so the unknown-alias rejection coverage
executes alongside the existing auto-injects and resolves tests.
In `@packages/script/src/module.ts`:
- Around line 521-530: Update the Nitro import setup in the Nuxt version branch,
especially resolveNitroImport, to verify each resolved helper file exists before
converting it with pathToFileURL or registering it through addServerImports.
Fail immediately when resolution returns a nonexistent fallback path, and
preserve registration only for valid Nitro runtime helpers.
🪄 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 Plus
Run ID: 9a1faeb1-1bf7-410a-9d33-fda6a68e809d
📒 Files selected for processing (19)
.github/workflows/ci.ymlpackages/script/src/module.tspackages/script/src/runtime/server/bluesky-embed.tspackages/script/src/runtime/server/google-maps-geocode-proxy.tspackages/script/src/runtime/server/google-static-maps-proxy.tspackages/script/src/runtime/server/gravatar-proxy.tspackages/script/src/runtime/server/instagram-embed.tspackages/script/src/runtime/server/proxy-handler.tspackages/script/src/runtime/server/utils/cached-upstream.tspackages/script/src/runtime/server/utils/withSigning.tspackages/script/src/runtime/server/x-embed.tstest/e2e/proxy-alias.test.tstest/fixtures/proxy-alias/nuxt.config.tstest/unit/__mocks__/stub-nitro-runtime.tstest/unit/cached-upstream.test.tstest/unit/proxy-handler-alias.test.tstest/unit/proxy-handler-body.test.tstest/unit/proxy-handler-hop-by-hop.test.tstest/unit/with-signing.test.ts
💤 Files with no reviewable changes (5)
- packages/script/src/runtime/server/gravatar-proxy.ts
- packages/script/src/runtime/server/proxy-handler.ts
- packages/script/src/runtime/server/google-static-maps-proxy.ts
- packages/script/src/runtime/server/utils/cached-upstream.ts
- packages/script/src/runtime/server/google-maps-geocode-proxy.ts
Co-authored-by: Harlan Wilton <harlan@harlanzw.com>
🔗 Linked issue
N/A
❓ Type of change
📚 Description
Nuxt 5 uses Nitro 3, which splits APIs previously exported by
nitropack/runtimeacrossnitro/app,nitro/cache, andnitro/runtime-config. Bare Nitro imports fail under strict pnpm isolation because Nuxt Scripts cannot depend directly on Nitro.This adds scoped
#nuxt-scripts/nitroand#nuxt-scripts/h3compatibility modules. Nitro 2 re-exports its existing runtime APIs. Nitro 3 entrypoints resolve through Nuxt's installed@nuxt/nitro-serverpackage. Server runtime files now use explicit scoped imports instead of ambient globals.Unit tests cover both compatibility paths. CI typechecks and runs the proxy fixture against Nuxt 5 and Nitro 3, while the existing suite covers Nuxt 4 and Nitro 2.
✅ Verification
pnpm lintpnpm typecheckpnpm build