From e61535250e49faf89c5e5f3f7776ff7bf8baad12 Mon Sep 17 00:00:00 2001 From: Charles Samborski Date: Fri, 29 Dec 2017 18:42:22 +0100 Subject: [PATCH] Drop dependency on deprecated `gulp-util` Closes dlmanning/gulp-sass#646 --- index.js | 21 ++++++++++++--------- package.json | 8 ++++++-- test/main.js | 4 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index a2a89a8..be45916 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,9 @@ '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 clonedeep = require('lodash.clonedeep'); var path = require('path'); @@ -23,13 +26,13 @@ var gulpSass = function gulpSass(options, sync) { return cb(null, file); } 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) { return cb(); } if (!file.contents.length) { - file.path = gutil.replaceExtension(file.path, '.css'); + file.path = replaceExtension(file.path, '.css'); 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) - sassMap.file = gutil.replaceExtension(sassFileSrc, '.css'); + sassMap.file = replaceExtension(sassFileSrc, '.css'); // Apply the map applySourceMap(file, sassMap); } file.contents = sassObj.css; - file.path = gutil.replaceExtension(file.path, '.css'); + file.path = replaceExtension(file.path, '.css'); cb(null, file); }; @@ -122,16 +125,16 @@ var gulpSass = function gulpSass(options, sync) { filePath = filePath ? filePath : file.path; relativePath = path.relative(process.cwd(), filePath); - message += gutil.colors.underline(relativePath) + '\n'; + message += chalk.underline(relativePath) + '\n'; message += error.formatted; error.messageFormatted = message; error.messageOriginal = error.message; - error.message = gutil.colors.stripColor(message); + error.message = stripAnsi(message); error.relativePath = relativePath; - return cb(new gutil.PluginError( + return cb(new PluginError( PLUGIN_NAME, error )); }; @@ -176,7 +179,7 @@ gulpSass.sync = function sync(options) { // Log errors nicely ////////////////////////////// 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'); this.emit('end'); }; diff --git a/package.json b/package.json index a2a36ba..031652f 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,12 @@ "url": "https://github.com/dlmanning/gulp-sass/issues" }, "dependencies": { - "gulp-util": "^3.0", + "chalk": "^2.3.0", "lodash.clonedeep": "^4.3.2", "node-sass": "^4.8.3", + "plugin-error": "^1.0.1", + "replace-ext": "^1.0.0", + "strip-ansi": "^4.0.0", "through2": "^2.0.0", "vinyl-sourcemaps-apply": "^0.2.0" }, @@ -40,6 +43,7 @@ "gulp-tap": "^0.1.3", "mocha": "^2.2.1", "rimraf": "^2.4.3", - "should": "^8.3.1" + "should": "^8.3.1", + "vinyl": "^2.1.0" } } diff --git a/test/main.js b/test/main.js index 6dd40f9..d6022cd 100644 --- a/test/main.js +++ b/test/main.js @@ -1,7 +1,7 @@ 'use strict'; var should = require('should'); -var gutil = require('gulp-util'); +var Vinyl = require('vinyl'); var path = require('path'); var fs = require('fs'); var sass = require('../index'); @@ -17,7 +17,7 @@ var createVinyl = function createVinyl(filename, contents) { var base = path.join(__dirname, 'scss'); var filePath = path.join(base, filename); - return new gutil.File({ + return new Vinyl({ 'cwd': __dirname, 'base': base, 'path': filePath,