Skip to content

Commit

Permalink
Merge pull request #936 from andrewbranch/bug/module-resolution
Browse files Browse the repository at this point in the history
Fix type reference directive resolution
  • Loading branch information
andrewbranch committed May 18, 2019
2 parents cc7b2b1 + 658d474 commit 0399864
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## v6.0.1

* [Fix issue with `resolveTypeReferenceDirective` causing errors like `Cannot find name 'it'` with Jest](https://github.com/TypeStrong/ts-loader/pull/936) (#934) (#919) - thanks @andrewbranch!

## v6.0.0

* [Drop support for node < 8.6 related to micromatch upgrade to 4](https://github.com/TypeStrong/ts-loader/pull/930); see: https://github.com/TypeStrong/ts-loader/issues/929
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "6.0.0",
"version": "6.0.1",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist/types/index.d.ts",
Expand Down
21 changes: 14 additions & 7 deletions src/servicesHost.ts
Expand Up @@ -69,7 +69,9 @@ export function makeServicesHost(
fileExists,
readFile: readFileWithFallback,
realpath: compiler.sys.realpath,
directoryExists: compiler.sys.directoryExists
directoryExists: compiler.sys.directoryExists,
getCurrentDirectory: compiler.sys.getCurrentDirectory,
getDirectories: compiler.sys.getDirectories
};

const clearCache = enableFileCaching ? addCache(moduleResolutionHost) : null;
Expand Down Expand Up @@ -187,8 +189,11 @@ function makeResolvers(
): (typescript.ResolvedTypeReferenceDirective | undefined)[] =>
typeDirectiveNames.map(
directive =>
resolveTypeReferenceDirective(directive, containingFile)
.resolvedTypeReferenceDirective
resolveTypeReferenceDirective(
directive,
containingFile,
_redirectedReference
).resolvedTypeReferenceDirective
);

const resolveModuleName = makeResolveModuleName(
Expand Down Expand Up @@ -500,7 +505,8 @@ export function makeWatchHost(

type ResolveTypeReferenceDirective = (
directive: string,
containingFile: string
containingFile: string,
redirectedReference?: typescript.ResolvedProjectReference
) => typescript.ResolvedTypeReferenceDirectiveWithFailedLookupLocations;

function makeResolveTypeReferenceDirective(
Expand All @@ -512,16 +518,17 @@ function makeResolveTypeReferenceDirective(
| undefined
): ResolveTypeReferenceDirective {
if (customResolveTypeReferenceDirective === undefined) {
return (directive: string, containingFile: string) =>
return (directive, containingFile, redirectedReference) =>
compiler.resolveTypeReferenceDirective(
directive,
containingFile,
compilerOptions,
moduleResolutionHost
moduleResolutionHost,
redirectedReference
);
}

return (directive: string, containingFile: string) =>
return (directive, containingFile) =>
customResolveTypeReferenceDirective(
directive,
containingFile,
Expand Down

0 comments on commit 0399864

Please sign in to comment.