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

sourcesContent: null for files in subdirectories with globbed gulp.src #278

Closed
neagle opened this issue May 14, 2015 · 2 comments
Closed

Comments

@neagle
Copy link

neagle commented May 14, 2015

I created an issue for gulp-sourcemaps yesterday, but after some investigation, I believe this is an issue with gulp-sass. First, I'll quote my original ticket:


I've been having a problem with blank source .scss files in Chrome's debugger. For a set of files I grab with gulp.src('somedir/**/*.scss'), I'm writing external sourcemaps with includeContent left to true (though I've also tried setting it explicitly). Files in the root directory have their sources included properly, but for any files in subdirectories, their source code is missing ("sourcesContent":[null]).

I created a brand-new project with nothing extraneous and had the same problem:

gulpfile:

var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('default', function () {
    return gulp.src('src/scss/**/*.scss')
        .pipe(sourcemaps.init())
        .pipe(sass())
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('build/css'));
});

There are two .scss files:

src/scss/app.scss and
src/scss/foo/bar.scss

When I run gulp, it properly generates these files:

build/css/app.css
build/css/app.css.map
build/css/foo/bar.css and
build/css/foo/bar.css.map

app.css.map contains the proper sourcesContent, but foo/bar.css.map has "sourcesContent":[null].

Any idea what could be going on? Is there an option I'm missing that I need to set? Thanks in advance for any help you can provide!

P.S.
node --version → v.0.12.0

{
  "gulp": "^3.8.11",
  "gulp-sass": "^2.0.1",
  "gulp-sourcemaps": "^1.5.2"
}

After some investigation, I found that the problem is happening at line 79 of index.js, when the vinyl-sourcemaps-apply module is called.

The problem seems to be that when it's called for sass files in child directories, file.sourceMap.sources === ['foo/bar.scss'], but sassMap.sources === ['bar.scss'] because of line 73.

At some point in source-map, the sourcesContent gets discarded and set to null because its key (foo/bar.scss) doesn't match the key it's dealing with (bar.scss).

This problem can be fixed by replacing line 75 of index.js with these two lines:

        var sourceIndex = sassMap.sources.indexOf(sassMapFile);
        sassMap.sources[sourceIndex] = file.sourceMap.sources[sourceIndex];

This resolves the problem, though I'd, of course, need your thoughts and approval to make sure it doesn't impact anything I might not be thinking about. I'm happy to submit this as a pull request if desired, but your admirably clear contribution guidelines made me stop and make this an issue instead.

@neagle
Copy link
Author

neagle commented May 18, 2015

Any thoughts on this? It's possible not that many projects want to compile a globbed source, but it'd definitely be useful for us to make this fix, barring any objection. 😄

@Keats
Copy link
Collaborator

Keats commented May 21, 2015

Can you do the PR and we discuss on it ?

neagle added a commit to neagle/gulp-sass that referenced this issue May 21, 2015
@Snugug Snugug closed this as completed in 2a4f945 Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants