* We need to make sure the file reading and parsing is lazy so that failure to * statically analyze the hyper configuration isn't fatal for all kinds of * subcommands. We can use memoization to make reading and parsing lazy.
(fn: T)
| 31 | * subcommands. We can use memoization to make reading and parsing lazy. |
| 32 | */ |
| 33 | function memoize<T extends (...args: any[]) => any>(fn: T): T { |
| 34 | let hasResult = false; |
| 35 | let result: any; |
| 36 | return ((...args: any[]) => { |
| 37 | if (!hasResult) { |
| 38 | result = fn(...args); |
| 39 | hasResult = true; |
| 40 | } |
| 41 | return result; |
| 42 | }) as T; |
| 43 | } |
| 44 | |
| 45 | const getFileContents = memoize(() => { |
| 46 | try { |