Skip to content

Commit

Permalink
chore: ensure root without trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Dec 10, 2023
1 parent 7c562d2 commit 6c1b741
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vite/src/node/fsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
normalizePath,
safeRealpathSync,
tryStatSync,
withoutTrailingSlash,
} from './utils'

export interface FsUtils {
Expand Down Expand Up @@ -142,7 +143,7 @@ function pathUntilPart(root: string, parts: string[], i: number): string {
}

export function createCachedFsUtils(config: ResolvedConfig): FsUtils {
const { root } = config
const root = withoutTrailingSlash(config.root)
const rootDirPath = `${root}/`
const rootCache = { type: 'directory' as DirentCacheType } // dirents will be computed lazily

Expand Down
7 changes: 7 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ export function withTrailingSlash(path: string): string {
return path
}

export function withoutTrailingSlash(path: string): string {
if (path[path.length - 1] === '/') {
return path.slice(0, -1)
}
return path
}

/**
* Check if dir is a parent of file
*
Expand Down

0 comments on commit 6c1b741

Please sign in to comment.