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

feat: default (runtime) Node.js version #2794

Draft
wants to merge 8 commits into
base: v2
Choose a base branch
from

Conversation

luc122c
Copy link
Contributor

@luc122c luc122c commented Oct 13, 2024

πŸ”— Linked issue

Closes #2716

❓ 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

A preset should accept the user's choice of Node.js runtime, as long as it is supported by the platform. In cases where the user's choice is not supported, or the user does not specify a runtime, a sensible default/fallback should be used.

Currently, the fallback is defined per preset. However, to ensure all deploy providers behave uniformly, we should define this globally at the Nitro level.

See #2654 (comment) for reference.

Methodology

To decide an appropriate fallback, we need to know two pieces of information:

  • Node versions supported by the platform
  • How to define a runtime from a node version

To do this, we can export a getDefaultNodeVersion utility which takes the supported Node versions as a set of numbers, and a function to convert the number to a runtime defintion. It then compared this to a globally set default. As Nitro is updated and newer Node features are used, this global can be increased to bump all presets.

Examples

const supportedNodeVersions = new Set([18, 20]);
const defineRuntime = (version) => `nodejs-${version}`;

const default = getDefaultNodeVersion(supportedNodeVersions, defineRuntime);
const supportedNodeVersions = new Set([16, 18, 20]);
const default = getDefaultNodeVersion(supportedNodeVersions, String);

Considerations

This utility should consider the case where the Nitro default is not supported by the platform yet.

The documentation for preset authors should be updated to only list GA node versions in supportedNodeVersions.

πŸ“ Checklist

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

@luc122c
Copy link
Contributor Author

luc122c commented Oct 13, 2024

Hi @pi0 I have written up my idea and implemented it into a couple of presets. Before I continue and implement it into others, I thought it would be wise to seek some feedbadk.

What do you think of the idea? Do you think the utilities and constants are located in the right places? Is there anything else you would like me to consider?

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.

Default (runtime) Node.js version
1 participant