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

24 lines
402 B
JavaScript
Raw Normal View History

2016-10-08 12:01:58 +00:00
import fs from 'mz/fs'
import resolve from './resolve'
/**
* resolve a file like `require.resolve`,
* and read and cache the file content
*/
2016-10-17 02:19:42 +00:00
async function read (path) {
2016-10-15 19:49:42 +00:00
const f = await resolve(path)
if (cache.hasOwnProperty(f)) {
return cache[f]
2016-10-08 12:01:58 +00:00
}
2016-10-14 15:05:08 +00:00
2016-10-15 19:49:42 +00:00
const data = fs.readFile(f, 'utf8')
cache[f] = data
return data
2016-10-08 12:01:58 +00:00
}
2016-10-15 19:49:42 +00:00
export default read
export const cache = {}
2016-10-08 12:01:58 +00:00
2016-10-15 19:49:42 +00:00
read.cache = cache