Skip to content

Commit 757137a

Browse files
fa93hwsjohnnyreilly
authored andcommitted
Upgrade typescript version (#954)
* Upgrade typescript version * ac * ac * add white space * make type of clearCache consistent
1 parent f667bb5 commit 757137a

File tree

4 files changed

+39
-52
lines changed

4 files changed

+39
-52
lines changed

CHANGELOG.md

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

3+
## v6.0.3
4+
* [Upgrade typescript version to 3.5.2](https://github.com/TypeStrong/ts-loader/pull/954) (#954) - thanks @fa93hws
5+
36
## v6.0.2
47
* [Set configFilePath when reading config file](https://github.com/TypeStrong/ts-loader/pull/942) (#939) - thanks @konpikwastaken!
58

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "6.0.2",
3+
"version": "6.0.3",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist/types/index.d.ts",
@@ -88,7 +88,7 @@
8888
"rimraf": "^2.6.2",
8989
"tslint": "^5.11.0",
9090
"tslint-config-prettier": "^1.15.0",
91-
"typescript": "^3.1.1",
91+
"typescript": "^3.5.2",
9292
"webpack": "^4.5.0",
9393
"webpack-cli": "^3.1.1"
9494
},

src/servicesHost.ts

+29-37
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export function makeServicesHost(
6565
compiler.sys.fileExists(filePathToCheck) ||
6666
readFile(filePathToCheck) !== undefined;
6767

68-
const moduleResolutionHost: ModuleResolutionHost = {
68+
let clearCache: Action | null = null;
69+
let moduleResolutionHost: ModuleResolutionHost = {
6970
fileExists,
7071
readFile: readFileWithFallback,
7172
realpath: compiler.sys.realpath,
@@ -74,7 +75,11 @@ export function makeServicesHost(
7475
getDirectories: compiler.sys.getDirectories
7576
};
7677

77-
const clearCache = enableFileCaching ? addCache(moduleResolutionHost) : null;
78+
if (enableFileCaching) {
79+
const cached = addCache(moduleResolutionHost);
80+
clearCache = cached.clearCache;
81+
moduleResolutionHost = cached.moduleResolutionHost;
82+
}
7883

7984
// loader.context seems to work fine on Linux / Mac regardless causes problems for @types resolution on Windows for TypeScript < 2.3
8085
const getCurrentDirectory = () => loader.context;
@@ -651,42 +656,29 @@ function populateDependencyGraphs(
651656
});
652657
}
653658

654-
type CacheableFunction = Extract<
655-
keyof typescript.ModuleResolutionHost,
656-
'fileExists' | 'directoryExists' | 'realpath'
657-
>;
658-
const cacheableFunctions: CacheableFunction[] = [
659-
'fileExists',
660-
'directoryExists',
661-
'realpath'
662-
];
663-
664-
function addCache(servicesHost: typescript.ModuleResolutionHost) {
659+
function addCache(
660+
servicesHost: typescript.ModuleResolutionHost
661+
): {
662+
moduleResolutionHost: typescript.ModuleResolutionHost;
663+
clearCache: () => void;
664+
} {
665665
const clearCacheFunctions: Action[] = [];
666-
667-
cacheableFunctions.forEach((functionToCache: CacheableFunction) => {
668-
const originalFunction = servicesHost[functionToCache];
669-
if (originalFunction !== undefined) {
670-
const cache = createCache<ReturnType<typeof originalFunction>>(
671-
originalFunction
672-
);
673-
servicesHost[
674-
functionToCache
675-
] = cache.getCached as typescript.ModuleResolutionHost[CacheableFunction];
676-
clearCacheFunctions.push(cache.clear);
677-
}
678-
});
679-
680-
return () => clearCacheFunctions.forEach(clear => clear());
681-
}
682-
683-
function createCache<TOut>(originalFunction: (arg: string) => TOut) {
684-
const cache = new Map<string, TOut>();
685666
return {
686-
clear: () => {
687-
cache.clear();
667+
moduleResolutionHost: {
668+
...servicesHost,
669+
fileExists: createCache(servicesHost.fileExists),
670+
directoryExists:
671+
servicesHost.directoryExists &&
672+
createCache(servicesHost.directoryExists),
673+
realpath: servicesHost.realpath && createCache(servicesHost.realpath)
688674
},
689-
getCached: (arg: string) => {
675+
clearCache: () => clearCacheFunctions.forEach(clear => clear())
676+
};
677+
678+
function createCache<TOut>(originalFunction: (arg: string) => TOut) {
679+
const cache = new Map<string, TOut>();
680+
clearCacheFunctions.push(() => cache.clear());
681+
return function getCached(arg: string) {
690682
let res = cache.get(arg);
691683
if (res !== undefined) {
692684
return res;
@@ -695,6 +687,6 @@ function createCache<TOut>(originalFunction: (arg: string) => TOut) {
695687
res = originalFunction(arg);
696688
cache.set(arg, res);
697689
return res;
698-
}
699-
};
690+
};
691+
}
700692
}

yarn.lock

+5-13
Original file line numberDiff line numberDiff line change
@@ -2942,15 +2942,7 @@ js-tokens@^4.0.0:
29422942
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
29432943
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
29442944

2945-
[email protected], js-yaml@^3.9.0:
2946-
version "3.13.1"
2947-
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
2948-
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
2949-
dependencies:
2950-
argparse "^1.0.7"
2951-
esprima "^4.0.0"
2952-
2953-
js-yaml@^3.13.0:
2945+
[email protected], js-yaml@^3.13.0, js-yaml@^3.9.0:
29542946
version "3.13.1"
29552947
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
29562948
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
@@ -5041,10 +5033,10 @@ typedarray@^0.0.6:
50415033
version "0.0.6"
50425034
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
50435035

5044-
typescript@^3.1.1:
5045-
version "3.4.5"
5046-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
5047-
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==
5036+
typescript@^3.5.2:
5037+
version "3.5.2"
5038+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.2.tgz#a09e1dc69bc9551cadf17dba10ee42cf55e5d56c"
5039+
integrity sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==
50485040

50495041
uglify-es@^3.3.4:
50505042
version "3.3.9"

0 commit comments

Comments
 (0)