Description
I was recently compiling TypeScript files into JavaScript using tsc
with the --sourcemap
option set. And I noticed that the paths in the "sources" field of the generated source-map changed in different ways depending on how I set the --sourceRoot
option. I always used the absolute path of the TS files when compiling. So here are the different scenarios I was getting:
- When I don't supply the
--sourceRoot
option, I get a source-map that has only the filename in the "sources" field. And, the "sourceRoot" field is empty. - When I supply
/
or any other value as the--sourceRoot
option, then I get a source-map where the "sourceRoot" field is appropriately set, but the value of the "sources" field is some relative path to the TS file.
And it seems that the relative path doesn't follow any trend when I checked with different files. But most importantly, this behavior is only present when I tried to compile an individual TS file that has references to external modules. I was not able to reproduce it with a simple TS file that doesn't have any references. In the case of a simple TS file, it didn't matter how I passed the --sourceRoot
option. The "sources" field only had the filename as the value. And in addition, the "soruceRoot" was set to the respective value.
So the only assumption I was able to make is that this path in the "sources" field is affected when the TS file to be compiled is referencing other external modules. I would appreciate any help in regards to this problem I am having. How is the value of the "sources" field computed when the source-map is generated?
Cheers!