Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

A more robust root check to fix an edge case #9

Merged
merged 1 commit into from Feb 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/config/GraphQLConfig.js
Expand Up @@ -22,19 +22,22 @@ const CUSTOM_VALIDATION_RULES_MODULE_PATH = 'custom-validation-rules';
* If the file isn't present in the provided directory path, walk up the
* directory tree until the file is found or it reaches the root directory.
*/
export async function findGraphQLConfigDir(dirPath: Uri): Promise<?string> {
export function findGraphQLConfigDir(dirPath: Uri): ?string {
let currentPath = path.resolve(dirPath);
let filePath;
while (currentPath.length > 1) {
while (true) {
filePath = path.join(currentPath, '.graphqlrc');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filePath is no longer used outside the loop, so I think we can make it const filePath = path.join('...').

if (fs.existsSync(filePath)) {
break;
}
if (isRootDir(currentPath)) {
break;
}

currentPath = path.dirname(currentPath);
}

return filePath ? currentPath : null;
return !isRootDir(currentPath) ? currentPath : null;
}

export async function getGraphQLConfig(configDir: Uri): Promise<GraphQLRC> {
Expand Down Expand Up @@ -181,3 +184,7 @@ export class GraphQLConfig {
return resolvedPath;
}
}

function isRootDir(dirPath: Uri): boolean {
return path.dirname(dirPath) === dirPath;
}