From 1080dfdbd678e41dc1af8b45ea3edac55fad2f2d Mon Sep 17 00:00:00 2001 From: Clark Du Date: Thu, 15 Mar 2018 18:09:36 +0800 Subject: [PATCH] deprecate: remove callback in module definition --- lib/core/module.js | 22 +++---------------- test/deprecate.test.js | 8 ------- .../modules/deprecated-apis/index.js | 1 - 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/lib/core/module.js b/lib/core/module.js index 05f313bac5..815d60ba77 100644 --- a/lib/core/module.js +++ b/lib/core/module.js @@ -138,32 +138,16 @@ module.exports = class ModuleContainer { } return new Promise((resolve, reject) => { - // Prepare callback - const cb = err => { - printWarn( - 'Supporting callbacks is deprecated and will be removed in next releases. Consider using async/await.', - src - ) - - /* istanbul ignore if */ - if (err) { - return reject(err) - } - resolve() - } - // Call module with `this` context and pass options - const result = handler.call(this, options, cb) + const result = handler.call(this, options) // If module send back a promise if (result && result.then) { return resolve(result) } - // If not expecting a callback but returns no promise (=synchronous) - if (handler.length < 2) { - return resolve() - } + // synchronous + return resolve() }) } } diff --git a/test/deprecate.test.js b/test/deprecate.test.js index c5c20869f7..a86ca2e428 100644 --- a/test/deprecate.test.js +++ b/test/deprecate.test.js @@ -31,14 +31,6 @@ test.serial('Deprecated: module.addVendor()', async t => { t.true(buildSpies.warn.calledWithMatch('module: addVendor is no longer necessary')) }) -test.serial('Deprecated: module callback', async t => { - t.true( - buildSpies.warn.calledWithMatch( - 'Supporting callbacks is deprecated and will be removed in next releases. Consider using async/await.' - ) - ) -}) - // Close server and ask nuxt to stop listening to file changes test.after.always('Closing server and nuxt.js', async t => { await nuxt.close() diff --git a/test/fixtures/deprecate/modules/deprecated-apis/index.js b/test/fixtures/deprecate/modules/deprecated-apis/index.js index d0a726b73e..9f06056b9e 100644 --- a/test/fixtures/deprecate/modules/deprecated-apis/index.js +++ b/test/fixtures/deprecate/modules/deprecated-apis/index.js @@ -1,4 +1,3 @@ module.exports = function basicModule(options, resolve) { this.addVendor('lodash') - resolve() }