Closed sadafie closed 8 years ago
I had the same error message. It seems you don't give the validator an object that contains the config. Can you show how you call webpack-validator and your complete config? Maybe you can share a gist?
My thought is that we should just do a check before validating the config. If it's an array, then iterate through it and pass each item into the validator.
Can you show how you call webpack-validator and your complete config? Maybe you can share a gist?
Sorry, I fixed a copy/paste error in my config. It's not an object, it's an array of objects. The following configs are nearly identical to the one I pasted.
If it's an array, then iterate through it and pass each item into the validator.
That's how I would expect it to work as well.
@sadafie would you be interested to makeapullrequest.com? The relevant code is here
Yep, I'll submit a PR
@kentcdodds I finally got around to looking at this today. The notion of iterating over each array item (seemingly?) doesn't work because the validate method is used to validate each of the properties as well, and adding the Array check breaks some of the existing tests (i.e., entry.test.js
).
An alternative that stood out to me was to update the base Joi schema type to be an array:
const schema = Joi.array().items(Joi.object({
amd: Joi.object(),
bail: Joi.boolean(),
cache: Joi.boolean(),
context: contextSchema,
debug: Joi.boolean(),
devServer: devServerSchema,
devtool: devtoolSchema,
entry: entrySchema,
externals: externalsSchema,
loader: Joi.any(), // ?
module: moduleSchema,
node: nodeSchema,
output: outputSchema,
plugins: pluginsSchema,
profile: Joi.boolean(),
progress: Joi.boolean(),
recordsInputPath: looksLikeAbsolutePath,
recordsOutputPath: looksLikeAbsolutePath,
recordsPath: looksLikeAbsolutePath,
resolve: resolveSchema,
resolveLoader: resolveSchema.concat(Joi.object({
moduleTemplates: Joi.array().items(Joi.string()),
})),
watch: Joi.boolean(),
watchOptions: watchOptionsSchema,
stats: Joi.any(), // TODO
target: Joi.any(), // TODO
// Plugins
postcss: Joi.any(),
eslint: Joi.any(),
tslint: Joi.any(),
metadata: Joi.any(),
})).single()
But that breaks the schemaExtension case where two schema's are concat
-ed together. Joi only concats schemas of the same type.
Not sure if there are any recommendations here, or if someone more familiar with this code wants to take a stab.
the validate method is used to validate each of the properties as well,
Ah, yeah, that makes sense. Maybe instead we can create a validateRoot
method which will be the new module.exports
and that will call the validate
method. That way we can separate the start of the validation at the root of the config from the property validation. Would that work?
Maybe instead we can create a validateRoot
Let me play around with that. It seems like it would work, but I wasn't sure if it'd be a non-ideal solution.
(Accidentally pressed the close button on mobile, doh. Sorry :))
Ok, I think I have a working solution, but cant commit because it's failing code coverage. Is there a way to check exactly which code branch is the one not covered?
Yeah, use --no-verify
when committing and push up your branch so we can chat about it :-)
Oh, sorry, I misread your message. You should be able to open the file: coverage/lcov-report/index.html
and that'll show you the code coverage reports :+1:
I'm facing this issue in the latest version (v2.2.8) and webpack v1.13.2
My config is:
module.exports = validate([
{},
{}
]);
$ npm list | grep webpack-validator
└─┬ webpack-validator@2.2.8
$ node_modules/.bin/webpack
[
{},
{}
]
[1] "value" must be an object
Using Webpack 2 and multi-configurations, I get the following output (shortened) and error:
Perhaps there is an error in my config (though it builds), but this error does not clearly point to the issue.