Skip to content

Commit df010a7

Browse files
fix(lib/options): handle {Object} return (options.plugins) (#301)
1 parent e7e5478 commit df010a7

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

lib/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function parseOptions (params) {
99

1010
if (typeof params.plugins === 'undefined') plugins = []
1111
else if (Array.isArray(params.plugins)) plugins = params.plugins
12-
else plugins = params.plugins
12+
else plugins = [ params.plugins ]
1313

1414
const options = {}
1515

lib/options.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
"stringifier": {
2626
"type": [ "string", "object" ]
2727
},
28+
"plugins": {
29+
"anyOf": [
30+
{ "type": "array" },
31+
{ "type": "object" },
32+
{ "instanceof": "Function" }
33+
]
34+
},
2835
"sourceMap": {
2936
"type": [ "string", "boolean" ]
3037
}

test/options/__snapshots__/plugins.test.js.snap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
exports[`Options Plugins - {Array} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;
44

5-
exports[`Options Plugins - {Function} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;
5+
exports[`Options Plugins - {Function} - {Array} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;
6+
7+
exports[`Options Plugins - {Function} - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;
8+
9+
exports[`Options Plugins - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;

test/options/plugins.test.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,25 @@ describe('Options', () => {
2222
})
2323
})
2424

25-
test('Plugins - {Function}', () => {
25+
test('Plugins - {Object}', () => {
26+
const config = {
27+
loader: {
28+
options: {
29+
ident: 'postcss',
30+
plugins: require('../fixtures/config/plugin')
31+
}
32+
}
33+
}
34+
35+
return webpack('css/index.js', config).then((stats) => {
36+
const src = loader(stats).src
37+
38+
expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
39+
expect(src).toMatchSnapshot()
40+
})
41+
})
42+
43+
test('Plugins - {Function} - {Array}', () => {
2644
const config = {
2745
loader: {
2846
options: {
@@ -39,4 +57,22 @@ describe('Options', () => {
3957
expect(src).toMatchSnapshot()
4058
})
4159
})
60+
61+
test('Plugins - {Function} - {Object}', () => {
62+
const config = {
63+
loader: {
64+
options: {
65+
ident: 'postcss',
66+
plugins: () => require('../fixtures/config/plugin')()
67+
}
68+
}
69+
}
70+
71+
return webpack('css/index.js', config).then((stats) => {
72+
const src = loader(stats).src
73+
74+
expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
75+
expect(src).toMatchSnapshot()
76+
})
77+
})
4278
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy