From dcde3e15307c9d0bd901232bb532c4deed172917 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sat, 23 Mar 2024 16:01:06 -0700 Subject: [PATCH 1/2] feat: Add deprecated warning for gulplog v1 messages --- lib/shared/log/to-console.js | 24 +++++++++++++++++++ lib/shared/translate.js | 3 +++ package.json | 3 ++- test/config-message-function.js | 15 ++++++++++++ .../theming/GULPLOG_DEPRECATED/.gulp.js | 15 ++++++++++++ .../theming/GULPLOG_DEPRECATED/gulpfile.js | 6 +++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js create mode 100644 test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index a3be2c48..e2d5f525 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -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); @@ -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') }; + // 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 diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 00c29ae6..3f46dd1e 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -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); } diff --git a/package.json b/package.json index d67c575d..5725a3a3 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/config-message-function.js b/test/config-message-function.js index e39c1ede..3a6eae5a 100644 --- a/test/config-message-function.js +++ b/test/config-message-function.js @@ -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(); + } + }); }); diff --git a/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js b/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js new file mode 100644 index 00000000..ba03ce27 --- /dev/null +++ b/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; + } +}; diff --git a/test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js b/test/fixtures/config/theming/GULPLOG_DEPRECATED/gulpfile.js new file mode 100644 index 00000000..aa34f0c8 --- /dev/null +++ b/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(); +} From 2e2ed57e035a9996eca29a07811f8cc3fbcea489 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sat, 23 Mar 2024 19:22:08 -0700 Subject: [PATCH 2/2] update messages --- lib/shared/log/to-console.js | 4 +++- lib/shared/translate.js | 6 +++--- package.json | 2 +- test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js | 3 +-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index e2d5f525..3cdf1ca2 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -1,5 +1,7 @@ 'use strict'; +var messages = require('@gulpjs/messages'); + /* istanbul ignore next */ function noop() {} @@ -49,7 +51,7 @@ function toConsole(log, opts, translate) { function onDeprecated() { if (!deprecatedPrinted) { - var msg = { tag: Symbol.for('GULP_CLI_GULPLOG_DEPRECATED') }; + 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); diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 3f46dd1e..1c1939c8 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -19,9 +19,6 @@ 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); } @@ -106,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'; } diff --git a/package.json b/package.json index 5725a3a3..99529c1c 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "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.2.0", diff --git a/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js b/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js index ba03ce27..413c704b 100644 --- a/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js +++ b/test/fixtures/config/theming/GULPLOG_DEPRECATED/.gulp.js @@ -1,9 +1,8 @@ -// 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')) { + if (data.tag === messages.GULPLOG_DEPRECATED) { return 'GULPLOG V1 IS DEPRECATED'; }