From 449f03f786d18af6a4c97d5554b3a2c802805957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Mon, 18 Jul 2022 08:41:31 +0200 Subject: [PATCH] feat: Remove bluebird + depd (#987) * feat: Remove bluebird * docs: Update * remove depd ans use node native deprecate msg warnings * fix: correct util import name * remove: contributor dev dependencie and add list of contributors in the readme --- README.md | 9 + doc/api.md | 18 -- index.js | 2 +- package.json | 486 +---------------------------------------- src/telegram.js | 40 +--- src/telegramPolling.js | 2 +- src/telegramWebHook.js | 2 - src/utils.js | 3 + test/telegram.js | 12 +- test/utils.js | 1 - 10 files changed, 18 insertions(+), 557 deletions(-) create mode 100644 src/utils.js diff --git a/README.md b/README.md index e609bc4..7268177 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,15 @@ Some things built using this library that might interest you: * [node-telegram-keyboard-wrapper](https://github.com/alexandercerutti/node-telegram-keyboard-wrapper): A wrapper to improve keyboards structures creation through a more easy-to-see way (supports Inline Keyboards, Reply Keyboard, Remove Keyboard and Force Reply) * [beetube-bot](https://github.com/kodjunkie/beetube-bot): A telegram bot for music, videos, movies, EDM tracks, torrent downloads, files and more. + +## Contributors + +

+ + + +

+ ## License **The MIT License (MIT)** diff --git a/doc/api.md b/doc/api.md index e6971a3..7b3f00d 100644 --- a/doc/api.md +++ b/doc/api.md @@ -123,7 +123,6 @@ TelegramBot * _static_ * [.errors](#TelegramBot.errors) : Object * [.messageTypes](#TelegramBot.messageTypes) : [ 'Array' ].<String> - * [.Promise](#TelegramBot.Promise) @@ -1847,23 +1846,6 @@ The different errors the library uses. The types of message updates the library handles. **Kind**: static property of [TelegramBot](#TelegramBot) - - -### TelegramBot.Promise -Change Promise library used internally, for all existing and new -instances. - -**Kind**: static property of [TelegramBot](#TelegramBot) - -| Param | Type | -| --- | --- | -| customPromise | function | - -**Example** -```js -const TelegramBot = require('node-telegram-bot-api'); -TelegramBot.Promise = myPromise; -``` * * * diff --git a/index.js b/index.js index 5743a57..86e0480 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ */ const majorVersion = parseInt(process.versions.node.split('.')[0], 10); if (majorVersion <= 5) { - const deprecate = require('depd')('node-telegram-bot-api'); + const deprecate = require('./src/utils').deprecate; deprecate('Node.js v5.x and below will no longer be supported in the future'); module.exports = require('./lib/telegram'); } else { diff --git a/package.json b/package.json index f815e4d..130c956 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,7 @@ "dependencies": { "array.prototype.findindex": "^2.0.2", "bl": "^1.2.3", - "bluebird": "^3.5.1", "debug": "^3.1.0", - "depd": "^1.1.1", "eventemitter3": "^3.0.0", "file-type": "^3.9.0", "mime": "^1.6.0", @@ -54,7 +52,6 @@ "babel-preset-es2015": "^6.24.1", "babel-register": "^6.26.0", "concat-stream": "^1.6.0", - "contributor": "^0.1.25", "eslint": "^2.13.1", "eslint-config-airbnb": "^6.2.0", "eslint-plugin-mocha": "^4.11.0", @@ -73,484 +70,5 @@ "bugs": { "url": "https://github.com/yagop/node-telegram-bot-api/issues" }, - "homepage": "https://github.com/yagop/node-telegram-bot-api", - "contributors": [ - { - "name": "Oleg", - "email": null, - "url": "https://github.com/olegmdev", - "contributions": 1, - "additions": 1, - "deletions": 0, - "hireable": true - }, - { - "name": "Archakov Dennis", - "email": null, - "url": "https://github.com/Archakov06", - "contributions": 1, - "additions": 1, - "deletions": 0, - "hireable": true - }, - { - "name": "drGOD", - "email": null, - "url": "https://github.com/drGOD", - "contributions": 1, - "additions": 1, - "deletions": 0, - "hireable": null - }, - { - "name": "MCSH", - "email": null, - "url": "https://github.com/MCSH", - "contributions": 1, - "additions": 2, - "deletions": 1, - "hireable": true - }, - { - "name": "Aaron Meese", - "email": null, - "url": "https://github.com/ajmeese7", - "contributions": 1, - "additions": 4, - "deletions": 4, - "hireable": true - }, - { - "name": "Misha", - "email": null, - "url": "https://github.com/mnb3000", - "contributions": 1, - "additions": 24, - "deletions": 12, - "hireable": null - }, - { - "name": "Savely Krasovsky", - "email": null, - "url": "https://github.com/L11R", - "contributions": 1, - "additions": 297, - "deletions": 1, - "hireable": null - }, - { - "name": "Victor Le", - "email": null, - "url": "https://github.com/Coac", - "contributions": 1, - "additions": 1, - "deletions": 1, - "hireable": null - }, - { - "name": null, - "email": null, - "url": "https://github.com/kucherenkovova", - "contributions": 1, - "additions": 1, - "deletions": 1, - "hireable": null - }, - { - "name": "Guidone", - "email": null, - "url": "https://github.com/guidone", - "contributions": 1, - "additions": 1, - "deletions": 0, - "hireable": true - }, - { - "name": "Jaakko Lipsanen", - "email": null, - "url": "https://github.com/JaakkoLipsanen", - "contributions": 1, - "additions": 3, - "deletions": 3, - "hireable": null - }, - { - "name": "Fabio Zuber", - "email": null, - "url": "https://github.com/Sirius-A", - "contributions": 1, - "additions": 12, - "deletions": 0, - "hireable": null - }, - { - "name": "Evgeny Bondarenko", - "email": null, - "url": "https://github.com/jehy", - "contributions": 1, - "additions": 8, - "deletions": 8, - "hireable": true - }, - { - "name": "Anton Mironov", - "email": null, - "url": "https://github.com/mironov", - "contributions": 1, - "additions": 51, - "deletions": 15, - "hireable": null - }, - { - "name": "Daniil Yastremskiy", - "email": null, - "url": "https://github.com/TheBeastOfCaerbannog", - "contributions": 1, - "additions": 36, - "deletions": 0, - "hireable": true - }, - { - "name": "Nikolay Ershov", - "email": null, - "url": "https://github.com/Ni2c2k", - "contributions": 1, - "additions": 4, - "deletions": 4, - "hireable": null - }, - { - "name": "Alexander Tarmolov", - "email": null, - "url": "https://github.com/tarmolov", - "contributions": 1, - "additions": 5, - "deletions": 0, - "hireable": null - }, - { - "name": null, - "email": null, - "url": "https://github.com/GingerPlusPlus", - "contributions": 1, - "additions": 6, - "deletions": 2, - "hireable": null - }, - { - "name": "Mikhail Burshteyn", - "email": null, - "url": "https://github.com/m-burst", - "contributions": 1, - "additions": 12, - "deletions": 5, - "hireable": null - }, - { - "name": "Sergey Bogdanov", - "email": null, - "url": "https://github.com/desunit", - "contributions": 1, - "additions": 1, - "deletions": 1, - "hireable": null - }, - { - "name": "Ola Flisbäck", - "email": null, - "url": "https://github.com/oflisback", - "contributions": 1, - "additions": 3, - "deletions": 3, - "hireable": true - }, - { - "name": "Horus Lugo", - "email": null, - "url": "https://github.com/HorusGoul", - "contributions": 1, - "additions": 108, - "deletions": 1, - "hireable": true - }, - { - "name": "Conor Fennell", - "email": null, - "url": "https://github.com/conorfennell", - "contributions": 1, - "additions": 50, - "deletions": 1, - "hireable": null - }, - { - "name": "Serhii Dmytruk", - "email": null, - "url": "https://github.com/imserhii", - "contributions": 1, - "additions": 35, - "deletions": 1, - "hireable": null - }, - { - "name": "Aleksandr L.", - "email": null, - "url": "https://github.com/w-site", - "contributions": 1, - "additions": 24, - "deletions": 0, - "hireable": null - }, - { - "name": "Matthew Brandly", - "email": null, - "url": "https://github.com/brandly", - "contributions": 1, - "additions": 1, - "deletions": 1, - "hireable": null - }, - { - "name": "Patricio López Juri", - "email": null, - "url": "https://github.com/mrpatiwi", - "contributions": 1, - "additions": 49, - "deletions": 2, - "hireable": true - }, - { - "name": "Anton", - "email": null, - "url": "https://github.com/Feverqwe", - "contributions": 1, - "additions": 23, - "deletions": 5, - "hireable": true - }, - { - "name": "Guido García", - "email": null, - "url": "https://github.com/palmerabollo", - "contributions": 1, - "additions": 1, - "deletions": 1, - "hireable": true - }, - { - "name": "Sebastian Troć", - "email": null, - "url": "https://github.com/SebastianTroc", - "contributions": 1, - "additions": 1, - "deletions": 1, - "hireable": null - }, - { - "name": "CapacitorSet", - "email": null, - "url": "https://github.com/CapacitorSet", - "contributions": 2, - "additions": 110, - "deletions": 2, - "hireable": true - }, - { - "name": "Plusb Preco", - "email": null, - "url": "https://github.com/preco21", - "contributions": 2, - "additions": 111, - "deletions": 200, - "hireable": null - }, - { - "name": "Jishnu Mohan", - "email": null, - "url": "https://github.com/jishnu7", - "contributions": 2, - "additions": 84, - "deletions": 0, - "hireable": true - }, - { - "name": "TJ Horner", - "email": null, - "url": "https://github.com/tjhorner", - "contributions": 2, - "additions": 223, - "deletions": 1, - "hireable": null - }, - { - "name": "Alex Godko", - "email": null, - "url": "https://github.com/koloboid", - "contributions": 2, - "additions": 2, - "deletions": 2, - "hireable": true - }, - { - "name": "Dardan Neziri", - "email": null, - "url": "https://github.com/knock-in", - "contributions": 2, - "additions": 22, - "deletions": 16, - "hireable": true - }, - { - "name": "Jérémy Gotteland", - "email": null, - "url": "https://github.com/Tketa", - "contributions": 2, - "additions": 81, - "deletions": 3, - "hireable": null - }, - { - "name": "Iiro Jäppinen", - "email": null, - "url": "https://github.com/iiroj", - "contributions": 2, - "additions": 40, - "deletions": 0, - "hireable": null - }, - { - "name": null, - "email": null, - "url": "https://github.com/evolun", - "contributions": 2, - "additions": 7, - "deletions": 3, - "hireable": null - }, - { - "name": "Vitaly Aminev", - "email": null, - "url": "https://github.com/AVVS", - "contributions": 2, - "additions": 1065, - "deletions": 1001, - "hireable": true - }, - { - "name": "Cristian Baldi", - "email": null, - "url": "https://github.com/crisbal", - "contributions": 2, - "additions": 26, - "deletions": 1, - "hireable": true - }, - { - "name": "Vítor Augusto da Silva Vasconcellos", - "email": null, - "url": "https://github.com/HeavenVolkoff", - "contributions": 2, - "additions": 12, - "deletions": 0, - "hireable": null - }, - { - "name": "Rey", - "email": null, - "url": "https://github.com/reyy", - "contributions": 2, - "additions": 34, - "deletions": 25, - "hireable": null - }, - { - "name": "Ivan Skorokhodov", - "email": null, - "url": "https://github.com/universome", - "contributions": 3, - "additions": 219, - "deletions": 5, - "hireable": null - }, - { - "name": "Rafael Kr", - "email": null, - "url": "https://github.com/RafaelKr", - "contributions": 3, - "additions": 3, - "deletions": 2, - "hireable": null - }, - { - "name": null, - "email": null, - "url": "https://github.com/EXL", - "contributions": 4, - "additions": 4, - "deletions": 4, - "hireable": true - }, - { - "name": "Riddler", - "email": null, - "url": "https://github.com/Waterloo", - "contributions": 3, - "additions": 64, - "deletions": 2, - "hireable": true - }, - { - "name": "Chris54721", - "email": null, - "url": "https://github.com/chris54721", - "contributions": 5, - "additions": 22, - "deletions": 6, - "hireable": null - }, - { - "name": "Ilias Ismanalijev", - "email": null, - "url": "https://github.com/Illyism", - "contributions": 7, - "additions": 140, - "deletions": 10, - "hireable": true - }, - { - "name": "Gocho Mugo", - "email": null, - "url": "https://github.com/GochoMugo", - "contributions": 152, - "additions": 7186, - "deletions": 3367, - "hireable": true - }, - { - "name": "Mohammed Sohail", - "email": null, - "url": "https://github.com/kamikazechaser", - "contributions": 12, - "additions": 523, - "deletions": 127, - "hireable": true - }, - { - "name": "Yago", - "email": null, - "url": "https://github.com/yagop", - "contributions": 197, - "additions": 3023, - "deletions": 1177, - "hireable": true - }, - { - "name": "Sedric Heidarizarei", - "email": null, - "url": "https://github.com/saeedhei", - "contributions": 1, - "additions": 1, - "deletions": 0, - "hireable": null - } - ] -} + "homepage": "https://github.com/yagop/node-telegram-bot-api" +} \ No newline at end of file diff --git a/src/telegram.js b/src/telegram.js index 2c964e1..03103fb 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -16,8 +16,7 @@ const path = require('path'); const URL = require('url'); const fs = require('fs'); const pump = require('pump'); -const deprecate = require('depd')('node-telegram-bot-api'); -let Promise = require('bluebird'); +const deprecate = require('./utils').deprecate; const _messageTypes = [ 'text', @@ -61,30 +60,6 @@ const _deprecatedMessageTypes = [ 'new_chat_participant', 'left_chat_participant' ]; - -if (!process.env.NTBA_FIX_319) { - // Enable Promise cancellation. - try { - const msg = - 'Automatic enabling of cancellation of promises is deprecated.\n' + - 'In the future, you will have to enable it yourself.\n' + - 'See https://github.com/yagop/node-telegram-bot-api/issues/319.'; - deprecate(msg); - Promise.config({ - cancellation: true, - }); - } catch (ex) { - /* eslint-disable no-console */ - const msg = - 'error: Enabling Promise cancellation failed.\n' + - ' Temporary fix is to load/require this library as early as possible before using any Promises.'; - console.error(msg); - throw ex; - /* eslint-enable no-console */ - } -} - - /** * JSON-serialize data. If the provided data is already a String, * return it as is. @@ -117,19 +92,6 @@ class TelegramBot extends EventEmitter { return _messageTypes; } - /** - * Change Promise library used internally, for all existing and new - * instances. - * @param {Function} customPromise - * - * @example - * const TelegramBot = require('node-telegram-bot-api'); - * TelegramBot.Promise = myPromise; - */ - static set Promise(customPromise) { - Promise = customPromise; - } - /** * Add listener for the specified [event](https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#events). * This is the usual `emitter.on()` method. diff --git a/src/telegramPolling.js b/src/telegramPolling.js index d867404..9e6cf90 100644 --- a/src/telegramPolling.js +++ b/src/telegramPolling.js @@ -1,6 +1,6 @@ const errors = require('./errors'); const debug = require('debug')('node-telegram-bot-api'); -const deprecate = require('depd')('node-telegram-bot-api'); +const deprecate = require('./utils').deprecate; const ANOTHER_WEB_HOOK_USED = 409; diff --git a/src/telegramWebHook.js b/src/telegramWebHook.js index f7233b1..998d10e 100644 --- a/src/telegramWebHook.js +++ b/src/telegramWebHook.js @@ -4,8 +4,6 @@ const https = require('https'); const http = require('http'); const fs = require('fs'); const bl = require('bl'); -const Promise = require('bluebird'); - class TelegramBotWebHook { /** diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..a2d36eb --- /dev/null +++ b/src/utils.js @@ -0,0 +1,3 @@ +const util = require('util'); +// Native deprecation warning +exports.deprecate = (msg) => util.deprecate(() => { }, msg, 'node-telegram-bot-api')(); diff --git a/test/telegram.js b/test/telegram.js index bd96467..2f6b726 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -1,5 +1,4 @@ const TelegramBot = require('..'); -const Promise = require('bluebird'); const request = require('request-promise'); const assert = require('assert'); const fs = require('fs'); @@ -121,15 +120,6 @@ describe('TelegramBot', function telegramSuite() { }); }); - it('allows providing custom Promise library', function test() { - TelegramBot.Promise = global.Promise; - const promise = bot.stopPolling(); - assert.ok(promise instanceof global.Promise); - assert.ok(!(promise instanceof Promise)); - // revert - TelegramBot.Promise = Promise; - }); - it('automatically starts polling', function test() { assert.strictEqual(botPolling.isPolling(), true); return utils.isPollingMockServer(pollingPort2); @@ -210,7 +200,7 @@ describe('TelegramBot', function telegramSuite() { }); it('only accepts POST method', function test() { const methods = ['GET', 'PUT', 'DELETE', 'OPTIONS']; - return Promise.each(methods, (method) => { + return Promise.all(methods, (method) => { return utils.sendWebHookMessage(webHookPort2, TOKEN, { method, }).then(() => { diff --git a/test/utils.js b/test/utils.js index f8ebe5e..07b5b22 100644 --- a/test/utils.js +++ b/test/utils.js @@ -81,7 +81,6 @@ exports = module.exports = { const assert = require('assert'); const http = require('http'); -const Promise = require('bluebird'); const request = require('request-promise'); const statics = require('node-static');