deprecate: remove callback in module definition

This commit is contained in:
Clark Du 2018-03-15 18:09:36 +08:00
parent 78aac2df26
commit 1080dfdbd6
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
3 changed files with 3 additions and 28 deletions

View File

@ -138,32 +138,16 @@ module.exports = class ModuleContainer {
} }
return new Promise((resolve, reject) => { 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 // 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 module send back a promise
if (result && result.then) { if (result && result.then) {
return resolve(result) return resolve(result)
} }
// If not expecting a callback but returns no promise (=synchronous) // synchronous
if (handler.length < 2) {
return resolve() return resolve()
}
}) })
} }
} }

View File

@ -31,14 +31,6 @@ test.serial('Deprecated: module.addVendor()', async t => {
t.true(buildSpies.warn.calledWithMatch('module: addVendor is no longer necessary')) 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 // Close server and ask nuxt to stop listening to file changes
test.after.always('Closing server and nuxt.js', async t => { test.after.always('Closing server and nuxt.js', async t => {
await nuxt.close() await nuxt.close()

View File

@ -1,4 +1,3 @@
module.exports = function basicModule(options, resolve) { module.exports = function basicModule(options, resolve) {
this.addVendor('lodash') this.addVendor('lodash')
resolve()
} }