Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function resolve(req, atPath) {
// can only resolve modules under node_modules
if (!isModuleRequest(req)) return undefined;
const splits = req.split("/");
const nameX = splits[0].startsWith("@") ? 2 : 1; // check for scoped module
const name = splits.slice(0, nameX).join("/");
//
// All modules must have package.json
//
const resolved = optionalRequire.resolve(
requireAt(atPath),
// ensure require request paths are POSIX
Path.posix.join(name, "package.json"),
false
);
if (!resolved) return undefined;
splits.splice(0, nameX, ".");
return {
path: Path.dirname(resolved),
request: splits.join("/")
};
}