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

@providesModule for public use? #2648

Closed
Ehesp opened this issue Oct 18, 2016 · 9 comments
Closed

@providesModule for public use? #2648

Ehesp opened this issue Oct 18, 2016 · 9 comments

Comments

@Ehesp
Copy link

Ehesp commented Oct 18, 2016

Hello,

The Facebook F8 App makes quite heavy use of @providesModule with Flow. Now it's possible to use this ourselves if we include the module/files in the .flowconfig and have access to "global" modules we define with @providesModule without figuring out the relative paths.

This works great, however I'm struggling to find much about it in the documentation. Are we supposed to use this in our own environment or not? If not, why not?

It makes life so much simpler, but I can't work out whether I should be doing it.

@zertosh
Copy link
Member

zertosh commented Oct 19, 2016

@providesModule is a facebookism. I do not recommend that you use it, since all of your infra has to support it. But you can find out more about it at https://github.com/facebookarchive/node-haste and https://github.com/facebook/jest/tree/master/packages/jest-haste-map.

@samwgoldman
Copy link
Member

Agree with @zertosh. Haste is something Flow supports, but people outside of FB probably shouldn't be using it (unless you are @ide).

@Ehesp
Copy link
Author

Ehesp commented Oct 20, 2016

Thanks guys.

@samwgoldman is there anything similar which is less internal which can potentially produce this sort of functionality?

@samwgoldman
Copy link
Member

You're welcome to use haste, but it's not a Flow thing, which is why we don't have documentation for it. Do either of the links Andres shared help?

@Ehesp
Copy link
Author

Ehesp commented Oct 20, 2016

Yeah they do thanks, just trying to get my head around it.

The confusion really comes from the open source example of "your" F8 App which uses this all over the place. There was an issue there (fbsamples/f8app#72) about this, hence me bringing this up here as I thought it was a flow thing

@ide
Copy link

ide commented Oct 20, 2016

@samwgoldman Just FYI we do use Haste in a couple of places with the understanding that it's on us to make it work for our use cases and that the code is the documentation.

Haste is pretty useful and I think the right way to do modules within packages (interpackage imports don't change at all in the spec I have in mind) so I'd like to see it proliferate but no one's working on making that happen at the moment.

@flegall
Copy link

flegall commented Jan 23, 2017

For the ones interested in using Haste, I've written a simple webpack resolver that can use it: https://github.com/flegall/haste-map-webpack-resolver

@AriaMinaei
Copy link

To have path aliasing, you can use webpack's resolve.alias. If you're using react-native and can't configure webpack, then babel's babel-plugin-module-resolver should work. If that, you'll also need to create an rn-cli.config.js file with this content:

'use strict'

var path = require('path')

var config = {
  getProjectRoots() {
    return getRoots()
  },

  getAssetRoots() {
    return getRoots()
  },
}

function getRoots() {
  return [
    __dirname
  ]
}

module.exports = config

@jedwards1211
Copy link
Contributor

@samwgoldman honesly I hope Facebook stops using it too, any time I (unintentionally wind up with multiple versions of a dep that uses @providesModule installed, I just get annoying useless errors: #6475

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

No branches or pull requests

7 participants