File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,23 +160,12 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
160160 }
161161 }
162162 } else {
163- // it's of the form ./path
164- file = new File ( parentDir , moduleName ) ;
165- if ( file . exists ( ) ) {
163+ if ( ( file = new File ( parentDir , moduleName ) ) . exists ( ) ) {
166164 return fileExists ( file ) ;
167- } 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-
165+ } else if ( ( file = new File ( parentDir , moduleName + ".js" ) ) . exists ( ) ) { // try .js extension
166+ return file ;
167+ } else if ( ( file = new File ( parentDir , moduleName + ".json" ) ) . exists ( ) ) { // try .json extension
168+ return file ;
180169 }
181170 }
182171 return null ;
@@ -250,6 +239,9 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
250239 }
251240 buffered . close ( ) ; // close the stream so there's no file locks
252241
242+ if ( canonizedFilename . toLowerCase ( ) . substring ( canonizedFilename . length - 5 ) === ".json" ) // patch code when it is json
243+ code = "module.exports = (" + code + ");" ;
244+
253245 moduleInfo = {
254246 loaded : false ,
255247 id : canonizedFilename ,
You can’t perform that action at this time.
0 commit comments