rsnext/packages/next/lib/file-exists.ts
Xinzi Zhou 9609fe453d Replace fs.exists with fs.access (#7742)
* Replace deprecated fs.exists with fs.access.

* Update packages/next/lib/file-exists.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Update packages/next/lib/file-exists.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>
2019-07-16 23:01:21 -07:00

16 lines
328 B
TypeScript

import fs from 'fs'
import { promisify } from 'util'
const access = promisify(fs.access)
export async function fileExists(fileName: string): Promise<boolean> {
try {
await access(fileName, fs.constants.F_OK)
return true
} catch (err) {
if (err.code === 'ENOENT') {
return false
}
throw err
}
}