aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2017-10-03 13:40:08 -0400
committereric <thul.eric@gmail.com>2017-10-03 13:41:52 -0400
commit94013ed76272114dd981919bfb56c932778d95a2 (patch)
tree3d0387a2bbc6cbbeb07ad6d7b38eaf40b9769c9c /src
parentaaf98ca8bccce1a8e2330184fb19aa4399f10f25 (diff)
downloadpurs-loader-94013ed76272114dd981919bfb56c932778d95a2.tar.gz
purs-loader-94013ed76272114dd981919bfb56c932778d95a2.tar.zst
purs-loader-94013ed76272114dd981919bfb56c932778d95a2.zip
Rebuild module map for new files
Resolves #100
Diffstat (limited to 'src')
-rw-r--r--src/to-javascript.js37
1 files 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) {
59 59
60 const result = `module.exports = require("${escaped}")["${name}"]`; 60 const result = `module.exports = require("${escaped}")["${name}"]`;
61 61
62 return result; 62 return Promise.resolve(result);
63} 63}
64 64
65// Replace require paths to output files generated by psc with paths 65// Replace require paths to output files generated by psc with paths
@@ -105,28 +105,33 @@ function makeJS(psModule, psModuleMap, js) {
105 105
106 const additionalImports = difference(imports, replacedImports); 106 const additionalImports = difference(imports, replacedImports);
107 107
108 if (additionalImports.length) { 108 if (!additionalImports.length) {
109 debugVerbose('additional imports for %s: %o', name, additionalImports); 109 return Promise.resolve(result);
110 } 110 }
111 else {
112 debug('rebuilding module map due to additional imports for %s: %o', name, additionalImports);
111 113
112 const additionalImportsResult = additionalImports.map(import_ => { 114 psModule.cache.psModuleMap = null;
113 const moduleValue = psModuleMap[import_];
114 115
115 if (!moduleValue) { 116 return updatePsModuleMap(psModule).then(updatedPsModuleMap => {
116 debug('module %s was not found in the map, skipping require', import_); 117 const additionalImportsResult = additionalImports.map(import_ => {
118 const moduleValue = updatedPsModuleMap[import_];
117 119
118 return null; 120 if (!moduleValue) {
119 } 121 debug('module %s was not found in the map, skipping require', import_);
120 else {
121 const escapedPath = jsStringEscape(moduleValue.src);
122 122
123 return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`; 123 return null;
124 } 124 }
125 }).filter(a => a !== null).join('\n'); 125 else {
126 const escapedPath = jsStringEscape(moduleValue.src);
126 127
127 const result_ = result + (additionalImports.length ? '\n' + additionalImportsResult : ''); 128 return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`;
129 }
130 }).filter(a => a !== null).join('\n');
128 131
129 return result_; 132 return result + '\n' + additionalImportsResult;
133 });
134 }
130} 135}
131 136
132module.exports = function toJavaScript(psModule) { 137module.exports = function toJavaScript(psModule) {