Skip to content

Commit

Permalink
Backport #1287 to v8 (#1291)
Browse files Browse the repository at this point in the history
* Backport "Use caches for module resolution and type reference directives when using compiler default functions" #1287 to v8

* regen comparison tests

* Revert "regen comparison tests"

This reverts commit f04c5cf.

* only the two failing tests rerun.

* yarn run comparison-tests -- --save-output --single-test projectReferencesSymLinks

* yarn run comparison-tests -- --single-test projectReferencesSymLinks_WatchApi --save-output

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
Co-authored-by: John Reilly <johnny_reilly@hotmail.com>
  • Loading branch information
3 people committed Apr 23, 2021
1 parent 8a32b04 commit 6787a39
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 63 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog

## v8.2.0

* [Use caches for module resolution and type reference directives when using compiler default functions](https://github.com/TypeStrong/ts-loader/pull/1287) - thanks @sheetalkamat - uses: https://github.com/microsoft/TypeScript/pull/43700
* This is a backport from v9.1.0 for webpack 4 compatibility

## v8.1.0
* [feat: remove top-level typescript import statements](https://github.com/TypeStrong/ts-loader/pull/1259) - thanks @ulivz

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "8.1.0",
"version": "8.2.0",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
48 changes: 46 additions & 2 deletions src/interfaces.ts
Expand Up @@ -102,8 +102,9 @@ export interface ServiceHostWhichMayBeCacheable

export interface WatchHost
extends typescript.WatchCompilerHostOfFilesAndCompilerOptions<
typescript.EmitAndSemanticDiagnosticsBuilderProgram
> {
typescript.EmitAndSemanticDiagnosticsBuilderProgram
>,
HostMayBeCacheable {
invokeFileWatcher: WatchFactory['invokeFileWatcher'];
updateRootFileNames(): void;
outputFiles: Map<FilePathKey, typescript.OutputFile[]>;
Expand Down Expand Up @@ -178,13 +179,56 @@ export interface ConfigFileInfo {
dtsFiles?: string[];
}

interface CacheWithRedirects<T> {
ownMap: Map<string, T>;
redirectsMap: Map<typescript.Path, Map<string, T>>;
getOrCreateMapOfCacheRedirects(
redirectedReference: typescript.ResolvedProjectReference | undefined
): Map<string, T>;
clear(): void;
setOwnOptions(newOptions: typescript.CompilerOptions): void;
setOwnMap(newOwnMap: Map<string, T>): void;
}
interface PerModuleNameCache {
get(
directory: string
): typescript.ResolvedModuleWithFailedLookupLocations | undefined;
set(
directory: string,
result: typescript.ResolvedModuleWithFailedLookupLocations
): void;
}
export interface ModuleResolutionCache
extends typescript.ModuleResolutionCache {
directoryToModuleNameMap: CacheWithRedirects<
Map<string, typescript.ResolvedModuleWithFailedLookupLocations>
>;
moduleNameToDirectoryMap: CacheWithRedirects<PerModuleNameCache>;
clear(): void;
update(compilerOptions: typescript.CompilerOptions): void;
getPackageJsonInfoCache?(): any;
}
// Until the API has been released and ts-loader is built against a version of TypeScript that contains it - see https://github.com/microsoft/TypeScript/blob/74993a2a64bb2e423b40204bb54ff749cdd4ef54/src/compiler/moduleNameResolver.ts#L458
export interface TypeReferenceDirectiveResolutionCache {
getOrCreateCacheForDirectory(
directoryName: string,
redirectedReference?: typescript.ResolvedProjectReference
): Map<
string,
typescript.ResolvedTypeReferenceDirectiveWithFailedLookupLocations
>;
clear(): void;
update(compilerOptions: typescript.CompilerOptions): void;
}
export interface TSInstance {
compiler: typeof typescript;
compilerOptions: typescript.CompilerOptions;
/** Used for Vue for the most part */
appendTsTsxSuffixesIfRequired: (filePath: string) => string;
loaderOptions: LoaderOptions;
rootFileNames: Set<string>;
moduleResolutionCache?: ModuleResolutionCache;
typeReferenceResolutionCache?: TypeReferenceDirectiveResolutionCache;
/**
* a cache of all the files
*/
Expand Down

0 comments on commit 6787a39

Please sign in to comment.