aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2017-02-25 09:55:18 -0500
committereric thul <thul.eric@gmail.com>2017-02-25 09:55:18 -0500
commit4305f5b0053d6fd2887b364c5da0a1ca6c06fc54 (patch)
tree541cfb21319f8cb6a751132ff0fdb09addfc000f /src
parent03f52cb367cc8f1e57c515e4ac61c49cb72773eb (diff)
downloadpurs-loader-4305f5b0053d6fd2887b364c5da0a1ca6c06fc54.tar.gz
purs-loader-4305f5b0053d6fd2887b364c5da0a1ca6c06fc54.tar.zst
purs-loader-4305f5b0053d6fd2887b364c5da0a1ca6c06fc54.zip
Handle missing module and adding debugging
Diffstat (limited to 'src')
-rw-r--r--src/PscIde.js23
-rw-r--r--src/index.js2
-rw-r--r--src/to-javascript.js23
3 files changed, 35 insertions, 13 deletions
diff --git a/src/PscIde.js b/src/PscIde.js
index 8a0e823..b164dc2 100644
--- a/src/PscIde.js
+++ b/src/PscIde.js
@@ -63,15 +63,28 @@ function connect(psModule) {
63 63
64 const serverArgs = dargs(Object.assign({ 64 const serverArgs = dargs(Object.assign({
65 outputDirectory: options.output, 65 outputDirectory: options.output,
66 "_": options.src 66 '_': options.src
67 }, options.pscIdeServerArgs)) 67 }, options.pscIdeServerArgs))
68 68
69 debug('attempting to start psc-ide-server', serverArgs) 69 debug('attempting to start psc-ide-server', serverArgs)
70 70
71 const ideServer = cache.ideServer = spawn('psc-ide-server', serverArgs) 71 const ideServer = cache.ideServer = spawn('psc-ide-server', serverArgs)
72
73 ideServer.stdout.on('data', data => {
74 debug('psc-ide-server stdout: %s', data.toString());
75 });
76
72 ideServer.stderr.on('data', data => { 77 ideServer.stderr.on('data', data => {
73 debug(data.toString()) 78 debug('psc-ide-server stderr: %s', data.toString());
74 }) 79 });
80
81 ideServer.on('error', error => {
82 debug('psc-ide-server error: %o', error);
83 });
84
85 ideServer.on('close', (code, signal) => {
86 debug('psc-ide-server close: %s %s', code, signal);
87 });
75 88
76 return retryPromise((retry, number) => { 89 return retryPromise((retry, number) => {
77 return connect_().catch(error => { 90 return connect_().catch(error => {
@@ -150,7 +163,7 @@ function rebuild(psModule) {
150 debug('unknown module, attempting full recompile') 163 debug('unknown module, attempting full recompile')
151 return Psc.compile(psModule) 164 return Psc.compile(psModule)
152 .then(() => PsModuleMap.makeMap(options.src).then(map => { 165 .then(() => PsModuleMap.makeMap(options.src).then(map => {
153 debug('rebuilt module map'); 166 debug('rebuilt module map after unknown module forced a recompile');
154 cache.psModuleMap = map; 167 cache.psModuleMap = map;
155 })) 168 }))
156 .then(() => request({ command: 'load' })) 169 .then(() => request({ command: 'load' }))
@@ -172,6 +185,8 @@ function rebuild(psModule) {
172 }) 185 })
173 }) 186 })
174 187
188 debug('psc-ide-client stdin: %o', body);
189
175 ideClient.stdin.write(JSON.stringify(body)) 190 ideClient.stdin.write(JSON.stringify(body))
176 ideClient.stdin.write('\n') 191 ideClient.stdin.write('\n')
177 }) 192 })
diff --git a/src/index.js b/src/index.js
index f4a6dff..6fb2fce 100644
--- a/src/index.js
+++ b/src/index.js
@@ -149,7 +149,7 @@ module.exports = function purescriptLoader(source, map) {
149 if (!cache.compilationStarted) { 149 if (!cache.compilationStarted) {
150 return Psc.compile(psModule) 150 return Psc.compile(psModule)
151 .then(() => PsModuleMap.makeMap(options.src).then(map => { 151 .then(() => PsModuleMap.makeMap(options.src).then(map => {
152 debug('rebuilt module map'); 152 debug('rebuilt module map after compile');
153 cache.psModuleMap = map; 153 cache.psModuleMap = map;
154 })) 154 }))
155 .then(() => Promise.map(cache.deferred, psModule => { 155 .then(() => Promise.map(cache.deferred, psModule => {
diff --git a/src/to-javascript.js b/src/to-javascript.js
index 237ef1e..0acf180 100644
--- a/src/to-javascript.js
+++ b/src/to-javascript.js
@@ -74,11 +74,20 @@ function makeJS(psModule, psModuleMap, js) {
74 74
75 const result = js 75 const result = js
76 .replace(requireRE, (m, p1) => { 76 .replace(requireRE, (m, p1) => {
77 const escapedPath = jsStringEscape(psModuleMap[p1].src); 77 const moduleValue = psModuleMap[p1];
78 78
79 replacedImports.push(p1); 79 if (!moduleValue) {
80 debug('module %s was not found in the map, replacing require with null', p1);
80 81
81 return `require("${escapedPath}")`; 82 return 'null';
83 }
84 else {
85 const escapedPath = jsStringEscape(moduleValue.src);
86
87 replacedImports.push(p1);
88
89 return `require("${escapedPath}")`;
90 }
82 }) 91 })
83 .replace(foreignRE, () => { 92 .replace(foreignRE, () => {
84 const escapedPath = jsStringEscape(psModuleMap[name].ffi); 93 const escapedPath = jsStringEscape(psModuleMap[name].ffi);
@@ -87,13 +96,11 @@ function makeJS(psModule, psModuleMap, js) {
87 }) 96 })
88 ; 97 ;
89 98
90 debug('imports %o', imports);
91
92 debug('replaced imports %o', replacedImports);
93
94 const additionalImports = difference(imports, replacedImports); 99 const additionalImports = difference(imports, replacedImports);
95 100
96 debug('additional imports for %s: %o', name, additionalImports); 101 if (additionalImports.length) {
102 debug('additional imports for %s: %o', name, additionalImports);
103 }
97 104
98 const additionalImportsResult = additionalImports.map(import_ => { 105 const additionalImportsResult = additionalImports.map(import_ => {
99 const escapedPath = jsStringEscape(psModuleMap[import_].src); 106 const escapedPath = jsStringEscape(psModuleMap[import_].src);