2021-12-06 18:13:26 +00:00
|
|
|
import LRU from 'lru-cache'
|
2020-02-05 12:16:31 +00:00
|
|
|
import * as fs from 'fs'
|
2020-12-24 13:03:14 +00:00
|
|
|
const lru = new LRU({ max: 256, maxAge: 250 })
|
2020-02-05 12:16:31 +00:00
|
|
|
const origLstat = fs.realpathSync.bind(fs)
|
2018-08-26 15:35:04 +00: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 13:41:28 +00:00
|
|
|
let r = lru.get(p)
|
2020-02-05 12:16:31 +00:00
|
|
|
if (r) {
|
|
|
|
return r
|
|
|
|
}
|
2018-08-26 15:35:04 +00:00
|
|
|
|
2018-08-31 13:41:28 +00:00
|
|
|
r = origLstat(p)
|
|
|
|
lru.set(p, r)
|
|
|
|
return r
|
2018-08-26 15:35:04 +00:00
|
|
|
}
|