From 8544ffad99ea877d984d505e7bd7ff2f5d762895 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Fri, 16 Jun 2017 18:33:29 +0200 Subject: [PATCH] Only base cache identifier on babel options from pkg.json (#468) --- .eslintrc | 1 + src/utils/exists.js | 6 +----- src/utils/read.js | 10 +++++++--- test/utils/read.test.js | 6 ++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index e5cddf5d..8ed70799 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,6 +7,7 @@ "plugins": ["prettier"], "rules": { "arrow-parens": "off", + "quotes": "off", "prettier/prettier": ["error", { "trailingComma": "all" }] } } diff --git a/src/utils/exists.js b/src/utils/exists.js index c3f79041..1b4372cd 100644 --- a/src/utils/exists.js +++ b/src/utils/exists.js @@ -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; }; diff --git a/src/utils/read.js b/src/utils/read.js index 643666e7..d2d403c0 100644 --- a/src/utils/read.js +++ b/src/utils/read.js @@ -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 diff --git a/test/utils/read.test.js b/test/utils/read.test.js index ed8da28c..35f721fc 100644 --- a/test/utils/read.test.js +++ b/test/utils/read.test.js @@ -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"); @@ -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}'); +});