Skip to content

Commit 55bba7b

Browse files
authored
fix: resolve root to real path (#22832)
1 parent 9beae37 commit 55bba7b

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎packages/vite/src/node/__tests__/config.spec.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,9 @@ describe('loadConfigFromFile', () => {
19831983
const config = await resolveConfig({ root: tempDir }, 'serve')
19841984

19851985
expect(config.cacheDir).toBe(
1986-
normalizePath(path.resolve(tempDir, 'node_modules/.vite')),
1986+
normalizePath(
1987+
path.resolve(fs.realpathSync.native(tempDir), 'node_modules/.vite'),
1988+
),
19871989
)
19881990
})
19891991

@@ -1994,7 +1996,7 @@ describe('loadConfigFromFile', () => {
19941996
const config = await resolveConfig({ root: tempDir }, 'serve')
19951997

19961998
expect(config.cacheDir).toBe(
1997-
normalizePath(path.resolve(tempDir, '.vite')),
1999+
normalizePath(path.resolve(fs.realpathSync.native(tempDir), '.vite')),
19982000
)
19992001
})
20002002
})

‎packages/vite/src/node/config.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import {
104104
normalizeAlias,
105105
normalizePath,
106106
resolveHostname,
107+
safeRealpathSync,
107108
setupRollupOptionCompat,
108109
} from './utils'
109110
import {
@@ -1593,9 +1594,13 @@ export async function resolveConfig(
15931594
}
15941595

15951596
// resolve root
1596-
const resolvedRoot = normalizePath(
1597-
config.root ? path.resolve(config.root) : process.cwd(),
1598-
)
1597+
let nonNormalizedResolvedRoot = config.root
1598+
? path.resolve(config.root)
1599+
: process.cwd()
1600+
try {
1601+
nonNormalizedResolvedRoot = safeRealpathSync(nonNormalizedResolvedRoot)
1602+
} catch {}
1603+
const resolvedRoot = normalizePath(nonNormalizedResolvedRoot)
15991604

16001605
checkBadCharactersInPath(
16011606
'The project root',

0 commit comments

Comments
 (0)