-
-
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.
- Loading branch information
1 parent
be187cd
commit 27f44f8
Showing
7 changed files
with
48 additions
and
229 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const path = require("path"); | ||
const exists = require("./utils/exists"); | ||
|
||
const configs = [".babelrc", ".babelrc.js", "package.json"]; | ||
|
||
module.exports = function find(fs, start) { | ||
for (let config of configs) { | ||
config = path.join(start, config); | ||
|
||
if (exists(fs, config)) { | ||
if ( | ||
path.basename(config) !== "package.json" || | ||
typeof require(config).babel === "object" | ||
) { | ||
return config; | ||
} | ||
} | ||
} | ||
|
||
const up = path.dirname(start); | ||
|
||
// Reached root | ||
if (up !== start) { | ||
return find(fs, up); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,12 +1,12 @@ | ||
const path = require("path"); | ||
|
||
module.exports = function readBabelConfig(fileSystem, filename) { | ||
if (path.basename(filename) === "package.json") { | ||
const pkg = require(filename); | ||
module.exports = function(fs, config) { | ||
if (path.basename(config) === "package.json") { | ||
const pkg = require(config); | ||
|
||
return JSON.stringify(pkg.babel); | ||
} | ||
|
||
// Webpack `fs` return Buffer | ||
return fileSystem.readFileSync(filename).toString("utf8"); | ||
// memoryFS (webpack) returns a {Buffer} | ||
return fs.readFileSync(config).toString("utf-8"); | ||
}; |
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,13 +1,14 @@ | ||
const path = require("path"); | ||
|
||
module.exports = function relative(sourceRoot, filename) { | ||
const rootPath = sourceRoot.replace(/\\/g, "/").split("/")[1]; | ||
const fileRootPath = filename.replace(/\\/g, "/").split("/")[1]; | ||
module.exports = function relative(root, file) { | ||
const rootPath = root.replace(/\\/g, "/").split("/")[1]; | ||
const filePath = file.replace(/\\/g, "/").split("/")[1]; | ||
|
||
// If the file is in a completely different root folder use the absolute path of file. | ||
if (rootPath && rootPath !== fileRootPath) { | ||
return filename; | ||
// If the file is in a completely different root folder | ||
// use the absolute path of the file | ||
if (rootPath && rootPath !== filePath) { | ||
return file; | ||
} | ||
|
||
return path.relative(sourceRoot, filename); | ||
return path.relative(root, 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 |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import test from "ava"; | ||
import path from "path"; | ||
import resolveRc from "../lib/resolve-rc"; | ||
|
||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
import rc from "../lib/config"; | ||
|
||
test("should find the .babelrc file", t => { | ||
const start = path.join(__dirname, "fixtures/babelrc-test/1/2/3"); | ||
const result = resolveRc(fs, start); | ||
const result = rc(fs, start); | ||
|
||
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); | ||
const result = rc(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); | ||
const result = rc(fs, start); | ||
|
||
t.is(result, path.join(__dirname, "fixtures/package-test/package.json")); | ||
}); |