mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-12-23 08:47:50 +00:00
fix: correctly handle relative user-specified output paths in compile command (#1941)
This change ensures that user-specified output paths in the compile command are properly handled, including relative paths. Previously, the export task would reject relative output paths with an error. This change converts relative paths to absolute paths by joining them with the current working directory, allowing users to specify relative paths like 'output/test.pdf' when compiling documents. The fix adds path normalization using PathClean and handles the conversion gracefully while maintaining the existing behavior for absolute paths. Fixes the issue where commands like: tinymist compile resume-en.typ ./output/test.pdf would fail with "output path is relative" error.
This commit is contained in:
parent
641b28fc45
commit
3821861134
2 changed files with 8 additions and 1 deletions
|
|
@ -207,7 +207,7 @@ impl TaskCompileArgs {
|
|||
|
||||
let export = ExportTask {
|
||||
when,
|
||||
output: None,
|
||||
output: self.output.as_deref().map(PathPattern::new),
|
||||
transform: transforms,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use reflexo_typst::{Bytes, CompilationTask, ExportComputation};
|
|||
use tinymist_project::LspWorld;
|
||||
use tinymist_std::error::prelude::*;
|
||||
use tinymist_std::fs::paths::write_atomic;
|
||||
use tinymist_std::path::PathClean;
|
||||
use tinymist_std::typst::TypstDocument;
|
||||
use tinymist_task::{get_page_selection, ExportMarkdownTask, ExportTarget, PdfExport, TextExport};
|
||||
use tokio::sync::mpsc;
|
||||
|
|
@ -178,6 +179,12 @@ impl ExportTask {
|
|||
let Some(write_to) = output.substitute(&entry) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let write_to = if write_to.is_relative() {
|
||||
let cwd = std::env::current_dir().context("failed to get current directory")?;
|
||||
cwd.join(write_to).clean()
|
||||
} else {
|
||||
write_to.to_path_buf()
|
||||
};
|
||||
if write_to.is_relative() {
|
||||
bail!("ExportTask({task:?}): output path is relative: {write_to:?}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue