Skip to content

Commit 8413052

Browse files
lazergsapphi-red
andauthored
fix: respect resolve.preserveSymlinks when resolving root (fix #23197) (#23198)
Co-authored-by: sapphi-red <green@sapphi.red>
1 parent 7ec81e2 commit 8413052

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,28 @@ describe('loadConfigFromFile', () => {
20372037
})
20382038
})
20392039

2040+
describe('root resolution', () => {
2041+
const fixtureRoot = path.resolve(
2042+
import.meta.dirname,
2043+
'./fixtures/config/root-resolution',
2044+
)
2045+
const realDir = path.join(fixtureRoot, 'real')
2046+
const linkDir = path.join(fixtureRoot, 'link')
2047+
2048+
test('resolves a symlinked root to its real path', async () => {
2049+
const config = await resolveConfig({ root: linkDir }, 'serve')
2050+
expect(config.root).toBe(normalizePath(fs.realpathSync.native(realDir)))
2051+
})
2052+
2053+
test('keeps a symlinked root when resolve.preserveSymlinks is true', async () => {
2054+
const config = await resolveConfig(
2055+
{ root: linkDir, resolve: { preserveSymlinks: true } },
2056+
'serve',
2057+
)
2058+
expect(config.root).toBe(normalizePath(linkDir))
2059+
})
2060+
})
2061+
20402062
describe('resolveServerOptions', () => {
20412063
const warnFn = vi.fn()
20422064
const logger = { warn: warnFn } as unknown as Logger
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
real
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

packages/vite/src/node/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,9 +1600,11 @@ export async function resolveConfig(
16001600
let nonNormalizedResolvedRoot = config.root
16011601
? path.resolve(config.root)
16021602
: process.cwd()
1603-
try {
1604-
nonNormalizedResolvedRoot = safeRealpathSync(nonNormalizedResolvedRoot)
1605-
} catch {}
1603+
if (!config.resolve?.preserveSymlinks) {
1604+
try {
1605+
nonNormalizedResolvedRoot = safeRealpathSync(nonNormalizedResolvedRoot)
1606+
} catch {}
1607+
}
16061608
const resolvedRoot = normalizePath(nonNormalizedResolvedRoot)
16071609

16081610
checkBadCharactersInPath(

0 commit comments

Comments
 (0)