deprecate: remove nuxt.plugin

This commit is contained in:
Clark Du 2018-03-15 17:49:14 +08:00
parent a52a68e47d
commit 78aac2df26
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
4 changed files with 2 additions and 39 deletions

View File

@ -5,7 +5,7 @@ module.exports = function () {
// overwrite nuxt.listen()
this.nuxt.listen = (port, host) => new Promise((resolve) => server.listen(port || 3000, host || 'localhost', resolve))
// close this server on 'close' event
this.nuxt.plugin('close', () => new Promise((resolve) => server.close(resolve)))
this.nuxt.hook('close', () => new Promise((resolve) => server.close(resolve)))
// Add socket.io events
let messages = []

View File

@ -5,7 +5,7 @@ const { isPlainObject } = require('lodash')
const chalk = require('chalk')
const { existsSync } = require('fs-extra')
const { Options } = require('../common')
const { sequence, printError, printWarn } = require('../common/utils')
const { sequence, printError } = require('../common/utils')
const { resolve, join } = require('path')
const { version } = require('../../package.json')
const ModuleContainer = require('./module')
@ -70,30 +70,6 @@ module.exports = class Nuxt {
return this
}
plugin(name, fn) {
// A tiny backward compatibility util
const hook = {
ready: 'ready',
close: 'close',
listen: 'listen',
built: 'build:done'
}[name]
if (hook) {
this.hook(hook, fn)
printWarn(
`nuxt.plugin('${name}',..) is deprecated. Use new hooks system.`
)
} else {
throw new Error(
`nuxt.plugin('${name}',..) is not supported. Use new hooks system.`
)
}
// Always return nuxt class which has plugin() for two level hooks
return this
}
hook(name, fn) {
if (!name || typeof fn !== 'function') {
return

View File

@ -27,10 +27,6 @@ test.serial('Init Nuxt.js', async t => {
t.true(buildSpies.log.calledWithMatch('OPEN'))
})
test.serial('Deprecated: nuxt.plugin()', async t => {
t.true(nuxt.__builder_plugin)
})
test.serial('Deprecated: module.addVendor()', async t => {
t.true(buildSpies.warn.calledWithMatch('module: addVendor is no longer necessary'))
})
@ -43,11 +39,6 @@ test.serial('Deprecated: module callback', async t => {
)
})
test.serial('Error: nuxt.plugin()', async t => {
const error = t.throws(() => nuxt.plugin('build:done', () => {}))
t.is(error.message, 'nuxt.plugin(\'build:done\',..) is not supported. Use new hooks system.')
})
// 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,8 +1,4 @@
module.exports = function basicModule(options, resolve) {
this.addVendor('lodash')
// Note: Plugin is deprecated. Please use new hooks system.
this.nuxt.plugin('built', (builder) => {
this.nuxt.__builder_plugin = true
})
resolve()
}