plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.25k stars 44 forks source link

Cache ability #15

Closed darky closed 5 years ago

darky commented 5 years ago

type-coverage spends lot of time to check big project. Need to have ability for caching file, that already checked and recheck it again, if file hash changed

plantain-00 commented 5 years ago

The CLI just run once every time. What's your use case? Are you expecting --watch?

darky commented 5 years ago

No --watch Would be better to have something like --cache and type-coverage create cache folder like .type-coverage, which contains sha1 or md5 hash signatures or checked files If cache contains hash singature of file, no need to check it, simply skip it. Otherwise need check and if file is ok, cache it.

plantain-00 commented 5 years ago

That may cause a wrong result, for example:

// a.ts
export const foo = 1 // if change type of `foo` to `any`, then `bar` in `b.ts` will be `any` too, even `b.ts` is not changed

// b.ts
import { foo } from './a.ts'

const bar = foo

Type check is a semantic analysis operation, rather than lexical analysis operation.

plantain-00 commented 5 years ago

This tool calls typescript API, typescript can cache by reusing the old Program object, but I cannot find a way to serialize/deserialize the Program object

darky commented 5 years ago

That may cause a wrong result, for example:

// a.ts
export const foo = 1 // if change type of `foo` to `any`, then `bar` in `b.ts` will be `any` too, even `b.ts` is not changed

// b.ts
import { foo } from './a.ts'

const bar = foo

Type check is a semantic analysis operation, rather than lexical analysis operation.

Maybe for resolving this problem some dependency tree package can help like this: https://github.com/dependents/node-dependency-tree

You can ignore cache of changed file and all files, that depends on changed file

plantain-00 commented 5 years ago

v1.10.0 support --cache now

darky commented 5 years ago

Great! Thanks so very much!)) I will test it tomorrow and if all ok, close this issue)

darky commented 5 years ago

Seems all fine, but slight increase in performance. Only 1-2 sec, elapsed time 13s -> 11s

darky commented 5 years ago

Now it 30s vs 16s Seems ok :)