Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
me.getModuleName = function (mpath) {
let m;
const stats = fs.statSync(mpath);
try {
m = require(mpath).name;
if (m) return m;
} catch (ex) {
/* not a warning yet. Eventually maybe */
}
if (stats.isDirectory()) {
try {
m = JSON.parse(fs.readFileSync(path.join(mpath, 'package.json'))).name;
if (m) return m;
} catch (ex) {
log.warn(ex, 'invalid package.json for %s', mpath);
}
}
return mpath;
};