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

Draft: add .node_version fallback #1974

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion crates/volta-core/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ impl Project {
extends = manifest.extends;
}

let platform = platform.map(TryInto::try_into).transpose()?;
let platform = match platform.map(TryInto::try_into).transpose()? {
Some(platform) => Some(platform),
None => Self::platform_from_node_version(&manifest_file),
};

Ok(Project {
manifest_file,
Expand All @@ -119,6 +122,25 @@ impl Project {
})
}

/// Returns a Node.js version from .node_version_file
fn platform_from_node_version(manifest_file: &Path) -> Option<PlatformSpec> {
// project path without package.json
let project_path = manifest_file.parent()?;

match std::fs::read_to_string(project_path.join(".node_version")) {
Ok(version) => match Version::parse(version) {

Choose a reason for hiding this comment

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

How Version::parse resolves ranges?
22 > 22.0.0?

Copy link
Author

@easymikey easymikey Jan 10, 2025

Choose a reason for hiding this comment

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

There will be a error in the current draft. It won't be difficult to add the latest available version.

Choose a reason for hiding this comment

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

@easymikey What needs to be done for this to be merged?

Copy link
Author

Choose a reason for hiding this comment

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

I can implement this logic on Monday, if needed quickly. But do you know if mentainers can merge it?

@andreassjoberg

Ok(node) => Some(PlatformSpec {
node,
yarn: None,
npm: None,
pnpm: None,
}),
Err(_) => None,
},
Err(_) => None,
}
}

/// Returns a reference to the manifest file for the current project
pub fn manifest_file(&self) -> &Path {
&self.manifest_file
Expand Down