Skip to content

Commit d920853

Browse files
author
bohendo
committed
implement correct fix for node_modules resolution
1 parent ed9a6f8 commit d920853

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

crytic_compile/utils/naming.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,17 @@ def convert_filename(
109109
if not filename.exists():
110110
# how node.js loads dependencies from node_modules:
111111
# https://nodejs.org/api/modules.html#loading-from-node_modules-folders
112-
if cwd.joinpath(Path("node_modules"), filename).exists():
113-
filename = cwd.joinpath("node_modules", filename)
114-
elif cwd.joinpath(Path("../node_modules"), filename).exists():
115-
filename = cwd.joinpath("contracts", filename)
116-
elif cwd.joinpath(Path("../../node_modules"), filename).exists():
117-
filename = cwd.joinpath("contracts", filename)
118-
elif cwd.joinpath(Path("contracts"), filename).exists():
112+
for folder in cwd.parents:
113+
if folder.joinpath(Path("node_modules"), filename).exists():
114+
filename = folder.joinpath("node_modules", filename)
115+
break
116+
if not filename.exists():
117+
if cwd.joinpath(Path("contracts"), filename).exists():
119118
filename = cwd.joinpath("contracts", filename)
120119
elif working_dir.joinpath(filename).exists():
121120
filename = working_dir.joinpath(filename)
122121
else:
123-
test = cwd.joinpath(Path("../node_modules"), filename);
124-
raise InvalidCompilation(f"Unknown file: {filename} {test}")
122+
raise InvalidCompilation(f"Unknown file: {filename}")
125123
elif not filename.is_absolute():
126124
filename = cwd.joinpath(filename)
127125

0 commit comments

Comments
 (0)