Skip to content

Commit e01be14

Browse files
authored
fix(typst): Skip typst when self-update is disabled (#1397)
1 parent dd6bc58 commit e01be14

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

Cargo.lock

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ rust-i18n = "3.0.1"
5454
sys-locale = "0.3.1"
5555
jetbrains-toolbox-updater = "5.0.0"
5656
indexmap = { version = "2.9.0", features = ["serde"] }
57+
serde_json = "1.0.145"
5758

5859
[package.metadata.generate-rpm]
5960
assets = [{ source = "target/release/topgrade", dest = "/usr/bin/topgrade" }]

src/steps/generic.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use jetbrains_toolbox_updater::{find_jetbrains_toolbox, update_jetbrains_toolbox
55
use regex::bytes::Regex;
66
use rust_i18n::t;
77
use semver::Version;
8+
use serde::Deserialize;
89
use std::ffi::OsString;
910
use std::iter::once;
1011
use std::path::PathBuf;
@@ -1779,9 +1780,40 @@ pub fn run_yazi(ctx: &ExecutionContext) -> Result<()> {
17791780
ctx.execute(ya).args(["pkg", "upgrade"]).status_checked()
17801781
}
17811782

1783+
#[derive(Deserialize)]
1784+
struct TypstInfo {
1785+
build: TypstBuild,
1786+
}
1787+
1788+
#[derive(Deserialize)]
1789+
struct TypstBuild {
1790+
settings: TypstSettings,
1791+
}
1792+
1793+
#[derive(Deserialize)]
1794+
#[serde(rename_all = "kebab-case")]
1795+
struct TypstSettings {
1796+
self_update: bool,
1797+
}
1798+
17821799
pub fn run_typst(ctx: &ExecutionContext) -> Result<()> {
17831800
let typst = require("typst")?;
17841801

1802+
let raw_info = ctx
1803+
.execute(&typst)
1804+
.args(["info", "-f", "json"])
1805+
.output_checked_utf8()?
1806+
.stdout;
1807+
let info: TypstInfo = serde_json::from_str(&raw_info).wrap_err_with(|| {
1808+
output_changed_message!(
1809+
"typst info -f json",
1810+
"json output invalid or does not contain .build.settings.self-update"
1811+
)
1812+
})?;
1813+
if !info.build.settings.self_update {
1814+
return Err(SkipStep("This build of typst does not have self-update enabled".to_string()).into());
1815+
}
1816+
17851817
print_separator("Typst");
17861818

17871819
ctx.execute(typst).args(["update"]).status_checked()

0 commit comments

Comments
 (0)