Skip to content

Commit b8c04ba

Browse files
le0nikKent C. Dodds
authored andcommitted
fix(loaders[i].loaders): allow mix of objects and strings in loaders array (#125)
1 parent f055505 commit b8c04ba

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/properties/module/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ const loaderSchemaFn = ({ rules }) => {
4040
include: conditionSchema,
4141
loader: Joi.string(),
4242
query: Joi.object(),
43-
loaders: Joi.array().items(Joi.string()),
43+
loaders: Joi.array().items(
44+
Joi.string(),
45+
Joi.object({
46+
loader: Joi.string().required(),
47+
query: Joi.object(),
48+
})
49+
),
4450
})
4551
.xor('loaders', 'loader')
4652
.nand('loaders', 'query')

src/properties/module/index.test.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ const validModuleConfigs = [
5151
},
5252
schema: schemaFn({ rules: { 'loader-prefer-include': true } }),
5353
},
54+
{
55+
// should allow mix of objects and strings in `loaders` array
56+
input: {
57+
loaders: [
58+
{
59+
test: /foo/,
60+
loaders: ['style-loader', { loader: 'file-loader' }],
61+
},
62+
],
63+
},
64+
},
5465
]
5566

5667
const invalidModuleConfigs = [
@@ -84,7 +95,10 @@ const invalidModuleConfigs = [
8495
{ test: /\.less$/, loaders: [1, 2] },
8596
],
8697
},
87-
error: { message: '"0" must be a string', path: 'loaders.0.loaders.0' },
98+
error: {
99+
message: '"loaders" at position 0 does not match any of the allowed types',
100+
path: 'loaders.0.loaders.0',
101+
},
88102
},
89103
{
90104
input: {
@@ -152,6 +166,37 @@ const invalidModuleConfigs = [
152166
},
153167
schema: schemaFn({ rules: { 'loader-enforce-include-or-exclude': true } }),
154168
},
169+
{
170+
// should enforce `loader` property, if object is found in `loaders` array
171+
input: {
172+
loaders: [{
173+
test: /foo/,
174+
loaders: [
175+
{ query: { foo: 'bar' } },
176+
],
177+
}],
178+
},
179+
error: {
180+
message: '"loaders" at position 0 does not match any of the allowed types',
181+
path: 'loaders.0.loaders.0',
182+
},
183+
},
184+
{
185+
// should disallow properties, other than `loader` and `query`
186+
// in objects inside the `loaders` array
187+
input: {
188+
loaders: [{
189+
test: /foo/,
190+
loaders: [
191+
{ loader: 'foo', query: { foo: 'bar' }, include: /foo/ },
192+
],
193+
}],
194+
},
195+
error: {
196+
message: '"loaders" at position 0 does not match any of the allowed types',
197+
path: 'loaders.0.loaders.0',
198+
},
199+
},
155200
]
156201

157202
const moduleSchema = schemaFn({

0 commit comments

Comments
 (0)