skutter
Version:
Skutter: Opinionated BDD Browser based test framework
19 lines (18 loc) • 824 B
JavaScript
;
const fs = require("fs");
const path = require("path");
class NodeModuleFinder {
static find(desired) {
let cwdToScriptRelativePrefix = path.relative(process.cwd(), __dirname);
let oldNestedLocation = `${cwdToScriptRelativePrefix}/../../../node_modules/${desired}`;
let newFlattenedLocation = `${cwdToScriptRelativePrefix}/../../../../../${desired}`;
if (fs.existsSync(oldNestedLocation)) {
return path.resolve(oldNestedLocation);
}
else if (fs.existsSync(newFlattenedLocation)) {
return path.resolve(newFlattenedLocation);
}
throw new Error(`Can't determine where '${desired}' file is located.\n\nSearched: '${oldNestedLocation}' and '${newFlattenedLocation}'.`);
}
}
exports.NodeModuleFinder = NodeModuleFinder;