mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
refactor: plugin sanity check (#3743)
This commit is contained in:
parent
5b98c1ccee
commit
50be809b1c
@ -446,9 +446,17 @@ export default class Builder {
|
|||||||
|
|
||||||
// Check plugins exist then set alias to their real path
|
// Check plugins exist then set alias to their real path
|
||||||
await Promise.all(this.plugins.map(async (p) => {
|
await Promise.all(this.plugins.map(async (p) => {
|
||||||
const pluginFile = `${p.src}${path.extname(p.src) ? '' : '.js'}`
|
const ext = path.extname(p.src) ? '' : '.+([^.])'
|
||||||
if (!await fsExtra.pathExists(pluginFile)) {
|
const pluginFiles = await glob(`${p.src}${ext}`)
|
||||||
throw new Error(`Plugin not found: ${pluginFile}`)
|
|
||||||
|
if (!pluginFiles || pluginFiles.length === 0) {
|
||||||
|
throw new Error(`Plugin not found: ${p.src}`)
|
||||||
|
} else if (pluginFiles.length > 1) {
|
||||||
|
consola.warn({
|
||||||
|
message: `Found ${pluginFiles.length} plugins that match the configuration, suggest to specify extension:`,
|
||||||
|
additional: ` ${pluginFiles.join('\n ')}`,
|
||||||
|
badge: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const src = this.relativeToBuild(p.src)
|
const src = this.relativeToBuild(p.src)
|
||||||
|
0
test/fixtures/with-config/plugins/test.json
vendored
Normal file
0
test/fixtures/with-config/plugins/test.json
vendored
Normal file
15
test/fixtures/with-config/with-config.test.js
vendored
15
test/fixtures/with-config/with-config.test.js
vendored
@ -1,3 +1,16 @@
|
|||||||
|
const consola = require('consola')
|
||||||
const { buildFixture } = require('../../utils/build')
|
const { buildFixture } = require('../../utils/build')
|
||||||
|
|
||||||
buildFixture('with-config')
|
describe('with-config', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
consola.warn = jest.fn()
|
||||||
|
})
|
||||||
|
buildFixture('with-config', () => {
|
||||||
|
expect(consola.warn).toHaveBeenCalledTimes(1)
|
||||||
|
expect(consola.warn.mock.calls[0]).toMatchObject([{
|
||||||
|
message: 'Found 2 plugins that match the configuration, suggest to specify extension:',
|
||||||
|
additional: expect.stringContaining('plugins/test.json'),
|
||||||
|
badge: true
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { loadFixture, Nuxt, Builder } from './index'
|
import { loadFixture, Nuxt, Builder } from './index'
|
||||||
|
|
||||||
export const buildFixture = function buildFixture(fixture) {
|
export const buildFixture = function (fixture, callback) {
|
||||||
test(`Build ${fixture}`, async () => {
|
test(`Build ${fixture}`, async () => {
|
||||||
const config = loadFixture(fixture)
|
const config = loadFixture(fixture)
|
||||||
const nuxt = new Nuxt(config)
|
const nuxt = new Nuxt(config)
|
||||||
@ -10,5 +10,8 @@ export const buildFixture = function buildFixture(fixture) {
|
|||||||
// 2: BUILD_DONE
|
// 2: BUILD_DONE
|
||||||
expect(builder._buildStatus).toBe(2)
|
expect(builder._buildStatus).toBe(2)
|
||||||
expect(buildDone).toHaveBeenCalledTimes(1)
|
expect(buildDone).toHaveBeenCalledTimes(1)
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback(builder)
|
||||||
|
}
|
||||||
}, 120000)
|
}, 120000)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user