Skip to content

Commit 77e511f

Browse files
authored
Enable TypeScript checking of javascript, and resolve or suppress errors (#1194)
1 parent 2491c76 commit 77e511f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const spawn = require('child_process').spawn;
77
const path = require('path');
88
const fs = require('fs');
99

10+
// @ts-check
11+
1012
class Option {
1113
/**
1214
* Initialize a new `Option` with the given `flags` and `description`.
@@ -22,10 +24,11 @@ class Option {
2224
this.optional = flags.indexOf('[') >= 0; // A value is optional when the option is specified.
2325
this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line.
2426
this.negate = flags.indexOf('-no-') !== -1;
25-
flags = flags.split(/[ ,|]+/);
26-
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();
27-
this.long = flags.shift();
27+
const flagParts = flags.split(/[ ,|]+/);
28+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1])) this.short = flagParts.shift();
29+
this.long = flagParts.shift();
2830
this.description = description || '';
31+
this.defaultValue = undefined;
2932
}
3033

3134
/**
@@ -83,6 +86,7 @@ class CommanderError extends Error {
8386
this.name = this.constructor.name;
8487
this.code = code;
8588
this.exitCode = exitCode;
89+
this.nestedError = undefined;
8690
}
8791
}
8892

@@ -98,6 +102,7 @@ class Command extends EventEmitter {
98102
super();
99103
this.commands = [];
100104
this.options = [];
105+
this.parent = null;
101106
this._allowUnknownOption = false;
102107
this._args = [];
103108
this.rawArgs = null;
@@ -112,6 +117,7 @@ class Command extends EventEmitter {
112117
this._executableFile = null; // custom name for executable
113118
this._defaultCommandName = null;
114119
this._exitCallback = null;
120+
this._alias = null;
115121

116122
this._noHelp = false;
117123
this._helpFlags = '-h, --help';
@@ -634,7 +640,7 @@ class Command extends EventEmitter {
634640
*
635641
* @param {string[]} [argv] - optional, defaults to process.argv
636642
* @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
637-
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
643+
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
638644
* @return {Command} for chaining
639645
* @api public
640646
*/
@@ -648,6 +654,7 @@ class Command extends EventEmitter {
648654
// Default to using process.argv
649655
if (argv === undefined) {
650656
argv = process.argv;
657+
// @ts-ignore
651658
if (process.versions && process.versions.electron) {
652659
parseOptions.from = 'electron';
653660
}
@@ -663,6 +670,7 @@ class Command extends EventEmitter {
663670
userArgs = argv.slice(2);
664671
break;
665672
case 'electron':
673+
// @ts-ignore
666674
if (process.defaultApp) {
667675
this._scriptPath = argv[1];
668676
userArgs = argv.slice(2);
@@ -780,6 +788,7 @@ class Command extends EventEmitter {
780788

781789
const signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
782790
signals.forEach((signal) => {
791+
// @ts-ignore
783792
process.on(signal, () => {
784793
if (proc.killed === false && proc.exitCode === null) {
785794
proc.kill(signal);
@@ -798,11 +807,13 @@ class Command extends EventEmitter {
798807
});
799808
}
800809
proc.on('error', (err) => {
810+
// @ts-ignore
801811
if (err.code === 'ENOENT') {
802812
const executableMissing = `'${bin}' does not exist
803813
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
804814
- if the default executable name is not suitable, use the executableFile option to supply a custom name`;
805815
throw new Error(executableMissing);
816+
// @ts-ignore
806817
} else if (err.code === 'EACCES') {
807818
throw new Error(`'${bin}' not executable`);
808819
}
@@ -1119,7 +1130,6 @@ class Command extends EventEmitter {
11191130
/**
11201131
* Unknown command.
11211132
*
1122-
* @param {string} flag
11231133
* @api private
11241134
*/
11251135

@@ -1145,7 +1155,7 @@ class Command extends EventEmitter {
11451155
* @param {string} str
11461156
* @param {string} [flags]
11471157
* @param {string} [description]
1148-
* @return {Command} for chaining
1158+
* @return {Command | string} this for chaining
11491159
* @api public
11501160
*/
11511161

0 commit comments

Comments
 (0)