From ebfcbdec15e10511f9225fec568dbc9375616163 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 2 Dec 2019 10:47:29 +0800 Subject: [PATCH] feat:protect debug error --- doric-cli/scripts/command.js | 2 -- doric-cli/scripts/watcher.js | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/doric-cli/scripts/command.js b/doric-cli/scripts/command.js index 471cfd89..2da4018e 100644 --- a/doric-cli/scripts/command.js +++ b/doric-cli/scripts/command.js @@ -26,9 +26,7 @@ function fromDir(startPath, filter) { }; }; function doMerge(startPath, fileName) { - // console.log('-- found: ', startPath, fileName); const filePath = fileName ? path.join(startPath, fileName) : startPath - // console.log('-- merge: ', filePath.replace(/bundle\//, 'build/'), filePath) const mergedMap = SourceMapMerger.createMergedSourceMapFromFiles([ filePath.replace(/bundle\//, 'build/'), filePath, diff --git a/doric-cli/scripts/watcher.js b/doric-cli/scripts/watcher.js index e08659e0..f1900464 100644 --- a/doric-cli/scripts/watcher.js +++ b/doric-cli/scripts/watcher.js @@ -16,15 +16,19 @@ setTimeout(() => { fs.readFile(path, 'utf-8', (error, data) => { if (!path.endsWith('.map')) { console.log('File change:', path) - const sourceMap = doMerge(path + ".map") - ws.connections.forEach(e => { - e.sendText(JSON.stringify({ - cmd: 'RELOAD', - script: data, - source: path.match(/[^/\\]*$/)[0], - sourceMap, - })) - }) + try { + const sourceMap = doMerge(path + ".map") + ws.connections.forEach(e => { + e.sendText(JSON.stringify({ + cmd: 'RELOAD', + script: data, + source: path.match(/[^/\\]*$/)[0], + sourceMap, + })) + }) + } catch (e) { + console.error(e) + } } }) });