Skip to content

Commit

Permalink
Tighten up logic around generated codegened spec filename
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman committed Sep 26, 2024
1 parent 4adf6d9 commit 51e2153
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions crates/ubrn_cli/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ impl TemplateConfig {
rust_crate: CrateMetadata,
modules: Vec<ModuleMetadata>,
) -> Self {
let mut modules = modules;
modules.sort_by_key(|m| m.ts());
Self {
project,
rust_crate,
Expand Down
2 changes: 1 addition & 1 deletion crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <React/RCTBridgeModule.h>

Expand Down
2 changes: 1 addition & 1 deletion crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion crates/ubrn_cli/src/codegen/templates/ModuleTemplate.mm
Original file line number Diff line number Diff line change
@@ -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) -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export interface Spec extends TurboModule {
cleanupRustCrate(): boolean;
}

export default TurboModuleRegistry.getEnforcing<Spec>('{{ self.config.project.name_upper_camel() }}');
export default TurboModuleRegistry.getEnforcing<Spec>('{{ self.config.project.tm.spec_name() }}');
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions crates/ubrn_cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod npm;

use camino::{Utf8Path, Utf8PathBuf};
use globset::GlobSet;
use heck::ToUpperCamelCase;
pub(crate) use npm::PackageJson;

use serde::Deserialize;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions crates/ubrn_cli/src/config/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion crates/ubrn_cli/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}

Expand Down

0 comments on commit 51e2153

Please sign in to comment.