Skip to content

Commit

Permalink
fix(nitro): skip non existing externals (nuxt#1876)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
  • Loading branch information
tobiasdiez and pi0 authored Nov 15, 2021
1 parent c339966 commit a7eacfe
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/nitro/src/rollup/plugins/externals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fsp } from 'fs'
import { resolve, dirname } from 'pathe'
import fse from 'fs-extra'
import { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft'
import type { Plugin } from 'rollup'

Expand Down Expand Up @@ -86,14 +86,11 @@ export function externals (opts: NodeExternalsOptions): Plugin {
}

const writeFile = async (file) => {
// Skip symlinks that are included in fileList
if (await fse.stat(file).then(i => i.isDirectory())) {
return
}
if (!await isFile(file)) { return }
const src = resolve(opts.traceOptions.base, file)
const dst = resolve(opts.outDir, 'node_modules', file.split('node_modules/').pop())
await fse.mkdirp(dirname(dst))
await fse.copyFile(src, dst)
await fsp.mkdir(dirname(dst), { recursive: true })
await fsp.copyFile(src, dst)
}
if (process.platform === 'win32') {
// Workaround for EBUSY on windows (#424)
Expand All @@ -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
}
}

0 comments on commit a7eacfe

Please sign in to comment.