File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed
Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -165,18 +165,12 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
165165 if ( file . exists ( ) ) {
166166 return fileExists ( file ) ;
167167 } else {
168- // try appending a .js to the end
169- pathWithJSExt = file . canonicalPath + '.js' ;
170- file = new File ( parentDir , pathWithJSExt ) ;
171- if ( file . exists ( ) ) {
172- return file ;
173- } else {
174- file = new File ( pathWithJSExt ) ;
175- if ( file . exists ( ) ) {
176- return file ;
177- }
178- }
179-
168+ if ( ( file = new File ( parentDir , moduleName ) ) . exists ( ) ) {
169+ return fileExists ( file ) ;
170+ } else if ( ( file = new File ( parentDir , moduleName + ".js" ) ) . exists ( ) ) { // try .js extension
171+ return file ;
172+ } else if ( ( file = new File ( parentDir , moduleName + ".json" ) ) . exists ( ) ) { // try .json extension
173+ return file ;
180174 }
181175 }
182176 return null ;
@@ -250,6 +244,9 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
250244 }
251245 buffered . close ( ) ; // close the stream so there's no file locks
252246
247+ if ( canonizedFilename . substring ( canonizedFilename . length - 5 ) === ".json" ) // patch code when it is json
248+ code = "module.exports = (" + code + ");" ;
249+
253250 moduleInfo = {
254251 loaded : false ,
255252 id : canonizedFilename ,
You can’t perform that action at this time.
0 commit comments