Skip to content

Commit 55c7baa

Browse files
committed
fix: processing of cli flags
1 parent 5de4eea commit 55c7baa

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

bin/cli-flags.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const normalizeOption = (option) => (typeof option === 'object' ? option : {});
4+
35
module.exports = {
46
devServer: [
57
{
@@ -47,7 +49,7 @@ module.exports = {
4749
],
4850
description: 'Directory for static contents.',
4951
processor(opts) {
50-
opts.static = opts.static || {};
52+
opts.static = normalizeOption(opts.static);
5153
opts.static.directory = opts.staticDirectory;
5254
delete opts.staticDirectory;
5355
},
@@ -64,7 +66,7 @@ module.exports = {
6466
'The bundled files will be available in the browser under this path.',
6567
multiple: true,
6668
processor(opts) {
67-
opts.static = opts.static || {};
69+
opts.static = normalizeOption(opts.static);
6870
opts.static.publicPath = opts.staticPublicPath;
6971
delete opts.staticPublicPath;
7072
},
@@ -82,7 +84,7 @@ module.exports = {
8284
'Do not tell dev-server to use serveIndex middleware.',
8385
negative: true,
8486
processor(opts) {
85-
opts.static = opts.static || {};
87+
opts.static = normalizeOption(opts.static);
8688
opts.static.serveIndex = opts.staticServeIndex;
8789
delete opts.staticServeIndex;
8890
},
@@ -99,7 +101,7 @@ module.exports = {
99101
negatedDescription: 'Do not watch for files in static content directory.',
100102
negative: true,
101103
processor(opts) {
102-
opts.static = opts.static || {};
104+
opts.static = normalizeOption(opts.static);
103105
opts.static.watch = opts.staticWatch;
104106
delete opts.staticWatch;
105107
},
@@ -138,7 +140,7 @@ module.exports = {
138140
],
139141
description: 'Passphrase for a pfx file.',
140142
processor(opts) {
141-
opts.https = typeof opts.https === 'object' ? opts.https : {};
143+
opts.https = normalizeOption(opts.https);
142144
opts.https.passphrase = opts.httpsPassphrase;
143145
delete opts.httpsPassphrase;
144146
},
@@ -153,7 +155,7 @@ module.exports = {
153155
],
154156
description: 'Path to an SSL key.',
155157
processor(opts) {
156-
opts.https = typeof opts.https === 'object' ? opts.https : {};
158+
opts.https = normalizeOption(opts.https);
157159
opts.https.key = opts.httpsKey;
158160
delete opts.httpsKey;
159161
},
@@ -168,7 +170,7 @@ module.exports = {
168170
],
169171
description: 'Path to an SSL pfx file.',
170172
processor(opts) {
171-
opts.https = typeof opts.https === 'object' ? opts.https : {};
173+
opts.https = normalizeOption(opts.https);
172174
opts.https.pfx = opts.httpsPfx;
173175
delete opts.httpsPfx;
174176
},
@@ -183,7 +185,7 @@ module.exports = {
183185
],
184186
description: 'Path to an SSL certificate.',
185187
processor(opts) {
186-
opts.https = typeof opts.https === 'object' ? opts.https : {};
188+
opts.https = normalizeOption(opts.https);
187189
opts.https.cert = opts.httpsCert;
188190
delete opts.httpsCert;
189191
},
@@ -198,7 +200,7 @@ module.exports = {
198200
],
199201
description: 'Path to an SSL CA certificate.',
200202
processor(opts) {
201-
opts.https = typeof opts.https === 'object' ? opts.https : {};
203+
opts.https = normalizeOption(opts.https);
202204
opts.https.cacert = opts.httpsCacert;
203205
delete opts.httpsCacert;
204206
},
@@ -214,7 +216,7 @@ module.exports = {
214216
description: 'Request for an SSL certificate.',
215217
negatedDescription: 'Do not request for an SSL certificate.',
216218
processor(opts) {
217-
opts.https = typeof opts.https === 'object' ? opts.https : {};
219+
opts.https = normalizeOption(opts.https);
218220
opts.https.requestCert = opts.httpsRequestCert;
219221
delete opts.httpsRequestCert;
220222
},
@@ -257,7 +259,7 @@ module.exports = {
257259
'Do not tell devServer to inject a Hot Module Replacement entry.',
258260
negative: true,
259261
processor(opts) {
260-
opts.client = opts.client || {};
262+
opts.client = normalizeOption(opts.client);
261263
opts.client.hotEntry = opts.clientHotEntry;
262264
delete opts.clientHotEntry;
263265
},
@@ -275,7 +277,7 @@ module.exports = {
275277
'Do not print compilation progress in percentage in the browser.',
276278
negative: true,
277279
processor(opts) {
278-
opts.client = opts.client || {};
280+
opts.client = normalizeOption(opts.client);
279281
opts.client.progress = opts.clientProgress;
280282
delete opts.clientProgress;
281283
},
@@ -294,11 +296,27 @@ module.exports = {
294296
'Do not show a full-screen overlay in the browser when there are compiler errors or warnings.',
295297
negative: true,
296298
processor(opts) {
297-
opts.client = opts.client || {};
299+
opts.client = normalizeOption(opts.client);
298300
opts.client.overlay = opts.clientOverlay;
299301
delete opts.clientOverlay;
300302
},
301303
},
304+
{
305+
name: 'client-logging',
306+
type: String,
307+
configs: [
308+
{
309+
type: 'string',
310+
},
311+
],
312+
description:
313+
'Log level in the browser (none, error, warn, info, log, verbose).',
314+
processor(opts) {
315+
opts.client = normalizeOption(opts.client);
316+
opts.client.logging = opts.clientLogging;
317+
delete opts.clientLogging;
318+
},
319+
},
302320
{
303321
name: 'open',
304322
type: [Boolean, String],
@@ -325,7 +343,7 @@ module.exports = {
325343
],
326344
description: 'Open specified browser.',
327345
processor(opts) {
328-
opts.open = opts.open || {};
346+
opts.open = normalizeOption(opts.open);
329347
opts.open.app = opts.openApp;
330348
delete opts.openApp;
331349
},
@@ -343,30 +361,14 @@ module.exports = {
343361
],
344362
description: 'Open specified route in browser.',
345363
processor(opts) {
346-
opts.open = opts.open || {};
364+
opts.open = normalizeOption(opts.open);
347365
opts.open.target = opts.openTarget;
348366
delete opts.openTarget;
349367
},
350368
negatedDescription: 'Do not open specified route in browser.',
351369
multiple: true,
352370
negative: true,
353371
},
354-
{
355-
name: 'client-logging',
356-
type: String,
357-
configs: [
358-
{
359-
type: 'string',
360-
},
361-
],
362-
description:
363-
'Log level in the browser (none, error, warn, info, log, verbose).',
364-
processor(opts) {
365-
opts.client = opts.client || {};
366-
opts.client.logging = opts.clientLogging;
367-
delete opts.clientLogging;
368-
},
369-
},
370372
{
371373
name: 'history-api-fallback',
372374
type: Boolean,

0 commit comments

Comments
 (0)