From a8410d6d39fc84499b5f804802b5b6e5ea07e92f Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 24 Aug 2017 19:58:05 -0400 Subject: Generate module map once (#105) Resolves #97 --- src/index.js | 14 -------------- src/to-javascript.js | 23 +++++++++++++---------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/index.js b/src/index.js index f90a218..eeabc4b 100644 --- a/src/index.js +++ b/src/index.js @@ -249,13 +249,6 @@ module.exports = function purescriptLoader(source, map) { .then(() => { cache.compilationFinished = true; }) - .then(() => - PsModuleMap.makeMap(options.src).then(map => { - debug('rebuilt module map after unknown module forced a recompilation'); - - cache.psModuleMap = map; - }) - ) .then(() => Promise.map(cache.deferred, psModule => ide.load(psModule) @@ -317,13 +310,6 @@ module.exports = function purescriptLoader(source, map) { return bundle(options, cache.bundleModules); } }) - .then(() => - PsModuleMap.makeMap(options.src).then(map => { - debug('rebuilt module map after compilation'); - - cache.psModuleMap = map; - }) - ) .then(() => Promise.map(cache.deferred, psModule => toJavaScript(psModule) diff --git a/src/to-javascript.js b/src/to-javascript.js index b3e3051..3cc9698 100644 --- a/src/to-javascript.js +++ b/src/to-javascript.js @@ -26,21 +26,24 @@ function updatePsModuleMap(psModule) { const filePurs = psModule.srcPath; if (!cache.psModuleMap) { - debug('module mapping does not exist'); + debugVerbose('module mapping does not exist - making a new module map'); - return PsModuleMap.makeMap(options.src).then(map => { - cache.psModuleMap = map; - return cache.psModuleMap; - }); + cache.psModuleMap = PsModuleMap.makeMap(options.src); + + return cache.psModuleMap; } else { - return PsModuleMap.makeMapEntry(filePurs).then(result => { - const map = Object.assign(cache.psModuleMap, result); + debugVerbose('module mapping exists - updating module map for %s', filePurs); + + cache.psModuleMap = cache.psModuleMap.then(psModuleMap => + PsModuleMap.makeMapEntry(filePurs).then(result => { + const map = Object.assign(psModuleMap, result); - cache.psModuleMap = map; + return map; + }) + ); - return cache.psModuleMap; - }); + return cache.psModuleMap; } } -- cgit v1.2.3