Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.
This repository was archived by the owner on Oct 2, 2021. It is now read-only.

Support manual override of sourceRoot #44

Closed

Description

@roblourens

There's a bug in gulp-sourcemaps < 2.0.0-alpha where it uses sourceRoot: /source/ by default. This impacts ionic, the ionic2 beta so far, and anyone else using gulp-sourcemaps directly or indirectly. The result is that the file path data in the sourcemap is simply wrong, but the source content is inlined, so it doesn't matter for browser devtools.

In the Ionic case, I honestly can't figure out how to set the sourceRoot from the gulpfile. But it would be really easy to have an option in the launch config to override the sourceRoot globally or for app.bundle.js.

Ignore this, I ended up doing it differently

"sourceRoot": "${workspaceRoot}"
...
"sourceRoot": "/.." // Looks like nonsense but the proper sourceRoot for the default Ionic2 config is the directory above the webRoot
...
"sourceRoot": {
    "bundle.js.map": "${workspaceRoot}",
    "bundle*": "${workspaceRoot}",
    "somethingElse.js.map": "c:\\project\\src"
}

Obviously it's better to fix your build config but this might be nice to get us through this gulp-sourcemaps bug, maybe combined with better logging and optional webRoot.

Activity

  1. added this to the milestone on Jul 6, 2016
  2. roblourens commented on Jul 7, 2016

    @roblourens
    MemberAuthor

    webpack and meteor also need the sources entries to be modified. And it would be great if this was doable without actually reading the sourcemap file. So it might make sense to have mappings for full paths, not sourceRoot or some other individual property.

    These would be applied after doing the 'sourceRoot' + 'sources' operation. After applying the mapping, it would continue to be resolved as usual relative to the sourcemap location or webRoot, if needed.

    On the right hand side of a mapping, "/something" is interpreted as a local path, not a path on the url, because there's no way to tell the difference. But on the left, "/something" is interpreted as a path from the url. What would we do when the right side is not an absolute path? I don't know what would make sense. So the right side should be required to be an absolute path.

    "sourceMapSourceOverrides": {
        "webpack:///*": "${workspaceRoot}/*", // Remove webpack://
        "webpack:///*": "${webRoot}/*", // Remove webpack://, resolve relative to webRoot
        "meteor:///<pc emoji>app/*": "*", // Remove meteor:///
        "/source/*": "${workspaceRoot}/*", // Remove source/
        "/dist/app/main.js": "${workspaceRoot}/../project/app/main.js", // Replace exact match to local path outside of workspaceRoot
        "main.js": "c:/project/app/main.js", // windows absolute path
        "main.js": "/project/app/main.js", // unix-style absolute path
        "main.js": "http://localhost/main.js", // invalid
        "*/app.js": "/project/src/app.js" // match app.js in any folder
    }
    

    Users can determine what the left side should be by looking at the path in Chrome DevTools.

  3. roblourens commented on Jul 7, 2016

    @roblourens
    MemberAuthor

    We have the sources, sourceRoot, webRoot, and overrides.

    For each source entry:

    1. If there's a sourceRoot specified in the sourceMap, prepend that to the sources entry. Test the result against the overrides. If something was applied, done.
    2. If it starts with file:///, remove file:/// and return that.
    3. Combine the source entry with the computed sourceRoot and return that.
    • 'computed sourceRoot' meaning code in sourceMapUtils.getAbsSourceRoot - produce an absolute local path which is computed from the sourceRoot, webRoot, and the location of the script, as needed.
  4. added a commit that references this issue on Jul 8, 2016
    775288a
  5. mvidailhet commented on Dec 7, 2016

    @mvidailhet

    OK, so after running on the same problems trying to debug our Ionic App, I had to add these lines to make it work:

    "sourceMapPathOverrides": {
        "webpack:///./*":   "${cwd}/*",
        "webpack:///*":     "*",
    },
    

    It seems that the launch.json uses cwd instead of webRoot

  6. locked and limited conversation to collaborators on Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions