Skip to content

Commit

Permalink
refactor: fully remove callback support
Browse files Browse the repository at this point in the history
BREAKING CHANGES:
- support for callbacks in `getInfo` and `getBasicInfo` has been
  removed, use promises or async/await
  • Loading branch information
fent committed Oct 25, 2020
1 parent 241f73d commit c483650
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 51 deletions.
20 changes: 1 addition & 19 deletions lib/info.js
Expand Up @@ -308,28 +308,10 @@ for (let fnName of ['getBasicInfo', 'getInfo']) {
/**
* @param {string} link
* @param {Object} options
* @param {Function(Error, Object)} callback
* @returns {Promise<Object>}
*/
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));
Expand Down
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
24 changes: 0 additions & 24 deletions test/info-test.js
Expand Up @@ -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()', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit c483650

Please sign in to comment.