diff --git a/Cargo.lock b/Cargo.lock index f294e76..b73c6a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2086,9 +2086,6 @@ name = "semver" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" -dependencies = [ - "serde", -] [[package]] name = "serde" @@ -2756,17 +2753,6 @@ dependencies = [ "syn", ] -[[package]] -name = "typst-project" -version = "0.1.0" -source = "git+https://github.com/tingerrr/typst-project?rev=a71db54#a71db5451ebdca2174adc0a323c71ba5ab2f8120" -dependencies = [ - "bitflags 2.6.0", - "semver", - "serde", - "toml", -] - [[package]] name = "typst-render" version = "0.12.0" @@ -2838,7 +2824,7 @@ dependencies = [ "tracing-tree", "typst", "typst-kit", - "typst-project", + "typst-syntax", "typst-test-lib", "typst-test-stdx", "ureq", diff --git a/Cargo.toml b/Cargo.toml index 415f14e..d4273b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,6 @@ keywords = ["typst", "test"] readme = "README.md" [workspace.dependencies] -typst-project = { git = "https://github.com/tingerrr/typst-project", rev = "a71db54" } - typst-test-lib = { path = "crates/typst-test-lib" } typst-test-stdx = { path = "crates/typst-test-stdx" } @@ -63,5 +61,6 @@ typst-assets = "0.12.0" typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "ee8ae61" } typst-kit = "0.12.0" typst-render = "0.12.0" +typst-syntax = "0.12.0" unscanny = "0.1.0" ureq = { version = "2.9.7", default-features = false } diff --git a/crates/typst-test-cli/Cargo.toml b/crates/typst-test-cli/Cargo.toml index 08fb92c..c83910f 100644 --- a/crates/typst-test-cli/Cargo.toml +++ b/crates/typst-test-cli/Cargo.toml @@ -49,8 +49,8 @@ tracing.workspace = true tracing-subscriber.workspace = true tracing-tree.workspace = true typst.workspace = true -typst-project.workspace = true typst-kit.workspace = true +typst-syntax.workspace = true ureq = { workspace = true, default-features = false, features = ["native-tls", "gzip", "json"] } [features] diff --git a/crates/typst-test-cli/src/cli.rs b/crates/typst-test-cli/src/cli.rs index 0644883..ee80ca7 100644 --- a/crates/typst-test-cli/src/cli.rs +++ b/crates/typst-test-cli/src/cli.rs @@ -6,6 +6,7 @@ use std::sync::{mpsc, Arc}; use chrono::{DateTime, Utc}; use clap::ColorChoice; +use ecow::EcoString; use termcolor::Color; use thiserror::Error; use typst_test_lib::store::vcs::{Git, Vcs}; @@ -75,7 +76,7 @@ impl Failure for NoProject { } #[derive(Debug, Error)] -pub struct ProjectNotInitialized(pub Option); +pub struct ProjectNotInitialized(pub Option); impl Display for ProjectNotInitialized { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -187,7 +188,7 @@ impl<'a> Context<'a> { Some(root) => root.to_path_buf(), None => { let pwd = std::env::current_dir()?; - match typst_project::try_find_project_root(&pwd)? { + match project::try_find_project_root(&pwd)? { Some(root) => { if !root.try_exists()? { anyhow::bail!(OperationFailure::from(RootNotFound(root.to_path_buf()))); diff --git a/crates/typst-test-cli/src/cli/init.rs b/crates/typst-test-cli/src/cli/init.rs index 88bda03..f3615a4 100644 --- a/crates/typst-test-cli/src/cli/init.rs +++ b/crates/typst-test-cli/src/cli/init.rs @@ -2,6 +2,7 @@ use std::fmt::Display; use std::io; use std::io::Write; +use ecow::EcoString; use serde::Serialize; use termcolor::{Color, WriteColor}; use thiserror::Error; @@ -35,7 +36,7 @@ pub enum Vcs { } #[derive(Debug, Error)] -pub struct ProjectAlreadyIntialized(Option); +pub struct ProjectAlreadyIntialized(Option); impl Display for ProjectAlreadyIntialized { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/crates/typst-test-cli/src/project.rs b/crates/typst-test-cli/src/project.rs index f76f426..ce28b97 100644 --- a/crates/typst-test-cli/src/project.rs +++ b/crates/typst-test-cli/src/project.rs @@ -5,10 +5,11 @@ use std::str::FromStr; use std::{fs, io}; use rayon::prelude::*; +use serde::Deserialize; use tiny_skia::Pixmap; use toml_edit::DocumentMut; use tracing::Level; -use typst_project::manifest::Manifest; +use typst_syntax::package::PackageManifest; use typst_test_lib::config::Config; use typst_test_lib::store::project::v1::ResolverV1; use typst_test_lib::store::project::Resolver; @@ -23,15 +24,34 @@ use typst_test_stdx::result::ResultEx; use crate::cli; +const MANIFEST_FILE: &str = "typst.toml"; +const MANIFEST_CONFIG_KEY: &str = "typst-test"; + const DEFAULT_TEST_INPUT: &str = include_str!("../../../assets/default-test/test.typ"); const DEFAULT_TEST_OUTPUT: &[u8] = include_bytes!("../../../assets/default-test/test.png"); -pub fn try_open_manifest(root: &Path) -> anyhow::Result> { +pub fn is_project_root(root: &Path) -> anyhow::Result { + let manifest_path = root.join(MANIFEST_FILE); + Ok(manifest_path.try_exists()?) +} + +pub fn try_find_project_root(root: &Path) -> anyhow::Result> { + for ancestor in root.ancestors() { + if is_project_root(ancestor)? { + return Ok(Some(ancestor)); + } + } + + Ok(None) +} + +pub fn try_open_manifest(root: &Path) -> anyhow::Result> { tracing::debug!(?root, "reading manifest"); - if typst_project::is_project_root(root)? { - let content = std::fs::read_to_string(root.join(typst_project::heuristics::MANIFEST_FILE))?; - let manifest = Manifest::from_str(&content)?; + if is_project_root(root)? { + let content = std::fs::read_to_string(root.join(MANIFEST_FILE))?; + let manifest = toml::from_str(&content)?; + Ok(Some(manifest)) } else { Ok(None) @@ -41,7 +61,7 @@ pub fn try_open_manifest(root: &Path) -> anyhow::Result> { #[derive(Debug)] pub struct Project { config: Config, - manifest: Option, + manifest: Option, resolver: ResolverV1, vcs: Option>, tests: BTreeMap, @@ -53,17 +73,13 @@ impl Project { pub fn new( root: PathBuf, vcs: Option>, - manifest: Option, + manifest: Option, ) -> anyhow::Result { let config = manifest .as_ref() - .and_then(|m| { - m.tool - .as_ref() - .map(|t| t.get_section::("typst-test")) - }) + .and_then(|m| m.tool.sections.get(MANIFEST_CONFIG_KEY)) + .map(|c| Config::deserialize(c.clone())) .transpose()? - .flatten() .inspect(|config| { tracing::trace!(?config, "read manifest config"); }) @@ -108,7 +124,7 @@ impl Project { &mut self.config } - pub fn manifest(&self) -> Option<&Manifest> { + pub fn manifest(&self) -> Option<&PackageManifest> { self.manifest.as_ref() } @@ -312,7 +328,7 @@ impl Project { #[tracing::instrument(level = Level::DEBUG, skip(self), fields(config = ?self.config))] pub fn write_config(&self) -> anyhow::Result<()> { - let path = self.root().join(typst_project::heuristics::MANIFEST_FILE); + let path = self.root().join(MANIFEST_FILE); let content = std::fs::read_to_string(&path) .ignore_default(|err| err.kind() == io::ErrorKind::NotFound)?;