-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to determine and track the config version.
- Loading branch information
1 parent
09df520
commit 8ff45a1
Showing
6 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//! For determining which configuration version we're using. | ||
use axoasset::SourceFile; | ||
use camino::Utf8PathBuf; | ||
use serde::Deserialize; | ||
|
||
use crate::{DistError, DistResult}; | ||
|
||
const MAX_VERSION: i64 = 1; | ||
|
||
// Extremely minimal struct designed to differentiate between config versions. | ||
// V0 does not have the `config-version` field, so will fail to parse. | ||
// V1+ should have it, so will parse, and contain a `config_version` field. | ||
#[derive(Deserialize)] | ||
#[serde(rename_all = "kebab-case")] | ||
struct FauxDistTable { | ||
#[allow(dead_code)] | ||
config_version: i64, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct FauxConfig { | ||
#[allow(dead_code)] | ||
dist: FauxDistTable, | ||
} | ||
|
||
/// Return the default versioni. | ||
pub fn default() -> i64 { | ||
1 | ||
} | ||
|
||
/// Return the config version used for the root workspace. | ||
pub fn get_version() -> DistResult<i64> { | ||
let workspaces = super::get_project()?; | ||
let root_workspace = workspaces.root_workspace(); | ||
|
||
get_version_for_manifest(root_workspace.manifest_path.to_owned()) | ||
} | ||
|
||
|
||
/// Given a path to a dist manifest (e.g. `dist-workspace.toml`), returns | ||
/// the config version being used. | ||
pub fn get_version_for_manifest(dist_manifest_path: Utf8PathBuf) -> DistResult<i64> { | ||
if dist_manifest_path.file_name() != Some("dist-workspace.toml") { | ||
// If the manifest is in Cargo.toml or dist.toml, we're | ||
// definitely using a v0 config. | ||
return Ok(0); | ||
} | ||
|
||
let src = SourceFile::load_local(&dist_manifest_path)?; | ||
|
||
let Ok(config) = src.deserialize_toml::<FauxConfig>() else { | ||
// If we could load it, but can't parse it, it's likely v0. | ||
return Ok(0); | ||
}; | ||
|
||
let version = config.dist.config_version; | ||
|
||
if version <= MAX_VERSION { | ||
Ok(version) | ||
} else { | ||
Err(DistError::InvalidConfigVersion { | ||
manifest_path: dist_manifest_path.into(), | ||
config_version: version, | ||
max_version: MAX_VERSION, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters