bundleModules.forEach(name => bundleArgs.push('--module', name))
- debug('bundle: %s %o', bundleCommand, bundleArgs);
+ debug('bundle: %s %O', bundleCommand, bundleArgs);
return (new Promise((resolve, reject) => {
debug('bundling PureScript...')
const stdout = [];
- debug('ide client %s %o %o', ideClientCommand, ideClientArgs, body);
+ debug('ide client %s %o %O', ideClientCommand, ideClientArgs, body);
return new Promise((resolve, reject) => {
const ideClient = spawn(ideClientCommand, ideClientArgs);
try {
const parsed = JSON.parse(response);
- debugVerbose('parsed JSON response: %o', parsed);
+ debugVerbose('parsed JSON response: %O', parsed);
return Promise.resolve(parsed);
}
const result = Array.isArray(parsed.result) ? parsed.result : [];
return Promise.map(result, (item, i) => {
- debugVerbose('formatting result %o', item);
+ debugVerbose('formatting result %O', item);
return formatIdeResult(item, options, i, result.length);
}).then(formatted => ({
return isModuleNotFound || isUnknownModule || isUnknownModuleImport;
})) {
- debug('failed to rebuild because the module is unknown')
+ debug('module %s was not rebuilt because the module is unknown', psModule.name);
return Promise.reject(new UnknownModuleError());
}
psModuleMap: cache.psModuleMap,
warnings: [],
errors: [],
- compilationStarted: cache.compilationStarted,
- compilationFinished: cache.compilationFinished,
+ compilationStarted: false,
+ compilationFinished: false,
installed: cache.installed,
srcOption: cache.srcOption
};
};
const rebuild = () =>
- ide.rebuild(psModule).catch(error => {
+ ide.rebuild(psModule)
+ .then(() =>
+ toJavaScript(psModule)
+ .then(psModule.load)
+ .catch(psModule.reject)
+ )
+ .catch(error => {
if (error instanceof ide.UnknownModuleError) {
+ // Store the modules that trigger a recompile due to an
+ // unknown module error. We need to wait until compilation is
+ // done before loading these files.
+
+ cache.deferred.push(psModule);
+
if (!cache.compilationStarted) {
cache.compilationStarted = true;
cache.psModuleMap = map;
})
)
- .then(() => ide.load(psModule))
- .then(() => psModule)
+ .then(() =>
+ Promise.map(cache.deferred, psModule =>
+ ide.load(psModule)
+ .then(() => toJavaScript(psModule))
+ .then(psModule.load)
+ )
+ )
+ .catch(error => {
+ cache.deferred[0].reject(error);
+
+ cache.deferred.slice(1).forEach(psModule => {
+ psModule.reject(new Error('purs-loader failed'));
+ })
+ })
;
}
else {
- return Promise.resolve(psModule);
+ // The compilation has started. We must wait until it is
+ // done in order to ensure the module map contains all of
+ // the unknown modules.
}
}
else {
debug('ide rebuild failed due to an unhandled error: %o', error);
- return Promise.reject(error);
+ psModule.reject(error);
}
})
;
- connect()
- .then(rebuild)
- .then(toJavaScript)
- .then(psModule.load)
- .catch(psModule.reject)
- ;
+ connect().then(rebuild);
}
else if (cache.compilationFinished) {
debugVerbose('compilation is already finished, loading module %s', psModule.name);
)
.then(() =>
Promise.map(cache.deferred, psModule =>
- toJavaScript(psModule).then(psModule.load)
+ toJavaScript(psModule)
+ .then(psModule.load)
)
)
.catch(error => {