Display proper error when specified plugin isn't found (#3672)

Picking up on https://github.com/nuxt/nuxt.js/pull/3434 -- synced with dev and tests included.
This commit is contained in:
Jonas Galvez 2018-08-10 11:48:27 -03:00 committed by Clark Du
parent 7c7701d622
commit 75d6c4e33a
3 changed files with 22 additions and 0 deletions

View File

@ -442,6 +442,13 @@ export default class Builder {
compilersOptions.push(serverConfig)
}
// Check plugins exist then set alias to their real path
await Promise.all(this.plugins.map(async (p) => {
if (!await fsExtra.pathExists(p.src)) {
throw new Error(`Plugin not found: ${r(p.src)}`)
}
}))
// Alias plugins to their real path
this.plugins.forEach((p) => {
const src = this.relativeToBuild(p.src)

View File

@ -0,0 +1,3 @@
export default {
plugins: ['~/plugins/missing.js']
}

View File

@ -43,4 +43,16 @@ describe('nuxt', () => {
await nuxt.close()
})
test('Fail to build when specified plugin isn\'t found', () => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname, '..', 'fixtures', 'missing-plugin')
})
return new Builder(nuxt).build().catch((err) => {
const s = String(err)
expect(s.includes('Plugin not found')).toBe(true)
})
})
})