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

Replace deprecated gulp-util #5

Merged
merged 17 commits into from Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -6,4 +6,5 @@ node_modules/
.settings
npm-debug.log
Desktop.ini
Thumbs.db
Thumbs.db
package-lock.json
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -23,10 +23,13 @@
"test": "mocha -R spec src/**/*.spec.js"
},
"dependencies": {
"through2": "^2.0.1",
"gulp-util": "^3.0.0",
"ansi-colors": "^1.0.1",
"escape-string-regexp": "^1.0.5",
"event-stream": "^3.1.0"
"event-stream": "^3.1.0",
"fancy-log": "^1.3.2",
"plugin-error": "^0.1.2",
"through2": "^2.0.1",
"vinyl": "^2.1.0"
},
"devDependencies": {
"mocha": "~2.0.1",
Expand Down
26 changes: 19 additions & 7 deletions src/index.js
@@ -1,12 +1,24 @@
'use strict';

//2018-01-02 sc mod: gulp-util deprecation
//2018-01-02 sc mod: require plugin-error to replace gutil.PluginError
//2018-01-02 sc mod: require fancy-log to replace gutil.log
//2018-01-02 sc mod: require ansi-colors to replace gutil.colors
//2018-01-02 sc mod: require vinyl to replace gutil.File

var through = require('through2');
var gutil = require('gulp-util');
//var gutil = require('gulp-util');
var PluginError = require('plugin-error');
var fancyLog = require('fancy-log');
var colors = require('ansi-colors');
var File = require('vinyl');
var path = require('path');
var fs = require('fs');
var escapeStringRegexp = require('escape-string-regexp');
var magenta = gutil.colors.magenta;
var cyan = gutil.colors.cyan;
var red = gutil.colors.red;
var magenta = colors.magenta;
var cyan = colors.cyan;
var red = colors.red;


/**
* Constants
Expand Down Expand Up @@ -186,7 +198,7 @@ function extractFilePaths(content, targetPath, opt, tagsRegExp) {
try {
var fileContent = fs.readFileSync(filePath);
files.push({
file: new gutil.File({
file: new File({
path: filePath,
cwd: __dirname,
base: path.resolve(__dirname, 'expected', path.dirname(filePath)),
Expand Down Expand Up @@ -244,14 +256,14 @@ function bool(options, prop, defaultVal) {
* @returns {*}
*/
function error(message) {
return new gutil.PluginError(PLUGIN_NAME, message);
return new PluginError(PLUGIN_NAME, message);
}

/**
* @param message
*/
function log(message) {
gutil.log(magenta(PLUGIN_NAME), message);
fancyLog(magenta(PLUGIN_NAME), message);
}

/**
Expand Down
18 changes: 12 additions & 6 deletions src/index.spec.js
@@ -1,8 +1,14 @@
'use strict';

//2018-01-02 sc mod: gulp-util deprecation
//2018-01-02 sc mod: require fancy-log to replace gutil.log
//2018-01-02 sc mod: require vinyl to replace gutil.File

var fs = require('fs');
var injectPartials = require('../.');
var gutil = require('gulp-util');
//var gutil = require('gulp-util');
var fancyLog =require('fancy-log');
var File = require('vinyl');
var es = require('event-stream');
var should = require('should');
var path = require('path');
Expand All @@ -12,15 +18,15 @@ describe('gulp-inject-partials', function(){
var logOutput = [];

beforeEach(function () {
log = gutil.log;
log = fancyLog.log;
Copy link

@demurgos demurgos Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend to use fancyLog.info (everywhere in this package) because of this kind of test relying on Node's cache to patch shared dependencies. (fancyLog.log does not exist)

I personally consider it a bit brittle so I exposed the logger on the main module in another PR. Finally, a solution would be to use proxy-require to stub fancy-log.

logOutput = [];
gutil.log = function () {
fancyLog.log = function () {
logOutput.push(arguments);
};
});

afterEach(function () {
gutil.log = log;
fancyLog.log = log;
});

it('should inject single partial', function (done){
Expand Down Expand Up @@ -122,7 +128,7 @@ function src(files, opt) {
// get expected file
function expectedFile(file) {
var filepath = path.resolve(__dirname, 'expected', file);
return new gutil.File({
return new File({
path: filepath,
cwd: __dirname,
base: path.resolve(__dirname, 'expected', path.dirname(file)),
Expand All @@ -133,7 +139,7 @@ function expectedFile(file) {
// get fixture
function fixture(file, read) {
var filepath = path.resolve(__dirname, 'fixtures', file);
return new gutil.File({
return new File({
path: filepath,
cwd: __dirname,
base: path.resolve(__dirname, 'fixtures', path.dirname(file)),
Expand Down