mirror of
https://github.com/typst/typst
synced 2025-06-28 08:12:53 +08:00
parent
c87f802cf6
commit
4e5cc61599
@ -199,22 +199,20 @@ impl FontsSettings {
|
|||||||
|
|
||||||
/// Execute a compilation command.
|
/// Execute a compilation command.
|
||||||
fn compile(mut command: CompileSettings) -> StrResult<()> {
|
fn compile(mut command: CompileSettings) -> StrResult<()> {
|
||||||
let root = if let Some(root) = &command.root {
|
// Determine the parent directory of the input file.
|
||||||
root.clone()
|
let parent = command
|
||||||
} else if let Some(dir) = command
|
|
||||||
.input
|
.input
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.ok()
|
.ok()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|path| path.parent())
|
.and_then(|path| path.parent())
|
||||||
{
|
.unwrap_or(Path::new("."))
|
||||||
dir.into()
|
.to_owned();
|
||||||
} else {
|
|
||||||
PathBuf::new()
|
let root = command.root.as_ref().unwrap_or(&parent);
|
||||||
};
|
|
||||||
|
|
||||||
// Create the world that serves sources, fonts and files.
|
// Create the world that serves sources, fonts and files.
|
||||||
let mut world = SystemWorld::new(root, &command.font_paths);
|
let mut world = SystemWorld::new(root.into(), &command.font_paths);
|
||||||
|
|
||||||
// Perform initial compilation.
|
// Perform initial compilation.
|
||||||
let ok = compile_once(&mut world, &command)?;
|
let ok = compile_once(&mut world, &command)?;
|
||||||
@ -236,10 +234,17 @@ fn compile(mut command: CompileSettings) -> StrResult<()> {
|
|||||||
let mut watcher = RecommendedWatcher::new(tx, notify::Config::default())
|
let mut watcher = RecommendedWatcher::new(tx, notify::Config::default())
|
||||||
.map_err(|_| "failed to watch directory")?;
|
.map_err(|_| "failed to watch directory")?;
|
||||||
|
|
||||||
// Watch root directory recursively.
|
// Watch the input file's parent directory recursively.
|
||||||
watcher
|
watcher
|
||||||
.watch(&world.root, RecursiveMode::Recursive)
|
.watch(&parent, RecursiveMode::Recursive)
|
||||||
.map_err(|_| "failed to watch directory")?;
|
.map_err(|_| "failed to watch parent directory")?;
|
||||||
|
|
||||||
|
// Watch the root directory recursively.
|
||||||
|
if world.root != parent {
|
||||||
|
watcher
|
||||||
|
.watch(&world.root, RecursiveMode::Recursive)
|
||||||
|
.map_err(|_| "failed to watch root directory")?;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle events.
|
// Handle events.
|
||||||
let timeout = std::time::Duration::from_millis(100);
|
let timeout = std::time::Duration::from_millis(100);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user