Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Hardhat CommonJS config, clean up platform ordering #468

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crytic_compile/crytic_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@


def get_platforms() -> List[Type[AbstractPlatform]]:
"""Return the available platforms classes
"""Return the available platforms classes in order of preference

Returns:
List[Type[AbstractPlatform]]: Available platforms
"""
platforms = [getattr(all_platforms, name) for name in dir(all_platforms)]
platforms = [d for d in platforms if inspect.isclass(d) and issubclass(d, AbstractPlatform)]
return sorted(platforms, key=lambda platform: platform.TYPE)
return sorted(platforms, key=lambda platform: (platform.TYPE.priority(), platform.TYPE))


def is_supported(target: str) -> bool:
Expand Down
10 changes: 4 additions & 6 deletions crytic_compile/platform/hardhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,10 @@ def is_supported(target: str, **kwargs: str) -> bool:
if hardhat_ignore:
return False

# If there is both foundry and hardhat, foundry takes priority
if os.path.isfile(os.path.join(target, "foundry.toml")):
return False

return os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile(
os.path.join(target, "hardhat.config.ts")
return (
os.path.isfile(os.path.join(target, "hardhat.config.js"))
or os.path.isfile(os.path.join(target, "hardhat.config.ts"))
or os.path.isfile(os.path.join(target, "hardhat.config.cjs"))
)

def is_dependency(self, path: str) -> bool:
Expand Down
6 changes: 0 additions & 6 deletions crytic_compile/platform/truffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,6 @@ def is_supported(target: str, **kwargs: str) -> bool:
if truffle_ignore:
return False

# Avoid conflicts with hardhat
if os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile(
os.path.join(target, "hardhat.config.ts")
):
return False

return os.path.isfile(os.path.join(target, "truffle.js")) or os.path.isfile(
os.path.join(target, "truffle-config.js")
)
Expand Down
21 changes: 21 additions & 0 deletions crytic_compile/platform/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,24 @@ def __str__(self) -> str: # pylint: disable=too-many-branches
if self == Type.FOUNDRY:
return "Foundry"
raise ValueError

def priority(self) -> int:
"""Return the priority for a certain platform.

A lower priority means the platform is more preferable. This is used to
consistently select a platform when two or more are available.

Returns:
int: priority number
"""

if self == Type.FOUNDRY:
return 100

if self == Type.HARDHAT:
return 200

if self in [Type.TRUFFLE, Type.WAFFLE]:
return 300

return 1000
6 changes: 0 additions & 6 deletions crytic_compile/platform/waffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@ def is_supported(target: str, **kwargs: str) -> bool:
if waffle_ignore:
return False

# Avoid conflicts with hardhat
if os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile(
os.path.join(target, "hardhat.config.ts")
):
return False

if os.path.isfile(os.path.join(target, "waffle.json")) or os.path.isfile(
os.path.join(target, ".waffle.json")
):
Expand Down