lru.ts 450 B

1234567891011121314151617
  1. import * as createLRU from 'lru-cache'
  2. import * as fs from 'fs'
  3. const lru = createLRU({ max: 256, maxAge: 250 })
  4. const origLstat = fs.realpathSync.bind(fs)
  5. // NB: The biggest offender of thrashing realpathSync is the node module system
  6. // itself, which we can't get into via any sane means.
  7. require('fs').realpathSync = function (p) {
  8. let r = lru.get(p)
  9. if (r) {
  10. return r
  11. }
  12. r = origLstat(p)
  13. lru.set(p, r)
  14. return r
  15. }