Skip to content

Commit eca25f7

Browse files
committed
Merging pull request #283 Merge branch 'MrVoltz-MrVoltz-requireJson'
2 parents badf8b5 + a0b46b0 commit eca25f7

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

src/main/js/lib/require.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)