Skip to content

feat(crnl): install nitro modules dependency automatically for local modules#828

Merged
satya164 merged 2 commits intomainfrom
local-nitro-module-install-rnnm
Apr 25, 2025
Merged

feat(crnl): install nitro modules dependency automatically for local modules#828
satya164 merged 2 commits intomainfrom
local-nitro-module-install-rnnm

Conversation

@atlj
Copy link
Copy Markdown
Collaborator

@atlj atlj commented Apr 22, 2025

Summary

  • create-react-native-library will install react-native-nitro-modules automatically for local libraries.

Test plan

  1. Create a new RN app
  2. Build the bob repo
  3. Link create-react-native-library to your RN app
  4. Run create-react-native-library in the app
  5. Answer yes when you're asked if you want to create a native module
  6. Select Nitro Modules
  7. Make sure react-native-nitro-modules is added to your app's dependencies.

Copy link
Copy Markdown

@renanmav renanmav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this manually, but LGTM.

Couple of Qs:

  1. How can I test this locally?
  2. Does it install react-native-nitro-modules for both local modules and standalone libraries?

const appPackageJson: PackageJson = await fs.readJson(appPackageJsonPath);
const dependencies = appPackageJson['dependencies'] ?? {};

dependencies['react-native-nitro-modules'] = config.versions.nitroModules;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

import fs from 'fs-extra';
import path from 'path';

export async function determinePackageManager() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is bun supported?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't officially support bun right now. That being said, there is no real reason libraries bob generates shouldn't work with bun. It might require some changes tho.

@atlj
Copy link
Copy Markdown
Collaborator Author

atlj commented Apr 22, 2025

@renanmav

  1. How can I test this locally?
  1. Checkout the code
  2. Follow the development workflow to build create-react-native-library
  3. Link the create-react-native-library binary you've built. I generally use yarn yarn link /path/to/bob/repo --all
  4. Call the binary you've linked in an existing app.
  1. Does it install react-native-nitro-modules for both local modules and standalone libraries?

That's a yes, react-native-nitro-modules is installed when the template is being generated on standalone modules.

@renanmav
Copy link
Copy Markdown

renanmav commented Apr 24, 2025

@atlj

Manually tested this branch on my machine. It works for the standalone library, but for local libraries it does not.

Check the screenshot below:

Screenshot 2025-04-24 at 13 23 49

Here are my terminal prompts:

Local library
~/renanmav/react-native-builder-bob on  local-nitro-module-install-rnnm is 📦 (independent)
λ /Users/renanmav/renanmav/react-native-builder-bob/packages/create-react-native-library/bin/create-react-native-library
✔ Looks like you're under a project folder. Do you want to create a local library? … yes
✔ Where do you want to create the library? … ./react-native-nitro-local-library
✔ What is the name of the npm package? … react-native-nitro-local-library
✔ What is the description for the package? … test local library with nitro
✔ What type of library do you want to develop? › Nitro module
✔ Project created successfully at react-native-nitro-local-library!

Get started with the project:

- Link the library at react-native-nitro-local-library based on your project setup
- Run pod install --project-directory=ios to install dependencies with CocoaPods
- Run npx react-native run-android or npx react-native run-ios to build and run the app
- Import from react-native-nitro-local-library and use it in your app.

Good luck!
Standalone library
~/renanmav/react-native-builder-bob on  local-nitro-module-install-rnnm [!?] is 📦 (independent)
λ /Users/renanmav/renanmav/react-native-builder-bob/packages/create-react-native-library/bin/create-react-native-library
✔ Looks like you're under a project folder. Do you want to create a local library? … no
✔ Where do you want to create the library? … react-native-nitro-standalone-library
✔ What is the name of the npm package? … react-native-nitro-standalone-library
✔ What is the description for the package? … test standalone library with nitro
✔ What is the name of package author? … Renan Mav
✔ What is the email address for the package author? … renan.mav@hotmail.com
✔ What is the URL for the package author? … https://github.com/renanmav
✔ What is the URL for the repository? … https://github.com/renanmav/react-native-nitro-standalone-library
✔ What type of library do you want to develop? › Nitro module
✔ Project created successfully at react-native-nitro-standalone-library!

Get started with the project:

  $ yarn

Run the example app on iOS:

  $ yarn example ios

Run the example app on Android:

  $ yarn example android

See CONTRIBUTING.md for more details. Good luck!

Also, looks like turbo module template is broken on CI.

@satya164
Copy link
Copy Markdown
Member

@renanmav dependencies for local libraries have been added to the project's package.json - otherwise it won't work unless it's a monorepo.

@satya164 satya164 merged commit 9ffb17c into main Apr 25, 2025
7 of 8 checks passed
@satya164 satya164 deleted the local-nitro-module-install-rnnm branch April 25, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants