index.js 552 B

123456789101112131415161718192021222324252627
  1. var Module = require("module");
  2. var resolve = module.exports = function (loc, _require) {
  3. try {
  4. return (_require || require).resolve(loc);
  5. } catch (err) {
  6. return null;
  7. }
  8. };
  9. var relativeMod;
  10. resolve.relative = function (loc) {
  11. // we're in the browser, probably
  12. if (typeof Module === "object") return null;
  13. if (!relativeMod) {
  14. relativeMod = new Module;
  15. relativeMod.paths = Module._nodeModulePaths(process.cwd());
  16. }
  17. try {
  18. return Module._resolveFilename(loc, relativeMod);
  19. } catch (err) {
  20. return null;
  21. }
  22. };