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

File System Paths in sources #44

Open
mitsuhiko opened this issue May 17, 2023 · 4 comments
Open

File System Paths in sources #44

mitsuhiko opened this issue May 17, 2023 · 4 comments

Comments

@mitsuhiko
Copy link
Contributor

mitsuhiko commented May 17, 2023

This relates to the conversation about sources from #42. There is something curious going on with sources today in practice and it relates to how filenames and URLs are handled. An entry in sources is relative to the source map and the source map is relative to the transpiled javascript file. This makes sense, but in practice you will see that people stash actual file names into sources which are not on the same "namespace" or "origin" as the script.

Specifically in theory you can have https://foo.invalid/app/whatever.js as the minified file, then that refers to whatever.js.map which contains a sources entry called whatever.js which however is not the generated whatever.js but the original whatever.js (before minification). Strict reading of the specification says that this is illegal. In fact, quite a bit of tooling relies on the fact that source files are in fact placed somewhere on the same URL namespace so they can be fetched, but in practice it just happens that source refer to paths as they were on the file system originally. Some tools emit webpack://foo or similar to "move" files into a separate independent namespace, but I have also seen tools throw things like /path/to/builder into the structure. On Windows I have even see drive letters pop up which are definitely not valid URLs.

One effect can also be that the path moves past the URL root. I have seen a source map at /dist/foo.map which itself contains sources that are at ../../../node_modules/foo.js.

I'm not sure if this particularly actionable, but maybe there should be some guidances around what is acceptable and what is not.

@mitsuhiko mitsuhiko changed the title File System Paths in Sources File System Paths in sources May 17, 2023
@jaro-sevcik
Copy link
Contributor

In Chrome, we have struggled with several issues around source paths:

@nicolo-ribaudo
Copy link
Member

I have been exploring how Babel handles this, and it is... terrible. Apparently we just put the filename in sources, and not a path. babel/babel#15911 is partially changing it to use paths relative to the cwd when compiling (that usually matches with the project root), but I'm not really sure about what we should do.

@mitsuhiko
Copy link
Contributor Author

I would be super curious if there is some sort of best practice at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants