From 3b11806493da49f99b6b05cb8cc2500d03e58bd0 Mon Sep 17 00:00:00 2001 From: Chiedo Date: Tue, 1 Nov 2016 14:48:03 -0400 Subject: [PATCH] Protect the script from failing in weird scenerios --- index.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index ac73ff4..989036f 100644 --- a/index.js +++ b/index.js @@ -91,15 +91,19 @@ module.exports = function(html, options) { return ''; }; - if (src.indexOf('//') === -1) { - path = options.cwd + '/' + src; - if (fs.existsSync(path)) { - file = setFile(String(fs.readFileSync(path))); - } - } - else if (src.indexOf('//') != -1) { - file = setFile(String(request(path).data)); - }; + try { + if (src.indexOf('//') === -1) { + path = options.cwd + '/' + src; + if (fs.existsSync(path)) { + file = setFile(String(fs.readFileSync(path))); + } + } + else if (src.indexOf('//') != -1) { + file = setFile(String(request(path).data)); + }; + } catch (err) { + console.dir(err); + } $(this).replaceWith(file); });