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

fix: correctly check mdBook version compatibility #45

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
22 changes: 18 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use anyhow::{anyhow, Context as _};
use mdbook::config::HtmlConfig;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

mod book;
Expand Down Expand Up @@ -53,14 +54,27 @@ impl mdbook::Renderer for Renderer {
}

fn render(&self, ctx: &mdbook::renderer::RenderContext) -> anyhow::Result<()> {
let compiled_mdbook_version = semver::VersionReq::parse(mdbook::MDBOOK_VERSION).unwrap();
// If we're compiled against mdbook version I.J.K, require ^I.J
// This allows using a version of mdbook with an earlier patch version as a server
static MDBOOK_VERSION_REQ: Lazy<semver::VersionReq> = Lazy::new(|| {
let compiled_mdbook_version = semver::Version::parse(mdbook::MDBOOK_VERSION).unwrap();
semver::VersionReq {
comparators: vec![semver::Comparator {
op: semver::Op::Caret,
major: compiled_mdbook_version.major,
minor: Some(compiled_mdbook_version.minor),
patch: None,
pre: Default::default(),
}],
}
});
let mdbook_server_version = semver::Version::parse(&ctx.version).unwrap();
if !compiled_mdbook_version.matches(&mdbook_server_version) {
if !MDBOOK_VERSION_REQ.matches(&mdbook_server_version) {
log::warn!(
"{} is semver-incompatible with mdbook {} (compiled against {})",
"{} is semver-incompatible with mdbook {} (requires {})",
env!("CARGO_PKG_NAME"),
mdbook_server_version,
compiled_mdbook_version,
*MDBOOK_VERSION_REQ,
);
}

Expand Down