diff --git a/src/lib/modules/solidity/index.js b/src/lib/modules/solidity/index.js index c526c84e2..eed2c7a84 100644 --- a/src/lib/modules/solidity/index.js +++ b/src/lib/modules/solidity/index.js @@ -112,7 +112,6 @@ class Solidity { } } }; - self._compile(jsonObj, returnAllErrors, callback); }, function createCompiledObject(output, callback) { @@ -164,7 +163,7 @@ class Solidity { let self = this; let input = {}; let originalFilepath = {}; - + async.waterfall([ function prepareInput(callback) { async.each(contractFiles, @@ -180,7 +179,7 @@ class Solidity { remapImports.prepareForCompilation(file, options.isCoverage) .then(fileContent => { - input[filename] = {content: fileContent.replace(/\r\n/g, '\n')}; + input[file.path] = {content: fileContent.replace(/\r\n/g, '\n')}; fileCb(); }).catch((_e) => { self.logger.error(__('Error while loading the content of ') + filename); diff --git a/src/lib/utils/solidity/remapImports.ts b/src/lib/utils/solidity/remapImports.ts index 8faaa4d3d..c64f9d1b6 100644 --- a/src/lib/utils/solidity/remapImports.ts +++ b/src/lib/utils/solidity/remapImports.ts @@ -84,11 +84,16 @@ const buildNewFile = (file: File, importPath: string) => { return new File({ path: to, type: Types.dappFile }); }; -const rescursivelyFindRemapImports = async (file: File) => { +const rescursivelyFindRemapImports = async (file: File, filesProcessed: string[] = []) => { let remapImports: RemapImport[] = []; const content = await file.content; const imports = getImports(content); + if (filesProcessed.includes(file.path)) { + return []; + } + filesProcessed.push(file.path); + // if no imports, break recursion if (!imports.length) { return []; @@ -99,7 +104,7 @@ const rescursivelyFindRemapImports = async (file: File) => { file.importRemappings.push({prefix: importPath, target: newFile.path}); remapImports.push({path: file.path, searchValue: importPath, replaceValue: newFile.path}); remapImports = remapImports.concat( - await rescursivelyFindRemapImports(newFile), + await rescursivelyFindRemapImports(newFile, filesProcessed), ); } @@ -123,7 +128,7 @@ const replaceImports = (remapImports: RemapImport[]) => { Object.keys(byPath).forEach((p) => { let source = fs.readFileSync(p, "utf-8"); byPath[p].forEach(({searchValue, replaceValue}) => { - source = source.replace(`import "${searchValue}";`, `import "${replaceValue}";`); + source = source.replace(`${searchValue}`, `${replaceValue}`); }); fs.writeFileSync(p, source); });