]> git.immae.eu Git - github/fretlink/purs-loader.git/commitdiff
Generate module map once (#105)
authoreric <thul.eric@gmail.com>
Thu, 24 Aug 2017 23:58:05 +0000 (19:58 -0400)
committerGitHub <noreply@github.com>
Thu, 24 Aug 2017 23:58:05 +0000 (19:58 -0400)
Resolves #97

src/index.js
src/to-javascript.js

index f90a21886065b1be7f808cfec4bc3483cf0f6a3e..eeabc4b6592607975ed2d70e1aeffc57fc4a5ae1 100644 (file)
@@ -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)
index b3e305123ed271927aef8da8bab7203927d07c57..3cc969871d7167c5129e9b25d2c71315c22a6934 100644 (file)
@@ -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;
   }
 }