fix(nitro): skip non existing externals (#1876)

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
Tobias Diez 2021-11-15 20:13:54 +01:00 committed by GitHub
parent c339966fad
commit a7eacfed88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import { promises as fsp } from 'fs'
import { resolve, dirname } from 'pathe' import { resolve, dirname } from 'pathe'
import fse from 'fs-extra'
import { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft' import { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft'
import type { Plugin } from 'rollup' import type { Plugin } from 'rollup'
@ -86,14 +86,11 @@ export function externals (opts: NodeExternalsOptions): Plugin {
} }
const writeFile = async (file) => { const writeFile = async (file) => {
// Skip symlinks that are included in fileList if (!await isFile(file)) { return }
if (await fse.stat(file).then(i => i.isDirectory())) {
return
}
const src = resolve(opts.traceOptions.base, file) const src = resolve(opts.traceOptions.base, file)
const dst = resolve(opts.outDir, 'node_modules', file.split('node_modules/').pop()) const dst = resolve(opts.outDir, 'node_modules', file.split('node_modules/').pop())
await fse.mkdirp(dirname(dst)) await fsp.mkdir(dirname(dst), { recursive: true })
await fse.copyFile(src, dst) await fsp.copyFile(src, dst)
} }
if (process.platform === 'win32') { if (process.platform === 'win32') {
// Workaround for EBUSY on windows (#424) // Workaround for EBUSY on windows (#424)
@ -107,3 +104,13 @@ export function externals (opts: NodeExternalsOptions): Plugin {
} }
} }
} }
async function isFile (file: string) {
try {
const stat = await fsp.stat(file)
return stat.isFile()
} catch (err) {
if (err.code === 'ENOENT') { return false }
throw err
}
}