Skip to content

Commit

Permalink
Making babel to use the babelrc file if we find it
Browse files Browse the repository at this point in the history
Summary:
This PR tells babel where the babelrc file is if it has been found in the project root. I know you guys are relying on babel to find it when you tell babel the filename and sourceFilename, this works fine in normal js/node projects, here is an example where this will not work.

We have a big repo that can contain a few react-native / js projects. Our build system is similar to BUCK and we keep our third party dependencies in a separate folder (having a global package.json at the project route is not feasible as everyone will have to install every apps dependencies even when they don't need them), the structure looks a bit like this:

`third_party/js/.` packages from node_modules
`common/js/` common code used by numerous apps, common components, services etc.
`my_app/native` the app

What's happening is something from `my_app/native` (where the .babelrc file is) is requiring something from `common/js` which is then requiring something from `third_party/js` and so babel has no idea what .babelrc file to use and
Closes #8131

Differential Revision: D4167844

Pulled By: hramos

fbshipit-source-id: 3569981e26ff8f8c632d8ae365a1f43a3483b13b
  • Loading branch information
benhughes authored and Facebook Github Bot committed Nov 11, 2016
1 parent 5daf1cf commit c83fc07
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packager/transformer.js
Expand Up @@ -37,11 +37,6 @@ const getBabelRC = (function() {
// Let's look for the .babelrc in the first project root.
// In the future let's look into adding a command line option to specify
// this location.
//
// NOTE: we're not reading the project's .babelrc here. We leave it up to
// Babel to do that automatically and apply the transforms accordingly
// (which works because we pass in `filename` and `sourceFilename` to
// Babel when we transform).
let projectBabelRCPath;
if (projectRoots && projectRoots.length > 0) {
projectBabelRCPath = path.resolve(projectRoots[0], '.babelrc');
Expand All @@ -58,6 +53,9 @@ const getBabelRC = (function() {
// Require the babel-preset's listed in the default babel config
babelRC.presets = babelRC.presets.map((preset) => require('babel-preset-' + preset));
babelRC.plugins = resolvePlugins(babelRC.plugins);
} else {
// if we find a .babelrc file we tell babel to use it
babelRC.extends = projectBabelRCPath;
}

return babelRC;
Expand Down

0 comments on commit c83fc07

Please sign in to comment.