Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vercel): clamp runtime config to valid node versions #2824

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

cjpearson
Copy link
Contributor

πŸ”— Linked issue

#2819

❓ 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

This change ensures that only supported node versions will be used as the default runtime value for the vercel preset. If a non-LTS version of node is used, it will use the previous LTS. If the version is outside the range supported by vercel, it will be clamped to the min/max of the supported range.

The runtime value can still be manually overridden as needed.

πŸ“ Checklist

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

@cjpearson cjpearson requested a review from pi0 as a code owner October 31, 2024 14:57
@pi0 pi0 changed the title fix(vercel): clamp runtime config to valid node versions (#2819) fix(vercel): clamp runtime config to valid node versions Oct 31, 2024
const runtimeVersion = `nodejs${systemNodeVersion}.x`;
const systemNodeVersion = getSystemNodeVersion();
const closestLtsVersion =
systemNodeVersion % 2 === 0 ? systemNodeVersion : systemNodeVersion - 1;
Copy link
Member

Choose a reason for hiding this comment

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

I think instead we can use an array of supported Node.js versions in vercel and clamp (up) to closest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you thinking something like this?

  let usedNodeVersion = 0;
  for (const version of SUPPORTED_NODE_VERSIONS) {
    if (Math.abs(systemNodeVersion - version) <= Math.abs(systemNodeVersion - usedNodeVersion)) {
      usedNodeVersion = version
    }
  }

Copy link
Member

Choose a reason for hiding this comment

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

Something like this could be nice πŸ‘πŸΌ I think if SUPPORTED_NODE_VERSIONS is sorted array, we can find first upper abound with simple find as well.

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