index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _default;
  6. exports.resolveFSPath = resolveFSPath;
  7. var _path = require("path");
  8. var _module = require("module");
  9. function _default(moduleName, dirname, absoluteRuntime) {
  10. if (absoluteRuntime === false) return moduleName;
  11. return resolveAbsoluteRuntime(moduleName, _path.resolve(dirname, absoluteRuntime === true ? "." : absoluteRuntime));
  12. }
  13. function resolveAbsoluteRuntime(moduleName, dirname) {
  14. try {
  15. return _path.dirname((((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, {
  16. paths: [b]
  17. }, M = require("module")) => {
  18. let f = M._findPath(r, M._nodeModulePaths(b).concat(b));
  19. if (f) return f;
  20. f = new Error(`Cannot resolve module '${r}'`);
  21. f.code = "MODULE_NOT_FOUND";
  22. throw f;
  23. })(`${moduleName}/package.json`, {
  24. paths: [dirname]
  25. })).replace(/\\/g, "/");
  26. } catch (err) {
  27. if (err.code !== "MODULE_NOT_FOUND") throw err;
  28. throw Object.assign(new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), {
  29. code: "BABEL_RUNTIME_NOT_FOUND",
  30. runtime: moduleName,
  31. dirname
  32. });
  33. }
  34. }
  35. function resolveFSPath(path) {
  36. return require.resolve(path).replace(/\\/g, "/");
  37. }