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

gulp-sass discards changes from earlier in the pipeline when generating source maps #158

Closed
jmm opened this issue Jan 2, 2015 · 8 comments

Comments

@jmm
Copy link

jmm commented Jan 2, 2015

I believe there's a serious flaw in this plugin with the logic around file.sourceMap and opts.sourceComments. It results in node-sass attemping to re-read the file from disk, which discards changes from earlier in the gulp pipeline, and if an earlier change is a rename (e.g. with gulp-rename) it results in node-sass attemping to read a file which either doesn't exist or is the wrong file. Here are a couple of simple examples:

Given:

Gulp 3.8.10, gulp-sass 1.2.4, Ubuntu 12.

var
  gulp = require('gulp'),
  sourcemaps = require('gulp-sourcemaps'),
  rename = require('gulp-rename'),
  sass = require('gulp-sass'),
  through = require('through2');

This (rename):

gulp.task('default', function () {
  return gulp.src('./src/x.scss')
    .pipe(rename('y.scss'))
    .pipe(sourcemaps.init())
      .pipe(sass())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./dist'));
});

Results in:

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: Error: File to read not found or unreadable: src/y.scss

And here is an example with a simple plugin that changes file contents (prepends a comment):

var prefix = function () {
  var prefix = new Buffer("\n/* Added dynamically */\n", 'utf-8');

  return through.obj(function (file, enc, cb) {
    file.contents = Buffer.concat([prefix, file.contents]);
    this.push(file);
    cb();
  })
};

gulp.task('default', function () {
  return gulp.src('./src/x.scss')
    .pipe(prefix())
    .pipe(sourcemaps.init())
      .pipe(sass())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./dist'));
});

This results in the changes from the prefix plugin being discarded.

This means that the changes proposed in Consistent file handling #66 should not be accepted -- things need to go the other way.

If we're on the same page about this, I may work on a pull request.

@Snugug
Copy link
Collaborator

Snugug commented Mar 31, 2015

@dlmanning @Keats So I've tracked down this problem. We're passing the file name to node-sass for libsass to compile instead of passing along the data stream and we should probably be passing along the data stream. The problem, however, with passing along the data stream is that we then need to pass along all of the includePaths for that file which would require us (or node-sass, or libsass if we can convince either of them) to build a graph the includePaths.

@jmm, your rename problem can be resolved by renaming it after compiling your file. The prefix problem persists until we determine what we're going to do about the data issue

@jmm
Copy link
Author

jmm commented Mar 31, 2015

@Snugug

your rename problem can be resolved by renaming it after compiling your file

That example is just to illustrate one of the failure modes. But, doing the rename after isn't equivalent, because then the original name winds up in the sources array of the source map.

@Snugug
Copy link
Collaborator

Snugug commented Mar 31, 2015

@jmm Understood, see the rest of my comment about the underlying issue.

@jmm
Copy link
Author

jmm commented Mar 31, 2015

@Snugug Yup, I read it all, but even the rename case isn't fully solved until the underlying issue is corrected.

@Snugug
Copy link
Collaborator

Snugug commented Mar 31, 2015

Right, I'm looking into a solution now.

@jmm
Copy link
Author

jmm commented Mar 31, 2015

Great, thanks!

Snugug added a commit to Snugug/gulp-sass that referenced this issue Mar 31, 2015
Resolves dlmanning#158 once I get it working
@Snugug Snugug mentioned this issue Mar 31, 2015
@Snugug
Copy link
Collaborator

Snugug commented Mar 31, 2015

@jmm Give this a test:

npm install snugug/gulp-sass#2.x-filedata --save-dev

I think I've fixed this to work as you're expecting. The two examples you've provided should now work.

@Snugug Snugug added this to the 2.0.0 milestone Mar 31, 2015
@Snugug Snugug self-assigned this Mar 31, 2015
@jmm
Copy link
Author

jmm commented Apr 1, 2015

Thanks @Snugug. I tried it and it does indeed work as it should now for the the test cases I posted.

@Snugug Snugug mentioned this issue Apr 1, 2015
@Snugug Snugug closed this as completed Apr 2, 2015
xmas7 pushed a commit to marks-5/gulp-sass that referenced this issue Oct 4, 2022
Resolves dlmanning/gulp-sass#158 once I get it working
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants