mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
canonicalize() through std gives \\?\C:\... on Windows: a path Git for Windows can neither read nor lock, Rolldown can't resolve, and which shares no root with the C:\... git and everything else print. It broke a new workspace's git config (fixed in apps/workspace earlier today). Here the calls in the apps (CapCut, check, direction, engines, fingerprint, game, interchange, judge, solid, sound, targets, tools), the bundler, the CLI, the modules loader, the native shim's realpath, the page's motion, io (assets, gen, home, shell), runtime/bundle/lib, js, track and world, the systems (fingerprint-use, footage, index, ml, page-net), the bridge bench's examples and the sdk/ui test tools use dunce::canonicalize, which gives C:\... wherever a path can be said so and is std's own call on the Mac and Linux.
Reads of the home folder took HOME alone, which Windows doesn't set for an app opened from the Start menu or Explorer, so the taste file, the settings file, the inbox, the npm store, the caches (sounds, splats, goo, ingest, speech, Core ML, the portable perceive models), the node shim's os.homedir() and CapCut's drafts were looked for under whatever folder raea ran in. raea_io_home::user_home() reads HOME, then USERPROFILE (Git for Windows' order; an empty one counts as unset), and models(), caches(), logs(), env_path() and offline() use it, as do the places that had their own fallback.
The caches that had their own copy of "this variable, else this folder under home" (splats, goo, ingest, the npm store, Core ML's models) now call raea_io_home::env_path and models(), and raea_io_home::real canonicalizes a path or keeps it as given, so tools/dupes.max comes down to 289 exact and 58 near. tools/skills.sh reads a variable from env_path("RAEA_...", ".raea/...") as it did from env::var, so files.md keeps RAEA_NPM_HOME on ~/.raea/npm (every generated reference is unchanged).
Five crates hold other sessions' uncommitted edits (engine/page/stage, engine/render, runtime/bundle, runtime/export, runtime/live): their few calls, and tools/windows-paths.sh, the check that keeps both at zero, land once those are committed.
Checked: cargo check --all-targets of every crate changed, and of sdk/ui/conformance and sdk/ui/parity. On a Windows 11 PC and on macOS the unit tests of raea-io-home (user_home's order and an empty HOME, now in caches_logs_and_the_home_folder_follow_the_platform), raea-app-check, raea-app-workspace, raea-app-registry and raea-core-facts pass (5, 27, 10, 7, 17).
72 lines
4.4 KiB
Rust
72 lines
4.4 KiB
Rust
//! An app's script (docs/targets.feature T0b, T1c): its TSX with React, @raea/ui and @raea/rune from raea's home (the
|
|
//! checkout's, or a release's share/raea), mounted in DOM mode, bundled in process. Both targets run the same script:
|
|
//! the page host on a Blitz page, the native host (raea-rune-host) on Rune.
|
|
|
|
use std::path::Path;
|
|
|
|
/// The entry every app is mounted by: the DOM installed before the app's module runs, its default export mounted at
|
|
/// the root with `props` (JS; an app's none) (an app that mounts itself with createRoot needs no default export)
|
|
fn entry(app: &Path, props: &str) -> String {
|
|
format!(
|
|
"import \"@raea/ui/dom-globals\";\nimport {{ createElement }} from \"react\";\nimport {{ mount }} from \"@raea/ui/react\";\nimport * as M from {:?};\nconst App = (M as any).default;\nif (typeof App === \"function\") mount(createElement(App, {props}), 0, {{ dom: true }});\n",
|
|
app.display().to_string()
|
|
)
|
|
}
|
|
|
|
/// The work folder's tsconfig: JSX by React's automatic runtime, @raea/ui and @raea/rune from the SDK's source
|
|
fn tsconfig(home: &Path) -> String {
|
|
let ui = home.join("sdk/ui/src");
|
|
let rune = home.join("sdk/rune/src/index.ts");
|
|
serde_json::json!({"compilerOptions": {"jsx": "react-jsx", "jsxImportSource": "react", "module": "esnext", "target": "es2022", "moduleResolution": "bundler",
|
|
"paths": {"@raea/ui/*": [format!("{}/*", ui.display())], "@raea/rune": [rune.display().to_string()]}}})
|
|
.to_string()
|
|
}
|
|
|
|
/// `@raea/ui/<module>` for each of sdk/ui/src's modules, by name: the work folder's tsconfig reaches only the entry,
|
|
/// and an app outside it (anywhere on disk) imports @raea/ui/wire, @raea/ui/platform... as well
|
|
fn ui(home: &Path) -> serde_json::Value {
|
|
let src = home.join("sdk/ui/src");
|
|
let mut m = serde_json::Map::new();
|
|
for e in std::fs::read_dir(&src).into_iter().flatten().flatten() {
|
|
let p = e.path();
|
|
if let (Some(stem), Some("ts" | "tsx")) = (p.file_stem().and_then(|s| s.to_str()), p.extension().and_then(|x| x.to_str())) {
|
|
m.insert(format!("@raea/ui/{stem}"), p.display().to_string().into());
|
|
}
|
|
}
|
|
m.into()
|
|
}
|
|
|
|
/// What an app's default export is given, for `bundle`: nothing, as an app in a window of its own is (it reads the
|
|
/// window)
|
|
pub const WINDOW: &str = "null";
|
|
|
|
/// What an app screen's module (`<Screen app="kit.tsx">`, docs/blitz-bevy.feature H12) is given: `{width, height}`, the
|
|
/// screen's size (its document's, so one bundle serves a screen of any size)
|
|
pub const SCREEN: &str = "{ width: innerWidth, height: innerHeight }";
|
|
|
|
/// `app` bundled against `home`, its default export mounted with `props` (WINDOW or SCREEN): its script and the CSS its
|
|
/// modules import
|
|
pub fn bundle(app: &Path, home: &Path, props: &str) -> Result<(String, String), String> {
|
|
// canonical, and on Windows without canonicalize()'s verbatim \\?\ prefix: Rolldown can't resolve an entry that
|
|
// imports a path written with it (T1f: the Windows release check, 11-07)
|
|
let app = raea_io_home::plain(dunce::canonicalize(&app).map_err(|e| format!("{}: {e}", app.display()))?);
|
|
// one path per file: a module reached by two spellings of its path is bundled twice (two wires, two call ids)
|
|
let home = &raea_io_home::plain(dunce::canonicalize(&home).map_err(|e| format!("{}: {e}", home.display()))?);
|
|
// one work folder per call: tests bundle on several threads of one process
|
|
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
|
let work = std::env::temp_dir().join(format!("raea-app-{}-{}", std::process::id(), N.fetch_add(1, std::sync::atomic::Ordering::Relaxed)));
|
|
let _ = std::fs::remove_dir_all(&work);
|
|
std::fs::create_dir_all(&work).map_err(|e| format!("{}: {e}", work.display()))?;
|
|
let entry_file = work.join("entry.tsx");
|
|
let wrote = std::fs::write(&entry_file, entry(&app, props)).and_then(|_| std::fs::write(work.join("tsconfig.json"), tsconfig(home)));
|
|
let r = wrote.map_err(|e| e.to_string()).and_then(|_| {
|
|
let opts = serde_json::json!({
|
|
"script": {"js": home.join("sdk/react/js"), "motion": home.join("sdk/raea/src"), "shell": home.join("sdk/shell/src/index.ts"), "aliases": ui(home), "stubs": []},
|
|
"defines": {},
|
|
});
|
|
crate::bundle(&entry_file, opts)
|
|
});
|
|
let _ = std::fs::remove_dir_all(&work);
|
|
r.map_err(|e| format!("couldn't bundle {}: {}", app.display(), e.lines().filter(|l| !l.trim().is_empty()).take(8).collect::<Vec<_>>().join(" | ")))
|
|
}
|