From c483650d7b5af120d216681b2d94a8c54c62bf1d Mon Sep 17 00:00:00 2001 From: fent <933490+fent@users.noreply.github.com> Date: Sat, 24 Oct 2020 04:44:41 -0700 Subject: [PATCH] refactor: fully remove callback support BREAKING CHANGES: - support for callbacks in `getInfo` and `getBasicInfo` has been removed, use promises or async/await --- lib/info.js | 20 +------------------- package-lock.json | 8 +------- package.json | 1 - test/info-test.js | 24 ------------------------ 4 files changed, 2 insertions(+), 51 deletions(-) diff --git a/lib/info.js b/lib/info.js index fb05712e..2131e241 100644 --- a/lib/info.js +++ b/lib/info.js @@ -308,28 +308,10 @@ for (let fnName of ['getBasicInfo', 'getInfo']) { /** * @param {string} link * @param {Object} options - * @param {Function(Error, Object)} callback * @returns {Promise} */ const fn = exports[fnName]; - exports[fnName] = (link, options, callback) => { - if (typeof options === 'function') { - callback = options; - options = {}; - } else if (!options) { - options = {}; - } - - if (callback) { - // TODO: Fully remove callback support in a future release. - // eslint-disable-next-line no-console - console.warn( - `Calling \`ytdl.${fnName}\` with a callback will be removed in a near future release. ` + - `Use async/await.`); - return exports[fnName](link, options) - .then(info => callback(null, info), callback); - } - + exports[fnName] = (link, options = {}) => { let id = util.getVideoID(link); const key = [fnName, id, options.lang].join('-'); return exports.cache.getOrSet(key, () => fn(id, options)); diff --git a/package-lock.json b/package-lock.json index 68e325dc..48a43878 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2821,12 +2821,6 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "muk-prop": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/muk-prop/-/muk-prop-2.0.0.tgz", - "integrity": "sha512-tIxpVLQBIwE0Rw1CH2AQ3fLulITQUGJQ60Ji496ZvTRX7EbhuR8DaXvaHASWfL0jUpBuZ/XjhhbyULJ0e4feZA==", - "dev": true - }, "muk-require": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/muk-require/-/muk-require-1.2.0.tgz", @@ -3629,7 +3623,7 @@ "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + "integrity": "sha1-KBYjTiN4vdxOU1T6tcqold9xANk=" }, "semver": { "version": "6.3.0", diff --git a/package.json b/package.json index 0bfb88d7..af3287d1 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "dtslint": "^3.6.14", "eslint": "^6.8.0", "mocha": "^7.0.0", - "muk-prop": "^2.0.0", "muk-require": "^1.2.0", "nock": "^12.0.0", "nyc": "^15.0.0", diff --git a/test/info-test.js b/test/info-test.js index cd49f563..d72a7e9d 100644 --- a/test/info-test.js +++ b/test/info-test.js @@ -3,8 +3,6 @@ const path = require('path'); const assert = require('assert-diff'); const nock = require('./nock'); const sinon = require('sinon'); -const spy = require('sinon').spy; -const muk = require('muk-prop'); describe('ytdl.getInfo()', () => { @@ -121,28 +119,6 @@ describe('ytdl.getInfo()', () => { assert.strictEqual(info2, info1); }); }); - - describe('Using the callback API', () => { - it('Retrieves correct metainfo, with a warning', done => { - const scope = nock(id, { - type: 'vevo', - player: true, - }); - - const warn = spy(); - muk(console, 'warn', warn); - after(muk.restore); - - ytdl.getInfo(id, (err, info) => { - assert.ifError(err); - scope.done(); - assert.ok(info.videoDetails.shortDescription.length); - assert.strictEqual(info.formats.length, expectedInfo.formats.length); - assert.ok(warn.called); - done(); - }); - }); - }); }); describe('From a non-existant video', () => {