diff --git a/crates/ubrn_cli/src/codegen/mod.rs b/crates/ubrn_cli/src/codegen/mod.rs index a1ed40f4..beee0dd4 100644 --- a/crates/ubrn_cli/src/codegen/mod.rs +++ b/crates/ubrn_cli/src/codegen/mod.rs @@ -64,6 +64,8 @@ impl TemplateConfig { rust_crate: CrateMetadata, modules: Vec, ) -> Self { + let mut modules = modules; + modules.sort_by_key(|m| m.ts()); Self { project, rust_crate, diff --git a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h index a5cf6732..cb2cdd4a 100644 --- a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h +++ b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h @@ -6,7 +6,7 @@ #ifdef RCT_NEW_ARCH_ENABLED #import "{{ self.config.project.tm.name() }}.h" -@interface {{ self.config.project.name_upper_camel() }} : NSObject <{{ self.config.project.tm.spec_name() }}> +@interface {{ self.config.project.name_upper_camel() }} : NSObject <{{ self.config.project.codegen_filename() }}Spec> #else #import diff --git a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java index 02d2d901..fffc7c89 100644 --- a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java +++ b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java @@ -11,7 +11,7 @@ import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; @ReactModule(name = {{ module_class_name }}.NAME) -public class {{ module_class_name }} extends {{ self.config.project.tm.spec_name() }} { +public class {{ module_class_name }} extends {{ self.config.project.codegen_filename() }}Spec { public static final String NAME = "{{ name }}"; public {{ module_class_name }}(ReactApplicationContext reactContext) { diff --git a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.mm b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.mm index fffc3795..f422ce73 100644 --- a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.mm +++ b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.mm @@ -1,5 +1,5 @@ {%- let module_name = self.config.project.name_upper_camel() %} -{%- let spec_jsi = self.config.project.tm.spec_name()|fmt("{}JSI") %} +{%- let spec_jsi = self.config.project.codegen_filename()|fmt("{}JSI") %} {%- let ns = self.config.project.cpp_namespace() %} {%- let uniffi_ns = "uniffi_generated" %} {%- let fn_prefix = "__hostFunction_{}"|format(module_name) -%} diff --git a/crates/ubrn_cli/src/codegen/templates/NativeCodegenTemplate.ts b/crates/ubrn_cli/src/codegen/templates/NativeCodegenTemplate.ts index 0b2e69be..67028849 100644 --- a/crates/ubrn_cli/src/codegen/templates/NativeCodegenTemplate.ts +++ b/crates/ubrn_cli/src/codegen/templates/NativeCodegenTemplate.ts @@ -7,4 +7,4 @@ export interface Spec extends TurboModule { cleanupRustCrate(): boolean; } -export default TurboModuleRegistry.getEnforcing('{{ self.config.project.name_upper_camel() }}'); +export default TurboModuleRegistry.getEnforcing('{{ self.config.project.tm.spec_name() }}'); diff --git a/crates/ubrn_cli/src/codegen/templates/TurboModuleTemplate.cpp b/crates/ubrn_cli/src/codegen/templates/TurboModuleTemplate.cpp index 8f46c267..341e0a7f 100644 --- a/crates/ubrn_cli/src/codegen/templates/TurboModuleTemplate.cpp +++ b/crates/ubrn_cli/src/codegen/templates/TurboModuleTemplate.cpp @@ -14,7 +14,7 @@ namespace {{ self.config.project.cpp_namespace() }} { {%- for m in self.config.modules %} {{ m.cpp_module() }}::registerModule(runtime, callInvoker); {%- endfor %} - return false; + return true; } uint8_t cleanupRustCrate(jsi::Runtime &runtime) { diff --git a/crates/ubrn_cli/src/config/mod.rs b/crates/ubrn_cli/src/config/mod.rs index 9e5806f6..ae26ea4a 100644 --- a/crates/ubrn_cli/src/config/mod.rs +++ b/crates/ubrn_cli/src/config/mod.rs @@ -7,6 +7,7 @@ mod npm; use camino::{Utf8Path, Utf8PathBuf}; use globset::GlobSet; +use heck::ToUpperCamelCase; pub(crate) use npm::PackageJson; use serde::Deserialize; @@ -45,7 +46,7 @@ pub(crate) struct ProjectConfig { impl ProjectConfig { fn default_name() -> String { - workspace::package_json().raw_name() + workspace::package_json().trimmed_name() } fn default_repository() -> String { @@ -73,7 +74,7 @@ impl ProjectConfig { impl ProjectConfig { fn name(&self) -> String { - trim_react_native(&self.name) + self.name.clone() } pub(crate) fn raw_name(&self) -> &str { @@ -180,8 +181,7 @@ impl TurboModulesConfig { fn default_spec_name() -> String { let package_json = workspace::package_json(); - let codegen_name = &package_json.codegen().name; - format!("Native{}", trim_react_native(codegen_name)) + trim_react_native(&package_json.codegen().name) } } @@ -201,7 +201,7 @@ impl TurboModulesConfig { } pub(crate) fn spec_name(&self) -> String { - self.spec_name.clone() + self.spec_name.to_upper_camel_case() } pub(crate) fn name(&self) -> String { diff --git a/crates/ubrn_cli/src/config/npm.rs b/crates/ubrn_cli/src/config/npm.rs index b42462d0..485c5a70 100644 --- a/crates/ubrn_cli/src/config/npm.rs +++ b/crates/ubrn_cli/src/config/npm.rs @@ -25,7 +25,7 @@ impl PackageJson { self.name.clone() } - pub(crate) fn name(&self) -> String { + pub(crate) fn trimmed_name(&self) -> String { trim_react_native(&self.name) } @@ -34,7 +34,14 @@ impl PackageJson { .android .java_package_name .clone() - .unwrap_or_else(|| format!("com.{}", self.name().to_upper_camel_case().to_lowercase())) + .unwrap_or_else(|| { + format!( + "com.{}", + trim_react_native(&self.raw_name()) + .to_upper_camel_case() + .to_lowercase() + ) + }) } pub(crate) fn repo(&self) -> &PackageJsonRepo { diff --git a/crates/ubrn_cli/src/ios.rs b/crates/ubrn_cli/src/ios.rs index abb7c05e..fcfa88fc 100644 --- a/crates/ubrn_cli/src/ios.rs +++ b/crates/ubrn_cli/src/ios.rs @@ -47,7 +47,9 @@ impl IOsConfig { fn default_framework_name() -> String { format!( "{}Framework", - workspace::package_json().name().to_upper_camel_case() + workspace::package_json() + .trimmed_name() + .to_upper_camel_case() ) }