-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[WIP] Allow react-native link <library> #485
Conversation
7b91209
to
7263692
Compare
7263692
to
3244850
Compare
I've also created a gist, with 3 files:
https://gist.github.com/tadeuzagallo/dd046e738f4c87edac4f I also added support for a It also tries to guess a lot of names, that should work well specially for the native libraries. |
👍 this will be a very convenient feature! No comment on the code itself. |
See also #235 |
The work on #235 is going to pave the way for a React Native ecosystem where different packages can share the same dependencies. For example React Core will probably have a dependency on pop for POPAnimation support, and someone else might publish a (hypothetical) ReverberatingSound library that uses pop's spring dynamics. The two modules must share the same copy of pop for the app to compile, and they may also have different version requirements (ex: React Core might need pop >= 1.0.7 while ReverberatingSound might only need pop ~1.0), which #235 will address. As facebook publishes more mobile infrastructure and projects line up (ex: React Native on ComponentKit with pop) I believe this is the direction to look in. |
Instead of inventing our own package.json schema, we might want to consider just using a BUCK file for the details, and package.json would just point to that. You might also want to use the xcodeproj tool to modify the xcode files instead of regexes: https://github.com/CocoaPods/Xcodeproj
|
Well, there some things to consider in it, first is that #235 makes a whole environment around CocoaPods, and I didn't think we had settled for it. I do understand what are shared dependencies, and cocoapods does solve a lot more than these few lines of code, and I do not intend to create a node-pods. The thing is that it doesn't solve the problem for android and it depends on ruby, for that I do agree that BUCK is a better choice, but as far as I know it's not settled as well. But for the sake of clarity, I didn't create a package manager, I wrote a couple lines of code that allow you to link projects via cli, it's not a fabulous module system, it's just so people that are not iOS developers don't have to keep dragging files around neither are required to use cocoapods and therefore ruby.
It doesn't rely on
It doesn't use any regex, and it would introduce a dependency on ruby all over again. |
Oh, and something that might not be clear, where I mention |
Sorry, I should have looked at your code more closely - this looks pretty sweet and is nice that it doesn't rely on any complex deps. I think once we have this, it shouldn't be too hard to create a |
My main concern is that it will introduce more problems in the future with supporting this. However, if you guys think it's worth doing I'd suggest to change the name of the command to something more concrete, like |
@@ -13,6 +15,7 @@ function printUsage() { | |||
'', | |||
'Commands:', | |||
' start: starts the webserver', | |||
' link: link the target library the current project', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I follow the description
Honestly, I don't feel comfortable landing it, but thanks for reviewing. |
} catch(err) { | ||
pkg = { 'react-native': {} }; | ||
} | ||
var name = pkg['react-native'].xcodeproj || path.basename(libraryPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if package.json
exists but doesn't contain react-native
, this will fail
Few ideas for tests, if you decide to add them:
|
@@ -31,6 +34,13 @@ function run() { | |||
process.cwd(), | |||
], {stdio: 'inherit'}); | |||
break; | |||
case 'link': | |||
if (!args[1]) { | |||
console.error('Usage: react-native link <path>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the description it's not clear how to use it. I think the most logical use case is something like react-native link react-native-video
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about changing the signature something more like react-native link MyProject[.xcodeproj] path/to/lib[.xcodeproj]
so it doesn't rely on any magic, and if we decide to something easier, we can build on top of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tadeuzagallo - good idea, the ideas are certainly not mutually exclusive - if we later add support for @frantic's proposed api (which looks ideal certainly) we can just switch between the two depending on the arity. I can imagine a number of edges cases that would get in the way of react-native link react-native-video
, which would require more careful consideration. It's not a big hassle to include in the README for a project npm i x --save && react-native link MyProject node_modules/x/X
@tadeuzagallo - any update here? |
@brentvatne Not yet. I'm on holidays and we'll be back next week. Feel free to jump in if you feel like helping! |
@tadeuzagallo - oh sorry for bothering you! Enjoy the well-deserved holidays 🍻 🌴! |
👍 |
Hi @tadeuzagallo! I was interested in pushing this forward and wanted to get your take on my path forward 😄
So before I dive in head first, what do you think? 😟 cc/ @brentvatne |
Hey @jordanbyron, it's great that you want to tackle it, I really haven't had any time to get to it lately :/ We cannot simply move this code into another project for now, but we can move it into a separate folder inside What really stopped me in first place is that "linking two projects" is a very vague thing, and we either end up assuming basically everything or we need some kind of configuration file, then we get back to the point of kinda creating a new package manager, that is totally not the idea. Something that also has to be figured out is that currently we don't do any validations, things are just added to project, even if it's already there. But this one should be trivial, even if you have any issues I can fix it. So, totally go for it, just give it a little bit of thought about what "link" in this context is going to mean: Can we specify a target? What if it's not a static library? What if it has a different name? Right now I add the headers path of the library being linked to the container library, but the library being linked will probably have to find And let me know if you need any help with the pbxproj tweaking code 😃 |
@tadeuzagallo updated the pull request. |
I've added the
link
method to the cli, but this relies on a minimum info on thepackage.json
of both, the target library and the current project.The only piece of info necessary is:
I've added a sample anyways... The code looks pretty messy right now, I still have to remove the RegExps but would like some input. Also it doesn't handle any edge cases as is, just looked at the result prxproj file after linking a library and reproduced it.
/cc @vjeux @sahrens