Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Bun to init command #2073

Merged
merged 8 commits into from
Sep 14, 2023

Conversation

TMisiukiewicz
Copy link
Collaborator

@TMisiukiewicz TMisiukiewicz commented Sep 12, 2023

Summary:

Adding support for Bun package manager with init command.
With template and dependencies installed via bun package manager, the JS code execution time went from ~41s to ~2,5s.

In order to make package managers easier to use, this PR deprecates --npm flag and introduces --pm flag where it's possible to use one of the packagers: yarn, npm or bun.

Test Plan:

Follow the contributing guide

  1. Run init command as usual. It should install template and dependencies using yarn and you should have yarn.lock file in created project.
  2. Run init command with --pm yarn flag. Once it's done, you should have yarn.lock file in created project.
  3. Run init command with --pm npm flag. Once it's done, you should have package-lock.json file in created project.
  4. Run init command with --pm bun flag. Once it's done, you should have bun.lockb file in created project.
  5. Run init command with --npm flag. It should show a deprecation warning in the console.
  6. Run bun run ./path-to-cli init ProjectName. It should use bun to install dependencies and template without any additional flag passed. Should also work with bunx once deployed.
  7. If bun is not installed on the machine, it should fallback to npm. Created project should have a package-lock.json file. throw an error that selected package manager is not available (only when using flag)
  8. Run clean command in the created project - the Bun option should be available. It runs bun pm cache rm under the hood.

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

@github-actions github-actions bot added docs Documentation change feature labels Sep 12, 2023
docs/commands.md Outdated Show resolved Hide resolved
@jaworek
Copy link

jaworek commented Sep 12, 2023

If bun is not installed on the machine, it should fallback to npm. Created project should have a package-lock.json file.

I think it would be safer to give user an error and let them know that bun is missing or cannot be found in path. Doing fallback to different tool might be unexpected and not something that user wants to do. As an alternative you could ask a followup question whether they want to use npm instead.

@TMisiukiewicz
Copy link
Collaborator Author

If bun is not installed on the machine, it should fallback to npm. Created project should have a package-lock.json file.

I think it would be safer to give user an error and let them know that bun is missing or cannot be found in path. Doing fallback to different tool might be unexpected and not something that user wants to do. As an alternative you could ask a followup question whether they want to use npm instead.

thanks, added this kind of a check 🙌

@shamilovtim
Copy link

Will bun be used as the runtime to run metro, prettier, tsc, eslint and so on with this change?

@mani-elumalai
Copy link

Nice work

@Jarred-Sumner
Copy link

Exciting. Let me know if you run into any issues with Bun

@tido64
Copy link
Contributor

tido64 commented Sep 13, 2023

Did you try building the project after initializing a project with Bun? bun react-native run-android --no-packager fails for me with

error Android project not found. Are you sure this is a React Native project? If your Android files are located in a non-standard location (e.g. not inside 'android' folder), consider setting `project.android.sourceDir` option to point to a new location.

@Jarred-Sumner
Copy link

Jarred-Sumner commented Sep 13, 2023

If postinstall of react-native dependencies is necessary, that will need to be worked around until we ship the default allowlist for trustedDependencies

@tido64
Copy link
Contributor

tido64 commented Sep 13, 2023

If postinstall of react-native dependencies is necessary, that will need to be worked around until we ship the default allowlist for trustedDependencies

Never mind, my workaround for oven-sh/bun#5063 didn't work properly. It works once I've fixed it.

@TMisiukiewicz
Copy link
Collaborator Author

Did you try building the project after initializing a project with Bun? bun react-native run-android --no-packager fails for me with

error Android project not found. Are you sure this is a React Native project? If your Android files are located in a non-standard location (e.g. not inside 'android' folder), consider setting `project.android.sourceDir` option to point to a new location.

Seems to be working

Screen.Recording.2023-09-13.at.12.06.17.mov

@TMisiukiewicz TMisiukiewicz force-pushed the feat/bun branch 2 times, most recently from 89669a0 to 873c7e4 Compare September 13, 2023 13:31
Copy link
Collaborator

@szymonrybczak szymonrybczak left a comment

Choose a reason for hiding this comment

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

Let's ship it :shipit:

@thymikee thymikee merged commit fd1b41b into react-native-community:main Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation change feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants