Drop dependency on deprecated gulp-util

Closes dlmanning/gulp-sass#646
This commit is contained in:
Charles Samborski 2017-12-29 18:42:22 +01:00 committed by xzyfer
parent 9a8a8797ca
commit e61535250e
3 changed files with 20 additions and 13 deletions

View file

@ -1,6 +1,9 @@
'use strict'; 'use strict';
var gutil = require('gulp-util'); var chalk = require('chalk');
var PluginError = require('plugin-error');
var replaceExtension = require('replace-ext');
var stripAnsi = require('strip-ansi');
var through = require('through2'); var through = require('through2');
var clonedeep = require('lodash.clonedeep'); var clonedeep = require('lodash.clonedeep');
var path = require('path'); var path = require('path');
@ -23,13 +26,13 @@ var gulpSass = function gulpSass(options, sync) {
return cb(null, file); return cb(null, file);
} }
if (file.isStream()) { if (file.isStream()) {
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
} }
if (path.basename(file.path).indexOf('_') === 0) { if (path.basename(file.path).indexOf('_') === 0) {
return cb(); return cb();
} }
if (!file.contents.length) { if (!file.contents.length) {
file.path = gutil.replaceExtension(file.path, '.css'); file.path = replaceExtension(file.path, '.css');
return cb(null, file); return cb(null, file);
} }
@ -100,13 +103,13 @@ var gulpSass = function gulpSass(options, sync) {
}); });
// Replace the map file with the original file name (but new extension) // Replace the map file with the original file name (but new extension)
sassMap.file = gutil.replaceExtension(sassFileSrc, '.css'); sassMap.file = replaceExtension(sassFileSrc, '.css');
// Apply the map // Apply the map
applySourceMap(file, sassMap); applySourceMap(file, sassMap);
} }
file.contents = sassObj.css; file.contents = sassObj.css;
file.path = gutil.replaceExtension(file.path, '.css'); file.path = replaceExtension(file.path, '.css');
cb(null, file); cb(null, file);
}; };
@ -122,16 +125,16 @@ var gulpSass = function gulpSass(options, sync) {
filePath = filePath ? filePath : file.path; filePath = filePath ? filePath : file.path;
relativePath = path.relative(process.cwd(), filePath); relativePath = path.relative(process.cwd(), filePath);
message += gutil.colors.underline(relativePath) + '\n'; message += chalk.underline(relativePath) + '\n';
message += error.formatted; message += error.formatted;
error.messageFormatted = message; error.messageFormatted = message;
error.messageOriginal = error.message; error.messageOriginal = error.message;
error.message = gutil.colors.stripColor(message); error.message = stripAnsi(message);
error.relativePath = relativePath; error.relativePath = relativePath;
return cb(new gutil.PluginError( return cb(new PluginError(
PLUGIN_NAME, error PLUGIN_NAME, error
)); ));
}; };
@ -176,7 +179,7 @@ gulpSass.sync = function sync(options) {
// Log errors nicely // Log errors nicely
////////////////////////////// //////////////////////////////
gulpSass.logError = function logError(error) { gulpSass.logError = function logError(error) {
var message = new gutil.PluginError('sass', error.messageFormatted).toString(); var message = new PluginError('sass', error.messageFormatted).toString();
process.stderr.write(message + '\n'); process.stderr.write(message + '\n');
this.emit('end'); this.emit('end');
}; };

View file

@ -24,9 +24,12 @@
"url": "https://github.com/dlmanning/gulp-sass/issues" "url": "https://github.com/dlmanning/gulp-sass/issues"
}, },
"dependencies": { "dependencies": {
"gulp-util": "^3.0", "chalk": "^2.3.0",
"lodash.clonedeep": "^4.3.2", "lodash.clonedeep": "^4.3.2",
"node-sass": "^4.8.3", "node-sass": "^4.8.3",
"plugin-error": "^1.0.1",
"replace-ext": "^1.0.0",
"strip-ansi": "^4.0.0",
"through2": "^2.0.0", "through2": "^2.0.0",
"vinyl-sourcemaps-apply": "^0.2.0" "vinyl-sourcemaps-apply": "^0.2.0"
}, },
@ -40,6 +43,7 @@
"gulp-tap": "^0.1.3", "gulp-tap": "^0.1.3",
"mocha": "^2.2.1", "mocha": "^2.2.1",
"rimraf": "^2.4.3", "rimraf": "^2.4.3",
"should": "^8.3.1" "should": "^8.3.1",
"vinyl": "^2.1.0"
} }
} }

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
var should = require('should'); var should = require('should');
var gutil = require('gulp-util'); var Vinyl = require('vinyl');
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var sass = require('../index'); var sass = require('../index');
@ -17,7 +17,7 @@ var createVinyl = function createVinyl(filename, contents) {
var base = path.join(__dirname, 'scss'); var base = path.join(__dirname, 'scss');
var filePath = path.join(base, filename); var filePath = path.join(base, filename);
return new gutil.File({ return new Vinyl({
'cwd': __dirname, 'cwd': __dirname,
'base': base, 'base': base,
'path': filePath, 'path': filePath,