/**
     * Implements the Nodejs require.resolve algorithm, see
     * https://nodejs.org/api/modules.html#modules_all_together
     *
     * <p>require(X) from module at path Y 1. If X is a core module, a. return the core module b. STOP
     * 2. If X begins with './' or '/' or '../' a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) 3.
     * LOAD_NODE_MODULES(X, dirname(Y)) 4. THROW "not found"
     *
     * @param dir Y in the pseudo algorithm
     * @param target X in the pseudo algorithm
     */
public static SourceFileModule resolve(File rootDir, File dir, String target) throws IOException, JSONException {
        // NOTE(Zhen): Ignore CoreModule for now to enable a more flexible semantic modeling
        // if (NodejsRequiredCoreModule.isCoreModule(target)) return NodejsRequiredCoreModule.make(target);
        if (target.startsWith("./") || target.startsWith("/") || target.startsWith("../")) {
            SourceFileModule module = loadAsFile(rootDir, new File(dir, target));
            if (module != null) return module;
            module = loadAsDirectory(rootDir, new File(dir, target));
            if (module != null) return module;
        }
        // NOTE(Zhen): it is not very useful to throw exception...
        return loadNodeModules(rootDir, dir, target);
    }
public static SourceFileModule resolve(File rootDir, File dir, String target) throws IOException, JSONException {
// NOTE(Zhen): Ignore CoreModule for now to enable a more flexible semantic modeling
// if (NodejsRequiredCoreModule.isCoreModule(target)) return NodejsRequiredCoreModule.make(target);
if (target.startsWith("./") || target.startsWith("/") || target.startsWith("../")) {
SourceFileModule module = loadAsFile(rootDir, new File(dir, target));
if (module != null) return module;
module = loadAsDirectory(rootDir, new File(dir, target));
if (module != null) return module;
}
// NOTE(Zhen): it is not very useful to throw exception...
return loadNodeModules(rootDir, dir, target);
}
public static SourceFileModule resolve(File rootDir, File dir, String target) throws IOException, JSONException {
// NOTE(Zhen): Ignore CoreModule for now to enable a more flexible semantic modeling
// if (NodejsRequiredCoreModule.isCoreModule(target)) return NodejsRequiredCoreModule.make(target);
if (target.startsWith("./") || target.startsWith("/") || target.startsWith("../")) {
SourceFileModule module = loadAsFile(rootDir, new File(dir, target));
if (module != null) return module;
module = loadAsDirectory(rootDir, new File(dir, target));
if (module != null) return module;
}
// NOTE(Zhen): it is not very useful to throw exception...
return loadNodeModules(rootDir, dir, target);
}
public static SourceFileModule resolve(File rootDir, File dir, String target) throws IOException, JSONException {
// NOTE(Zhen): Ignore CoreModule for now to enable a more flexible semantic modeling
// if (NodejsRequiredCoreModule.isCoreModule(target)) return NodejsRequiredCoreModule.make(target);
if (target.startsWith("./") || target.startsWith("/") || target.startsWith("../")) {
SourceFileModule module = loadAsFile(rootDir, new File(dir, target));
if (module != null) return module;
module = loadAsDirectory(rootDir, new File(dir, target));
if (module != null) return module;
}
// NOTE(Zhen): it is not very useful to throw exception...
return loadNodeModules(rootDir, dir, target);
}