fix(nitro): avoid using fs/promises

node 12 compat for vercel
This commit is contained in:
Pooya Parsa 2021-04-23 23:01:00 +02:00
parent 0d92f1a042
commit 47c28551c8

View File

@ -1,4 +1,4 @@
import { readFile, stat } from 'fs/promises' import { promises as fsp } from 'fs'
import type { Plugin } from 'rollup' import type { Plugin } from 'rollup'
import createEtag from 'etag' import createEtag from 'etag'
import mime from 'mime' import mime from 'mime'
@ -81,8 +81,8 @@ export function getAsset (id) {
if (dirOpts.meta) { if (dirOpts.meta) {
let type = mime.getType(id) || 'text/plain' let type = mime.getType(id) || 'text/plain'
if (type.startsWith('text')) { type += '; charset=utf-8' } if (type.startsWith('text')) { type += '; charset=utf-8' }
const etag = createEtag(await readFile(fsPath)) const etag = createEtag(await fsp.readFile(fsPath))
const mtime = await stat(fsPath).then(s => s.mtime.toJSON()) const mtime = await fsp.stat(fsPath).then(s => s.mtime.toJSON())
assets[id].meta = { type, etag, mtime } assets[id].meta = { type, etag, mtime }
} }
} }