Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_yNXxbjBfCU5yfBpY1nXMQ.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-naming/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch"},"note":"Fix export issue","date":"2026-04-01T19:42:05.213092500Z"}
75 changes: 31 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions crates/vespertide-cli/src/commands/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub async fn cmd_export(orm: OrmArg, export_dir: Option<PathBuf>) -> Result<()>

// Ensure mod chain for SeaORM (must be done after all files are written)
if matches!(orm_kind, Orm::SeaOrm) {
for (_, rel_path) in &normalized_models {
for (_table, rel_path) in &normalized_models {
let out_path = build_output_path(&target_root, rel_path, orm_kind);
ensure_mod_chain(&target_root, rel_path)
.await
Expand Down Expand Up @@ -342,8 +342,7 @@ async fn load_models_recursive(base: &Path) -> Result<Vec<(TableDef, PathBuf)>>
}

async fn ensure_mod_chain(root: &Path, rel_path: &Path) -> Result<()> {
// Only needed for SeaORM (Rust) exports to wire modules.
// Strip extension and ".vespertide" suffix from filename
// SeaORM exports use a standard nested Rust module tree.
let path_without_ext = rel_path.with_extension("");
let path_stripped = if let Some(stem) = path_without_ext.file_stem().and_then(|s| s.to_str()) {
let stripped_stem = stem.strip_suffix(".vespertide").unwrap_or(stem);
Expand All @@ -366,7 +365,7 @@ async fn ensure_mod_chain(root: &Path, rel_path: &Path) -> Result<()> {
if comps.is_empty() {
return Ok(());
}
// Build from deepest file up to root: dir/mod.rs should include child module.

while let Some(child) = comps.pop() {
let dir = root.join(comps.join(std::path::MAIN_SEPARATOR_STR));
let mod_path = dir.join("mod.rs");
Expand All @@ -375,13 +374,15 @@ async fn ensure_mod_chain(root: &Path, rel_path: &Path) -> Result<()> {
{
fs::create_dir_all(parent).await?;
}

let mut content = if mod_path.exists() {
fs::read_to_string(&mod_path).await?
} else {
String::new()
};
let decl = format!("pub mod {};", child);
if !content.lines().any(|l| l.trim() == decl) {

let decl = format!("pub mod {child};");
if !content.lines().any(|line| line.trim() == decl) {
if !content.is_empty() && !content.ends_with('\n') {
content.push('\n');
}
Expand All @@ -390,6 +391,7 @@ async fn ensure_mod_chain(root: &Path, rel_path: &Path) -> Result<()> {
fs::write(mod_path, content).await?;
}
}

Ok(())
}

Expand Down Expand Up @@ -535,7 +537,7 @@ mod tests {
let content = std_fs::read_to_string(out).unwrap();
assert!(content.contains("#[sea_orm(table_name = \"posts\")]"));

// mod.rs wiring
// nested mod.rs wiring
let root_mod = custom.join("mod.rs");
let blog_mod = custom.join("blog/mod.rs");
assert!(root_mod.exists());
Expand Down Expand Up @@ -779,6 +781,7 @@ mod tests {
let blog_mod = std_fs::read_to_string(root.join("blog/mod.rs")).unwrap();
assert!(root_mod.contains("pub mod blog;"));
assert!(blog_mod.contains("pub mod post;"));
assert!(!root_mod.contains("post_vespertide"));
assert!(!blog_mod.contains("post_vespertide"));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vespertide-exporter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ thiserror = "2"

[dev-dependencies]
rstest = "0.26"
insta = { version = "1.46", features = ["yaml"] }
insta = { version = "1.47", features = ["yaml"] }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
Loading