Skip to content

Commit fda579d

Browse files
authored
Merge pull request #468 from crytic/dev-hardhat-cjs
Add support for Hardhat CommonJS config, clean up platform ordering
2 parents 9cfa803 + e337b30 commit fda579d

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

crytic_compile/crytic_compile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636

3737

3838
def get_platforms() -> List[Type[AbstractPlatform]]:
39-
"""Return the available platforms classes
39+
"""Return the available platforms classes in order of preference
4040
4141
Returns:
4242
List[Type[AbstractPlatform]]: Available platforms
4343
"""
4444
platforms = [getattr(all_platforms, name) for name in dir(all_platforms)]
4545
platforms = [d for d in platforms if inspect.isclass(d) and issubclass(d, AbstractPlatform)]
46-
return sorted(platforms, key=lambda platform: platform.TYPE)
46+
return sorted(platforms, key=lambda platform: (platform.TYPE.priority(), platform.TYPE))
4747

4848

4949
def is_supported(target: str) -> bool:

crytic_compile/platform/hardhat.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,10 @@ def is_supported(target: str, **kwargs: str) -> bool:
212212
if hardhat_ignore:
213213
return False
214214

215-
# If there is both foundry and hardhat, foundry takes priority
216-
if os.path.isfile(os.path.join(target, "foundry.toml")):
217-
return False
218-
219-
return os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile(
220-
os.path.join(target, "hardhat.config.ts")
215+
return (
216+
os.path.isfile(os.path.join(target, "hardhat.config.js"))
217+
or os.path.isfile(os.path.join(target, "hardhat.config.ts"))
218+
or os.path.isfile(os.path.join(target, "hardhat.config.cjs"))
221219
)
222220

223221
def is_dependency(self, path: str) -> bool:

crytic_compile/platform/truffle.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,6 @@ def is_supported(target: str, **kwargs: str) -> bool:
305305
if truffle_ignore:
306306
return False
307307

308-
# Avoid conflicts with hardhat
309-
if os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile(
310-
os.path.join(target, "hardhat.config.ts")
311-
):
312-
return False
313-
314308
return os.path.isfile(os.path.join(target, "truffle.js")) or os.path.isfile(
315309
os.path.join(target, "truffle-config.js")
316310
)

crytic_compile/platform/types.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,24 @@ def __str__(self) -> str: # pylint: disable=too-many-branches
6666
if self == Type.FOUNDRY:
6767
return "Foundry"
6868
raise ValueError
69+
70+
def priority(self) -> int:
71+
"""Return the priority for a certain platform.
72+
73+
A lower priority means the platform is more preferable. This is used to
74+
consistently select a platform when two or more are available.
75+
76+
Returns:
77+
int: priority number
78+
"""
79+
80+
if self == Type.FOUNDRY:
81+
return 100
82+
83+
if self == Type.HARDHAT:
84+
return 200
85+
86+
if self in [Type.TRUFFLE, Type.WAFFLE]:
87+
return 300
88+
89+
return 1000

crytic_compile/platform/waffle.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,6 @@ def is_supported(target: str, **kwargs: str) -> bool:
245245
if waffle_ignore:
246246
return False
247247

248-
# Avoid conflicts with hardhat
249-
if os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile(
250-
os.path.join(target, "hardhat.config.ts")
251-
):
252-
return False
253-
254248
if os.path.isfile(os.path.join(target, "waffle.json")) or os.path.isfile(
255249
os.path.join(target, ".waffle.json")
256250
):

0 commit comments

Comments
 (0)