Skip to content
Permalink
Browse files

refactor(util): extend requireSearch to export a raw search fn

  • Loading branch information
anulman authored and MarshallOfSound committed Feb 23, 2017
1 parent eefa93f commit 84f0134be4bfdd3ecdb08285f2f45483b51833ce
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/util/require-search.js
@@ -3,20 +3,23 @@ import path from 'path';

const d = debug('electron-forge:require-search');

export default (relativeTo, paths) => {
export function requireSearchRaw(relativeTo, paths) {
const testPaths = paths
.concat(paths.map(mapPath => path.resolve(relativeTo, mapPath)))
.concat(paths.map(mapPath => path.resolve(relativeTo, 'node_modules', mapPath)));
d('searching', testPaths, 'relative to', relativeTo);
let result;
for (const testPath of testPaths) {
try {
d('testing', testPath);
result = require(testPath);
return typeof result === 'object' && result && result.default ? result.default : result;
return require(testPath);
} catch (err) {
// Ignore the error
}
}
d('failed to find a module in', testPaths);
}

export default (relativeTo, paths) => {
const result = requireSearchRaw(relativeTo, paths);
return typeof result === 'object' && result && result.default ? result.default : result;
};

0 comments on commit 84f0134

Please sign in to comment.
You can’t perform that action at this time.