Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade typescript version #954

Merged
merged 5 commits into from Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.1",
"webpack": "^4.5.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we go for TypeScript 3.5.2 since it's out?

Copy link
Contributor Author

@fa93hws fa93hws Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem!
The version goes so quick

"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: null | (() => void) = 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.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"
Expand Down