Allow loading json using require()
This commit is contained in:
parent
4aa28c0af3
commit
7b309dba16
1 changed files with 9 additions and 12 deletions
|
@ -165,18 +165,12 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
|
||||||
if ( file.exists() ) {
|
if ( file.exists() ) {
|
||||||
return fileExists(file);
|
return fileExists(file);
|
||||||
} else {
|
} else {
|
||||||
// try appending a .js to the end
|
if ((file = new File(parentDir, moduleName)).exists()) {
|
||||||
pathWithJSExt = file.canonicalPath + '.js';
|
return fileExists(file);
|
||||||
file = new File( parentDir, pathWithJSExt );
|
} else if ((file = new File(parentDir, moduleName + ".js")).exists()) { // try .js extension
|
||||||
if (file.exists()) {
|
return file;
|
||||||
return file;
|
} else if ((file = new File(parentDir, moduleName + ".json")).exists()) { // try .json extension
|
||||||
} else {
|
return file;
|
||||||
file = new File(pathWithJSExt);
|
|
||||||
if ( file.exists() ) {
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -250,6 +244,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.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,
|
||||||
|
|
Reference in a new issue