dlmanning / gulp-sass

SASS plugin for gulp
MIT License
1.57k stars 381 forks source link

CSS file on the output inherits the whole file.stats from SCSS file on the input #722

Closed generalov closed 2 years ago

generalov commented 5 years ago

gulp-sass 4.0.2

Actual: CSS file on the output inherits the whole file.stats object from SCSS file on the input. Expected: reuse file systems stat for a CSS file when the file exists.

Let's imaging the following file system layout:

sass/main.scss (read only)
sass/_include.scss (writable)
main.css (writable)

main.scss with read only attribute includes a writable _include.scss. _include.scss file is changed. After processing by gulp-sass main.css on the output is read only.

This plugin receives a SASS file object then overrides its file.path and file.contents properties. file.stat is not touched. The plugin outputs the modified file object as CSS file. Writing the CSS file to file system, gulp.dest() use file.stat property to set attributes of a destination file if the property is not null. That's why main.css will read only if source file is read only.

WraithKenny commented 3 years ago

I think this current behavior is correct, in that the source file is the template for a newly created css file that essentially overwrites the destination, not updates it.

That said, there's a workaround where you can build an inline plugin that could adjust the file.stat however you like using through2 or similar:

.pipe( through2.obj( function( file, enc, cb ) {
    // work out how to get 'some_path'
    file.stat = fs.statSync( some_path );
    cb( null, file );
}) )
.pipe( gulp.dest( './' ) )