8000 feat(schema): add `#server` alias for server directory imports by Flo0806 · Pull Request #33870 · nuxt/nuxt · GitHub
[go: up one dir, main page]

Skip to content

feat(schema): add #server alias for server directory imports#33870

Merged
danielroe merged 3 commits intonuxt:mainfrom
Flo0806:feat/server-alias
Dec 16, 2025
Merged

feat(schema): add #server alias for server directory imports#33870
danielroe merged 3 commits intonuxt:mainfrom
Flo0806:feat/server-alias

Conversation

@Flo0806
Copy link
Member
@Flo0806 Flo0806 commented Dec 13, 2025

🔗 Linked issue

Fixes: #33853

Summary

Adds a #server alias for clean imports within the server directory.

Before:

// server/api/users/[id]/profile.ts
import { helper } from '../../../../utils/helper'

After:

import { helper } from '#server/utils/helper'
  • Works like #shared but for server directory
  • Import protection prevents usage in client/shared context

Docs

  • Added a short description to the server docs.

Tests

  • Test added in packages/nuxt/test/load-nuxt.test.ts

@Flo0806 Flo0806 requested a review from danielroe as a code owner December 13, 2025 22:12
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Contributor
coderabbitai bot commented Dec 13, 2025

Walkthrough

This pull request adds a new public alias #server mapping to the configured serverDir in the alias resolver, appends an import-protection rule matching /^#server(\/|$)/ to disallow server alias usage in non-server contexts, and adds tests asserting #server and #server/* appear in Nitro TypeScript config paths. No exported/public function signatures were changed.

Possibly related PRs

  • nuxt/nuxt PR 33767: Modifies the same import-protection module (packages/nuxt/src/core/plugins/import-protection.ts) and its protection patterns, closely related to the added #server pattern.
  • nuxt/nuxt PR 32119: Alters the alias resolver in packages/schema/src/config/common.ts, affecting alias map entries like the newly added #server.
  • nuxt/nuxt PR 28682: Updates import-protection patterns and alias handling for layer-specific aliases (e.g. #shared), overlapping the same codepaths changed here.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly describes the main change: adding a #server alias for server directory imports, which aligns with all file modifications.
Description check ✅ Passed The PR description is directly related to the changeset, providing context about the #server alias feature, before/after examples, and testing approach.
Linked Issues check ✅ Passed The PR addresses the core objective from #33853 by introducing the #server alias for server directory imports and establishing correct tsconfig path mappings through import protection rules.
Out of Scope Changes check ✅ Passed All changes directly support the #server alias feature: schema changes define the alias, import protection enforces usage scope, tests verify functionality, and documentation describes usage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e128c0f and 380bc49.

📒 Files selected for processing (1)
  • docs/2.directory-structure/1.server.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/2.directory-structure/1.server.md

[uncategorized] ~146-~146: Loose punctuation mark.
Context: ...seful in deeply nested route handlers. ::note The #server alias can only be us...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~148-~148: Loose punctuation mark.
Context: ...in client code will result in an error. :: ## Server Types Auto-imports and oth...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: test-benchmark
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: code
🔇 Additional comments (1)
docs/2.directory-structure/1.server.md (1)

133-149: Documentation for #server alias is clear and well-integrated.

The new Server Alias section provides a clear explanation of the feature, includes a practical example showing the improvement over relative imports, and properly documents the scope constraint that the alias can only be used within the server/ directory. The placement between "Server Utilities" and "Server Types" sections is logical.

The static analysis tools flagged two "UNLIKELY_OPENING_PUNCTUATION" warnings related to the ::note directive blocks at lines 147–149. These appear to be false positives, as the ::note syntax is used consistently throughout the document (e.g. lines 60, 70, 101, 171, 247, 264, 346, 371, 402, 429, 458, 469). Please verify that this markdown directive syntax is correct for your documentation system and suppress these warnings if they are indeed false positives.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
pkg-pr-new bot commented Dec 13, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33870

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@33870

nuxt

npm i https://pkg.pr.new/nuxt@33870

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33870

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33870

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33870

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33870

commit: 380bc49

Copy link
Contributor
@coderabbitai coderabbitai bot left a 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 (1)
packages/kit/test/load-nuxt-config.spec.ts (1)

10-27: Consider making the alias assertion less brittle (and avoid for...in).

Adding #server to the snapshot looks correct, but snapshotting the entire config.alias object makes the test sensitive to unrelated alias insertions/order changes. Also, for...in can (in edge cases) traverse inherited enumerable props—Object.keys(config.alias) is a clearer intent for plain-object keys.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca5d51c and e128c0f.

📒 Files selected for processing (1)
  • packages/kit/test/load-nuxt-config.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/kit/test/load-nuxt-config.spec.ts
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently

Files:

  • packages/kit/test/load-nuxt-config.spec.ts
**/*.{test,spec}.{ts,tsx,js}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for core functionality using vitest

Files:

  • packages/kit/test/load-nuxt-config.spec.ts
🧠 Learnings (1)
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.

Applied to files:

  • packages/kit/test/load-nuxt-config.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: build
  • GitHub Check: code

@codspeed-hq
Copy link
codspeed-hq bot commented Dec 13, 2025

CodSpeed Performance Report

Merging #33870 will not alter performance

Comparing Flo0806:feat/server-alias (380bc49) with main (01d459e)

Summary

✅ 10 untouched

@danielroe danielroe added this to the 4.3 milestone Dec 16, 2025
@colinmollenhour
Copy link

Oof, just spent hours trying to get #server to work only to dig in and find that although this feature was merged and docs updated, it isn't actually available in the latest release yet..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsconfig.server.json has wrong alias for ~

5 participants

0