-
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(resolve-rc): look for babel in package.json and .babelrc.js (#465)
- Loading branch information
Showing
8 changed files
with
232 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,24 @@ | ||
/** | ||
* The purpose of this module, is to find the project's .babelrc and | ||
* use its contents to bust the babel-loader's internal cache whenever an option | ||
* changes. | ||
* | ||
* @see https://github.com/babel/babel-loader/issues/62 | ||
* @see http://git.io/vLEvu | ||
*/ | ||
const path = require("path"); | ||
const exists = require("./utils/exists"); | ||
|
||
const findBabelrcPath = function find(fileSystem, start, rel) { | ||
const file = path.join(start, rel); | ||
module.exports = function find(fileSystem, start) { | ||
for (const fileName of [".babelrc", ".babelrc.js", "package.json"]) { | ||
const file = path.join(start, fileName); | ||
|
||
if (exists(fileSystem, file)) { | ||
return file; | ||
if (exists(fileSystem, file)) { | ||
if ( | ||
fileName !== "package.json" || | ||
typeof require(file).babel === "object" | ||
) { | ||
return file; | ||
} | ||
} | ||
} | ||
|
||
const up = path.dirname(start); | ||
|
||
// Reached root | ||
if (up !== start) { | ||
// Reached root | ||
return find(fileSystem, up, rel); | ||
return find(fileSystem, up); | ||
} | ||
}; | ||
|
||
module.exports = function(fileSystem, loc, rel) { | ||
rel = rel || ".babelrc"; | ||
|
||
return findBabelrcPath(fileSystem, loc, rel); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "package-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"babel": { | ||
"stage": 3 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
import test from "ava"; | ||
import path from "path"; | ||
import resolveRc from "../lib/resolve-rc.js"; | ||
import resolveRc from "../lib/resolve-rc"; | ||
import fs from "fs"; | ||
|
||
test("should find the .babelrc file", t => { | ||
const start = path.join(__dirname, "fixtures/babelrc-test/1/2/3"); | ||
const result = resolveRc(fs, start); | ||
|
||
t.true(typeof result === "string"); | ||
t.is(result, path.join(__dirname, "fixtures/babelrc-test/.babelrc")); | ||
}); | ||
|
||
test("should find the .babelrc.js config", t => { | ||
const start = path.join(__dirname, "fixtures/babelrc-test/1/2/5/4"); | ||
const result = resolveRc(fs, start); | ||
|
||
t.is(result, path.join(__dirname, "fixtures/babelrc-test/1/2/5/.babelrc.js")); | ||
}); | ||
|
||
test("should find the package.json babel config", t => { | ||
const start = path.join(__dirname, "fixtures/package-test"); | ||
const result = resolveRc(fs, start); | ||
|
||
t.is(result, path.join(__dirname, "fixtures/package-test/package.json")); | ||
}); |
Oops, something went wrong.