From 109a8beb87725846dd2ca23188e5693047fdb65d Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 13 Jun 2019 23:53:53 +1000 Subject: [PATCH 1/5] Upgrade typescript version --- package.json | 4 ++-- src/servicesHost.ts | 16 +++++++++++++--- yarn.lock | 18 +++++------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 184e92a4d..e61414355 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.1", "webpack": "^4.5.0", "webpack-cli": "^3.1.1" }, diff --git a/src/servicesHost.ts b/src/servicesHost.ts index f54e9d71c..1071c7a54 100644 --- a/src/servicesHost.ts +++ b/src/servicesHost.ts @@ -670,9 +670,19 @@ function addCache(servicesHost: typescript.ModuleResolutionHost) { const cache = createCache>( originalFunction ); - servicesHost[ - functionToCache - ] = cache.getCached as typescript.ModuleResolutionHost[CacheableFunction]; + switch (functionToCache) { + case 'fileExists': + servicesHost.fileExists = cache.getCached as typescript.ModuleResolutionHost['fileExists']; + break; + case 'directoryExists': + servicesHost.directoryExists = cache.getCached as typescript.ModuleResolutionHost['directoryExists']; + break; + case 'realpath': + servicesHost.realpath = cache.getCached as typescript.ModuleResolutionHost['realpath']; + break; + default: + throw new Error(`functionToCache ${functionToCache} not found`); + } clearCacheFunctions.push(cache.clear); } }); diff --git a/yarn.lock b/yarn.lock index d8c6ffc16..e545a392f 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.1: + version "3.5.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.1.tgz#ba72a6a600b2158139c5dd8850f700e231464202" + integrity sha512-64HkdiRv1yYZsSe4xC1WVgamNigVYjlssIoaH2HcZF0+ijsk5YK2g0G34w9wJkze8+5ow4STd22AynfO6ZYYLw== uglify-es@^3.3.4: version "3.3.9" From 9ac6c90c465cc831100d6bbb4a0d953edcae8b88 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 17 Jun 2019 22:10:15 +1000 Subject: [PATCH 2/5] ac --- src/servicesHost.ts | 76 +++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/src/servicesHost.ts b/src/servicesHost.ts index 1071c7a54..f8eeef08d 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: null | (() => void) = 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,52 +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 - ); - switch (functionToCache) { - case 'fileExists': - servicesHost.fileExists = cache.getCached as typescript.ModuleResolutionHost['fileExists']; - break; - case 'directoryExists': - servicesHost.directoryExists = cache.getCached as typescript.ModuleResolutionHost['directoryExists']; - break; - case 'realpath': - servicesHost.realpath = cache.getCached as typescript.ModuleResolutionHost['realpath']; - break; - default: - throw new Error(`functionToCache ${functionToCache} not found`); - } - 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; @@ -705,6 +687,6 @@ function createCache(originalFunction: (arg: string) => TOut) { res = originalFunction(arg); cache.set(arg, res); return res; - } - }; + }; + } } From d4bac2e4315fa90f05ff132a86999374ef570e2f Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 17 Jun 2019 22:46:32 +1000 Subject: [PATCH 3/5] ac --- CHANGELOG.md | 3 +++ package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 908a1b0d4..7ef89cf44 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 e61414355..69a57801a 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "rimraf": "^2.6.2", "tslint": "^5.11.0", "tslint-config-prettier": "^1.15.0", - "typescript": "^3.5.1", + "typescript": "^3.5.2", "webpack": "^4.5.0", "webpack-cli": "^3.1.1" }, diff --git a/yarn.lock b/yarn.lock index e545a392f..f81b5d42a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5033,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.5.1: - version "3.5.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.1.tgz#ba72a6a600b2158139c5dd8850f700e231464202" - integrity sha512-64HkdiRv1yYZsSe4xC1WVgamNigVYjlssIoaH2HcZF0+ijsk5YK2g0G34w9wJkze8+5ow4STd22AynfO6ZYYLw== +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" From 09fe49eb34a7bdb062ea04fa3c4f606c5f77b414 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 17 Jun 2019 22:48:38 +1000 Subject: [PATCH 4/5] add white space --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ef89cf44..ed284eb34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## v6.0.3 -* [Upgrade typescript version to 3.5.2](https://github.com/TypeStrong/ts-loader/pull/954)(#954) - thanks @fa93hws +* [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! From 839e6fe567e5c0b05355b85cc91489dd08f36d8a Mon Sep 17 00:00:00 2001 From: John Reilly Date: Mon, 17 Jun 2019 18:01:00 +0100 Subject: [PATCH 5/5] make type of clearCache consistent --- src/servicesHost.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/servicesHost.ts b/src/servicesHost.ts index f8eeef08d..6415bafa1 100644 --- a/src/servicesHost.ts +++ b/src/servicesHost.ts @@ -65,7 +65,7 @@ export function makeServicesHost( compiler.sys.fileExists(filePathToCheck) || readFile(filePathToCheck) !== undefined; - let clearCache: null | (() => void) = null; + let clearCache: Action | null = null; let moduleResolutionHost: ModuleResolutionHost = { fileExists, readFile: readFileWithFallback,