Skip to content

Commit

Permalink
feat: Add deprecated warning for gulplog v1 messages (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 24, 2024
1 parent f06ff30 commit affeda9
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 2 deletions.
26 changes: 26 additions & 0 deletions lib/shared/log/to-console.js
@@ -1,5 +1,7 @@
'use strict';

var messages = require('@gulpjs/messages');

/* istanbul ignore next */
function noop() {}

Expand All @@ -17,6 +19,9 @@ function toConsole(log, opts, translate) {
// Default loglevel to info level (3).
var loglevel = opts.logLevel || 3;

var deprecatedPrinted = false;
log.on('deprecated', onDeprecated);

// -L: Logs error events.
if (loglevel > 0) {
log.on('error', onError);
Expand All @@ -37,12 +42,33 @@ function toConsole(log, opts, translate) {
}

return function () {
log.removeListener('deprecated', onDeprecated);
log.removeListener('error', onError);
log.removeListener('warn', onWarn);
log.removeListener('info', onInfo);
log.removeListener('debug', onDebug);
};

function onDeprecated() {
if (!deprecatedPrinted) {
var msg = { tag: messages.GULPLOG_DEPRECATED };
// Get message and timestamp before printing anything to avoid
// logging a half message if there's an error in one of them
var message = translate.message(msg);
var timestamp = translate.timestamp(msg);

if (message) {
// Ensure timestamp is not written without a message
if (timestamp) {
process.stderr.write(timestamp + ' ');
}
console.error(message);
}

deprecatedPrinted = true;
}
}

function onError(msg) {
// Get message and timestamp before printing anything to avoid
// logging a half message if there's an error in one of them
Expand Down
3 changes: 3 additions & 0 deletions lib/shared/translate.js
Expand Up @@ -103,6 +103,9 @@ function getDefaultMessage(data) {
case messages.NPM_INSTALL_GULP: {
return chalk.red('Try running: npm install gulp');
}
case messages.GULPLOG_DEPRECATED: {
return chalk.yellow("gulplog v1 is deprecated. Please help your plugins update!");
}
case messages.COMPLETION_TYPE_MISSING: {
return 'Missing completion type';
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -30,10 +30,10 @@
"cover": "nyc mocha --async-only --timeout 5000 test/lib test"
},
"dependencies": {
"@gulpjs/messages": "^1.0.0",
"@gulpjs/messages": "^1.1.0",
"chalk": "^4.1.2",
"copy-props": "^4.0.0",
"gulplog": "^2.1.0",
"gulplog": "^2.2.0",
"interpret": "^3.1.1",
"liftoff": "^5.0.0",
"mute-stdout": "^2.0.0",
Expand All @@ -47,6 +47,7 @@
"@babel/core": "^7.20.2",
"@babel/preset-env": "^7.20.2",
"@babel/register": "^7.18.9",
"@gulpjs/gulplog-v1": "npm:gulplog@1.0.0",
"eslint": "^7.32.0",
"eslint-config-gulp": "^5.0.1",
"expect": "^27.5.1",
Expand Down
15 changes: 15 additions & 0 deletions test/config-message-function.js
Expand Up @@ -472,4 +472,19 @@ describe('config: message function', function() {
done();
}
});

it('can change GULPLOG_DEPRECATED with .gulp.*', function(done) {
var cwd = path.join(baseDir, 'GULPLOG_DEPRECATED');
var expected = 'GULPLOG V1 IS DEPRECATED\n';

var opts = { cwd: cwd };
exec(gulp(), opts, cb);

function cb(err, stdout, stderr) {
expect(err).toBeNull();
expect(stdout).toEqual('');
expect(stderr).toEqual(expected);
done();
}
});
});
14 changes: 14 additions & 0 deletions test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js
@@ -0,0 +1,14 @@
var messages = require('@gulpjs/messages');

module.exports = {
message: function (data) {
if (data.tag === messages.GULPLOG_DEPRECATED) {
return 'GULPLOG V1 IS DEPRECATED';
}

return false;
},
timestamp: function () {
return false;
}
};
6 changes: 6 additions & 0 deletions test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js
@@ -0,0 +1,6 @@
var gulplog = require('@gulpjs/gulplog-v1');

exports.default = function(done) {
gulplog.error('Some error here');
done();
}

0 comments on commit affeda9

Please sign in to comment.