cjs-resolve-hooks.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.installCommonjsResolveHooksIfNecessary = void 0;
  4. /**
  5. * @internal
  6. */
  7. function installCommonjsResolveHooksIfNecessary(tsNodeService) {
  8. const Module = require('module');
  9. const originalResolveFilename = Module._resolveFilename;
  10. const originalFindPath = Module._findPath;
  11. const shouldInstallHook = tsNodeService.options.experimentalResolver;
  12. if (shouldInstallHook) {
  13. const { Module_findPath, Module_resolveFilename } = tsNodeService.getNodeCjsLoader();
  14. Module._resolveFilename = _resolveFilename;
  15. Module._findPath = _findPath;
  16. function _resolveFilename(request, parent, isMain, options, ...rest) {
  17. if (!tsNodeService.enabled())
  18. return originalResolveFilename.call(this, request, parent, isMain, options, ...rest);
  19. return Module_resolveFilename.call(this, request, parent, isMain, options, ...rest);
  20. }
  21. function _findPath() {
  22. if (!tsNodeService.enabled())
  23. return originalFindPath.apply(this, arguments);
  24. return Module_findPath.apply(this, arguments);
  25. }
  26. }
  27. }
  28. exports.installCommonjsResolveHooksIfNecessary = installCommonjsResolveHooksIfNecessary;
  29. //# sourceMappingURL=cjs-resolve-hooks.js.map