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

feat: Add deprecated warning for gulplog v1 messages #266

Merged
merged 2 commits into from Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions lib/shared/log/to-console.js
Expand Up @@ -17,6 +17,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 +40,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: Symbol.for('GULP_CLI_GULPLOG_DEPRECATED') };
phated marked this conversation as resolved.
Show resolved Hide resolved
// 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 @@ -19,6 +19,9 @@ Timestamp.prototype[util.inspect.custom] = function (depth, opts) {

function getDefaultMessage(data) {
switch (data.tag) {
case Symbol.for('GULP_CLI_GULPLOG_DEPRECATED'): {
return chalk.yellow("gulplog v1 is deprecated. Please help your plugins update!");
}
case messages.PRELOAD_BEFORE: {
return 'Preloading external module: ' + chalk.magenta(data.name);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -33,7 +33,7 @@
"@gulpjs/messages": "^1.0.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",
phated marked this conversation as resolved.
Show resolved Hide resolved
"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);
phated marked this conversation as resolved.
Show resolved Hide resolved
done();
}
});
});
15 changes: 15 additions & 0 deletions test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js
@@ -0,0 +1,15 @@
// TODO: Add the symbol to messages
var messages = require('@gulpjs/messages');

module.exports = {
message: function (data) {
if (data.tag === Symbol.for('GULP_CLI_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();
}