-
Notifications
You must be signed in to change notification settings - Fork 60
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
Fix paths in sourcemaps #109
Conversation
Great catch. I think this should definitely be merged, only thing I'd say is maybe move the added functionality out to a function? This would make the logic a little easier to decipher. |
What about something like this: makePathsRelative(file.base, res.sourcemap.sources);
function makePathsRelative(base, paths) {
for (var i = 0; i < paths.length; i++) {
paths[i] = path.relative(base, paths[i]);
}
} Or this: var makePathRelative = path.relative.bind(null, file.base);
res.sourcemap.sources = res.sourcemap.sources.map(makePathRelative); Or even combo: res.sourcemap.sources = makePathsRelative(file.base, res.sourcemap.sources);
function makePathsRelative(base, paths) {
var makePathRelative = path.relative.bind(null, base);
return paths.map(makePathRelative);
} Or just oneliner: res.sourcemap.sources = res.sourcemap.sources.map(path.relative.bind(null, file.base)); I can't decide what is more readable. |
I would say the first one strikes me as most readable. It also follows the same form as vinyl-sourcemaps-apply, which is right below it, for continuity. Maybe you could have the first arg just be |
@faergeek the first one is best, please declare it to a variable as an anonymous function. |
I'd much prefer a named function actually, as that way you could place it at the bottom of the file and it would be hoisted. Named functions are entirely legitimate and safe, and often make code more readable 😀 |
Check this out |
I like that, though I do not like to use named functions... |
That looks sexy as hell @faergeek. 👍 for merge from me! |
Also happy to make a case for why named functions are better if you want to hear my opinion on it @stevelacy -- there are a number of very good reasons 😀 |
@stevelacy what's wrong with named functions? |
@Jenius and I discussed the functions conventions. |
How about to make this functionality conditional? My project have next structure:
and gulp config is: var
gulp = require('gulp'),
stylus = require('gulp-stylus'),
sourcemaps = require('gulp-sourcemaps');
gulp.task('styles', function () {
gulp.src('src/styles/styles.styl')
.pipe(sourcemaps.init())
.pipe(stylus({
'include css': true,
import: require.resolve('normalize.css'),
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dst'));
}); So, after stylus rendering sourcemap looks like this: {
"sources": [
"node_modules/normalize.css/normalize.css",
"src/styles/styles.styl"
],
"file": "styles.css"
...
} And, after {
"sources": [
"../../node_modules/normalize.css/normalize.css",
"styles.styl"
],
"file": "styles.css"
...
} At the end of it all, gulp-sourcemaps adds {
"sources": [
"../../node_modules/normalize.css/normalize.css",
"styles.styl"
],
"file": "styles.css"
"sourceRoot": "/sources/"
...
} In this way, for normalize.css we have path So, I propose to apply
|
@revyh Can you provide some minimal example to test against? |
@faergeek At the moment, I doubt that we really need Here, I'll try cover all possible ways of using sourcemaps:
In general,
As I think, if (file.sourceMap) {
opts.sourcemap = true;
}
...
stylus.render(file.contents.toString('utf8'), opts) Correct me if I'm wrong. |
@revyh I partly agree with you, but I checked another example and can't agree that we do not need |
Correct me if I'm wrong, but I think the only right solution here is to provide The problem is that when So it depends on depths of your folder structure for source and destination plus @stevelacy @Jenius thoughts? |
Here's my test case |
@faergeek Yeah, the picture is old, but still funny 😄 tl;dr. For now I think that my issue was because of FF bug, but I still don't think that we need
Well, I don't think it must works like this. When I tried several combinations of
When Now the most interesting part. It looks like FF doesn't work if This problem can be solved many ways, for example with mold-source-map. @faergeek's solution will work as long as the As for And I agree with @faergeek: It would be great to hear @stevelacy or @Jenius thoughts. |
@revyh @faergeek Thanks for debugging! I played with both test cases, with screenshots for reference: @revyh's case: Top left: Chrome Without Removing @faergeek's case: Top left: Chrome I am considering adding a That way it would be false be default, enabling it would then change the sources array with .pipe(stylus({
relativePaths: true
})) |
@stevelacy Yes, option seems like the only solution for now. |
@stevelacy @faergeek Sorry for delay. I don't think we need a new option. I created demo to illustrate it. In this demo gulp default task creates three example page:
makePathsRelative and basePathRelative are identical. So, we can replace I think that Anyway, in order to use |
Hello again, guys. It's been two weeks and no feedback from you. Maybe you don't want to solve this problem or you don't have enough time for it, or the problem is paltry? Or maybe you are waiting for some action from me (make PR or open an issue, or leave you alone)? Whatever it was, I just want to know. |
@faergeek see any issues with base paths? |
@stevelacy I'm not sure if it won't break anything. So anyway would be better to write some tests for sourcemaps, try to use base paths and bump major release after that. But actually I'm not sure if I could do that. I don't use gulp in my projects now, sorry. @revyh Would you like to submit such pull request? |
Replace 'makePathRelative' with 'basePath' - #109
Now sourcemap paths are relative to cwd (or gulpfile.js) and for external sourcemaps and
includeContent: false
it's useless.Here is the same fix as applied in gulp-less.