index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _normalizeOptions = _interopRequireDefault(require("./normalizeOptions"));
  5. var _resolvePath = _interopRequireDefault(require("./resolvePath"));
  6. exports.resolvePath = _resolvePath.default;
  7. var _call = _interopRequireDefault(require("./transformers/call"));
  8. var _import = _interopRequireDefault(require("./transformers/import"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. // Public API for external plugins
  11. const importVisitors = {
  12. CallExpression: _call.default,
  13. 'ImportDeclaration|ExportDeclaration': _import.default
  14. };
  15. const visitor = {
  16. Program: {
  17. enter(programPath, state) {
  18. programPath.traverse(importVisitors, state);
  19. },
  20. exit(programPath, state) {
  21. programPath.traverse(importVisitors, state);
  22. }
  23. }
  24. };
  25. var _default = ({
  26. types
  27. }) => ({
  28. name: 'module-resolver',
  29. manipulateOptions(opts) {
  30. if (opts.filename === undefined) {
  31. opts.filename = 'unknown';
  32. }
  33. },
  34. pre(file) {
  35. this.types = types;
  36. const currentFile = file.opts.filename;
  37. this.normalizedOpts = (0, _normalizeOptions.default)(currentFile, this.opts); // We need to keep track of all handled nodes so we do not try to transform them twice,
  38. // because we run before (enter) and after (exit) all nodes are handled
  39. this.moduleResolverVisited = new Set();
  40. },
  41. visitor,
  42. post() {
  43. this.moduleResolverVisited.clear();
  44. }
  45. });
  46. exports.default = _default;