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 runtime/bundle/src/fresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub fn bundle_fresh(tsx: &Path, out_js: &Path, o: &CompOpts, portable: Option<&P
let work = std::env::temp_dir().join(format!("raea-cli-b{}", std::process::id()));
remove_work(&work);
copy_dir(&dir, &work.join("src"), 0)?;
drop_tsconfigs(&work.join("src"), 0);
let motion_src = raea_io_home::home().join("sdk/raea/src").canonicalize().map_err(|e| format!("raea/motion/src: {e}"))?;
copy_dir(&motion_src, &work.join("motion"), 0)?;
let sdks = sdks();
Expand Down
19 changes: 19 additions & 0 deletions runtime/bundle/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ pub fn copy_dir(from: &Path, to: &Path, depth: usize) -> R<()> {
Ok(())
}

/// The copy of an edit's folder without its own tsconfig.json and jsconfig.json files: the work folder's is the one a
/// bundle resolves by. A project's own (raea writes one into every new project, for its editor) is the nearest to its
/// sources, so the bundler read it in place of the work folder's: its `paths` name no live runtime, a played
/// composition's `react` was the engine's React, and `raea play`, the app's stage and every still drawn by playing
/// threw "__at is not a function" before the first frame (0.1.2; a render, which needs no such path, went through).
pub fn drop_tsconfigs(dir: &Path, depth: usize) {
let Ok(entries) = std::fs::read_dir(dir) else { return };
for e in entries.flatten() {
let p = e.path();
if p.is_dir() {
if depth < 6 {
drop_tsconfigs(&p, depth + 1);
}
} else if matches!(e.file_name().to_str(), Some("tsconfig.json" | "jsconfig.json")) {
let _ = std::fs::remove_file(&p);
}
}
}

pub const MEDIA_EXTS: [&str; 10] = ["mp4", "mov", "m4v", "mp3", "wav", "m4a", "png", "jpg", "webp", "gif"];

/// The edit's source with its imports pointed at the bundle's copy of the SDK (its package name, a subpath such as /3d,
Expand Down
18 changes: 18 additions & 0 deletions runtime/bundle/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,21 @@ fn outside_copies_what_the_edit_imports_beyond_its_folder() {
assert!(e.contains("lib/c.ts") && e.contains("outside raea's home"), "{e}");
std::fs::remove_dir_all(&t).unwrap();
}

#[test]
fn a_project_s_own_tsconfig_is_not_in_the_work_copy() {
// raea writes a tsconfig.json into every new project: copied with the sources, it shadowed the work folder's
let d = std::env::temp_dir().join(format!("raea-bundle-tsconfig-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
std::fs::create_dir_all(d.join("from/components")).unwrap();
for f in ["from/tsconfig.json", "from/components/jsconfig.json", "from/a.tsx", "from/components/data.json"] {
std::fs::write(d.join(f), "{}").unwrap();
}
copy_dir(&d.join("from"), &d.join("to"), 0).unwrap();
drop_tsconfigs(&d.join("to"), 0);
assert!(!d.join("to/tsconfig.json").exists() && !d.join("to/components/jsconfig.json").exists());
assert!(d.join("to/a.tsx").exists() && d.join("to/components/data.json").exists());
// the project's own files are untouched
assert!(d.join("from/tsconfig.json").exists());
let _ = std::fs::remove_dir_all(&d);
}
Loading