Skip to content

Commit

Permalink
chore: remove tryResolve dependency (#10428)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored and nicolo-ribaudo committed Sep 11, 2019
1 parent 53af9e8 commit 1b352ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/babel-helper-fixtures/package.json
Expand Up @@ -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"
}
}
14 changes: 10 additions & 4 deletions packages/babel-helper-fixtures/src/index.js
@@ -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";
Expand Down Expand Up @@ -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.`);
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 1b352ca

Please sign in to comment.