Skip to content
Open
Changes from 1 commit
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
27 changes: 26 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,28 @@ 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()?;
let version_file_path = project_path.join(".node-version");
let version_content = std::fs::read_to_string(version_file_path).ok()?;
let version = version_content
.trim()
.strip_prefix('v')
.unwrap_or(version_content.trim());

match Version::parse(version) {
Ok(node) => Some(PlatformSpec {
node,
yarn: None,
npm: None,
pnpm: 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
Loading