|
1 | | -/** |
2 | | - * The purpose of this module, is to find the project's .babelrc and |
3 | | - * use its contents to bust the babel-loader's internal cache whenever an option |
4 | | - * changes. |
5 | | - * |
6 | | - * @see https://github.com/babel/babel-loader/issues/62 |
7 | | - * @see http://git.io/vLEvu |
8 | | - */ |
9 | 1 | const path = require("path"); |
10 | 2 | const exists = require("./utils/exists"); |
11 | 3 |
|
12 | | -const findBabelrcPath = function find(fileSystem, start, rel) { |
13 | | - const file = path.join(start, rel); |
| 4 | +module.exports = function find(fileSystem, start) { |
| 5 | + for (const fileName of [".babelrc", ".babelrc.js", "package.json"]) { |
| 6 | + const file = path.join(start, fileName); |
14 | 7 |
|
15 | | - if (exists(fileSystem, file)) { |
16 | | - return file; |
| 8 | + if (exists(fileSystem, file)) { |
| 9 | + if ( |
| 10 | + fileName !== "package.json" || |
| 11 | + typeof require(file).babel === "object" |
| 12 | + ) { |
| 13 | + return file; |
| 14 | + } |
| 15 | + } |
17 | 16 | } |
18 | 17 |
|
19 | 18 | const up = path.dirname(start); |
| 19 | + |
| 20 | + // Reached root |
20 | 21 | if (up !== start) { |
21 | | - // Reached root |
22 | | - return find(fileSystem, up, rel); |
| 22 | + return find(fileSystem, up); |
23 | 23 | } |
24 | 24 | }; |
25 | | - |
26 | | -module.exports = function(fileSystem, loc, rel) { |
27 | | - rel = rel || ".babelrc"; |
28 | | - |
29 | | - return findBabelrcPath(fileSystem, loc, rel); |
30 | | -}; |
0 commit comments