From e5289365decf1ae1789dce21b94bee7c8ac59d2e Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Thu, 22 Oct 2026 18:41:15 +0200 Subject: [PATCH] refactor: drop platform prefixes from nitro.json keys The keys repeat the section they live in. Rename them: - `apple.appleModuleName` to `apple.moduleName` - `android.androidNamespace` to `android.namespace` - `android.androidCxxLibName` to `android.cxxLibName` `namespace` keeps the meaning of `cxxNamespace`: segments relative to `com.margelo.nitro`. Nitrogen's getters and the template's `$$...$$` variables keep their names. There is no fallback for the old keys. --- docs/docs/concepts/nitrogen.md | 8 +++--- .../configuration-nitro-json.md | 28 +++++++++---------- docs/static/nitro.schema.json | 10 +++---- .../js/src/HybridObjectPlatformOptions.ts | 4 +-- packages/nitrogen/README.md | 16 +++++------ .../autolinking/apple/checkSwiftPMConfig.ts | 2 +- packages/nitrogen/src/config/NitroConfig.ts | 8 +++--- .../nitrogen/src/config/NitroUserConfig.ts | 6 ++-- packages/nitrogen/src/init.ts | 6 ++-- packages/template/nitro.json | 6 ++-- scripts/releases/check-consumer.mjs | 6 ++-- .../nitro.json | 6 ++-- .../react-native-nitro-test/nitro.json | 6 ++-- .../standalone/nitro-test-external/nitro.json | 6 ++-- tests/standalone/nitro-test/nitro.json | 6 ++-- 15 files changed, 62 insertions(+), 62 deletions(-) diff --git a/docs/docs/concepts/nitrogen.md b/docs/docs/concepts/nitrogen.md index a6a0663767..8988552da2 100644 --- a/docs/docs/concepts/nitrogen.md +++ b/docs/docs/concepts/nitrogen.md @@ -91,11 +91,11 @@ Create a `nitro.json` file in the root directory of your Nitro Module (next to ` "$schema": "https://nitro.margelo.com/nitro.schema.json", "cxxNamespace": ["math"], "apple": { - "appleModuleName": "NitroMath" + "moduleName": "NitroMath" }, "android": { - "androidNamespace": ["math"], - "androidCxxLibName": "NitroMath" + "namespace": ["math"], + "cxxLibName": "NitroMath" } } ``` @@ -273,7 +273,7 @@ Add `swiftpmConfig` to your library's `package.json` so React Native links the g } ``` -`name` must match `apple.appleModuleName` in `nitro.json`. Add the npm names of any other Nitro modules your library depends on to +`name` must match `apple.moduleName` in `nitro.json`. Add the npm names of any other Nitro modules your library depends on to `dependencies`. Keep a `.podspec` with your library's metadata so React Native CLI can discover the iOS dependency, as in the diff --git a/docs/docs/getting-started/configuration-nitro-json.md b/docs/docs/getting-started/configuration-nitro-json.md index 4535f77d28..d89aaf2512 100644 --- a/docs/docs/getting-started/configuration-nitro-json.md +++ b/docs/docs/getting-started/configuration-nitro-json.md @@ -16,11 +16,11 @@ description: "environment": "react-native", "cxxNamespace": ["$$cxxNamespace$$"], "apple": { - "appleModuleName": "$$appleModuleName$$" + "moduleName": "$$appleModuleName$$" }, "android": { - "androidNamespace": ["$$androidNamespace$$"], - "androidCxxLibName": "$$androidCxxLibName$$" + "namespace": ["$$androidNamespace$$"], + "cxxLibName": "$$androidCxxLibName$$" }, "ignorePaths": ["**/node_modules"] } @@ -64,16 +64,16 @@ have multiple sub-namespaces: Settings for the Apple platforms: iOS, macOS, tvOS and visionOS. -### `appleModuleName` +### `moduleName` -The `appleModuleName` names the generated Swift module and SwiftPM library product. Use the same name in your library's `swiftpmConfig`: +The `moduleName` names the generated Swift module and SwiftPM library product. Use the same name in your library's `swiftpmConfig`:
```json { "apple": { - "appleModuleName": "NitroMath" + "moduleName": "NitroMath" } } ``` @@ -97,19 +97,19 @@ configuration. Settings specifically for the Android platform. -### `androidNamespace` +### `namespace` -The `androidNamespace` represents the package namespace in which all Java/Kotlin files are generated and written in. Similar to the -`cxxNamespace`, this is always relative to `com.margelo.nitro`, and can also have multiple sub-namespaces. +The `namespace` represents the package namespace in which all Java/Kotlin files are generated and written in. Similar to the `cxxNamespace`, +this is always relative to `com.margelo.nitro`, and can also have multiple sub-namespaces. -In most cases, you should keep this in sync with the `namespace` specified in your `build.gradle`. +In most cases, keep it in sync with the `namespace` in your `build.gradle`, which holds the full package (`com.margelo.nitro.math.extra`).
```json { "android": { - "androidNamespace": ["math", "extra"] + "namespace": ["math", "extra"] } } ``` @@ -124,9 +124,9 @@ In most cases, you should keep this in sync with the `namespace` specified in yo
-### `androidCxxLibName` +### `cxxLibName` -The `androidCxxLibName` represents the name of the native C++ library that JNI will load to connect Java/Kotlin to C++. +The `cxxLibName` represents the name of the native C++ library that JNI will load to connect Java/Kotlin to C++. When this Nitro Module is using CMake, this is the same thing as the library defined in `CMakeLists.txt`. Nitro will load this library at runtime using `System.loadLibrary`. @@ -136,7 +136,7 @@ Nitro will load this library at runtime using `System.loadLibrary`. ```json { "android": { - "androidCxxLibName": "NitroMath" + "cxxLibName": "NitroMath" } } ```` diff --git a/docs/static/nitro.schema.json b/docs/static/nitro.schema.json index e3fb05b081..bf7f75c446 100644 --- a/docs/static/nitro.schema.json +++ b/docs/static/nitro.schema.json @@ -29,9 +29,9 @@ }, "apple": { "type": "object", - "required": ["appleModuleName"], + "required": ["moduleName"], "properties": { - "appleModuleName": { + "moduleName": { "$ref": "#/definitions/name", "description": "Represents the Apple module name of the module that will be generated. It names the generated Swift module and SwiftPM library product. Use the same name in the library's `swiftpmConfig` in package.json." } @@ -40,9 +40,9 @@ }, "android": { "type": "object", - "required": ["androidNamespace", "androidCxxLibName"], + "required": ["namespace", "cxxLibName"], "properties": { - "androidNamespace": { + "namespace": { "type": "array", "items": { "$ref": "#/definitions/name" @@ -50,7 +50,7 @@ "minItems": 1, "description": "Represents the Android namespace ('package') of the module that will be generated. This can have multiple sub-namespaces, and is always relative to `com.margelo.nitro`." }, - "androidCxxLibName": { + "cxxLibName": { "$ref": "#/definitions/name", "description": "Represents the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`). This will be loaded via `System.loadLibrary(...)`." } diff --git a/packages/nitro-core/js/src/HybridObjectPlatformOptions.ts b/packages/nitro-core/js/src/HybridObjectPlatformOptions.ts index 544c6680b6..2192973269 100644 --- a/packages/nitro-core/js/src/HybridObjectPlatformOptions.ts +++ b/packages/nitro-core/js/src/HybridObjectPlatformOptions.ts @@ -37,7 +37,7 @@ export interface CppHybridObjectImplementation { */ export interface KotlinHybridObjectImplementation { /** - * The implementation's sub-package within the declaring spec's `androidNamespace` in nitro.json. + * The implementation's sub-package within the declaring spec's `android.namespace` in nitro.json. * Omit this or use an empty array to select that project's package. * @example ["internal"] // com.margelo.nitro..internal */ @@ -77,7 +77,7 @@ export interface KotlinImplementedInterface { */ interface: string /** - * The full package declaring the interface, not relative to `androidNamespace`. + * The full package declaring the interface, not relative to `android.namespace`. * For a nested interface, this includes its outer class, e.g. "android.view.SurfaceHolder". * The generated spec imports the interface from there. * @example "com.margelo.nitro.renderer" diff --git a/packages/nitrogen/README.md b/packages/nitrogen/README.md index c7eb3488d5..45221ad497 100644 --- a/packages/nitrogen/README.md +++ b/packages/nitrogen/README.md @@ -100,7 +100,7 @@ The `implementation` object identifies the native type and, for C++ or Kotlin, i | Kotlin | `{ className: 'HybridImage' }` | C++ `namespace` and Kotlin `package` are optional arrays of segments within the declaring spec's own `nitro.json` project. Omit them or use -`[]` for that project's `cxxNamespace` or `androidNamespace`. For a project configured with `['image']`, `['internal']` selects +`[]` for that project's `cxxNamespace` or `android.namespace`. For a project configured with `['image']`, `['internal']` selects `margelo::nitro::image::internal` or `com.margelo.nitro.image.internal`. Imported specs use their owning project's config. These options cannot select a namespace or package outside that project, and `null` is invalid. The C++ `include` must contain angle brackets or double quotes, for example `''` or `'"HybridImage.hpp"'`. Nitrogen uses that header and the fully qualified C++ class @@ -262,7 +262,7 @@ The registry key uses the `cxxNamespace` from `nitro.json` as a prefix, with dot modules can declare their own `Image` class. The JavaScript constructor's `name` remains `Image`. HybridObject headers also have module-qualified include paths. In handwritten C++, use `#include `, where -`NitroImage` is the `appleModuleName`, to select the owning module when another library declares `Image`. +`NitroImage` is the `apple.moduleName`, to select the owning module when another library declares `Image`. Nitrogen only generates code for HybridObject classes. Other exports from a spec, such as types or helper functions, are ordinary TypeScript. @@ -473,8 +473,8 @@ abstract class HybridImageSpec: HybridObject(), ImageSource, Cacheable { } ``` -`package` is required and holds the interface's full package. Unlike `implementation.package`, it is not relative to `androidNamespace`. For -a nested interface, put its outer class in `package`, e.g. `{ interface: 'Callback', package: 'android.view.SurfaceHolder' }`. Generic +`package` is required and holds the interface's full package. Unlike `implementation.package`, it is not relative to `android.namespace`. +For a nested interface, put its outer class in `package`, e.g. `{ interface: 'Callback', package: 'android.view.SurfaceHolder' }`. Generic interfaces are not supported. Nitrogen imports each interface by name, so its name must not match another type the spec uses, and the Gradle module must depend on the library declaring it. Implementations must implement each interface's abstract members. A derived spec inherits the interfaces through its parent's spec class. @@ -508,8 +508,8 @@ addNitrogenTargets(to: package) Running Nitrogen adds the helper between `// nitrogen:begin` and `// nitrogen:end` and replaces that section on every run. Keep your package declaration and helper call outside that section. Nitrogen leaves manifests without an `addNitrogenTargets` call alone. -Add React Native's SwiftPM configuration to `package.json`. Set `name` to your `apple.appleModuleName`, and list the npm names of every -Nitro module your library depends on: +Add React Native's SwiftPM configuration to `package.json`. Set `name` to your `apple.moduleName`, and list the npm names of every Nitro +module your library depends on: ```json "swiftpmConfig": { @@ -525,12 +525,12 @@ library at `ios/build/generated/autolinking/libs/`, where these relat | ----------------------- | ---------------------------- | | `ReactNative` | `../../../../xcframeworks` | | `NitroModules` | `../NitroModules` | -| Referenced Nitro module | `../` | +| Referenced Nitro module | `../` | `NitroModules` also depends on React Native's `React-GeneratedCode` package at `../../../ios`. React Native generates these framework and codegen packages when preparing the app's iOS build. -For `apple.appleModuleName: "NitroImage"`, the helper adds the `NitroImage` library and four targets: +For `apple.moduleName: "NitroImage"`, the helper adds the `NitroImage` library and four targets: - `NitroImageCxx`: your C++ sources in `cpp/` and the specs in `nitrogen/generated/shared/c++`. - `NitroImageAppleCxx`: the C++ bridge declarations imported by Swift, including the header declaring `registerHybridClasses()`. diff --git a/packages/nitrogen/src/autolinking/apple/checkSwiftPMConfig.ts b/packages/nitrogen/src/autolinking/apple/checkSwiftPMConfig.ts index 900e34fbd5..c175d055bd 100644 --- a/packages/nitrogen/src/autolinking/apple/checkSwiftPMConfig.ts +++ b/packages/nitrogen/src/autolinking/apple/checkSwiftPMConfig.ts @@ -32,7 +32,7 @@ export function checkSwiftPMConfig(packageDirectory: string): void { if (swiftName !== moduleName) { Logger.warn( `⚠️ ${chalk.dim('package.json')} should set ${chalk.bold(`"swiftpmConfig": { "name": "${moduleName}" }`)} ` + - `(the \`appleModuleName\` in nitro.json), so React Native's Swift Package Manager autolinking links the \`${moduleName}\` product.` + `(\`apple.moduleName\` in nitro.json), so React Native's Swift Package Manager autolinking links the \`${moduleName}\` product.` ) } const dependencies = packageJson.swiftpmConfig?.dependencies ?? [] diff --git a/packages/nitrogen/src/config/NitroConfig.ts b/packages/nitrogen/src/config/NitroConfig.ts index 6f92da7e2d..6093c96334 100644 --- a/packages/nitrogen/src/config/NitroConfig.ts +++ b/packages/nitrogen/src/config/NitroConfig.ts @@ -36,7 +36,7 @@ export class NitroConfig { * @example `NitroTest` */ getAndroidCxxLibName(): string { - return this.config.android.androidCxxLibName + return this.config.android.cxxLibName } /** @@ -44,7 +44,7 @@ export class NitroConfig { * @example `NitroTest` */ getAppleModuleName(): string { - return this.config.apple.appleModuleName + return this.config.apple.moduleName } /** Returns the registry key for a HybridObject in this module. */ @@ -76,7 +76,7 @@ export class NitroConfig { * @example `['image']` -> `com.margelo.nitro.image` */ getAndroidPackage(language: 'java/kotlin' | 'c++/jni', ...subPackage: string[]): string { - const userPackage = this.config.android.androidNamespace + const userPackage = this.config.android.namespace const namespace = [...ANDROID_BASE_NAMESPACE, ...userPackage, ...subPackage] switch (language) { @@ -94,7 +94,7 @@ export class NitroConfig { * This will be used on android to put files from a package in their respective package folder. */ getAndroidPackageDirectory(...subPackage: string[]): string[] { - const userPackage = this.config.android.androidNamespace + const userPackage = this.config.android.namespace return [...ANDROID_BASE_NAMESPACE, ...userPackage, ...subPackage] } diff --git a/packages/nitrogen/src/config/NitroUserConfig.ts b/packages/nitrogen/src/config/NitroUserConfig.ts index 8329c2198e..ee8edd92de 100644 --- a/packages/nitrogen/src/config/NitroUserConfig.ts +++ b/packages/nitrogen/src/config/NitroUserConfig.ts @@ -33,7 +33,7 @@ export const NitroUserConfigSchema = z.object({ * Use the same name in the library's `swiftpmConfig` in package.json. * @example `NitroTest` */ - appleModuleName: z.string().regex(safeNamePattern).refine(isNotReservedKeyword, isReservedKeywordError), + moduleName: z.string().regex(safeNamePattern).refine(isNotReservedKeyword, isReservedKeywordError), }), /** * Android specific options. @@ -45,14 +45,14 @@ export const NitroUserConfigSchema = z.object({ * This can have multiple sub-namespaces, and is always relative to `com.margelo.nitro`. * @example `['image']` -> `com.margelo.nitro.image` */ - androidNamespace: z.array(z.string().regex(safeNamePattern).refine(isNotReservedKeyword, isReservedKeywordError)).min(1), + namespace: z.array(z.string().regex(safeNamePattern).refine(isNotReservedKeyword, isReservedKeywordError)).min(1), /** * Represents the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`). * This will be loaded via `System.loadLibrary(...)`. * @example `NitroTest` */ - androidCxxLibName: z.string().regex(safeNamePattern).refine(isNotReservedKeyword, isReservedKeywordError), + cxxLibName: z.string().regex(safeNamePattern).refine(isNotReservedKeyword, isReservedKeywordError), }), /** * A list of paths relative to the project directory that should be ignored by nitrogen. diff --git a/packages/nitrogen/src/init.ts b/packages/nitrogen/src/init.ts index f8bb3b52a0..cfe0f370c9 100644 --- a/packages/nitrogen/src/init.ts +++ b/packages/nitrogen/src/init.ts @@ -35,9 +35,9 @@ export async function initNewNitroModule(baseDirectory: string, moduleName: stri } await replaceTemplate(modulePath, `cxxNamespace`, cxxNamespace) - await replaceTemplate(modulePath, `androidNamespace`, cxxNamespace) - await replaceTemplate(modulePath, `androidCxxLibName`, camelCaseName) - await replaceTemplate(modulePath, `appleModuleName`, camelCaseName) + await replaceTemplate(modulePath, `android.namespace`, cxxNamespace) + await replaceTemplate(modulePath, `android.cxxLibName`, camelCaseName) + await replaceTemplate(modulePath, `apple.moduleName`, camelCaseName) await replaceTemplate(modulePath, `packageName`, moduleName) await replaceTemplate(modulePath, `packageDescription`, moduleName) await replaceTemplate(modulePath, `nitroVersion`, NITROGEN_VERSION) diff --git a/packages/template/nitro.json b/packages/template/nitro.json index 9117832527..b3c5168c26 100644 --- a/packages/template/nitro.json +++ b/packages/template/nitro.json @@ -3,11 +3,11 @@ "environment": "react-native", "cxxNamespace": ["$$cxxNamespace$$"], "apple": { - "appleModuleName": "$$appleModuleName$$" + "moduleName": "$$appleModuleName$$" }, "android": { - "androidNamespace": ["$$androidNamespace$$"], - "androidCxxLibName": "$$androidCxxLibName$$" + "namespace": ["$$androidNamespace$$"], + "cxxLibName": "$$androidCxxLibName$$" }, "ignorePaths": ["**/node_modules"] } diff --git a/scripts/releases/check-consumer.mjs b/scripts/releases/check-consumer.mjs index baff3dfd7f..b5f34633dc 100644 --- a/scripts/releases/check-consumer.mjs +++ b/scripts/releases/check-consumer.mjs @@ -90,10 +90,10 @@ export declare class Math extends HybridObject { writeJSON(path.join(consumer, 'nitro.json'), { environment: 'bare', cxxNamespace: ['releasecheck'], - apple: { appleModuleName: 'ReleaseCheck' }, + apple: { moduleName: 'ReleaseCheck' }, android: { - androidNamespace: ['releasecheck'], - androidCxxLibName: 'ReleaseCheck', + namespace: ['releasecheck'], + cxxLibName: 'ReleaseCheck', }, ignorePaths: ['**/node_modules'], }) diff --git a/tests/react-native/packages/react-native-nitro-test-external/nitro.json b/tests/react-native/packages/react-native-nitro-test-external/nitro.json index e7b11add5b..5d708a4569 100644 --- a/tests/react-native/packages/react-native-nitro-test-external/nitro.json +++ b/tests/react-native/packages/react-native-nitro-test-external/nitro.json @@ -3,11 +3,11 @@ "environment": "react-native", "cxxNamespace": ["test", "external"], "apple": { - "appleModuleName": "NitroTestExternal" + "moduleName": "NitroTestExternal" }, "android": { - "androidNamespace": ["test", "external"], - "androidCxxLibName": "NitroTestExternal" + "namespace": ["test", "external"], + "cxxLibName": "NitroTestExternal" }, "ignorePaths": ["**/node_modules"] } diff --git a/tests/react-native/packages/react-native-nitro-test/nitro.json b/tests/react-native/packages/react-native-nitro-test/nitro.json index 8c13a0b080..92c503f07a 100644 --- a/tests/react-native/packages/react-native-nitro-test/nitro.json +++ b/tests/react-native/packages/react-native-nitro-test/nitro.json @@ -3,11 +3,11 @@ "environment": "react-native", "cxxNamespace": ["test"], "apple": { - "appleModuleName": "NitroTest" + "moduleName": "NitroTest" }, "android": { - "androidNamespace": ["test"], - "androidCxxLibName": "NitroTest" + "namespace": ["test"], + "cxxLibName": "NitroTest" }, "ignorePaths": ["**/node_modules"] } diff --git a/tests/standalone/nitro-test-external/nitro.json b/tests/standalone/nitro-test-external/nitro.json index c4daf8334c..a5a8ea7a11 100644 --- a/tests/standalone/nitro-test-external/nitro.json +++ b/tests/standalone/nitro-test-external/nitro.json @@ -3,11 +3,11 @@ "environment": "bare", "cxxNamespace": ["test", "external"], "apple": { - "appleModuleName": "NitroTestExternal" + "moduleName": "NitroTestExternal" }, "android": { - "androidNamespace": ["test", "external"], - "androidCxxLibName": "NitroTestExternal" + "namespace": ["test", "external"], + "cxxLibName": "NitroTestExternal" }, "ignorePaths": ["**/node_modules", "**/build"] } diff --git a/tests/standalone/nitro-test/nitro.json b/tests/standalone/nitro-test/nitro.json index 2548cdd6ed..118dfce134 100644 --- a/tests/standalone/nitro-test/nitro.json +++ b/tests/standalone/nitro-test/nitro.json @@ -3,11 +3,11 @@ "environment": "bare", "cxxNamespace": ["test"], "apple": { - "appleModuleName": "NitroTest" + "moduleName": "NitroTest" }, "android": { - "androidNamespace": ["test"], - "androidCxxLibName": "NitroTest" + "namespace": ["test"], + "cxxLibName": "NitroTest" }, "ignorePaths": ["**/node_modules", "**/build"] }