Sitelet https://github.com/zkmopro/mopro/pull/727/files
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
3 changes: 3 additions & 0 deletions cli/src/build/react_native_noir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use anyhow::Context;
use mopro_ffi::app_config::android::AndroidBindingsParams;
use mopro_ffi::app_config::constants::Mode;
use mopro_ffi::app_config::project_name_from_toml;
use mopro_ffi::app_config::react_native::remove_unrequested_wasm_stubs;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -77,6 +78,8 @@ pub fn build(
bindgen_lib.display()
);
}

remove_unrequested_wasm_stubs(bindings_dir)?;
Ok(())
}

Expand Down
22 changes: 4 additions & 18 deletions cli/src/create/react_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::style::print_green_bold;

use anyhow::{Context, Error, Result};
use mopro_ffi::app_config::constants::{REACT_NATIVE_APP_DIR, REACT_NATIVE_BINDINGS_DIR};
use mopro_ffi::app_config::react_native::patch_gradle_properties_architectures;
use mopro_ffi::app_config::react_native::{
patch_gradle_properties_architectures, remove_unrequested_wasm_stubs,
};
use std::{fs, path::PathBuf};

pub struct ReactNative;
Expand Down Expand Up @@ -39,7 +41,7 @@ impl Create for ReactNative {
react_native_bindings_dir.as_ref().unwrap(),
&mopro_module_dir,
)?;
remove_stale_web_entrypoint(&mopro_module_dir)?;
remove_unrequested_wasm_stubs(&mopro_module_dir)?;

let assets_dir = target_dir.join("assets/keys");
fs::remove_dir_all(&assets_dir)?;
Expand Down Expand Up @@ -87,19 +89,3 @@ impl Create for ReactNative {
print_footer_message();
}
}

/// The downloaded `zkmopro/react-native-app` scaffold ships a static
/// `src/index.web.ts` (for optional web/wasm support) that imports from
/// `./generated/wasm-bindgen/index.js` and `index_bg.wasm`. `mopro build` never
/// generates that `generated/wasm-bindgen` directory — React Native builds only
/// target iOS/Android — so the file is always a dangling reference. Since
/// `copy_dir` only overwrites files present in the built bindings dir, it can't
/// remove this pre-existing one; left in place, it breaks `npm install`'s
/// `prepare: bob build` step (`tsc` fails to resolve the missing module).
fn remove_stale_web_entrypoint(mopro_module_dir: &std::path::Path) -> Result<()> {
let index_web_ts = mopro_module_dir.join("src").join("index.web.ts");
if index_web_ts.exists() {
fs::remove_file(&index_web_ts)?;
}
Ok(())
}
20 changes: 20 additions & 0 deletions mopro-ffi/src/app_config/react_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,23 @@ pub fn patch_gradle_properties_architectures(
.with_context(|| format!("Failed to patch {:?}", gradle_properties_path))?;
Ok(())
}

/// Remove leftover WASM scaffolding that `uniffi-bindgen-react-native generate all`
/// writes into the React Native bindings dir (`src/index.web.ts` and `rust_modules/wasm/`).
///
/// Mopro's React Native path only targets iOS/Android. `generate all` with no
/// platform still emits ubrn's web templates, but never runs wasm-pack, so
/// `src/generated/wasm-bindgen/` is missing. Left in place, `src/index.web.ts`
/// is a dangling import and `bob build` / `tsc` fails.
pub fn remove_unrequested_wasm_stubs(bindings_dir: &Path) -> anyhow::Result<()> {
let index_web_file = bindings_dir.join("src").join("index.web.ts");
if index_web_file.exists() {
fs::remove_file(&index_web_file)?;
}

let wasm_crate = bindings_dir.join("rust_modules").join("wasm");
if wasm_crate.exists() {
fs::remove_dir_all(&wasm_crate)?;
}
Ok(())
}
Loading