UNPKG

1.33 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.installCommonjsResolveHooksIfNecessary = void 0;
4/**
5 * @internal
6 */
7function 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}
28exports.installCommonjsResolveHooksIfNecessary = installCommonjsResolveHooksIfNecessary;
29//# sourceMappingURL=cjs-resolve-hooks.js.map
\No newline at end of file