-
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
Use "babel-preset-react-native" #5214
Conversation
By analyzing the blame information on this pull request, we identified @tadeuzagallo, @davidaurelio and @kittens to be potential reviewers. |
e008d2d
to
151c85e
Compare
@skevy updated the pull request. |
2aedde7
to
ed0b665
Compare
@martinbigio and/or @davidaurelio...vjeux suggested that one of you guys review :) |
Awesome! |
Can you make a folder inside of this repo like we do for react-native-cli? Would be easier to manage |
@vjeux that seems reasonable to me. Should it be committed through the shipit bot? Or should it live in OSS only? |
Any reason for the rename of '.babelrc'? |
Guys, let me discuss this with @martinbigio, we need to sort out one thing ;-) |
@skevy @vjeux: About moving the preset under a folder, sounds good. I'm also happy to add whoever needs to be a collaborator to the repo & npm owners list. I think we can figure that out later. The main thing I think is important is that the babelrc.json file depends on the preset so that RN's internal configuration stays in sync with people's custom .babelrc files that are using the preset. Also the preset should follow semver, just like any other npm package. |
|
||
function transform(src, filename, options) { | ||
options = options || {}; | ||
const projectBabelRCPath = path.resolve(__dirname, '..', '..', '..', '.babelrc'); |
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.
Thinking about this some more, I think the babelrc under the path specified by --projectRoots
is what we want to use. That way if you invoke the packager and point it at another directory, we'd correctly use that directory's .babelrc.
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 thought about that -- but what are your thoughts on if there are multiple project roots?
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.
This line only works for OS and if react native is in ${projectDirectory}/node_modules/react-native
. I’m a little bit afraid of the apocalyptic potential of this innocent path lookup ;-)
Is anybody outside of Facebook using multiple project roots? The first project root might be a saner choice. Or we can add a command line option.
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.
Let's default to the first project root, and I'll add a command line option to specify a babelrc path.
@skevy Just to note, I presume some people have a {
"extends": "react-native/packager/react-packager/.babelrc"
} Which will break after the rename. Not a big deal, just wanted to note. |
@satya164 Good point. We should mention it under Breaking Changes in the release notes. |
@ide Yup. |
@@ -16,7 +16,7 @@ var path = require('path'); | |||
var _only = []; | |||
|
|||
function readBabelRC() { | |||
var rcpath = path.join(__dirname, 'react-packager', '.babelrc'); | |||
var rcpath = path.join(__dirname, 'react-packager', '.babelrc.json'); |
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.
Let’s remove the leading dot.
Summary: At the moment we have to disable strict mode for the transform-es2015-modules-commonjs because strict mode leaks to the global scope and breaks the bridge. It was due to the way the polyfills were bundled in the package. To fix it, I wrapped the polyfill modules in an IIFE. Then when strict mode was enabled some polyfills were broken due to strict mode errors so that was fixed too. Also removed the IIFE from the polyfills that included one. This diff doesn't enable the strict mode transform since some internal facebook modules depend on it not being enabled. When #5214 lands we could make the default babel config shipped with OSS react-native use strict mode modules and facebook could just modify the babel config to disable it if needed. This will allow removing `"strict": false` from https://github.com/facebook/react-native/blob/master/packager/react-packager/.babelrc#L16 Fixes #5316 Closes #5422 Reviewed By: svcscm Differential Revision: D2846422 Pulled By: davidaurelio fb-gh-sync-id: a3e2f8909aa87dabab2b872c61b887e80220fb56
Summary: At the moment we have to disable strict mode for the transform-es2015-modules-commonjs because strict mode leaks to the global scope and breaks the bridge. It was due to the way the polyfills were bundled in the package. To fix it, I wrapped the polyfill modules in an IIFE. Then when strict mode was enabled some polyfills were broken due to strict mode errors so that was fixed too. Also removed the IIFE from the polyfills that included one. This diff doesn't enable the strict mode transform since some internal facebook modules depend on it not being enabled. When facebook#5214 lands we could make the default babel config shipped with OSS react-native use strict mode modules and facebook could just modify the babel config to disable it if needed. This will allow removing `"strict": false` from https://github.com/facebook/react-native/blob/master/packager/react-packager/.babelrc#L16 Fixes facebook#5316 Closes facebook#5422 Reviewed By: svcscm Differential Revision: D2846422 Pulled By: davidaurelio fb-gh-sync-id: a3e2f8909aa87dabab2b872c61b887e80220fb56
}); | ||
|
||
const result = babel.transform(src, Object.assign({}, babelRC, config)); | ||
return Object.assign({}, babelRC, extraConfig); |
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.
Shouldn't extraConfig
be config
instead? config
doesn't seems to be used anywhere.
ed0b665
to
c5dd703
Compare
@skevy updated the pull request. |
1 similar comment
@skevy updated the pull request. |
…itializeJavaScriptAppEngine
…en using the default Babel config
@skevy updated the pull request. |
…'t complain about conflict
@skevy updated the pull request. |
a439c19
to
e5e3ba7
Compare
@skevy updated the pull request. |
@skevy updated the pull request. |
@skevy updated the pull request. |
e6cb02d
👍 |
@vjeux I definitely think we should crash earlier if not using Node 4. No one should be using less than Node 4, and it already says at the top of your screenshot that React Native runs on Node 4.0 or newer. |
@vjeux ah so i guess just exit there if less than node 4. |
Cool, i'll send a pull request |
Be careful with version checks though. On Thursday, 4 February 2016, Adam Miskiewicz notifications@github.com
|
Is there an ETA on this? Thanks! |
@lrettig this is already merged in master. It should be in the current RC and will be officially released in 0.20. |
Thanks. Didn't see it mentioned in the release notes! On Thu, Feb 11, 2016 at 12:02 PM, Adam Miskiewicz notifications@github.com
|
@skevy updated the pull request. |
Summary: Rather than specifying Babel plugins in the `.babelrc` packaged with react-native, leverage a Babel preset to define the plugins (https://github.com/exponentjs/babel-preset-react-native). This allows for a much better user experience for those who want (or need) to override options in their project's `.babelrc`. Prior to this PR, if a user wanted to use a custom babel-plugin (or a custom set of babel plugins), they'd have either 1) manually override the `.babelrc` in the react-packager directory (or fork RN), or 2) specify a custom transformer to use when running the packager that loaded their own `.babelrc`. Note - the custom transformer was necessary because without it, RN's `.babelrc` options would supersede the options defined in the project's `.babelrc`...potentially causing issues with plugin ordering. This PR makes the transformer check for the existence of a project-level `.babelrc`, and if it it's there, it _doesn't_ use the react-native `.babelrc`. This prevents any oddities with Babel plug Closes facebook#5214 Reviewed By: davidaurelio Differential Revision: D2881814 Pulled By: martinbigio fb-gh-sync-id: 4168144b7a365fae62bbeed094d8a03a48b4798c
Summary:Since #5422 react-native works with strict mode modules but the transform was not updated since Facebook has some non strict mode compatible internal modules. Now that #5214 has landed and it is easy to change the babel config I think we should enable it by default to make es2015 modules spec compliant. Someone at Facebook will have to make the internal changes necessary to disable strict mode modules for their projects that use non strict mode compatible modules by including a .babelrc file with ``` json { "presets": [ "react-native" ], "plugins": [ ["transform-es2015-modules-commonjs", { "strict": false, "allowTopLevelThis": true }] ] } ``` before merging this. We might also want to mention this in the breaking change section for the next release. Closes #5796 Differential Revision: D3075802 fb-gh-sync-id: e807b67401107e1e944db38453e254025ce0a6c7 shipit-source-id: e807b67401107e1e944db38453e254025ce0a6c7
Summary:Since facebook#5422 react-native works with strict mode modules but the transform was not updated since Facebook has some non strict mode compatible internal modules. Now that facebook#5214 has landed and it is easy to change the babel config I think we should enable it by default to make es2015 modules spec compliant. Someone at Facebook will have to make the internal changes necessary to disable strict mode modules for their projects that use non strict mode compatible modules by including a .babelrc file with ``` json { "presets": [ "react-native" ], "plugins": [ ["transform-es2015-modules-commonjs", { "strict": false, "allowTopLevelThis": true }] ] } ``` before merging this. We might also want to mention this in the breaking change section for the next release. Closes facebook#5796 Differential Revision: D3075802 fb-gh-sync-id: e807b67401107e1e944db38453e254025ce0a6c7 shipit-source-id: e807b67401107e1e944db38453e254025ce0a6c7
Summary: Rather than specifying Babel plugins in the `.babelrc` packaged with react-native, leverage a Babel preset to define the plugins (https://github.com/exponentjs/babel-preset-react-native). This allows for a much better user experience for those who want (or need) to override options in their project's `.babelrc`. Prior to this PR, if a user wanted to use a custom babel-plugin (or a custom set of babel plugins), they'd have either 1) manually override the `.babelrc` in the react-packager directory (or fork RN), or 2) specify a custom transformer to use when running the packager that loaded their own `.babelrc`. Note - the custom transformer was necessary because without it, RN's `.babelrc` options would supersede the options defined in the project's `.babelrc`...potentially causing issues with plugin ordering. This PR makes the transformer check for the existence of a project-level `.babelrc`, and if it it's there, it _doesn't_ use the react-native `.babelrc`. This prevents any oddities with Babel plug Closes facebook/react-native#5214 Reviewed By: davidaurelio Differential Revision: D2881814 Pulled By: martinbigio fb-gh-sync-id: 4168144b7a365fae62bbeed094d8a03a48b4798c
Rather than specifying Babel plugins in the
.babelrc
packaged with react-native, leverage a Babel preset to define the plugins (https://github.com/exponentjs/babel-preset-react-native).This allows for a much better user experience for those who want (or need) to override options in their project's
.babelrc
.Prior to this PR, if a user wanted to use a custom babel-plugin (or a custom set of babel plugins), they'd have either 1) manually override the
.babelrc
in the react-packager directory (or fork RN), or 2) specify a custom transformer to use when running the packager that loaded their own.babelrc
. Note - the custom transformer was necessary because without it, RN's.babelrc
options would supersede the options defined in the project's.babelrc
...potentially causing issues with plugin ordering.This PR makes the transformer check for the existence of a project-level
.babelrc
, and if it it's there, it doesn't use the react-native.babelrc
. This prevents any oddities with Babel plugin ordering, and leaves that up to the RN user. The RN user would then just include a.babelrc
file in their project that looks like:They can then add whatever other presets or plugins that they'd like (such as the Babel Relay Plugin or a decorators plugin, for example).
Super important note: after the fbjs changes are merged...this is really the final piece of getting Relay running OOTB in RN
/cc @ide @vjeux