Skip to content

Commit

Permalink
Only base cache identifier on babel options from pkg.json (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez authored Jun 16, 2017
1 parent ea2eafa commit 8544ffa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"plugins": ["prettier"],
"rules": {
"arrow-parens": "off",
"quotes": "off",
"prettier/prettier": ["error", { "trailingComma": "all" }]
}
}
6 changes: 1 addition & 5 deletions src/utils/exists.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
module.exports = function(fileSystem, filename) {
if (!filename) return false;

let exists = false;

try {
exists = fileSystem.statSync(filename).isFile();
} catch (ignoreError) {
return false;
}
} catch (e) {}

return exists;
};
10 changes: 7 additions & 3 deletions src/utils/read.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = function(fileSystem, filename) {
if (!filename) {
throw new Error("filename must be a string");
const path = require("path");

module.exports = function readBabelConfig(fileSystem, filename) {
if (path.basename(filename) === "package.json") {
const pkg = require(filename);

return JSON.stringify(pkg.babel);
}

// Webpack `fs` return Buffer
Expand Down
6 changes: 6 additions & 0 deletions test/utils/read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import read from "../../lib/utils/read.js";

const files = {
existent: path.join(__dirname, "../fixtures/basic.js"),
pkg: path.join(__dirname, "../fixtures/package-test/package.json"),
};

const content = fs.readFileSync(files.existent, "utf8");
Expand All @@ -13,3 +14,8 @@ test("should return contents if file exists", t => {
const realFile = read(fs, files.existent);
t.is(realFile, content);
});

test("should only return config from package.json", t => {
const realFile = read(fs, files.pkg);
t.is(realFile, '{"stage":3}');
});

0 comments on commit 8544ffa

Please sign in to comment.