From 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 28 May 2017 00:38:50 +0200 Subject: add linting (and some initial fixes) --- .../hullabaloo-config-manager/lib/readSafe.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 node_modules/hullabaloo-config-manager/lib/readSafe.js (limited to 'node_modules/hullabaloo-config-manager/lib/readSafe.js') diff --git a/node_modules/hullabaloo-config-manager/lib/readSafe.js b/node_modules/hullabaloo-config-manager/lib/readSafe.js new file mode 100644 index 000000000..568258ac6 --- /dev/null +++ b/node_modules/hullabaloo-config-manager/lib/readSafe.js @@ -0,0 +1,29 @@ +'use strict' + +const gfs = require('graceful-fs') + +function readSafe (source, cache) { + if (cache && cache.files && cache.files.has(source)) { + return cache.files.get(source) + } + + const promise = new Promise((resolve, reject) => { + gfs.readFile(source, (err, contents) => { + if (err) { + if (err.code === 'ENOENT') { + resolve(null) + } else { + reject(err) + } + } else { + resolve(contents) + } + }) + }) + + if (cache && cache.files) { + cache.files.set(source, promise) + } + return promise +} +module.exports = readSafe -- cgit v1.2.3