chore: remove tryResolve dependency (#10428)

This commit is contained in:
Huáng Jùnliàng 2019-09-11 06:25:18 -04:00 committed by Nicolò Ribaudo
parent 53af9e8b7a
commit 1b352ca8a1
2 changed files with 11 additions and 6 deletions

View File

@ -11,7 +11,6 @@
"main": "lib/index.js",
"dependencies": {
"lodash": "^4.17.13",
"semver": "^5.3.0",
"try-resolve": "^1.0.0"
"semver": "^5.3.0"
}
}

View File

@ -1,5 +1,4 @@
import cloneDeep from "lodash/cloneDeep";
import resolve from "try-resolve";
import clone from "lodash/clone";
import extend from "lodash/extend";
import semver from "semver";
@ -35,6 +34,13 @@ type Suite = {
filename: string,
};
function tryResolve(module) {
try {
return require.resolve(module);
} catch (e) {
return null;
}
}
function assertDirectory(loc) {
if (!fs.statSync(loc).isDirectory()) {
throw new Error(`Expected ${loc} to be a directory.`);
@ -76,7 +82,7 @@ export default function get(entryLoc): Array<Suite> {
const suites = [];
let rootOpts = {};
const rootOptsLoc = resolve(entryLoc + "/options");
const rootOptsLoc = tryResolve(entryLoc + "/options");
if (rootOptsLoc) rootOpts = require(rootOptsLoc);
for (const suiteName of fs.readdirSync(entryLoc)) {
@ -92,7 +98,7 @@ export default function get(entryLoc): Array<Suite> {
assertDirectory(suite.filename);
suites.push(suite);
const suiteOptsLoc = resolve(suite.filename + "/options");
const suiteOptsLoc = tryResolve(suite.filename + "/options");
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
for (const taskName of fs.readdirSync(suite.filename)) {
@ -139,7 +145,7 @@ export default function get(entryLoc): Array<Suite> {
const taskOpts = cloneDeep(suite.options);
const taskOptsLoc = resolve(taskDir + "/options");
const taskOptsLoc = tryResolve(taskDir + "/options");
if (taskOptsLoc) extend(taskOpts, require(taskOptsLoc));
const test = {