power-assert-js / espower-source

Power Assert instrumentor from code to code, with SourceMap.
MIT License
11 stars 7 forks source link

escodegenOptions why not set sourceMapRoot ? #16

Closed okoala closed 6 years ago

okoala commented 7 years ago

https://github.com/power-assert-js/espower-source/blob/master/index.js#L193

My question is when i debug test file, vscode cannot find the correct file path.

image

vscode log:

SourceMaps.getMapForGeneratedPath: Using inlined sourcemap in d:\Code\github\egg-example\test\app\controller\home.test.js
SourceMap: creating for d:\Code\github\egg-example\test\app\controller\home.test.js
SourceMap: sourceRoot: undefined
SourceMap: sources: ["test\\app\\controller\\home.test.js"]
SourceMap: no sourceRoot specified, using script dirname: d:\Code\github\egg-example\test\app\controller
Warning: sourceMapPathOverrides entry does not map to an absolute path - "webpack:///./*": "${cwd}/*"
Warning: sourceMapPathOverrides entry does not map to an absolute path - "webpack:///*": "*"
Warning: sourceMapPathOverrides entry does not map to an absolute path - "meteor://💻app/*": "${cwd}/*"
SourceMaps.scriptParsed: d:\Code\github\egg-example\test\app\controller\home.test.js was just loaded and has mapped sources: ["d:\\Code\\github\\egg-example\\test\\app\\controller\\test\\app\\controller\\home.test.js"]
SourceMaps.setBP: Mapped d:\Code\github\egg-example\test\app\controller\test\app\controller\home.test.js to d:\Code\github\egg-example\test\app\controller\home.test.js
SourceMaps.setBP: Mapped d:\Code\github\egg-example\test\app\controller\test\app\controller\home.test.js:7:1 to d:\Code\github\egg-example\test\app\controller\home.test.js:37:9
SourceMaps.setBP: Mapped d:\Code\github\egg-example\test\app\controller\test\app\controller\home.test.js:14:1 to d:\Code\github\egg-example\test\app\controller\home.test.js:54:9
SourceMaps.setBP: SourceMaps are enabled but d:\Code\github\egg-example\test\app\controller\home.test.js is a runtime script
SourceMaps.setBP: Mapped d:\Code\github\egg-example\test\app\controller\home.test.js:37:9 to d:\Code\github\egg-example\test\app\controller\test\app\controller\home.test.js:7
SourceMaps.setBP: Mapped d:\Code\github\egg-example\test\app\controller\home.test.js:54:9 to d:\Code\github\egg-example\test\app\controller\test\app\controller\home.test.js:14

but i when i set escodegenOptions.sourceMapRoot and it works.

if (options.sourceRoot) {
    escodegenOptions.sourceMapRoot = options.sourceRoot;
}
okoala commented 7 years ago

eggjs/egg#839

twada commented 7 years ago

@okoala Thank you for reporting. I'll working on this.

twada commented 7 years ago

Let me explain the background of this issue.

I have been tackling with sourcemap issues for a couple of years, and for filepaths, had faced 2 problems.

These are why I don't use sourceMapRoot option.

Then I've found that sourcesContent property for the rescue. If original code is embedded in sourcesContent property, debuggers use content of sourcesContent instead of reading original files from URL/filesystem. It'd solved annoying path problems and security issues. Keeps everything self-contained.

Chrome, Firefox, Safari and WebStorm/IntelliJ uses sourcesContent for debugging.

How about VSCode? Unfortunately, VSCode ignores sourcesContent "by design" (OMG).

I'm going to accept and fix this issue for now since Chrome/Firefox/Safari and WebStorm will continue to use sourcesContent for debugging. However, if there are some issues caused by sourceRoot, I'll revert the fix here and try to fix this again at espower-loader level.

twada commented 7 years ago

@okoala espower-source 2.2.0 is out. Would you give it a try?

okoala commented 7 years ago

@twada thinks a lot, i try it now.

twada commented 6 years ago

Closing for now. Please feel free to reopen this issue when reproduced.