Skip to content

presets(vercel): hard link custom function dirs instead of copying#4373

Open
RihanArfan wants to merge 3 commits into
mainfrom
vercel-symlink-functions
Open

presets(vercel): hard link custom function dirs instead of copying#4373
RihanArfan wants to merge 3 commits into
mainfrom
vercel-symlink-functions

Conversation

@RihanArfan

Copy link
Copy Markdown
Member

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Instead of copying __server.func when there is modifications to .vc-config.json, we now hard link all files to it. We cannot symlink within a functions dir to another since on Vercel the builder cannot resolve the files, which is why we recursively hard link.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@RihanArfan RihanArfan requested a review from pi0 as a code owner June 23, 2026 03:19
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Jun 29, 2026 9:27pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c9c62fbe-90a6-4ca0-b69d-680383dddb37

📥 Commits

Reviewing files that changed from the base of the PR and between 6de81ee and d5bda43.

📒 Files selected for processing (2)
  • src/presets/_utils/fs.ts
  • src/presets/vercel/utils.ts

📝 Walkthrough

Walkthrough

A new hardLinkDir function is added to the shared filesystem utilities, recursively recreating a directory tree using hard links (with symlink preservation and a copyFile fallback). The Vercel preset's createFunctionDirWithCustomConfig is updated to use this helper instead of fsp.cp, skipping .vc-config.json.

Changes

Hard-link based Vercel function directory creation

Layer / File(s) Summary
hardLinkDir utility implementation
src/presets/_utils/fs.ts
Adds join to the pathe import and exports a new hardLinkDir(src, dest, options?) function that recursively builds a directory tree at dest via hard links, re-creates symlinks, recurses into subdirectories, and falls back to copyFile on EXDEV/EPERM. Accepts an optional skip set to exclude named entries.
Vercel preset integration
src/presets/vercel/utils.ts
Adds hardLinkDir to the fs utilities import and replaces the fsp.cp recursive copy in createFunctionDirWithCustomConfig with hardLinkDir(serverDir, funcDir, { skip: new Set(['.vc-config.json']) }).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title follows conventional commits format with type prefix and clearly describes the main change of switching from copying to hard linking for Vercel function directories.
Description check ✅ Passed Description is directly related to the changeset, explaining the motivation for replacing copying with hard linking in the Vercel preset's custom function directory handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch vercel-symlink-functions

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4373

commit: 3675810

Comment thread src/presets/_utils/fs.ts
*
* Entries listed in `skip` are ignored at the top level only.
*/
export async function hardLinkDir(src: string, dest: string, options: { skip?: Set<string> } = {}) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried fs.cp (https://nodejs.org/api/fs.html#fspromisescpsrc-dest-options) with COPYFILE_FICLONE flag? (https://nodejs.org/api/fs.html#fspromisescopyfilesrc-dest-mode) (it should have same CoW effect but hopefully faster since we don't do recursion ourselve.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants