-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add a new project root option (fixes #1513). #2034
Conversation
When generating source maps, if the sourceRoot option is specified and the projectRoot is specified, then the filenames that appear in the "sources" field of the source map are relative to the projectRoot.
Hi @msprotz, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
This is a preliminary pull request to discuss the proposed change. (There's no test at the moment.) I'd be happy to know whether the change looks good, or if you'd rather have me modify something. Thanks, Jonathan |
Thanks for the PR. +1 for the flag, i think it is a common pain point and we need to fix it. A few comments though,
|
Thanks for the review!
Which files get generated, and where they get generated, remains unchanged. Furthermore, there is no way the code can figure out by itself that the common source root is |
Sorry for the delay. yes that is one application of a commonRoot, other ones are related to --outDir use, where you want to mimic the input directory structure in the output (this is where my overwrite comment fits). I thnink plugging this in the common path calculation would work for outDir as well as your scenario, is that accurate? |
@msprotz can you refresh and resubmit? |
Shouldn't commonSourceRoot be driven by the location of tsconfig.json ? |
it think this is fair. currently it is the longest common path of all input files.. so
so the common root is a\c |
I would expect:
the common root to be Consider
i.e copy the entire structure starting from |
i think this makes sense. I would say we need a new commandline argument, to allow you to change that if you are not using a tsconfig.json or you want to modified. i am thinking of --commonSourceRoot. |
The suggestions above definitely make sense, both for the output file hierarchy and the source maps. The trick about using tsconfig.json or, if no such file is present, an option, seems good to me. (--commonSourceRoot is fine, I also thought of it in #2034 (comment)). I just need to update the patch so that the option is also used when computing the output file names. I'll try to find some time to do that soon. |
I've requested something like this in the past, I called it I also like it to be implict now that we have tsconfig.json. Don't want to end up with:
where
|
@basarat, as i started working on this I realized that the implicit tsconfig.json path will not work, as the rootDir/baseDir has to encompass all input files, but tsconfig.json does not have this restriction. "files" property can reference files outside the directory, and /// references as well as imports can pull in files from outside the directory. we do not want to make these an error, specially that you only care about this if you have outDir. you can always specify a rootDir in your tsconfig to always be "." to work around this. |
Okay ❤️ |
Worth mentioning: If someone does that then they are going to have a really hard time if they open a file that doesn't have |
When generating source maps, if the sourceRoot option is specified and the
projectRoot is specified, then the filenames that appear in the "sources" field
of the source map are relative to the projectRoot.