mirror of
https://github.com/typst/typst
synced 2025-06-28 08:12:53 +08:00
Allow packages to specify their minimum compiler version
This commit is contained in:
parent
68a25f497e
commit
2f672b4e2e
@ -265,6 +265,17 @@ pub struct PackageVersion {
|
|||||||
pub patch: u32,
|
pub patch: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PackageVersion {
|
||||||
|
/// The current compiler version.
|
||||||
|
pub fn compiler() -> Self {
|
||||||
|
Self {
|
||||||
|
major: env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(),
|
||||||
|
minor: env!("CARGO_PKG_VERSION_MINOR").parse().unwrap(),
|
||||||
|
patch: env!("CARGO_PKG_VERSION_PATCH").parse().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for PackageVersion {
|
impl FromStr for PackageVersion {
|
||||||
type Err = EcoString;
|
type Err = EcoString;
|
||||||
|
|
||||||
|
@ -1920,6 +1920,16 @@ impl PackageManifest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(compiler) = self.package.compiler {
|
||||||
|
let current = PackageVersion::compiler();
|
||||||
|
if current < compiler {
|
||||||
|
bail!(
|
||||||
|
"package requires typst {compiler} or newer \
|
||||||
|
(current version is {current})"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1935,6 +1945,8 @@ struct PackageInfo {
|
|||||||
version: PackageVersion,
|
version: PackageVersion,
|
||||||
/// The path of the entrypoint into the package.
|
/// The path of the entrypoint into the package.
|
||||||
entrypoint: EcoString,
|
entrypoint: EcoString,
|
||||||
|
/// The minimum required compiler version for the package.
|
||||||
|
compiler: Option<PackageVersion>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eval for ast::LoopBreak<'_> {
|
impl Eval for ast::LoopBreak<'_> {
|
||||||
|
1
tests/packages/future-0.1.0/lib.typ
vendored
Normal file
1
tests/packages/future-0.1.0/lib.typ
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
#future
|
5
tests/packages/future-0.1.0/typst.toml
vendored
Normal file
5
tests/packages/future-0.1.0/typst.toml
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[package]
|
||||||
|
name = "future"
|
||||||
|
version = "0.1.0"
|
||||||
|
entrypoint = "lib.typ"
|
||||||
|
compiler = "1.0.0"
|
@ -25,7 +25,7 @@ use typst::doc::{Document, Frame, FrameItem, Meta};
|
|||||||
use typst::eval::{eco_format, func, Bytes, Datetime, Library, NoneValue, Tracer, Value};
|
use typst::eval::{eco_format, func, Bytes, Datetime, Library, NoneValue, Tracer, Value};
|
||||||
use typst::font::{Font, FontBook};
|
use typst::font::{Font, FontBook};
|
||||||
use typst::geom::{Abs, Color, RgbaColor, Smart};
|
use typst::geom::{Abs, Color, RgbaColor, Smart};
|
||||||
use typst::syntax::{FileId, Source, Span, SyntaxNode, VirtualPath};
|
use typst::syntax::{FileId, PackageVersion, Source, Span, SyntaxNode, VirtualPath};
|
||||||
use typst::{World, WorldExt};
|
use typst::{World, WorldExt};
|
||||||
use typst_library::layout::{Margin, PageElem};
|
use typst_library::layout::{Margin, PageElem};
|
||||||
use typst_library::text::{TextElem, TextSize};
|
use typst_library::text::{TextElem, TextSize};
|
||||||
@ -719,7 +719,10 @@ fn parse_part_metadata(source: &Source) -> TestPartMetadata {
|
|||||||
let mut s = Scanner::new(expectation);
|
let mut s = Scanner::new(expectation);
|
||||||
let range = range(&mut s);
|
let range = range(&mut s);
|
||||||
let rest = if range.is_some() { s.after() } else { s.string() };
|
let rest = if range.is_some() { s.after() } else { s.string() };
|
||||||
let message = rest.trim().into();
|
let message = rest
|
||||||
|
.trim()
|
||||||
|
.replace("VERSION", &PackageVersion::compiler().to_string())
|
||||||
|
.into();
|
||||||
annotations.insert(Annotation { kind, range, message });
|
annotations.insert(Annotation { kind, range, message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
#import "@test/adder:0.1.0": add
|
#import "@test/adder:0.1.0": add
|
||||||
#test(add(2, 8), 10)
|
#test(add(2, 8), 10)
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test too high required compiler version.
|
||||||
|
// Error: 9-29 package requires typst 1.0.0 or newer (current version is VERSION)
|
||||||
|
#import "@test/future:0.1.0": future
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 9-13 `@` is not a valid package namespace
|
// Error: 9-13 `@` is not a valid package namespace
|
||||||
#import "@@": *
|
#import "@@": *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user