From d9435ce8d55b69b80a40e4a30c5e17a590df6b7c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 12 Nov 2021 02:33:03 +0100 Subject: [PATCH 1/3] fix(nitro): Properly handle packages with no package.json --- packages/nitro/src/rollup/plugins/externals.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nitro/src/rollup/plugins/externals.ts b/packages/nitro/src/rollup/plugins/externals.ts index e8403e33241..ed6660e7990 100644 --- a/packages/nitro/src/rollup/plugins/externals.ts +++ b/packages/nitro/src/rollup/plugins/externals.ts @@ -87,7 +87,7 @@ 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())) { + if (await fse.stat(file).then((i) => i.isDirectory()).catch(() => true)) { return } const src = resolve(opts.traceOptions.base, file) From a23501f11147d7db2c9ab4b9cb262e9ba762553d Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 15 Nov 2021 13:17:49 +0100 Subject: [PATCH 2/3] Fix style --- packages/nitro/src/rollup/plugins/externals.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nitro/src/rollup/plugins/externals.ts b/packages/nitro/src/rollup/plugins/externals.ts index ed6660e7990..e64c9d39e62 100644 --- a/packages/nitro/src/rollup/plugins/externals.ts +++ b/packages/nitro/src/rollup/plugins/externals.ts @@ -87,7 +87,7 @@ 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()).catch(() => true)) { + if (await fse.stat(file).then(i => i.isDirectory()).catch(() => true)) { return } const src = resolve(opts.traceOptions.base, file) From fee8ed4978444d16a3baa9e66043072e08ceb94e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 15 Nov 2021 20:08:37 +0100 Subject: [PATCH 3/3] refactor: isFile utility --- .../nitro/src/rollup/plugins/externals.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/nitro/src/rollup/plugins/externals.ts b/packages/nitro/src/rollup/plugins/externals.ts index e64c9d39e62..49b03def1b3 100644 --- a/packages/nitro/src/rollup/plugins/externals.ts +++ b/packages/nitro/src/rollup/plugins/externals.ts @@ -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' @@ -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()).catch(() => true)) { - 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) @@ -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 + } +}