Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: importActual path resolution for non-child paths (fix #1864) #1868

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/vite-node/src/utils.ts
@@ -1,4 +1,5 @@
import { fileURLToPath, pathToFileURL } from 'url'
import { existsSync } from 'fs'
import { relative, resolve } from 'pathe'
import type { TransformResult } from 'vite'
import { isNodeBuiltin } from 'mlly'
Expand Down Expand Up @@ -75,13 +76,18 @@ export function pathFromRoot(root: string, filename: string) {
}

export function toFilePath(id: string, root: string): string {
let absolute = id.startsWith('/@fs/')
? id.slice(4)
: id.startsWith(root)
? id
: id.startsWith('/')
? resolve(root, id.slice(1))
: id
let absolute = (() => {
if (id.startsWith('/@fs/'))
return id.slice(4)
if (!id.startsWith(root) && id.startsWith('/')) {
const resolved = resolve(root, id.slice(1))
// The resolved path can have query values. Remove them before checking
// the file path.
if (existsSync(resolved.replace(/\?.*$/, '')))
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
return resolved
}
return id
})()

if (absolute.startsWith('//'))
absolute = absolute.slice(1)
Expand Down
116 changes: 44 additions & 72 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.