Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/vite/src/node/fsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ export function createCachedFsUtils(config: ResolvedConfig): FsUtils {
function getDirentCacheFromPath(
normalizedFile: string,
): DirentCache | false | undefined {
// path.posix.normalize may return a path either with / or without /
if (normalizedFile[normalizedFile.length - 1] === '/') {
normalizedFile = normalizedFile.slice(0, -1)
}
if (normalizedFile === root) {
return rootCache
}
Expand Down
4 changes: 4 additions & 0 deletions playground/resolve/__tests__/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ test('Resolve doesnt interrupt page request with trailing query and .css', async
expect(await page.textContent('h1')).toBe('Resolve')
})

test('resolve non-normalized absolute path', async () => {
expect(await page.textContent('.non-normalized')).toMatch('[success]')
})

test.runIf(!isWindows)(
'Resolve doesnt interrupt page request that clashes with local project package.json',
async () => {
Expand Down
6 changes: 6 additions & 0 deletions playground/resolve/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ <h2>resolve.conditions</h2>
<h2>resolve package that contains # in path</h2>
<p class="path-contains-sharp-symbol"></p>

<h2>resolve non normalized absolute path</h2>
<p class="non-normalized"></p>

<script type="module">
import '@generated-content-virtual-file'
function text(selector, text) {
Expand Down Expand Up @@ -384,6 +387,9 @@ <h2>resolve package that contains # in path</h2>
'.path-contains-sharp-symbol',
`[success] ${contains.call('#', '#')} ${last.call('#')}`,
)

import nonNormalizedAbsolute from '@non-normalized'
text('.non-normalized', nonNormalizedAbsolute)
</script>

<style>
Expand Down
1 change: 1 addition & 0 deletions playground/resolve/non-normalized.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default '[success] non normalized absolute path'
7 changes: 7 additions & 0 deletions playground/resolve/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export default defineConfig({
}
},
},
{
name: 'resolve to non normalized absolute',
async resolveId(id) {
if (id !== '@non-normalized') return
return this.resolve(__dirname + '//non-normalized')
},
},
],
optimizeDeps: {
include: [
Expand Down