From 2a782fddbcc644245f911f9bc978ea0f84f4606f Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 9 Jan 2017 15:46:27 +0300 Subject: [PATCH] Deprecate support for Node.js v0.12 Notes: We are deprecating support for Node.js v0.12, to be removed in next major version! --- .npmignore | 1 - index.js | 14 +++++++++++++- package.json | 2 +- test/telegram.js | 14 +++++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.npmignore b/.npmignore index 7b45d546..4bdcd350 100644 --- a/.npmignore +++ b/.npmignore @@ -7,7 +7,6 @@ coverage/ README.hbs output.md output/ -src/ test/ examples/ lib-doc/ diff --git a/index.js b/index.js index adb731fa..6165386a 100644 --- a/index.js +++ b/index.js @@ -1 +1,13 @@ -module.exports = require('./src/telegram'); +/** + * If running on Nodejs 0.12, we load the transpiled code. + * Otherwise, we use the ES6 code. + * We are deprecating support for Node.js v0.x + */ +const majorVersion = process.versions.node.split('.')[0]; +if (majorVersion === '0') { + const deprecate = require('depd')('node-telegram-bot-api'); + deprecate('Node.js v0.12 and below will no longer be supported in the future'); + module.exports = require('./lib/telegram'); +} else { + module.exports = require('./src/telegram'); +} diff --git a/package.json b/package.json index a53a609e..1dcdcd50 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-telegram-bot-api", "version": "0.25.0", "description": "Telegram Bot API", - "main": "./lib/telegram.js", + "main": "./index.js", "directories": { "example": "examples", "test": "test" diff --git a/test/telegram.js b/test/telegram.js index a2b18b44..d1731e44 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -1,4 +1,4 @@ -const TelegramBot = require('../lib/telegram'); +const TelegramBot = require('..'); const Promise = require('bluebird'); const request = require('request-promise'); const assert = require('assert'); @@ -42,6 +42,18 @@ before(function beforeAll() { }); }); + +describe('module.exports', function moduleExportsSuite() { + it('is loaded from src/ if NOT on Node.js 0.12', function test() { + if (process.versions.node.split('.')[0] === '0') this.skip(); // skip on Node.js v0.12 + assert.equal(TelegramBot, require('../src/telegram')); + }); + it('is loaded from lib/ if on Node.js 0.12', function test() { + if (process.versions.node.split('.')[0] !== '0') this.skip(); // skip on newer versions + assert.equal(TelegramBot, require('../lib/telegram')); + }); +}); + describe('TelegramBot', function telegramSuite() { let bot; let testbot;