Cache buble/register transformations
This speeds up app startup with buble/register
by caching transformations. On reading a file, it creates a SHA256 hash of the source code, then attempts to read the contents of $HOME/.buble-cache/{node_version}/{hash}.json
. If it succeeds, it uses those contents, otherwise it does the transformation and saves the result to that file. It speeds up Bublé's own tests by about half a second.
I considered doing it on a per-filename basis with fs.statSync
and mtime
, but fs.readFileSync
and SHA256 are so fast that there's really no point. This approach saves retransforming identical files that exist in multiple locations.