const result = `module.exports = require("${escaped}")["${name}"]`;
- return result;
+ return Promise.resolve(result);
}
// Replace require paths to output files generated by psc with paths
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) {