From 75d6c4e33ae97a668c43c2d5c38104373112b26c Mon Sep 17 00:00:00 2001 From: Jonas Galvez Date: Fri, 10 Aug 2018 11:48:27 -0300 Subject: [PATCH] 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. --- lib/builder/builder.js | 7 +++++++ test/fixtures/missing-plugin/nuxt.config.js | 3 +++ test/unit/nuxt.test.js | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 test/fixtures/missing-plugin/nuxt.config.js diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 4992870b96..1c3e00dacd 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -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) diff --git a/test/fixtures/missing-plugin/nuxt.config.js b/test/fixtures/missing-plugin/nuxt.config.js new file mode 100644 index 0000000000..dd6fcfa085 --- /dev/null +++ b/test/fixtures/missing-plugin/nuxt.config.js @@ -0,0 +1,3 @@ +export default { + plugins: ['~/plugins/missing.js'] +} diff --git a/test/unit/nuxt.test.js b/test/unit/nuxt.test.js index 46395238d9..badb30dbf3 100644 --- a/test/unit/nuxt.test.js +++ b/test/unit/nuxt.test.js @@ -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) + }) + }) })