Skip to content

Commit

Permalink
chore: add plugins as known valid options and concat with instance
Browse files Browse the repository at this point in the history
  • Loading branch information
DSchau committed Sep 19, 2019
1 parent 01f4b8f commit f0ef733
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/gatsby/src/utils/validate-plugin-options.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
const Joi = require(`@hapi/joi`)

const baseSchema = Joi.object().keys({
plugins: Joi.array(
Joi.alternatives(
Joi.string(),
Joi.object().keys({
resolve: Joi.string().required(),
options: Joi.object()
.keys()
.unknown(),
})
)
),
})

exports.validatePluginOptions = (res, options = {}) => {
let chain = Promise.resolve(res)
if (res && res.validate) {
chain = res.validate(options, {
chain = baseSchema.concat(res).validate(options, {
abortEarly: false,
allowUnknown: true,
})
}
return chain
Expand Down

0 comments on commit f0ef733

Please sign in to comment.