Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit 512680b

Browse files
committed
Support contracts with the same name #1203
1 parent 4577820 commit 512680b

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"ethereumjs-util": "^6.1.0",
7171
"find-up": "^3.0.0",
7272
"fs-extra": "^7.0.1",
73+
"fs-readdir-recursive": "^1.1.0",
7374
"inquirer": "^6.4.1",
7475
"is-url": "^1.2.4",
7576
"lockfile": "^1.0.4",

packages/cli/src/models/compiler/solidity/SolidityProjectCompiler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import pick from 'lodash.pick';
55
import omitBy from 'lodash.omitby';
66
import isUndefined from 'lodash.isundefined';
77
import { readJsonSync, ensureDirSync, readJSON, writeJson, unlink } from 'fs-extra';
8-
import { statSync, existsSync, readdirSync, lstatSync } from 'fs';
8+
import { statSync, existsSync, lstatSync } from 'fs';
9+
import readdirSync from 'fs-readdir-recursive';
910
import { Loggy, Contracts } from '@openzeppelin/upgrades';
1011
import {
1112
RawContract,
@@ -188,7 +189,9 @@ class SolidityProjectCompiler {
188189
await Promise.all(
189190
this.compilerOutput.map(async data => {
190191
const name = data.contractName;
191-
const buildFileName = `${this.outputDir}/${name}.json`;
192+
const buildDirName = `${this.outputDir}/${data.sourcePath.replace(/^contracts\/(.*)$/, `$1`)}`;
193+
ensureDirSync(buildDirName);
194+
const buildFileName = `${buildDirName}/${name}.json`;
192195
if (networksInfo[name]) Object.assign(data, { networks: networksInfo[name] });
193196
await writeJson(buildFileName, data, { spaces: 2 });
194197
}),

packages/cli/src/models/local/ContractManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Dependency from '../dependency/Dependency';
33
import ProjectFile from '../files/ProjectFile';
44
import ConfigManager from '../config/ConfigManager';
55
import path from 'path';
6+
import readdirSync from 'fs-readdir-recursive';
67

78
export default class ContractManager {
89
public projectFile: ProjectFile;
@@ -35,7 +36,7 @@ export default class ContractManager {
3536
const buildDir = ConfigManager.getBuildDir();
3637
const contractsDir = Contracts.getLocalContractsDir();
3738
if (FileSystem.exists(buildDir)) {
38-
return FileSystem.readDir(buildDir)
39+
return readdirSync(buildDir)
3940
.filter(name => name.match(/\.json$/))
4041
.map(name => FileSystem.parseJsonIfExists(`${buildDir}/${name}`))
4142
.filter(contract => {
@@ -45,7 +46,7 @@ export default class ContractManager {
4546
!this.isAbstractContract(contract)
4647
);
4748
})
48-
.map(({ contractName }) => contractName);
49+
.map(({ sourcePath, contractName }) => `${sourcePath.replace(/contracts\/(.*)/, `$1`)}/${contractName}`);
4950
} else return [];
5051
}
5152

0 commit comments

Comments
 (0)