Skip to content

Commit

Permalink
lint-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Jan 31, 2022
1 parent 272dfd8 commit 98fb61a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/cjs-resolve-filename-hook.ts
Expand Up @@ -50,16 +50,21 @@ export function installCommonjsResolveHookIfNecessary(tsNodeService: Service) {
...rest
);
}
if (!tsNodeService.enabled())
return defer();
if (!tsNodeService.enabled()) return defer();

// Map from emit to source extensions
if (!isMain && canReplaceJsWithTsExt(tsNodeService, request, parent?.filename)) {
if (
!isMain &&
canReplaceJsWithTsExt(tsNodeService, request, parent?.filename)
) {
try {
return originalResolveFilename.call(
this,
request.slice(0, -3),
parent, isMain, options, ...rest
parent,
isMain,
options,
...rest
);
} catch (e) {
const mainFile = defer();
Expand All @@ -68,7 +73,10 @@ export function installCommonjsResolveHookIfNecessary(tsNodeService: Service) {
return originalResolveFilename.call(
this,
mainFile.slice(0, -3),
parent, isMain, options, ...rest
parent,
isMain,
options,
...rest
);
}
return mainFile;
Expand All @@ -80,7 +88,11 @@ export function installCommonjsResolveHookIfNecessary(tsNodeService: Service) {
}
}

function canReplaceJsWithTsExt(service: Service, request: string, parentPath?: string) {
function canReplaceJsWithTsExt(
service: Service,
request: string,
parentPath?: string
) {
if (!parentPath || service.ignored(parentPath)) return false;
if (isRelativeSpecifier(request) && request.slice(-3) === '.js') {
if (!parentPath) return true;
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Expand Up @@ -25,7 +25,10 @@ import {
} from './module-type-classifier';
import { createResolverFunctions } from './resolver-functions';
import type { createEsmHooks as createEsmHooksFn } from './esm';
import {installCommonjsResolveHookIfNecessary, ModuleConstructorWithInternals} from './cjs-resolve-filename-hook';
import {
installCommonjsResolveHookIfNecessary,
ModuleConstructorWithInternals,
} from './cjs-resolve-filename-hook';

export { TSCommon };
export {
Expand Down

0 comments on commit 98fb61a

Please sign in to comment.