-
Notifications
You must be signed in to change notification settings - Fork 24.6k
Make providesModuleNodeModules
behavior to be more deterministic.
#5985
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
3666826
to
4c84cfb
Compare
Wow that's a lot of issues :( https://github.com/facebook/react-native/issues?utf8=%E2%9C%93&q=naming+collision+detected First things I asked people on the JS infra team when I joined RN was why Haste existed at all. The answer is the same system worked really well for us in PHP - you can move files around without having to codemod thousands of files importing them for example. Thanks for doing this as well as #5084. |
@mkonicek to be clear, I love Haste. We use it at Exponent on internal projects, and I'm working on a project that let's me use it with Node. However, I think where it shines, and why it works for Facebook, is that it's suited particularly to product code. The issue, and the "hard part", is that we have a packager that (currently) has to understand both systems. I know that it's the goal of people (@spicyj, @cpojer, and others) to remove the magic from the packager. This PR specifically is really meant as a stop gap, and to make the behavior that's currently there make a bit more sense and produce more desirable behavior. The end goal, of course, is that this option wouldn't need to exist at all... |
Thanks for implementing this so quickly! |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1680514035538734/int_phab to review. |
@ide lol. |
@martinbigio can you hold this for the moment? I need to fix some weird issue with the obj-c/android tests. |
sure |
@skevy lol sorry about that. my chrome extension must have gone off -_- |
@skevy updated the pull request. |
1 similar comment
@skevy updated the pull request. |
Does this work if you install fbjs and react-native as siblings? Also, it seems like maybe you could use path.resolve instead of manually concatenating |
Ok, @martinbigio, I think if you take a look at this and are OK with it we should be good to go. I refactored @spicyj yes, this works if fbjs and react-native are siblings...because now we guarantee that we're using the version of |
@skevy updated the pull request. |
In a holding pattern on this until facebookarchive/node-haste#33 is resolved and merged...then I'll update this PR accordingly with any RN specific changes (most likely will just be the update to the providesModuleNodeModules option in Resolver). |
@skevy updated the pull request. |
db82b0d
to
e06186f
Compare
@skevy updated the pull request. |
1 similar comment
@skevy updated the pull request. |
Any ETA on this one? |
158a40e
to
b5c5bd8
Compare
@skevy updated the pull request. |
Currently, the
providesModuleNodeModules
option allows for specifying an array of package names, that the packager will look for within node_modules, no matter how deep they're nested, and treat them as packages that use the@providesModule
pragma.In reality, this is not actually the behavior we want.
NPM, because of how it handles dependencies, can do all kinds of arbitrary nesting of packages when
npm install
is run. This causes a problem for how we deal withprovidesModuleNodeModules
. Specifically...takefbjs
. Currently, React Native relies on using the Haste version offbjs
(will be resolved in #5084). Thus if npm installs multiple copies of fbjs...which is a very common thing for it to do (as can be seen by this list of issues: https://github.com/facebook/react-native/issues?utf8=%E2%9C%93&q=naming+collision+detected), we get into a state where the packager fails and says that we have a naming collision.Really, the behavior we want is for the packager to treat only a single copy of a given package, that we specify in the
Resolver
in theprovidesModuleNodeModules
option, as the package that it uses when trying to resolve Haste modules.This PR provides that behavior, by changing
providesModuleNodeModules
from a list of strings to a list of objects that have aname
key, specifying the package name, as well as aparent
key. Ifparent
is null, it will look for the package at the top level (directly undernode_modules
). Ifparent
is specified, it will use the package that is nested under that parent as the Haste module.To anyone who reads this PR and is familiar with the differences between npm2 and npm3 -- this solution works under both, given the fact that we are now shipping the NPM Shrinkwrap file with React Native when it's installed through
npm
. In both the npm2 and npm3 case, node_modules specified by RN's package.json are nested underneathreact-native
in node_modules, thus allowing us to specify, for example, that we want to use React Native's copy offbjs
(not any other copy that may be installed) as the module used by the packager to resolve anyrequires
that reference a module infbjs
.Test Plan:
npm 2
react-native init
a new projectnpm install --save skevy/react-native#fix-providesModuleNodeModules react@0.14.5
react
andfbjs
being installed.npm 3
react-native init
a new projectnpm install --save skevy/react-native#fix-providesModuleNodeModules react@0.14.5
react
andfbjs
being installed./cc @martinbigio @mkonicek @bestander @davidaurelio @ide