Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/main/javascript/jvm-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ module = (typeof module == 'undefined') ? {} : module;
} catch(ex) {
throw new ModuleError("Cannot load JSON file", "PARSE_ERROR", ex);
}
}
return resolveAsFile('index.js', base);
}
return resolveCoreModule([id, 'index.js'].join('/'), root) ||
resolveAsFile('index.js', base);
}

function resolveAsFile(id, root, ext) {
Expand All @@ -232,13 +233,24 @@ module = (typeof module == 'undefined') ? {} : module;
if (file.exists()) {
return file.getCanonicalPath();
}
var result = resolveCoreModule(id, root);
if ( result ) {
return result;
}
}

function resolveCoreModule(id, root) {
var name = normalizeName(id);
var classloader = java.lang.Thread.currentThread().getContextClassLoader();
if (classloader.getResource(name))
return { path: name, core: true };
if(name.indexOf('./',0)==0)
name = name.substring(2);
if (classloader.getResource(name))
return { path: name, core: true };
var path = [root, name].join('/');
if (classloader.getResource(path))
return { path: path, core: true };
}

function normalizeName(fileName, ext) {
Expand Down