mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(tooling): repair test, i18n and docs verification gates (#3331)
This commit is contained in:
1 parent
ece622e800
commit
f390e610b9
107 files changed
+5144
-3004
No files matched your search
@@ -74,7 +74,7 @@ struct StepMetadata {
|
||||
type Metadata = BTreeMap<String, StepMetadata>;
|
||||
|
||||
pub async fn run(args: AppDevServerArgs) -> Result<()> {
|
||||
let project_root = args.app_dir.unwrap_or(resolve_app_dir()?);
|
||||
let project_root = resolve_app_dir(args.app_dir)?;
|
||||
let mut server = AppDevServer::new(project_root);
|
||||
server.run().await
|
||||
}
|
||||
|
||||
+86
-14
@@ -34,14 +34,14 @@ pub struct BuildMarkdownParserWasmArgs {
|
||||
}
|
||||
|
||||
pub fn run_build_app_wasm(args: BuildAppWasmArgs) -> Result<()> {
|
||||
let app_dir = args.app_dir.unwrap_or(resolve_app_dir()?);
|
||||
let app_dir = resolve_app_dir(args.app_dir)?;
|
||||
build_markdown_parser_wasm(&app_dir)?;
|
||||
build_libfluxcore_wasm(&app_dir)?;
|
||||
build_libfluxwebp_wasm(&app_dir)
|
||||
}
|
||||
|
||||
pub fn run_build_markdown_parser_wasm(args: BuildMarkdownParserWasmArgs) -> Result<()> {
|
||||
let app_dir = args.app_dir.unwrap_or(resolve_app_dir()?);
|
||||
let app_dir = resolve_app_dir(args.app_dir)?;
|
||||
build_markdown_parser_wasm(&app_dir)
|
||||
}
|
||||
|
||||
@@ -176,6 +176,24 @@ fn build_markdown_parser_wasm(app_dir: &Path) -> Result<()> {
|
||||
.with_context(|| format!("Failed to write {}", bytes_path.display()))
|
||||
}
|
||||
|
||||
fn libfluxcore_build_command(rust_package_dir: &Path, target_dir: &Path) -> CommandSpec {
|
||||
CommandSpec::new("cargo")
|
||||
.args([
|
||||
"build",
|
||||
"--release",
|
||||
"--target",
|
||||
"wasm32-unknown-unknown",
|
||||
"--manifest-path",
|
||||
])
|
||||
.arg(rust_package_dir.join("Cargo.toml"))
|
||||
.env("CARGO_TARGET_DIR", target_dir.as_os_str())
|
||||
.current_dir(rust_package_dir)
|
||||
}
|
||||
|
||||
fn libfluxcore_wasm_path(target_dir: &Path) -> PathBuf {
|
||||
target_dir.join("wasm32-unknown-unknown/release/libfluxcore.wasm")
|
||||
}
|
||||
|
||||
fn build_libfluxcore_wasm(app_dir: &Path) -> Result<()> {
|
||||
let rust_package_dir = app_dir.join("rust/libfluxcore");
|
||||
let out_dir = app_dir.join("pkgs/libfluxcore");
|
||||
@@ -185,16 +203,8 @@ fn build_libfluxcore_wasm(app_dir: &Path) -> Result<()> {
|
||||
fs::create_dir_all(&out_dir)
|
||||
.with_context(|| format!("Failed to create {}", out_dir.display()))?;
|
||||
|
||||
let mut build = CommandSpec::new("cargo")
|
||||
.args([
|
||||
"build",
|
||||
"--release",
|
||||
"--target",
|
||||
"wasm32-unknown-unknown",
|
||||
"--manifest-path",
|
||||
])
|
||||
.arg(rust_package_dir.join("Cargo.toml"))
|
||||
.current_dir(&rust_package_dir);
|
||||
let target_dir = rust_package_dir.join("target");
|
||||
let mut build = libfluxcore_build_command(&rust_package_dir, &target_dir);
|
||||
|
||||
if env_bool("FLUXCORE_WASM_SIMD") {
|
||||
let rustflags = match env::var("RUSTFLAGS") {
|
||||
@@ -208,7 +218,7 @@ fn build_libfluxcore_wasm(app_dir: &Path) -> Result<()> {
|
||||
let temp = TempDir::new().context("Failed to create libfluxcore wasm-bindgen temp dir")?;
|
||||
let bindgen_dir = temp.path().join("bindgen");
|
||||
run_wasm_bindgen(
|
||||
&rust_package_dir.join("target/wasm32-unknown-unknown/release/libfluxcore.wasm"),
|
||||
&libfluxcore_wasm_path(&target_dir),
|
||||
&bindgen_dir,
|
||||
"libfluxcore",
|
||||
)?;
|
||||
@@ -612,7 +622,11 @@ fn patch_libfluxcore_bindgen_dts(content: &str) -> Result<String> {
|
||||
Ok(content.replacen(MARKER, &format!("{RESET_EXPORT}{MARKER}"), 1))
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_app_dir() -> Result<PathBuf> {
|
||||
pub(crate) fn resolve_app_dir(explicit: Option<PathBuf>) -> Result<PathBuf> {
|
||||
if let Some(app_dir) = explicit {
|
||||
return fs::canonicalize(&app_dir)
|
||||
.with_context(|| format!("Failed to resolve app directory {}", app_dir.display()));
|
||||
}
|
||||
let cwd = env::current_dir().context("Failed to resolve current directory")?;
|
||||
if cwd.file_name().and_then(|value| value.to_str()) == Some("fluxer_app") {
|
||||
return Ok(cwd);
|
||||
@@ -735,6 +749,36 @@ export const MARKDOWN_PARSER_WASM_BASE64 =\n\
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn explicit_app_dir_is_used_without_looking_at_the_current_directory() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let app_dir = temp.path().join("my_app");
|
||||
fs::create_dir(&app_dir).unwrap();
|
||||
let resolved = resolve_app_dir(Some(app_dir.clone())).unwrap();
|
||||
assert_eq!(resolved, fs::canonicalize(&app_dir).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relative_explicit_app_dir_becomes_absolute() {
|
||||
let resolved = resolve_app_dir(Some(PathBuf::from("."))).unwrap();
|
||||
assert!(resolved.is_absolute());
|
||||
assert_eq!(
|
||||
resolved,
|
||||
fs::canonicalize(env::current_dir().unwrap()).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_explicit_app_dir_is_an_error() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let error = resolve_app_dir(Some(temp.path().join("missing"))).unwrap_err();
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("Failed to resolve app directory")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markdown_wasm_bytes_content_matches_legacy_node_output() {
|
||||
assert_eq!(
|
||||
@@ -745,6 +789,34 @@ export const MARKDOWN_PARSER_WASM_BASE64 =\n\
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn libfluxcore_build_keeps_its_output_in_the_crate_target_dir() {
|
||||
let package_dir = Path::new("/repo/fluxer_app/rust/libfluxcore");
|
||||
let target_dir = package_dir.join("target");
|
||||
let command = libfluxcore_build_command(package_dir, &target_dir);
|
||||
|
||||
assert_eq!(
|
||||
command.env,
|
||||
vec![(
|
||||
OsString::from("CARGO_TARGET_DIR"),
|
||||
OsString::from("/repo/fluxer_app/rust/libfluxcore/target"),
|
||||
)]
|
||||
);
|
||||
assert_eq!(command.cwd.as_deref(), Some(package_dir));
|
||||
assert_eq!(
|
||||
command.args.last(),
|
||||
Some(&OsString::from(
|
||||
"/repo/fluxer_app/rust/libfluxcore/Cargo.toml"
|
||||
))
|
||||
);
|
||||
assert_eq!(
|
||||
libfluxcore_wasm_path(&target_dir),
|
||||
Path::new(
|
||||
"/repo/fluxer_app/rust/libfluxcore/target/wasm32-unknown-unknown/release/libfluxcore.wasm"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn libfluxcore_index_reexports_bindgen_module() {
|
||||
let content = libfluxcore_index_js_content();
|
||||
|
||||
Reference in new issue
Block a user