From d717c82dbbda2ecc9939953f2c748320b9a2d49e Mon Sep 17 00:00:00 2001 From: fi3ework Date: Wed, 31 May 2023 02:14:07 +0800 Subject: [PATCH 1/2] fix: remove extra path shorten when resolving from a dir --- packages/vite/src/node/plugins/resolve.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 4b28e810ab2c6e..7083cd27eb561d 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -700,7 +700,11 @@ export function tryNodeResolve( // css processing appends `*` for importer (importer[importer.length - 1] === '*' || fs.existsSync(cleanUrl(importer))) ) { - basedir = path.dirname(importer) + if (tryStatSync(importer)?.isFile()) { + basedir = path.dirname(importer) + } else { + basedir = importer + } } else { basedir = root } From de68bc29c10603d09e7060a4b541eecec2171e8a Mon Sep 17 00:00:00 2001 From: fi3ework Date: Thu, 1 Jun 2023 23:11:50 +0800 Subject: [PATCH 2/2] fix: resolve from package.json --- packages/vite/src/node/optimizer/index.ts | 7 ++++++- packages/vite/src/node/plugins/resolve.ts | 6 +----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 5947305115c548..e476f61d5eef13 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -892,7 +892,12 @@ function createOptimizeDepsIncludeResolver( config.root, config.resolve.preserveSymlinks, ) - return await resolve(nestedPath, basedir, undefined, ssr) + return await resolve( + nestedPath, + path.resolve(basedir, 'package.json'), + undefined, + ssr, + ) } } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 7083cd27eb561d..4b28e810ab2c6e 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -700,11 +700,7 @@ export function tryNodeResolve( // css processing appends `*` for importer (importer[importer.length - 1] === '*' || fs.existsSync(cleanUrl(importer))) ) { - if (tryStatSync(importer)?.isFile()) { - basedir = path.dirname(importer) - } else { - basedir = importer - } + basedir = path.dirname(importer) } else { basedir = root }