diff --git a/CHANGELOG.md b/CHANGELOG.md index 908a1b0d4..ed284eb34 100644 --- a/CHANGELOG.md +++ b/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! diff --git a/package.json b/package.json index 184e92a4d..69a57801a 100644 --- a/package.json +++ b/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", @@ -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" }, diff --git a/src/servicesHost.ts b/src/servicesHost.ts index f54e9d71c..6415bafa1 100644 --- a/src/servicesHost.ts +++ b/src/servicesHost.ts @@ -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, @@ -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; @@ -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>( - originalFunction - ); - servicesHost[ - functionToCache - ] = cache.getCached as typescript.ModuleResolutionHost[CacheableFunction]; - clearCacheFunctions.push(cache.clear); - } - }); - - return () => clearCacheFunctions.forEach(clear => clear()); -} - -function createCache(originalFunction: (arg: string) => TOut) { - const cache = new Map(); 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(originalFunction: (arg: string) => TOut) { + const cache = new Map(); + clearCacheFunctions.push(() => cache.clear()); + return function getCached(arg: string) { let res = cache.get(arg); if (res !== undefined) { return res; @@ -695,6 +687,6 @@ function createCache(originalFunction: (arg: string) => TOut) { res = originalFunction(arg); cache.set(arg, res); return res; - } - }; + }; + } } diff --git a/yarn.lock b/yarn.lock index d8c6ffc16..f81b5d42a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== @@ -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"