Skip to content

Commit

Permalink
Upgrade typescript version (#954)
Browse files Browse the repository at this point in the history
* Upgrade typescript version

* ac

* ac

* add white space

* make type of clearCache consistent
  • Loading branch information
fa93hws authored and johnnyreilly committed Jun 17, 2019
1 parent f667bb5 commit 757137a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 52 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog

## v6.0.3
* [Upgrade typescript version to 3.5.2](https://github.com/TypeStrong/ts-loader/pull/954) (#954) - thanks @fa93hws

## v6.0.2
* [Set configFilePath when reading config file](https://github.com/TypeStrong/ts-loader/pull/942) (#939) - thanks @konpikwastaken!

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "6.0.2",
"version": "6.0.3",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist/types/index.d.ts",
Expand Down Expand Up @@ -88,7 +88,7 @@
"rimraf": "^2.6.2",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"typescript": "^3.1.1",
"typescript": "^3.5.2",
"webpack": "^4.5.0",
"webpack-cli": "^3.1.1"
},
Expand Down
66 changes: 29 additions & 37 deletions src/servicesHost.ts
Expand Up @@ -65,7 +65,8 @@ export function makeServicesHost(
compiler.sys.fileExists(filePathToCheck) ||
readFile(filePathToCheck) !== undefined;

const moduleResolutionHost: ModuleResolutionHost = {
let clearCache: Action | null = null;
let moduleResolutionHost: ModuleResolutionHost = {
fileExists,
readFile: readFileWithFallback,
realpath: compiler.sys.realpath,
Expand All @@ -74,7 +75,11 @@ export function makeServicesHost(
getDirectories: compiler.sys.getDirectories
};

const clearCache = enableFileCaching ? addCache(moduleResolutionHost) : null;
if (enableFileCaching) {
const cached = addCache(moduleResolutionHost);
clearCache = cached.clearCache;
moduleResolutionHost = cached.moduleResolutionHost;
}

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

type CacheableFunction = Extract<
keyof typescript.ModuleResolutionHost,
'fileExists' | 'directoryExists' | 'realpath'
>;
const cacheableFunctions: CacheableFunction[] = [
'fileExists',
'directoryExists',
'realpath'
];

function addCache(servicesHost: typescript.ModuleResolutionHost) {
function addCache(
servicesHost: typescript.ModuleResolutionHost
): {
moduleResolutionHost: typescript.ModuleResolutionHost;
clearCache: () => void;
} {
const clearCacheFunctions: Action[] = [];

cacheableFunctions.forEach((functionToCache: CacheableFunction) => {
const originalFunction = servicesHost[functionToCache];
if (originalFunction !== undefined) {
const cache = createCache<ReturnType<typeof originalFunction>>(
originalFunction
);
servicesHost[
functionToCache
] = cache.getCached as typescript.ModuleResolutionHost[CacheableFunction];
clearCacheFunctions.push(cache.clear);
}
});

return () => clearCacheFunctions.forEach(clear => clear());
}

function createCache<TOut>(originalFunction: (arg: string) => TOut) {
const cache = new Map<string, TOut>();
return {
clear: () => {
cache.clear();
moduleResolutionHost: {
...servicesHost,
fileExists: createCache(servicesHost.fileExists),
directoryExists:
servicesHost.directoryExists &&
createCache(servicesHost.directoryExists),
realpath: servicesHost.realpath && createCache(servicesHost.realpath)
},
getCached: (arg: string) => {
clearCache: () => clearCacheFunctions.forEach(clear => clear())
};

function createCache<TOut>(originalFunction: (arg: string) => TOut) {
const cache = new Map<string, TOut>();
clearCacheFunctions.push(() => cache.clear());
return function getCached(arg: string) {
let res = cache.get(arg);
if (res !== undefined) {
return res;
Expand All @@ -695,6 +687,6 @@ function createCache<TOut>(originalFunction: (arg: string) => TOut) {
res = originalFunction(arg);
cache.set(arg, res);
return res;
}
};
};
}
}
18 changes: 5 additions & 13 deletions yarn.lock
Expand Up @@ -2942,15 +2942,7 @@ js-tokens@^4.0.0:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

js-yaml@3.13.1, js-yaml@^3.9.0:
version "3.13.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.13.0:
js-yaml@3.13.1, js-yaml@^3.13.0, js-yaml@^3.9.0:
version "3.13.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
Expand Down Expand Up @@ -5041,10 +5033,10 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^3.1.1:
version "3.4.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==
typescript@^3.5.2:
version "3.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.2.tgz#a09e1dc69bc9551cadf17dba10ee42cf55e5d56c"
integrity sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==

uglify-es@^3.3.4:
version "3.3.9"
Expand Down

0 comments on commit 757137a

Please sign in to comment.