chore: remove tryResolve dependency (#10428)
This commit is contained in:
parent
53af9e8b7a
commit
1b352ca8a1
@ -11,7 +11,6 @@
|
|||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.13",
|
"lodash": "^4.17.13",
|
||||||
"semver": "^5.3.0",
|
"semver": "^5.3.0"
|
||||||
"try-resolve": "^1.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
import resolve from "try-resolve";
|
|
||||||
import clone from "lodash/clone";
|
import clone from "lodash/clone";
|
||||||
import extend from "lodash/extend";
|
import extend from "lodash/extend";
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
@ -35,6 +34,13 @@ type Suite = {
|
|||||||
filename: string,
|
filename: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function tryResolve(module) {
|
||||||
|
try {
|
||||||
|
return require.resolve(module);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
function assertDirectory(loc) {
|
function assertDirectory(loc) {
|
||||||
if (!fs.statSync(loc).isDirectory()) {
|
if (!fs.statSync(loc).isDirectory()) {
|
||||||
throw new Error(`Expected ${loc} to be a directory.`);
|
throw new Error(`Expected ${loc} to be a directory.`);
|
||||||
@ -76,7 +82,7 @@ export default function get(entryLoc): Array<Suite> {
|
|||||||
const suites = [];
|
const suites = [];
|
||||||
|
|
||||||
let rootOpts = {};
|
let rootOpts = {};
|
||||||
const rootOptsLoc = resolve(entryLoc + "/options");
|
const rootOptsLoc = tryResolve(entryLoc + "/options");
|
||||||
if (rootOptsLoc) rootOpts = require(rootOptsLoc);
|
if (rootOptsLoc) rootOpts = require(rootOptsLoc);
|
||||||
|
|
||||||
for (const suiteName of fs.readdirSync(entryLoc)) {
|
for (const suiteName of fs.readdirSync(entryLoc)) {
|
||||||
@ -92,7 +98,7 @@ export default function get(entryLoc): Array<Suite> {
|
|||||||
assertDirectory(suite.filename);
|
assertDirectory(suite.filename);
|
||||||
suites.push(suite);
|
suites.push(suite);
|
||||||
|
|
||||||
const suiteOptsLoc = resolve(suite.filename + "/options");
|
const suiteOptsLoc = tryResolve(suite.filename + "/options");
|
||||||
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
|
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
|
||||||
|
|
||||||
for (const taskName of fs.readdirSync(suite.filename)) {
|
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 taskOpts = cloneDeep(suite.options);
|
||||||
|
|
||||||
const taskOptsLoc = resolve(taskDir + "/options");
|
const taskOptsLoc = tryResolve(taskDir + "/options");
|
||||||
if (taskOptsLoc) extend(taskOpts, require(taskOptsLoc));
|
if (taskOptsLoc) extend(taskOpts, require(taskOptsLoc));
|
||||||
|
|
||||||
const test = {
|
const test = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user