Skip to content

Commit

Permalink
fix(vite-node): remove suffix slash on file protocol for window (#6109)
Browse files Browse the repository at this point in the history
  • Loading branch information
syi0808 committed Jul 15, 2024
1 parent 407f12f commit 93ebdef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/vite-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export function normalizeRequestId(id: string, base?: string): string {
.replace(/^\/@id\/__x00__/, '\0') // virtual modules start with `\0`
.replace(/^\/@id\//, '')
.replace(/^__vite-browser-external:/, '')
.replace(/^file:/, '')
.replace(/^\/+/, '/') // remove duplicate leading slashes
.replace(/^file:(\/+)/, isWindows ? '' : '/') // remove file protocol and duplicate leading slashes
.replace(/\?v=\w+/, '?') // remove ?v= query
.replace(/&v=\w+/, '') // remove &v= query
.replace(/\?t=\w+/, '?') // remove ?t= query
Expand Down
15 changes: 15 additions & 0 deletions test/core/test/write-file-dynamic-import.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { unlinkSync, writeFileSync } from 'node:fs'
import { pathToFileURL } from 'node:url'
import { afterEach, expect, it } from 'vitest'

const filename = 'bar.js'

afterEach(() => unlinkSync(filename))

it('write file and import created file it should return created content.', async () => {
writeFileSync(filename, 'export default 123')

const mod = await import(pathToFileURL(filename).href)

expect(mod.default).toBe(123)
})

0 comments on commit 93ebdef

Please sign in to comment.