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) => {
// 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) {
// synchronous
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'))
})
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()

View File

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