Merging pull request #283 Merge branch 'MrVoltz-MrVoltz-requireJson'

This commit is contained in:
walterhiggins 2016-01-02 11:23:02 +00:00
commit eca25f7628

View file

@ -160,23 +160,12 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
} }
} }
} else { } else {
// it's of the form ./path if ((file = new File(parentDir, moduleName)).exists()) {
file = new File(parentDir, moduleName);
if ( file.exists() ) {
return fileExists(file); return fileExists(file);
} else { } else if ((file = new File(parentDir, moduleName + ".js")).exists()) { // try .js extension
// try appending a .js to the end return file;
pathWithJSExt = file.canonicalPath + '.js'; } else if ((file = new File(parentDir, moduleName + ".json")).exists()) { // try .json extension
file = new File( parentDir, pathWithJSExt ); return file;
if (file.exists()) {
return file;
} else {
file = new File(pathWithJSExt);
if ( file.exists() ) {
return file;
}
}
} }
} }
return null; return null;
@ -250,6 +239,9 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
} }
buffered.close(); // close the stream so there's no file locks buffered.close(); // close the stream so there's no file locks
if(canonizedFilename.toLowerCase().substring(canonizedFilename.length - 5) === ".json") // patch code when it is json
code = "module.exports = (" + code + ");";
moduleInfo = { moduleInfo = {
loaded: false, loaded: false,
id: canonizedFilename, id: canonizedFilename,