Skip to content

Commit ec1e69a

Browse files
authoredMar 30, 2020
fix(server): replace optimist on yargs lib (#3451)
fix #2473
1 parent ffad7fa commit ec1e69a

File tree

4 files changed

+330
-59
lines changed

4 files changed

+330
-59
lines changed
 

‎lib/cli.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const path = require('path')
44
const assert = require('assert')
5-
const optimist = require('optimist')
5+
const yargs = require('yargs')
66
const fs = require('graceful-fs')
77

88
const Server = require('./server')
@@ -11,7 +11,7 @@ const constant = require('./constants')
1111

1212
function processArgs (argv, options, fs, path) {
1313
if (argv.help) {
14-
console.log(optimist.help())
14+
console.log(yargs.help())
1515
process.exit(0)
1616
}
1717

@@ -152,7 +152,7 @@ function argsBeforeDoubleDash (argv) {
152152
}
153153

154154
function describeShared () {
155-
optimist
155+
yargs
156156
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
157157
'Usage:\n' +
158158
' $0 <command>\n\n' +
@@ -167,7 +167,7 @@ function describeShared () {
167167
}
168168

169169
function describeInit () {
170-
optimist
170+
yargs
171171
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
172172
'INIT - Initialize a config file.\n\n' +
173173
'Usage:\n' +
@@ -179,7 +179,7 @@ function describeInit () {
179179
}
180180

181181
function describeStart () {
182-
optimist
182+
yargs
183183
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
184184
'START - Start the server / do a single run.\n\n' +
185185
'Usage:\n' +
@@ -205,7 +205,7 @@ function describeStart () {
205205
}
206206

207207
function describeRun () {
208-
optimist
208+
yargs
209209
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
210210
'RUN - Run the tests (requires running server).\n\n' +
211211
'Usage:\n' +
@@ -221,7 +221,7 @@ function describeRun () {
221221
}
222222

223223
function describeStop () {
224-
optimist
224+
yargs
225225
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
226226
'STOP - Stop the server (requires running server).\n\n' +
227227
'Usage:\n' +
@@ -232,7 +232,7 @@ function describeStop () {
232232
}
233233

234234
function describeCompletion () {
235-
optimist
235+
yargs
236236
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
237237
'COMPLETION - Bash/ZSH completion for karma.\n\n' +
238238
'Installation:\n' +
@@ -245,7 +245,7 @@ function printRunnerProgress (data) {
245245
}
246246

247247
exports.process = function () {
248-
const argv = optimist.parse(argsBeforeDoubleDash(process.argv.slice(2)))
248+
const argv = yargs.parse(argsBeforeDoubleDash(process.argv.slice(2)))
249249
const options = {
250250
cmd: argv._.shift()
251251
}
@@ -280,7 +280,7 @@ exports.process = function () {
280280
} else {
281281
console.error('Unknown command "' + options.cmd + '".')
282282
}
283-
optimist.showHelp()
283+
yargs.showHelp()
284284
process.exit(1)
285285
}
286286

‎package-lock.json

+312-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -406,30 +406,30 @@
406406
"log4js": "^4.0.0",
407407
"mime": "^2.3.1",
408408
"minimatch": "^3.0.2",
409-
"optimist": "^0.6.1",
410409
"qjobs": "^1.1.4",
411410
"range-parser": "^1.2.0",
412411
"rimraf": "^2.6.0",
413412
"socket.io": "2.1.1",
414413
"source-map": "^0.6.1",
415414
"tmp": "0.0.33",
416-
"ua-parser-js": "0.7.21"
415+
"ua-parser-js": "0.7.21",
416+
"yargs": "^15.3.1"
417417
},
418418
"devDependencies": {
419+
"@commitlint/cli": "^8.3.4",
420+
"@commitlint/config-conventional": "^8.3.4",
419421
"browserify": "^16.2.3",
420422
"chai": "^4.2.0",
421423
"chai-as-promised": "^7.1.1",
422424
"chai-subset": "^1.2.2",
423-
"@commitlint/cli": "^8.3.4",
424-
"@commitlint/config-conventional": "^8.3.4",
425425
"cucumber": "^3.1.0",
426426
"eslint": "^5.16.0",
427427
"eslint-config-standard": "^12.0.0",
428428
"eslint-plugin-import": "^2.17.2",
429429
"eslint-plugin-node": "^9.0.1",
430430
"eslint-plugin-promise": "^4.1.1",
431431
"eslint-plugin-standard": "^4.0.0",
432-
"grunt": "^1.0.4",
432+
"grunt": "^1.1.0",
433433
"grunt-auto-release": "^0.0.7",
434434
"grunt-browserify": "^5.0.0",
435435
"grunt-bump": "^0.8.0",

‎test/unit/cli.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const optimist = require('optimist')
3+
const yargs = require('yargs')
44
const path = require('path')
55
const mocks = require('mocks')
66

@@ -34,7 +34,7 @@ describe('cli', () => {
3434
}
3535

3636
const processArgs = (args, opts) => {
37-
const argv = optimist.parse(args)
37+
const argv = yargs.parse(args)
3838
return e.processArgs(argv, opts || {}, fsMock, pathMock)
3939
}
4040

@@ -62,7 +62,7 @@ describe('cli', () => {
6262

6363
describe('processArgs', () => {
6464
it('should override if multiple options given', () => {
65-
// optimist parses --port 123 --port 456 as port = [123, 456] which makes no sense
65+
// yargs parses --port 123 --port 456 as port = [123, 456] which makes no sense
6666
const options = processArgs(['some.conf', '--port', '12', '--log-level', 'info', '--port', '34', '--log-level', 'debug'])
6767

6868
expect(options.port).to.equal(34)

0 commit comments

Comments
 (0)
Please sign in to comment.