curiosity-ai / h5

🚀 The next generation C# to JavaScript compiler
https://github.com/curiosity-ai/h5
Apache License 2.0
224 stars 31 forks source link

Sets sourceRoot in the source maps #86

Closed mjrist closed 1 year ago

mjrist commented 1 year ago

Currently the source map generator sets the sourceRoot to the empty string. However, the sources are relative paths to the C# files from the project directory.

Example of current source map:

{
  "version": 3,
  "file": "MyCoolApp.js",
  "sourceRoot": "",
  "sources": [
    "App.cs",
    "views/LogTable.cs",

If building and debugging in the same repo (standard development workflow), the sourceRoot property should be set to the project path. This allows the debugger to locate the source files.

Example: for a project at "/MyRepo/Applications/MyCoolApp" the source map should be:

{
  "version": 3,
  "file": "MyCoolApp.js",
  "sourceRoot": "/MyRepo/Applications/MyCoolApp",
  "sources": [
    "App.cs",
    "views/LogTable.cs",

I tested these changes using vscode with chrome remote debugging and verified it was able to find my code files with the sourceRoot set.

There could be cases in which you might want the sourceRoot to be different than the project directory - E.g. building and debugging in different environments. However, I don't think leaving it empty makes sense. By defaulting to the project directory the source maps will work for most development workflows.

mjrist commented 1 year ago

@theolivenbaum any thoughts on this change? I'm open to suggestions. I've tested this out and it works great for us. We would love to see this merged in.

theolivenbaum commented 1 year ago

@mjrist looks good, thanks for sending the PR!