diff --git a/.changeset/kind-cherries-poke.md b/.changeset/kind-cherries-poke.md new file mode 100644 index 0000000000..e2faa90190 --- /dev/null +++ b/.changeset/kind-cherries-poke.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Display file name on duplicate contract names diff --git a/packages/cli/src/cli/index.ts b/packages/cli/src/cli/index.ts index 6046361dc7..c5ebc0ae83 100644 --- a/packages/cli/src/cli/index.ts +++ b/packages/cli/src/cli/index.ts @@ -101,6 +101,14 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$ "-n, --name [name]", "Name of the pre-built or released contract (such as nft-drop)", ) + .option( + "-f, --file [name]", + "Filter for contract files that contain this file name", + ) + .option( + "-cn, --contract-name [name]", + "Filter for contracts that contain this contract name", + ) .option( "-cv, --contract-version [version]", "Version of the released contract", @@ -120,6 +128,14 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$ "Release your protocol so other devs can deploy them and unlock SDKs, Dashboards and Analytics", ) .option("-p, --path ", "path to project", ".") + .option( + "-f, --file [name]", + "Filter for contract files that contain the file name", + ) + .option( + "-cn, --contract-name [name]", + "Filter for contracts that contain this contract name", + ) .option("--dry-run", "dry run (skip actually publishing)") .option("-d, --debug", "show debug logs") .option("--ci", "Continuous Integration mode") diff --git a/packages/cli/src/common/processor.ts b/packages/cli/src/common/processor.ts index 8ba1d638f7..0d30baf379 100644 --- a/packages/cli/src/common/processor.ts +++ b/packages/cli/src/common/processor.ts @@ -76,7 +76,7 @@ export async function processProject( } } - let compiledResult; + let compiledResult: { contracts: ContractPayload[] }; const compileLoader = spinner("Compiling project..."); try { compiledResult = await build(projectPath, projectType); @@ -106,10 +106,47 @@ export async function processProject( if (options.ci) { selectedContracts = compiledResult.contracts; } else { - const choices = compiledResult.contracts.map((c) => ({ - name: c.name, - value: c, - })); + const filtered = compiledResult.contracts + .filter((c) => { + if (typeof options.file === "string" && options.file.length > 0) { + return c.fileName.includes(options.file); + } + + return true; + }) + .filter((c) => { + if ( + typeof options.contractName === "string" && + options.contractName.length > 0 + ) { + return c.name.includes(options.contractName); + } + + return true; + }); + + if (filtered.length === 0) { + logger.error(`No contracts found matching the specified filters.`); + process.exit(1); + } + + const choices = filtered.map((c) => { + if ( + compiledResult.contracts.filter( + (other: ContractPayload) => other.name === c.name, + ).length > 1 + ) { + return { + name: `${c.name} - ${chalk.gray(c.fileName)}`, + value: c, + }; + } + + return { + name: c.name, + value: c, + }; + }); const prompt = createContractsPrompt( choices, `Choose which contract(s) to ${command}`, diff --git a/packages/cli/src/core/builder/brownie.ts b/packages/cli/src/core/builder/brownie.ts index bbfc66987b..348a446e52 100644 --- a/packages/cli/src/core/builder/brownie.ts +++ b/packages/cli/src/core/builder/brownie.ts @@ -55,6 +55,7 @@ export class BrownieBuilder extends BaseBuilder { metadata: {}, bytecode, sources: [], // TODO + fileName: "", // TODO name: contractName, }); break; diff --git a/packages/cli/src/core/builder/foundry.ts b/packages/cli/src/core/builder/foundry.ts index c8a2462ab7..ef81bdf4b2 100644 --- a/packages/cli/src/core/builder/foundry.ts +++ b/packages/cli/src/core/builder/foundry.ts @@ -88,6 +88,11 @@ export class FoundryBuilder extends BaseBuilder { }) .filter((path) => path !== undefined) as string[]; + const fileNames = Object.keys( + parsedMetadata?.settings?.compilationTarget || {}, + ); + const fileName = fileNames.length > 0 ? fileNames[0] : ""; + if ( this.shouldProcessContract( contractInfo.abi, @@ -99,6 +104,7 @@ export class FoundryBuilder extends BaseBuilder { name: contractName, metadata, bytecode, + fileName, sources, }); } diff --git a/packages/cli/src/core/builder/hardhat.ts b/packages/cli/src/core/builder/hardhat.ts index 43658a2ce4..1a1cd4eeed 100644 --- a/packages/cli/src/core/builder/hardhat.ts +++ b/packages/cli/src/core/builder/hardhat.ts @@ -123,11 +123,17 @@ export class HardhatBuilder extends BaseBuilder { }) .filter((path) => path !== undefined) as string[]; + const fileNames = Object.keys( + meta?.settings?.compilationTarget || {}, + ); + const fileName = fileNames.length > 0 ? fileNames[0] : ""; + if (this.shouldProcessContract(abi, deployedBytecode, contractName)) { contracts.push({ metadata, bytecode, name: contractName, + fileName, sources, }); } diff --git a/packages/cli/src/core/builder/solc.ts b/packages/cli/src/core/builder/solc.ts index 333c54a6bd..2258e5d1aa 100644 --- a/packages/cli/src/core/builder/solc.ts +++ b/packages/cli/src/core/builder/solc.ts @@ -140,11 +140,17 @@ export class SolcBuilder extends BaseBuilder { }) .filter((path) => path !== undefined) as string[]; + const fileNames = Object.keys( + parsedMetadata?.settings?.compilationTarget || {}, + ); + const fileName = fileNames.length > 0 ? fileNames[0] : ""; + if (this.shouldProcessContract(abi, deployedBytecode, contractName)) { contracts.push({ metadata, bytecode, name: contractName, + fileName, sources: _sources, }); } diff --git a/packages/cli/src/core/builder/truffle.ts b/packages/cli/src/core/builder/truffle.ts index ba6ac1db09..d1ca10607f 100644 --- a/packages/cli/src/core/builder/truffle.ts +++ b/packages/cli/src/core/builder/truffle.ts @@ -72,11 +72,18 @@ export class TruffleBuilder extends BaseBuilder { return undefined; }) .filter((path) => path !== undefined) as string[]; + + const fileNames = Object.keys( + parsedMetadata?.settings?.compilationTarget || {}, + ); + const fileName = fileNames.length > 0 ? fileNames[0] : ""; + if (this.shouldProcessContract(abi, deployedBytecode, contractName)) { contracts.push({ metadata, bytecode, name: contractName, + fileName, sources, }); } diff --git a/packages/cli/src/core/interfaces/ContractPayload.ts b/packages/cli/src/core/interfaces/ContractPayload.ts index 64dc6375d7..ea69a0f85d 100644 --- a/packages/cli/src/core/interfaces/ContractPayload.ts +++ b/packages/cli/src/core/interfaces/ContractPayload.ts @@ -17,6 +17,11 @@ export interface ContractPayload { */ metadata: any; + /** + * The file name of the original compiled file + */ + fileName: string; + /** * The source file paths */