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
|
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 (14)
🚧 Files skipped from review as they are similar to previous changes (9)
📝 WalkthroughWalkthroughThe module adds Nuxt 5+ Nitro runtime helper registration. Server handlers now use globally registered Nitro composables and zero-argument 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
🔗 Linked issue
N/A
❓ Type of change
📚 Description
Warning
Feel free to close this PR if there is another way to make this work. I did it like this so I can also have the pkg.pr.new and be unblocked. Hopefully this is ok :)
Nuxt 5 uses Nitro 3, which splits the server runtime APIs previously exported by
nitropack/runtimeacrossnitro/app,nitro/cache, andnitro/runtime-config. Importing either version's entrypoints directly would make the other supported line fail to resolve.Nuxt 4 keeps using Nitro 2's built-in server auto-imports. On Nuxt 5, the module registers the three required Nitro 3 APIs with
addServerImports, resolving them from Nuxt's installed Nitro server package so this also works with strict pnpm dependency isolation.The existing test job continues to cover Nuxt 4/Nitro 2. A focused Nitro 3 job installs Nuxt 5, builds the existing proxy fixture, and exercises the live runtime config, cache, and proxy paths.
✅ Verification
pnpm lintpnpm typecheckpnpm buildpnpm exec vitest run --project unit --reporter=dot(779 passed, 2 todo)