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

VS Code breakpoints not hit due to incorrect paths in sourcemap sources #1117

Closed
AquilaSands opened this issue Jun 14, 2019 · 2 comments

Comments

@AquilaSands
Copy link

commented Jun 14, 2019

I'm submitting a bug report

  • Library Version:
    1.0.0

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    12.3.1

  • NPM Version:
    6.9.0
  • Browser:
    Chrome

  • Language:
    TypeScript 3.5.1

  • Loader/bundler:
    RequireJS

Current behavior:
When creating a plugin the generated paths for the plugin source files in app-bundle.js.map sources array have duplicated directories e.g.

"sources":["../src/attributes/attributes/color.ts","../src/binding-behaviors/binding-behaviors/primary-click.ts","../src/elements/elements/hello-world.ts","../src/elements/elements/hello-world.css","../src/elements/elements/hello-world.html", ...]

This causes breakpoints set in VS Code to be missed. Breakpoints set in Chrome dev tools will still work though.

What is the expected behavior?

Source paths should be correct e.g. "sources":["../src/attributes/color.ts", ...] and VS Code will then hit breakpoints.

Repro Steps

  • Create a plugin with example content au new sad-vscode -u -s typescript,vscode,plugin-scaffold-basic -p
  • au run
  • Set breakpoint in one of the plugin source files
  • Start debugging, the breakpoint will not be hit
  • Sourcemap file has the wrong source paths

Fix Suggestion
I don't really have the time to test this properly but this fixes the scaffolded plugin. I don't know if it impacts the standard app or how it behaves with deeper/more complex directory structures.

Change

cli/lib/build/bundle.js

Lines 315 to 320 in 1dc6179

if (sourceMap && parsedPath) {
let sourceRoot = parsedPath.dir.slice(process.cwd().length + 1);
sourceMap.sourceRoot = sourceRoot.replace(/\\/g, '\/');
needsSourceMap = true;
content = Convert.removeMapFileComments(currentFile.contents);
}

To

if (sourceMap && parsedPath) {
  let sourceRoot = parsedPath.dir.slice(process.cwd().length + 1);            
  let relativeFolderPath = currentFile.file.relative;
  relativeFolderPath = relativeFolderPath.slice(0, relativeFolderPath.length - parsedPath.base.length);
            
  if (relativeFolderPath) {
    sourceRoot = sourceRoot.slice(0, sourceRoot.length - relativeFolderPath.length);
  }

  sourceMap.sourceRoot = sourceRoot.replace(/\\/g, '\/');
  needsSourceMap = true;
  content = Convert.removeMapFileComments(currentFile.contents);
}
  • What is the motivation / use case for changing the behavior?
    VS Code debugging works
@3cp

This comment has been minimized.

Copy link
Member

commented Jun 15, 2019

Thx, I will test your suggestion in few days.

@3cp

This comment has been minimized.

Copy link
Member

commented Jun 18, 2019

The source map is all messed up in normal app project too. The existing code does not work for local source, it should only apply to dependency sources (npm packages).

3cp added a commit to 3cp/cli that referenced this issue Jun 18, 2019
3cp added a commit to 3cp/cli that referenced this issue Jun 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.