Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
use a more Node.js-like approach to finding node_modules directories
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Jan 18, 2015
1 parent 13ff969 commit 41d827e
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions src/org/jsdoc/JsDocModuleProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private URI getModuleUri(URI uri, URI base, boolean checkForSubmodules)
// 1. The file jsFile.
// 2. The "main" property of the JSON file packageFile.
// 3. The file indexFile.
// 4. A submodule of the current module that matches #1, #2, or #3 (if checkForSubmodules
// 4. A node_modules directory that matches #1, #2, or #3 (if checkForSubmodules
// is true).
if (new File(jsUri).isFile()) {
moduleUri = jsUri;
Expand All @@ -133,32 +133,21 @@ private URI getModuleUri(URI uri, URI base, boolean checkForSubmodules)

private URI getSubmoduleUri(URI uri, URI base)
throws SecurityException, IOException, ParseException, URISyntaxException {
URI currentModuleUri = getCurrentModuleUri();
String childSubmoduleDir = null;
String relativeModuleUriString = base.relativize(uri).toString();
URI submoduleUri = null;
String currentModule = getCurrentModuleUri().toString();

// Find the child submodule, if any.
URI childSubmoduleUri = new URI(currentModule + SUBMODULE_DIRECTORY);
File childSubmoduleDir = new File(childSubmoduleUri);

if (childSubmoduleDir.isDirectory()) {
submoduleUri = getModuleUri(new URI(childSubmoduleUri.toString() + PATH_SEPARATOR +
base.relativize(uri).toString()), childSubmoduleUri, false);
}

if (submoduleUri == null) {
// Find the nearest parent module, if any.
int submoduleParentIndex = currentModule.lastIndexOf(SUBMODULE_DIRECTORY + PATH_SEPARATOR);
if (submoduleParentIndex != -1) {
int parentIndex = currentModule.indexOf(PATH_SEPARATOR, submoduleParentIndex +
SUBMODULE_DIRECTORY.length() + 1);
if (parentIndex != -1) {
String parentModule = currentModule.substring(0, parentIndex);
String submoduleDir = parentModule + PATH_SEPARATOR + SUBMODULE_DIRECTORY;

URI submoduleSearchUri = new URI(submoduleDir + PATH_SEPARATOR +
base.relativize(uri).toString());
submoduleUri = getModuleUri(submoduleSearchUri, base, false);
}
// Search for node_modules directories, walking back up to the file system root.
while (currentModuleUri != null && submoduleUri == null) {
childSubmoduleDir = new File(currentModuleUri.toString() + PATH_SEPARATOR +
SUBMODULE_DIRECTORY).toString();
submoduleUri = getModuleUri(new URI(childSubmoduleDir + PATH_SEPARATOR +
relativeModuleUriString), new URI(childSubmoduleDir), false);

if (submoduleUri == null) {
String currentModuleDir = new File(currentModuleUri.toString()).getParent();
currentModuleUri = new URI(currentModuleDir);
}
}

Expand Down

0 comments on commit 41d827e

Please sign in to comment.