-
Notifications
You must be signed in to change notification settings - Fork 117
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
sourceRoot doesn't work for files in sub folders #191
Comments
+1 I've been struggling with this also |
👍 |
Any solution?? |
This solution worked for me on Ubuntu but may not work on Windows, haven't tested that.
|
Thanks @ckiely91 - I only change |
Yes, but I prefer to keep in mind that this is only a workaround. No-one out there is aware of that quirk. It should get fixed soon. |
Hi gulp.task('build', () => {
const project = ts.createProject('tsconfig.json');
return gulp.src('./app/**/*.ts')
.pipe(sourcemaps.init())
.pipe(ts(project))
.js
.pipe(sourcemaps.write('./', {
includeContent: false,
sourceRoot: file => `${'../'.repeat(file.relative.split(/^win/.test(process.platform) ? '\\' : '/').length)}app`
}))
.pipe(gulp.dest('./dist'));
}); I found following code in sources of plugin if (typeof options.sourceRoot === 'function') {
sourceMap.sourceRoot = options.sourceRoot(file);
} else {
sourceMap.sourceRoot = options.sourceRoot;
} Looks like sourceMap passed to output as is without, resolution of extra |
@zhakhalov, found that you can actually just use path.sep instead of |
I agree that the Here's a workaround using the
|
workaround ( version 2.2.0 ) didn't work for me. |
For whatever reason updating the sourceRoot as above didn't work for me so I updated the mapSources directly. Thanks to everyone for leading me to this! mapSources: function(sourcePath, file) { |
The same problem when working with gulp-less. The less files in sub folders cannot pointing to less but css file. |
+1 |
Well, I had lots of trouble, trying to find the right combination to make it work. In the end I found a simple expression that worked for any combination of subdirectories, depth or relative location between the source and build directories: const writeSourceMapsOptions = {
sourceRoot: (file) => {
return path.posix.relative(path.posix.dirname(file.relative), "");
},
}; and then just pass it to This works for both Istambul reports and the Node debugger. |
@demurgos I wonder if you solution should become the default. Except, that it should work regardless of OS type. Feel free to add a PR with some specs. |
Relative posix paths are compatible with both Linux and Windows so I use them (tested on both platforms). It works fine if everything happens inside the project's directory. I don't have enough experience with Windows to know how it would handle source and dest directories on different drives. I'll find some time next week to submit a PR with spec so source roots work out of the box. |
I have stored my source files in a number of sub folders.
It looks like the
sourceRoot
parameter doesn't correctly handle those files. It doesn't consider the relative part beginning at the sources' root up to their actual location when creating the source map entry.Please refer to this issue for reference:
microsoft/vscode#4705
The text was updated successfully, but these errors were encountered: