From d74f1949b8317d5bfee13f1677481c0f1bab90c5 Mon Sep 17 00:00:00 2001 From: Alex Brausewetter Date: Fri, 15 May 2015 11:05:48 +0000 Subject: [PATCH] Do not use fs.exists and handle error instead --- plugins/c9.static/cdn.cli.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/c9.static/cdn.cli.js b/plugins/c9.static/cdn.cli.js index e826d37a..747e987e 100644 --- a/plugins/c9.static/cdn.cli.js +++ b/plugins/c9.static/cdn.cli.js @@ -186,18 +186,20 @@ define(function(require, exports, module) { var sourcePath = path.resolve(pathMap[prefix], path.relative(prefix, targetPath)); - if (!fs.existsSync(sourcePath)) - return; - - var files = fs - .readdirSync(sourcePath) - .filter(function(p) { - return !excludePattern.test(p) - && !/[\s#]/.test(p) - && /\.js$/.test(p); - }); + try { + var files = fs.readdirSync(sourcePath); + } catch (e) { + if (e.code === "ENOENT") return; + else throw e; + } - files.map(function(p) { + files = files.filter(function(p) { + return !excludePattern.test(p) + && !/[\s#]/.test(p) + && /\.js$/.test(p); + }); + + files.forEach(function(p) { result.push(targetPath + "/" + path.basename(p, ".js")); }); }