-
-
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.
Fixed: watch configuration files. (#460)
- Loading branch information
1 parent
de2d3f3
commit 91f2658
Showing
7 changed files
with
55 additions
and
63 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,22 +1,21 @@ | ||
const fs = require("fs"); | ||
/** | ||
* Check if file exists and cache the result | ||
* return the result in cache | ||
* | ||
* @example | ||
* var exists = require('./helpers/fsExists')({}); | ||
* exists('.babelrc'); // false | ||
* var exists = require('./helpers/fsExists'); | ||
* exists(require('fs'), '.babelrc'); // false | ||
*/ | ||
module.exports = function(cache) { | ||
cache = cache || {}; | ||
module.exports = function(fileSystem, filename) { | ||
if (!filename) return false; | ||
|
||
return function(filename) { | ||
if (!filename) return false; | ||
let exists = false; | ||
|
||
cache[filename] = | ||
cache[filename] || | ||
(fs.existsSync(filename) && fs.statSync(filename).isFile()); | ||
try { | ||
exists = fileSystem.statSync(filename).isFile(); | ||
} catch (ignoreError) { | ||
return false; | ||
} | ||
|
||
return cache[filename]; | ||
}; | ||
return exists; | ||
}; |
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,22 +1,16 @@ | ||
const fs = require("fs"); | ||
/** | ||
* Read the file and cache the result | ||
* return the result in cache | ||
* | ||
* @example | ||
* var read = require('./helpers/fsExists')({}); | ||
* read('.babelrc'); // file contents... | ||
* var read = require('./helpers/fsExists'); | ||
* read(require('fs'), '.babelrc'); // file contents... | ||
*/ | ||
module.exports = function(cache) { | ||
cache = cache || {}; | ||
module.exports = function(fileSystem, filename) { | ||
if (!filename) { | ||
throw new Error("filename must be a string"); | ||
} | ||
|
||
return function(filename) { | ||
if (!filename) { | ||
throw new Error("filename must be a string"); | ||
} | ||
|
||
cache[filename] = cache[filename] || fs.readFileSync(filename, "utf8"); | ||
|
||
return cache[filename]; | ||
}; | ||
// Webpack `fs` return Buffer | ||
return fileSystem.readFileSync(filename).toString("utf8"); | ||
}; |
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,10 +1,11 @@ | ||
import test from "ava"; | ||
import path from "path"; | ||
import resolveRc from "../lib/resolve-rc.js"; | ||
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(start); | ||
const result = resolveRc(fs, start); | ||
|
||
t.true(typeof result === "string"); | ||
}); |
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,20 +1,17 @@ | ||
import test from "ava"; | ||
import path from "path"; | ||
import exists from "../../lib/utils/exists.js"; | ||
import fs from "fs"; | ||
|
||
const cache = {}; | ||
const files = { | ||
const files = { | ||
existent: path.join(__dirname, "../fixtures/basic.js"), | ||
fake: path.join(__dirname, "../fixtures/nonExistentFile.js"), | ||
}; | ||
|
||
test("should return boolean if file exists", (t) => { | ||
const realFile = exists(cache)(files.existent); | ||
const fakeFile = exists(cache)(files.fake); | ||
test("should return boolean if file exists", t => { | ||
const realFile = exists(fs, files.existent); | ||
const fakeFile = exists(fs, files.fake); | ||
|
||
t.true(realFile); | ||
t.false(fakeFile); | ||
|
||
t.true(cache[files.existent]); | ||
t.false(cache[files.fake]); | ||
}); |
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