-
-
Notifications
You must be signed in to change notification settings - Fork 99
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(vitePreprocess): use relative paths in sourcemap sources and output css dependencies #625
Conversation
The removeSuffix implementation might be too aggressive in changing the sources and a hair slower, compared to the exact match implementation we had before, but the chances a developer is creating The Should we add standalone unittests for the
and the variant with a sourceRoot:
or would that be overkill? |
no, the additional unit tests for the util sound like a good idea. While trying to fix the windows fail (god those fs paths on windows are a pita) i've come across the fact that vitePreprocess can also emit |
Oh, and is a sourcesRoot is set, it would have to account for that when turning the path to a relative one. Although having a sourcesRoot and then absolute entries in sources counts as a crime against tooling developers 👿 |
The endsWith implementation was done because it's possible that vite already rewrites the path and then we would no longer strip the suffix. The case that someone has eg cc @bluwy |
the unique suffix separator actually simplifies suffix removal and avoids the userspace collisions. 🥳 |
Dear microsoft, please get rid of drive letters and use / . Thanks |
import { fileURLToPath } from "url" is useful for handling file urls. Yeah, working with files on windows is complicated. Had an issue a while back because some node ap'si return c: (lowercase) and some apis return C: (uppercase) |
sourceRoot can actually be a problem when converting to relative. We can't convert some and leave sourceRoot intact, that could end up with invalid paths when sourceroot is prepended to the relative output. So if sourceRoot is set, we have to make sure all paths are converted to relative and then unset it? damn this stuff is messy |
What is the reason we do the conversion to relative? Can we assume the sources are correct if the map contains a sourceRoot? |
Unfortunately I don't think we can. It's possible that no tool used by vite currently emits sourcemaps with sourceRoot set, but if one did, it would have to be accounted for and if sourceRoot+source turned out to be an absolute path, that would be bad. Always using relative paths from the location of the sourcemap (sibling of the file it maps) prevents leaking file system information like your home directory and is required for reproducible builds. source paths are also used by the svelte compiler later on to merge sourcemaps with the additional work it is doing, so it is helpful if we only send one consistent output to that, not sometimes sourceroot, sometimes absolute paths, sometimes relative. Ideally it would be relative paths only all the time. |
I didn't think about sourcemap as an attack vector, but changing absolute |
It's not about paths outside of vite root, thats a different problem. In both locations, the sourcemaps produced by |
I see, still think that's vite problem, not a vite-plugin issue. When running a build, vite should always generate relative sourcemaps. |
@bmeurer - sorry to cold-tag you here but i'd love to pick your brain on a way to safely convert all file references in a sourcemap to relative paths, regardless of what they are. This PR contains a function that achieves it in my opinion for outputs of vite's css transform, which surprisingly can even container One area where i am not 100% sure is how |
FWIW, Vite uses |
The specification isn't really clear here. I went with just |
went with fileURLToPath after all to avoid encoded chars being a problem and also adding a single slash between sourceRoot and source. While not sure this is perfect, i assume this is as close as it gets within the spec. sourceRoot is not prepended to file:/// style sources as that doesn't make any sense |
@bfanger readded your e2e test for dev sourcemap but sprouced it up with an scss import and changing the assertions from snapshot to decoding the sourcemap comment to see that files are there. During all this I also realized we didn't pass on the dependencies, this has been added as well to allow better hmr experience when editing these |
…h use as it turns out there can be file:///<not-absolute-path> inputs wtf
based on the work done in #621 by @bfanger , but uses a unit test and more generic implementation.