From: eric thul Date: Sat, 25 Feb 2017 14:55:18 +0000 (-0500) Subject: Handle missing module and adding debugging X-Git-Tag: 2.4.0-beta.2~2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=4305f5b0053d6fd2887b364c5da0a1ca6c06fc54;p=github%2Ffretlink%2Fpurs-loader.git Handle missing module and adding debugging --- 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) { const serverArgs = dargs(Object.assign({ outputDirectory: options.output, - "_": options.src + '_': options.src }, options.pscIdeServerArgs)) debug('attempting to start psc-ide-server', serverArgs) const ideServer = cache.ideServer = spawn('psc-ide-server', serverArgs) + + ideServer.stdout.on('data', data => { + debug('psc-ide-server stdout: %s', data.toString()); + }); + ideServer.stderr.on('data', data => { - debug(data.toString()) - }) + debug('psc-ide-server stderr: %s', data.toString()); + }); + + ideServer.on('error', error => { + debug('psc-ide-server error: %o', error); + }); + + ideServer.on('close', (code, signal) => { + debug('psc-ide-server close: %s %s', code, signal); + }); return retryPromise((retry, number) => { return connect_().catch(error => { @@ -150,7 +163,7 @@ function rebuild(psModule) { debug('unknown module, attempting full recompile') return Psc.compile(psModule) .then(() => PsModuleMap.makeMap(options.src).then(map => { - debug('rebuilt module map'); + debug('rebuilt module map after unknown module forced a recompile'); cache.psModuleMap = map; })) .then(() => request({ command: 'load' })) @@ -172,6 +185,8 @@ function rebuild(psModule) { }) }) + debug('psc-ide-client stdin: %o', body); + ideClient.stdin.write(JSON.stringify(body)) ideClient.stdin.write('\n') }) 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) { if (!cache.compilationStarted) { return Psc.compile(psModule) .then(() => PsModuleMap.makeMap(options.src).then(map => { - debug('rebuilt module map'); + debug('rebuilt module map after compile'); cache.psModuleMap = map; })) .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) { const result = js .replace(requireRE, (m, p1) => { - const escapedPath = jsStringEscape(psModuleMap[p1].src); + const moduleValue = psModuleMap[p1]; - replacedImports.push(p1); + if (!moduleValue) { + debug('module %s was not found in the map, replacing require with null', p1); - return `require("${escapedPath}")`; + return 'null'; + } + else { + const escapedPath = jsStringEscape(moduleValue.src); + + replacedImports.push(p1); + + return `require("${escapedPath}")`; + } }) .replace(foreignRE, () => { const escapedPath = jsStringEscape(psModuleMap[name].ffi); @@ -87,13 +96,11 @@ function makeJS(psModule, psModuleMap, js) { }) ; - debug('imports %o', imports); - - debug('replaced imports %o', replacedImports); - const additionalImports = difference(imports, replacedImports); - debug('additional imports for %s: %o', name, additionalImports); + if (additionalImports.length) { + debug('additional imports for %s: %o', name, additionalImports); + } const additionalImportsResult = additionalImports.map(import_ => { const escapedPath = jsStringEscape(psModuleMap[import_].src);