From 5e210a67fa8737a7bfb6c63d76d649d9fb5238c9 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 12 Jul 2018 10:23:24 -0400 Subject: [PATCH] fix duplicate dependencies and warn correctly for length --- lib/contracts/contract_deployer.js | 6 +++--- lib/contracts/contracts.js | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/contracts/contract_deployer.js b/lib/contracts/contract_deployer.js index 50140085b..51c661c75 100644 --- a/lib/contracts/contract_deployer.js +++ b/lib/contracts/contract_deployer.js @@ -178,12 +178,12 @@ class ContractDeployer { deployedAddress = deployedAddress.substr(2); } let linkReference = '__' + filename + ":" + contractObj.className; - if (contractCode.indexOf(linkReference) < 0) { - continue; - } if (linkReference.length > 40) { return next(new Error(__("{{linkReference}} is too long, try reducing the path of the contract ({{filename}}) and/or its name {{contractName}}", {linkReference: linkReference, filename: filename, contractName: contractObj.className}))); } + if (contractCode.indexOf(linkReference) < 0) { + continue; + } let toReplace = linkReference + "_".repeat(40 - linkReference.length); if (deployedAddress === undefined) { let libraryName = contractObj.className; diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index cff1b19e8..a11e4fd23 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -215,7 +215,7 @@ class ContractsManager { contract = self.contracts[className]; // look in code for dependencies - let libMatches = (contract.code.match(/\:(.*?)(?=_)/g) || []); + let libMatches = (contract.code.match(/:(.*?)(?=_)/g) || []); for (let match of libMatches) { self.contractDependencies[className] = self.contractDependencies[className] || []; self.contractDependencies[className].push(match.substr(1)); @@ -251,14 +251,24 @@ class ContractsManager { } // look in onDeploy for dependencies - if (contract.onDeploy === [] || contract.onDeploy === undefined) continue; - let regex = /\$\w+/g; - contract.onDeploy.map((cmd) => { - cmd.replace(regex, (match) => { - self.contractDependencies[className] = self.contractDependencies[className] || []; - self.contractDependencies[className].push(match.substr(1)); + if (contract.onDeploy !== [] && contract.onDeploy !== undefined) { + let regex = /\$\w+/g; + contract.onDeploy.map((cmd) => { + cmd.replace(regex, (match) => { + self.contractDependencies[className] = self.contractDependencies[className] || []; + self.contractDependencies[className].push(match.substr(1)); + }); }); - }); + } + + // Remove duplicates + if (self.contractDependencies[className]) { + const o = {}; + self.contractDependencies[className].forEach(function (e) { + o[e] = true; + }); + self.contractDependencies[className] = Object.keys(o); + } } callback(); },