mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
23 lines
385 B
JavaScript
23 lines
385 B
JavaScript
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
|