@@ -109,19 +109,17 @@ def convert_filename(
109
109
if not filename .exists ():
110
110
# how node.js loads dependencies from node_modules:
111
111
# 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 ():
119
118
filename = cwd .joinpath ("contracts" , filename )
120
119
elif working_dir .joinpath (filename ).exists ():
121
120
filename = working_dir .joinpath (filename )
122
121
else :
123
- test = cwd .joinpath (Path ("../node_modules" ), filename );
124
- raise InvalidCompilation (f"Unknown file: { filename } { test } " )
122
+ raise InvalidCompilation (f"Unknown file: { filename } " )
125
123
elif not filename .is_absolute ():
126
124
filename = cwd .joinpath (filename )
127
125
0 commit comments