Move versions file to cache

feature/lookup-installed
trivernis 1 year ago
parent b628d8860c
commit 1db8ffda5c
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -15,7 +15,6 @@ pub struct Config {
pub struct NodeConfig {
/// The default version if no version is specified
/// in the `package.json` file or `NODE_VERSION` environment variable
#[serde(with = "NodeVersion")]
pub default_version: NodeVersion,
}

@ -14,7 +14,7 @@ lazy_static! {
.unwrap_or_else(|| PathBuf::from(".cache"))
.join(PathBuf::from("nenv"));
pub static ref CFG_FILE_PATH: PathBuf = CFG_DIR.join("config.toml");
pub static ref VERSION_FILE_PATH: PathBuf = DATA_DIR.join("versions.cache");
pub static ref VERSION_FILE_PATH: PathBuf = CACHE_DIR.join("versions.cache");
pub static ref BIN_DIR: PathBuf = DATA_DIR.join("bin");
pub static ref NODE_VERSIONS_DIR: PathBuf = DATA_DIR.join("versions");
pub static ref NODE_ARCHIVE_SUFFIX: String = format!("-{OS}-{ARCH}.{ARCHIVE_TYPE}");

@ -56,13 +56,23 @@ impl FromStr for NodeVersion {
}
}
impl NodeVersion {
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
impl<'de> Deserialize<'de> for NodeVersion {
#[inline]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
Self::from_str(&string).map_err(serde::de::Error::custom)
}
}
pub fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
impl Serialize for NodeVersion {
#[inline]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
self.to_string().serialize(serializer)
}
}
@ -165,7 +175,9 @@ impl Repository {
#[tracing::instrument(level = "debug", skip(self))]
pub async fn install_version(&self, version: &NodeVersion) -> Result<()> {
let info = self.lookup_version(version)?;
self.downloader.download(&info.version).await
self.downloader.download(&info.version).await?;
Ok(())
}
/// Performs a lookup for the given node version

Loading…
Cancel
Save