Skip to content

leading slash of compileOptions.filename is stripped in output, breaking absolute paths #8343

Open
@dominikg

Description

@dominikg

Describe the bug

The svelte compiler adds information about the compiled files filename to the output. While doing so, it strips cwd and a leading slash.

Stripping the leading slash breaks absolute paths that don't start with cwd as the result would be

home/user/some/path/to/Component.svelte

which is relative and does not exist within cwd (/home/user/elsewhere/)

This results in svelte-inspector not being able to open components referenced via absolute paths, which can happen in a monorepo setup, see vite discord: https://discord.com/channels/804011606160703521/1075471833442287677

Strip happens here: https://github.com/sveltejs/svelte/blob/master/src/compiler/compile/Component.ts#L144
Introduced here: #1499

My best guess for a fix is that it should only strip the slash if it has stripped cwd, leaving other absolute paths alone.

Reproduction

Not reproducible in repl as process isn't defined there

go to https://vite.new/svelte , inspect the site with the counter button, enter document.getElementsByTagName('button')[0].__svelte_meta.loc.file in console and note that the path does not start with a /

document.getElementsByTagName('button')[0].__svelte_meta.loc.file
'src/lib/Counter.svelte'

Logs

n/a

System Info

linux, svelte 3.55.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions