2020-02-05 15:22:28 +03:00
|
|
|
import * as createLRU from 'lru-cache'
|
2020-02-05 15:16:31 +03:00
|
|
|
import * as fs from 'fs'
|
|
|
|
const lru = createLRU({ max: 256, maxAge: 250 })
|
|
|
|
const origLstat = fs.realpathSync.bind(fs)
|
2018-08-26 18:35:04 +03:00
|
|
|
|
|
|
|
// NB: The biggest offender of thrashing realpathSync is the node module system
|
|
|
|
// itself, which we can't get into via any sane means.
|
|
|
|
require('fs').realpathSync = function (p) {
|
2018-08-31 16:41:28 +03:00
|
|
|
let r = lru.get(p)
|
2020-02-05 15:16:31 +03:00
|
|
|
if (r) {
|
|
|
|
return r
|
|
|
|
}
|
2018-08-26 18:35:04 +03:00
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
r = origLstat(p)
|
|
|
|
lru.set(p, r)
|
|
|
|
return r
|
2018-08-26 18:35:04 +03:00
|
|
|
}
|