From 94013ed76272114dd981919bfb56c932778d95a2 Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 3 Oct 2017 13:40:08 -0400 Subject: Rebuild module map for new files Resolves #100 --- src/to-javascript.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/to-javascript.js b/src/to-javascript.js index 3cc9698..28dde7a 100644 --- a/src/to-javascript.js +++ b/src/to-javascript.js @@ -59,7 +59,7 @@ function makeBundleJS(psModule) { const result = `module.exports = require("${escaped}")["${name}"]`; - return result; + return Promise.resolve(result); } // Replace require paths to output files generated by psc with paths @@ -105,28 +105,33 @@ function makeJS(psModule, psModuleMap, js) { const additionalImports = difference(imports, replacedImports); - if (additionalImports.length) { - debugVerbose('additional imports for %s: %o', name, additionalImports); + if (!additionalImports.length) { + return Promise.resolve(result); } + else { + debug('rebuilding module map due to additional imports for %s: %o', name, additionalImports); - const additionalImportsResult = additionalImports.map(import_ => { - const moduleValue = psModuleMap[import_]; + psModule.cache.psModuleMap = null; - if (!moduleValue) { - debug('module %s was not found in the map, skipping require', import_); + return updatePsModuleMap(psModule).then(updatedPsModuleMap => { + const additionalImportsResult = additionalImports.map(import_ => { + const moduleValue = updatedPsModuleMap[import_]; - return null; - } - else { - const escapedPath = jsStringEscape(moduleValue.src); + if (!moduleValue) { + debug('module %s was not found in the map, skipping require', import_); - return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`; - } - }).filter(a => a !== null).join('\n'); + return null; + } + else { + const escapedPath = jsStringEscape(moduleValue.src); - const result_ = result + (additionalImports.length ? '\n' + additionalImportsResult : ''); + return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`; + } + }).filter(a => a !== null).join('\n'); - return result_; + return result + '\n' + additionalImportsResult; + }); + } } module.exports = function toJavaScript(psModule) { -- cgit v1.2.3