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
2016-10-16 04:49:42 +09:00

24 lines
413 B
JavaScript

import fs from 'mz/fs'
import resolve from './resolve'
/**
* resolve a file like `require.resolve`,
* and read and cache the file content
*/
async function read (path, opts = {}) {
const f = await resolve(path)
if (cache.hasOwnProperty(f)) {
return cache[f]
}
const data = fs.readFile(f, 'utf8')
cache[f] = data
return data
}
export default read
export const cache = {}
read.cache = cache