in src/main/java/org/apache/sling/scripting/esx/Module.java [350:399]
public ModuleScript loadAsFile(String module, String path,
Resource currentResource, String loader) throws ScriptException {
int type = ModuleScript.JS_FILE;
// this is need to be refactored, it is this way because I followed the
// node.js extension handling at first but switched over to requirejs
// loader notation
Resource file = currentResource.getResourceResolver().getResource(path);
// require.extensions is deprecated, however to implement this might
// be a good way to handle .resource loading or to implemend loader
// like in requirejs e.g. similar to https://github.com/requirejs/text
// "text!some/module.html"
// or require("resource!/content/homepage/jcr:content")
if (LOADER_RESOURCE.equals(loader) && file != null) {
return new ModuleScript(ModuleScript.RESOURCE_FILE, file);
}
if (LOADER_TEXT.equals(loader) && file != null) {
return new ModuleScript(ModuleScript.TEXT_FILE, file);
}
//special handling for json file require
if (path.endsWith(".json") && file != null) {
return new ModuleScript(ModuleScript.JSON_FILE, file);
}
if (path.endsWith(".bin") && file != null) {
log.warn(".bin loder are currently not supported (file requested: " + path);
}
try {
if (file == null || !file.adaptTo(Node.class).isNodeType(NodeType.NT_FILE)) {
file = currentResource.getResourceResolver().getResource(path + ".js");
if (file == null) {
file = currentResource.getResourceResolver().getResource(path + ".json");
if (file == null) {
return null;
}
type = ModuleScript.JSON_FILE;
} else {
type = ModuleScript.JS_FILE;
}
}
} catch (RepositoryException ex) {
log.error(module + "", ex);
}
return createModuleScript(file, type);
}