Skip to content

Commit 6787a39

Browse files
JasonKlebansheetalkamatjohnnyreilly
authored
Backport #1287 to v8 (#1291)
* 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 <[email protected]> Co-authored-by: John Reilly <[email protected]>
1 parent 8a32b04 commit 6787a39

File tree

9 files changed

+219
-63
lines changed

9 files changed

+219
-63
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v8.2.0
4+
5+
* [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
6+
* This is a backport from v9.1.0 for webpack 4 compatibility
7+
38
## v8.1.0
49
* [feat: remove top-level typescript import statements](https://github.com/TypeStrong/ts-loader/pull/1259) - thanks @ulivz
510

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.1.0",
3+
"version": "8.2.0",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/interfaces.ts

+46-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ export interface ServiceHostWhichMayBeCacheable
102102

103103
export interface WatchHost
104104
extends typescript.WatchCompilerHostOfFilesAndCompilerOptions<
105-
typescript.EmitAndSemanticDiagnosticsBuilderProgram
106-
> {
105+
typescript.EmitAndSemanticDiagnosticsBuilderProgram
106+
>,
107+
HostMayBeCacheable {
107108
invokeFileWatcher: WatchFactory['invokeFileWatcher'];
108109
updateRootFileNames(): void;
109110
outputFiles: Map<FilePathKey, typescript.OutputFile[]>;
@@ -178,13 +179,56 @@ export interface ConfigFileInfo {
178179
dtsFiles?: string[];
179180
}
180181

182+
interface CacheWithRedirects<T> {
183+
ownMap: Map<string, T>;
184+
redirectsMap: Map<typescript.Path, Map<string, T>>;
185+
getOrCreateMapOfCacheRedirects(
186+
redirectedReference: typescript.ResolvedProjectReference | undefined
187+
): Map<string, T>;
188+
clear(): void;
189+
setOwnOptions(newOptions: typescript.CompilerOptions): void;
190+
setOwnMap(newOwnMap: Map<string, T>): void;
191+
}
192+
interface PerModuleNameCache {
193+
get(
194+
directory: string
195+
): typescript.ResolvedModuleWithFailedLookupLocations | undefined;
196+
set(
197+
directory: string,
198+
result: typescript.ResolvedModuleWithFailedLookupLocations
199+
): void;
200+
}
201+
export interface ModuleResolutionCache
202+
extends typescript.ModuleResolutionCache {
203+
directoryToModuleNameMap: CacheWithRedirects<
204+
Map<string, typescript.ResolvedModuleWithFailedLookupLocations>
205+
>;
206+
moduleNameToDirectoryMap: CacheWithRedirects<PerModuleNameCache>;
207+
clear(): void;
208+
update(compilerOptions: typescript.CompilerOptions): void;
209+
getPackageJsonInfoCache?(): any;
210+
}
211+
// 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
212+
export interface TypeReferenceDirectiveResolutionCache {
213+
getOrCreateCacheForDirectory(
214+
directoryName: string,
215+
redirectedReference?: typescript.ResolvedProjectReference
216+
): Map<
217+
string,
218+
typescript.ResolvedTypeReferenceDirectiveWithFailedLookupLocations
219+
>;
220+
clear(): void;
221+
update(compilerOptions: typescript.CompilerOptions): void;
222+
}
181223
export interface TSInstance {
182224
compiler: typeof typescript;
183225
compilerOptions: typescript.CompilerOptions;
184226
/** Used for Vue for the most part */
185227
appendTsTsxSuffixesIfRequired: (filePath: string) => string;
186228
loaderOptions: LoaderOptions;
187229
rootFileNames: Set<string>;
230+
moduleResolutionCache?: ModuleResolutionCache;
231+
typeReferenceResolutionCache?: TypeReferenceDirectiveResolutionCache;
188232
/**
189233
* a cache of all the files
190234
*/

0 commit comments

Comments
 (0)