index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _default;
  6. var _path = _interopRequireDefault(require("path"));
  7. var _resolve = _interopRequireDefault(require("resolve"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function _default(moduleName, dirname, absoluteRuntime) {
  10. if (absoluteRuntime === false) return moduleName;
  11. return resolveAbsoluteRuntime(moduleName, _path.default.resolve(dirname, absoluteRuntime === true ? "." : absoluteRuntime));
  12. }
  13. function resolveAbsoluteRuntime(moduleName, dirname) {
  14. try {
  15. return _path.default.dirname(_resolve.default.sync(`${moduleName}/package.json`, {
  16. basedir: dirname
  17. })).replace(/\\/g, "/");
  18. } catch (err) {
  19. if (err.code !== "MODULE_NOT_FOUND") throw err;
  20. throw Object.assign(new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), {
  21. code: "BABEL_RUNTIME_NOT_FOUND",
  22. runtime: moduleName,
  23. dirname
  24. });
  25. }
  26. }