mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 01:17:16 +00:00
fix(nitro): skip non existing externals (#1876)
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
parent
c339966fad
commit
a7eacfed88
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user