1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/read.js

23 lines
385 B
JavaScript
Raw Normal View History

2016-10-08 12:01:58 +00:00
import fs from 'mz/fs'
import resolve from './resolve'
const cache = {}
/**
* resolve a file like `require.resolve`,
* and read and cache the file content
*/
async function read (path) {
const f = await resolve(path)
let promise = cache[f]
if (!promise) {
promise = cache[f] = fs.readFile(f, 'utf8')
}
return promise
}
module.exports = read
exports.cache = cache