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

fix: use prepack instead of prepare #497

Closed
wants to merge 1 commit into from
Closed

Conversation

pwltr
Copy link

@pwltr pwltr commented Nov 17, 2023

Summary

Since Yarn v2 and upwards doesn't support prepare script anymore I believe prepack should be used in the template to run bob build on install.

This comment says this should already be set but it wasn't in my case.

@satya164
Copy link
Member

prepare is used because it runs when people install the package from git. yarn 3 not running it on install is not important since it's not necessary anyway.

@pwltr
Copy link
Author

pwltr commented Nov 17, 2023

yarn 3 not running it on install is not important since it's not necessary anyway

Could you elaborate? I am running yarn v1 and prepare is not running so I'm trying to migrate to v4 and using prepack. How is transpiling source files on install not necessary with yarn 3+? What would be the canonical way to get the build files if not with prepare/prepack?

@satya164
Copy link
Member

satya164 commented Nov 17, 2023

yarn 3 not running it on install is not important since it's not necessary anyway

Could you elaborate? I am running yarn v1 and prepare is not running so I'm trying to migrate to v4 and using prepack. How is transpiling source files on install not necessary with yarn 3+? What would be the canonical way to get the build files if not with prepare/prepack?

Why is it necessary to compile files during install? Yarn 3 or otherwise. Compiled files are for consumers of the npm package and they only need to be compiled during publish step or when installing from Git/local directory.

What problem exactly are you trying to solve?

@pwltr
Copy link
Author

pwltr commented Nov 17, 2023

I'm pulling the package from Github (no npm package yet) and using yarn v1 prepare/prepack is not running. Only working setup is with prepack and yarn v4 so far. Also tried postinstall but no luck either. I would like to stick with install the package from Github but it sounds like that is not a good option?

@satya164
Copy link
Member

satya164 commented Nov 17, 2023

https://callstack.github.io/react-native-builder-bob/build#manual-configuration

  • prepare is run when the package is published, as well as when it's installed from a git URL. It may also run when dependencies are installed based on the package manager.
  • prepack only runs when the package is packed for publishing.

You want prepare because that's run when people when publishing and when package is installed from Git repo with npm. npm doesn't run prepack script when installing from Git callstack/react-native-paper#4082 so it makes it unusable. If Yarn doesn't run prepare on installing from Git then that's a Yarn issue - this makes no single script compatible with both package managers which is a nightmare for package devs.

Either way both prepack and prepare run when publishing the package as the default setup is configured for npm and npm is used to publish the library.

If you only use Yarn then you can make the change in your project but it doesn't make sense as a default as npm is more widely used.

@satya164 satya164 closed this Nov 17, 2023
@satya164
Copy link
Member

I also tested a bit more and when installing from git:

  • Yarn 1 and npm run only prepare
  • Yarn 4 runs only prepack

So Yarn 4's behavior makes no sense and if the package is for general consumption, prepare is more appropriate.

@pwltr
Copy link
Author

pwltr commented Nov 17, 2023

Very much appreciated, will try again with prepare that would save me a ton of headaches.

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.

2 participants