-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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: use relative paths in sources
for transformed source maps
#12079
fix: use relative paths in sources
for transformed source maps
#12079
Conversation
c135fca
to
b81a561
Compare
Let's make sure to run this PR against the ecosystem CI once the Vite tests are passing |
b81a561
to
0bad9e6
Compare
sources
for esbuildsources
for esbuild
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
About ecosystem-ci: the Qwik fail should be unrelated, and the vite-plugin-vue fail is due to outdated snapshots. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this PR with plugin-vue and plugin-react.
By running playground/vue in plugin-vue repo with this branch, I saw some of them working and some of them not working. (playground/vue
doesn't have css.devSourcemap
enabled)
The result with playground/react in plugin-react was:
I guess these requires a fix on the plugin side and I think it's fine to merge this PR.
Though I think we should not merge this until the minor beta period as this requires other plugins to update their sourcemap handlings.
How do I "run" the playgrounds? |
The steps to run the playground of plugin-vue/plugin-react repos are:
|
The |
No, I don't think these are artifacts of the playground setup. I guess |
Ooohhhh, you're right. It never occurred to me that we also need to pay special attention to potential Windows paths in sourcemaps. I'll dig into that (https://crbug.com/1417564). |
Quick follow up here: After some discussion with the team, there's nothing we can do about this in DevTools, since The correct fix here is to avoid putting absolute (Windows) paths into source maps in the first place. |
I have a fix for the |
I was just discussing this with @danielroe and we might need to move this a layer up. Please don't merge this yet. |
0bad9e6
to
bfca7dc
Compare
sources
for esbuildsources
for transformed source maps
Based on the session earlier with @danielroe, I now changed the patch to hook into the choke-point after the transformer is called, which seems to completely fix it for Vue and React! |
bfca7dc
to
f58ebde
Compare
map.sources[sourcesIndex] = path.relative( | ||
path.dirname(mod.file), | ||
sourcePath, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sapphi-red just checking here that this path.relative
call won't be affected by issues like the one you were worried about with paths in different drives on windows that can't be expressed as relative paths. I assume the path would be returned as absolute in this case. To be honest, maybe we should document having Vite work across hard drives as out of scope if this will increase complexity for everyone else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows also has this concept of relative paths with drive letters, which I think would also break vite.
I suppose instead of using path.relative
here, we could also do string gymnastics ourselves, but that likely would be even worse / unpredictable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the path would be returned as absolute in this case.
Yes, you're correct. I think we can ignore the cross drive usage as it doesn't work in many places already at least for now.
This refines the fix from vitejs#4985 to turn absolute paths into relative paths for the `sources` array in source maps for transformer outputs (and thereby completely avoids the Windows drive letter problem). In order to minimize unintended negative side effects, we perform this step only when the source file name is absolute. This addresses the issue that source files show up with an absolute path prefix in case of Vue[^1]. Bug: https://crbug.com/1411596 Ref: vitejs#4964 Ref: vitejs#4912 [^1]: https://goo.gle/devtools-vite-interoperability
1c53299
to
172c3e3
Compare
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
ecosystem-ci looks good now, fails are the same as current ones against |
Because we trigger the CI by app, I guess just adding the username here might work. vite/.github/workflows/ecosystem-ci-trigger.yml Lines 18 to 31 in 3d3788d
|
Alright, thanks folks. So this is ready to land then? |
Yes, let's merge it so we can test it during the 4.2 beta period |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm late but looks good to me 👍
@patak-dev this broke Vitest's typechecking feature (it relies on |
@sheremet-va That doesn't sound reliable. Couldn't vitest simply resolve relative entries in |
I am not sure what you mean by "other tools". esbuild, for example, returns absolute paths. |
And it doesn't seem like Vite returns "sourceRoot" that can be used to identify the actual path. |
This is not about source map generators; for those it's perfectly valid to put relative paths (or just file names) into the This is about source map consumers, and vitest is one of those consumers, just like debuggers (i.e. browser devtools) and other tools like bundlers or post-mortem stack processors; for consumers the Source Map Revision 3 Proposal states how to resolve
|
Vite's Another thing is that |
In the end, Vitest modifies all maps to have absolute sources because this is how other tools consume it in Node.js environment, as far as I can see (e.g., source-map-support) |
Without having the specific context of vitest, my reading of this would be that vite should supply the necessary information for tools to properly resolve |
Also, as far as I understood this doesn't rule out the fact that source map's "sources" can be absolute paths. If there is no const sourceMapUrl = '/absolute`
const map = {
sourceRoot: '',
sources: ['entry.js']
...
}
resolve(sourceMapUrl, map.sources[0]) === '/absolute/entry.js' const sourceMapUrl = '/absolute`
const map = {
sourceRoot: '',
sources: ['/absolute/entry.js']
...
}
map.sourceRoot + map.sources[0] // already absolute, skip next line
resolve(sourceMapUrl, map.sources[0]) === '/absolute/entry.js' |
The current specification does not rule that out, yes. I also don't want to block fixing the vitest feature. It's of course up to @patak-dev to decide whether having a different mode for |
Description
This refines the fix from #4985 to
turn absolute paths into relative paths for the
sources
array insource maps for transformer outputs (and thereby completely avoids the
Windows drive letter problem). In order to minimize unintended negative
side effects, we perform this step only when the source file name is
absolute.
This addresses the issue that source files show up with an absolute path
prefix in case of Vue1.
Additional context
Bug: https://crbug.com/1411596
Ref: #4964
Ref: #4912
What is the purpose of this pull request?
cc @jecfish
Footnotes
https://goo.gle/devtools-vite-interoperability ↩