Skip to content

Commit

Permalink
Remove 'findup' dependency (palantir#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and nchen63 committed May 6, 2017
1 parent 7f2c118 commit 96a5a4e
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 131 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"babel-code-frame": "^6.22.0",
"colors": "^1.1.2",
"diff": "^3.2.0",
"findup-sync": "~0.3.0",
"glob": "^7.1.1",
"optimist": "~0.6.0",
"resolve": "^1.3.2",
Expand All @@ -55,7 +54,6 @@
"@types/chai": "^3.5.0",
"@types/colors": "^1.1.3",
"@types/diff": "0.0.31",
"@types/findup-sync": "^0.3.29",
"@types/glob": "^5.0.30",
"@types/js-yaml": "^3.5.29",
"@types/mocha": "^2.2.35",
Expand Down
34 changes: 31 additions & 3 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import findup = require("findup-sync");
import * as fs from "fs";
import * as path from "path";
import * as resolve from "resolve";
Expand Down Expand Up @@ -122,8 +121,8 @@ export function findConfigurationPath(suppliedConfigFilePath: string | null, inp
}
} else {
// search for tslint.json from input file location
let configFilePath = findup(CONFIG_FILENAME, { cwd: inputFilePath, nocase: true });
if (configFilePath != null && fs.existsSync(configFilePath)) {
let configFilePath = findup(CONFIG_FILENAME, inputFilePath);
if (configFilePath !== undefined) {
return path.resolve(configFilePath);
}

Expand All @@ -141,6 +140,35 @@ export function findConfigurationPath(suppliedConfigFilePath: string | null, inp
}
}

/**
* Find a file by name in a directory or any ancestory directory.
* This is case-insensitive, so it can find 'TsLiNt.JsOn' when searching for 'tslint.json'.
*/
function findup(filename: string, directory: string): string | undefined {
while (true) {
const res = findFile(directory);
if (res) {
return res;
}

const parent = path.dirname(directory);
if (parent === directory) {
return undefined;
}
directory = parent;
}

function findFile(cwd: string): string | undefined {
if (fs.existsSync(path.join(cwd, filename))) {
return filename;
}

// Try reading in the entire directory and looking for a file with different casing.
const filenameLower = filename.toLowerCase();
return fs.readdirSync(cwd).find((entry) => entry.toLowerCase() === filenameLower);
}
}

/**
* Used Node semantics to load a configuration file given configFilePath.
* For example:
Expand Down
Loading

0 comments on commit 96a5a4e

Please sign in to comment.