Skip to content

Commit 0802c42

Browse files
fix: upgrade commander 4 -> 11 (#3848)
* build(deps): upgrade `commander` 4 -> 11 * Update packages/api/cli/src/electron-forge.ts Co-authored-by: Kevin Cui <[email protected]> --------- Co-authored-by: Kevin Cui <[email protected]>
1 parent e1b4551 commit 0802c42

11 files changed

+77
-94
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@octokit/rest": "^18.0.11",
4646
"@octokit/types": "^6.1.2",
4747
"chalk": "^4.0.0",
48-
"commander": "^4.1.1",
48+
"commander": "^11.1.0",
4949
"cross-spawn": "^7.0.3",
5050
"cross-zip": "^4.0.0",
5151
"debug": "^4.3.1",

packages/api/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@electron-forge/shared-types": "7.6.1",
2121
"@electron/get": "^3.0.0",
2222
"chalk": "^4.0.0",
23-
"commander": "^4.1.1",
23+
"commander": "^11.1.0",
2424
"debug": "^4.3.1",
2525
"fs-extra": "^10.0.0",
2626
"listr2": "^7.0.2",

packages/api/cli/src/electron-forge-import.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import path from 'node:path';
2-
31
import { api } from '@electron-forge/core';
4-
import program from 'commander';
5-
import fs from 'fs-extra';
2+
import { program } from 'commander';
63

74
import './util/terminate';
5+
import packageJSON from '../package.json';
6+
87
import workingDir from './util/working-dir';
98

109
(async () => {
1110
let dir = process.cwd();
1211
program
13-
.version((await fs.readJson(path.resolve(__dirname, '../package.json'))).version, '-V, --version', 'Output the current version')
12+
.version(packageJSON.version, '-V, --version', 'Output the current version')
1413
.helpOption('-h, --help', 'Output usage information')
1514
.arguments('[name]')
1615
.action((name) => {
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import path from 'node:path';
2-
31
import { api, InitOptions } from '@electron-forge/core';
4-
import program from 'commander';
5-
import fs from 'fs-extra';
2+
import { program } from 'commander';
63

74
import './util/terminate';
5+
import packageJSON from '../package.json';
6+
87
import workingDir from './util/working-dir';
98

109
(async () => {
1110
let dir = process.cwd();
1211
program
13-
.version((await fs.readJson(path.resolve(__dirname, '../package.json'))).version, '-V, --version', 'Output the current version')
12+
.version(packageJSON.version, '-V, --version', 'Output the current version')
1413
.arguments('[name]')
1514
.option('-t, --template [name]', 'Name of the Forge template to use')
1615
.option('-c, --copy-ci-files', 'Whether to copy the templated CI files', false)
@@ -21,13 +20,15 @@ import workingDir from './util/working-dir';
2120
})
2221
.parse(process.argv);
2322

23+
const options = program.opts();
24+
2425
const initOpts: InitOptions = {
2526
dir,
2627
interactive: true,
27-
copyCIFiles: !!program.copyCiFiles,
28-
force: !!program.force,
28+
copyCIFiles: !!options.copyCiFiles,
29+
force: !!options.force,
2930
};
30-
if (program.template) initOpts.template = program.template;
31+
if (options.template) initOpts.template = options.template;
3132

3233
await api.init(initOpts);
3334
})();

packages/api/cli/src/electron-forge-make.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import path from 'node:path';
2-
31
import { initializeProxy } from '@electron/get';
42
import { api, MakeOptions } from '@electron-forge/core';
5-
import program from 'commander';
6-
import fs from 'fs-extra';
3+
import { program } from 'commander';
74

85
import './util/terminate';
6+
import packageJSON from '../package.json';
7+
98
import workingDir from './util/working-dir';
109

1110
export async function getMakeOptions(): Promise<MakeOptions> {
1211
let dir = process.cwd();
1312
program
14-
.version((await fs.readJson(path.resolve(__dirname, '../package.json'))).version, '-V, --version', 'Output the current version')
13+
.version(packageJSON.version, '-V, --version', 'Output the current version')
1514
.arguments('[cwd]')
1615
.option('--skip-package', 'Assume the app is already packaged')
1716
.option('-a, --arch [arch]', 'Target architecture')
@@ -24,14 +23,16 @@ export async function getMakeOptions(): Promise<MakeOptions> {
2423
})
2524
.parse(process.argv);
2625

26+
const options = program.opts();
27+
2728
const makeOpts: MakeOptions = {
2829
dir,
2930
interactive: true,
30-
skipPackage: program.skipPackage,
31+
skipPackage: options.skipPackage,
3132
};
32-
if (program.targets) makeOpts.overrideTargets = program.targets.split(',');
33-
if (program.arch) makeOpts.arch = program.arch;
34-
if (program.platform) makeOpts.platform = program.platform;
33+
if (options.targets) makeOpts.overrideTargets = options.targets.split(',');
34+
if (options.arch) makeOpts.arch = options.arch;
35+
if (options.platform) makeOpts.platform = options.platform;
3536

3637
return makeOpts;
3738
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import path from 'node:path';
2-
31
import { initializeProxy } from '@electron/get';
42
import { api, PackageOptions } from '@electron-forge/core';
5-
import program from 'commander';
6-
import fs from 'fs-extra';
3+
import { program } from 'commander';
74

85
import './util/terminate';
6+
import packageJSON from '../package.json';
7+
98
import workingDir from './util/working-dir';
109

1110
(async () => {
1211
let dir: string = process.cwd();
1312
program
14-
.version((await fs.readJson(path.resolve(__dirname, '../package.json'))).version, '-V, --version', 'Output the current version')
13+
.version(packageJSON.version, '-V, --version', 'Output the current version')
1514
.arguments('[cwd]')
1615
.option('-a, --arch [arch]', 'Target architecture')
1716
.option('-p, --platform [platform]', 'Target build platform')
@@ -21,14 +20,16 @@ import workingDir from './util/working-dir';
2120
})
2221
.parse(process.argv);
2322

23+
const options = program.opts();
24+
2425
initializeProxy();
2526

2627
const packageOpts: PackageOptions = {
2728
dir,
2829
interactive: true,
2930
};
30-
if (program.arch) packageOpts.arch = program.arch;
31-
if (program.platform) packageOpts.platform = program.platform;
31+
if (options.arch) packageOpts.arch = options.arch;
32+
if (options.platform) packageOpts.platform = options.platform;
3233

3334
await api.package(packageOpts);
3435
})();

packages/api/cli/src/electron-forge-publish.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import path from 'node:path';
2-
31
import { initializeProxy } from '@electron/get';
42
import { api, PublishOptions } from '@electron-forge/core';
5-
import program from 'commander';
6-
import fs from 'fs-extra';
3+
import { program } from 'commander';
74

85
import './util/terminate';
6+
import packageJSON from '../package.json';
7+
98
import { getMakeOptions } from './electron-forge-make';
109
import workingDir from './util/working-dir';
1110

1211
(async () => {
1312
let dir = process.cwd();
1413
program
15-
.version((await fs.readJson(path.resolve(__dirname, '../package.json'))).version, '-V, --version', 'Output the current version')
14+
.version(packageJSON.version, '-V, --version', 'Output the current version')
1615
.arguments('[cwd]')
1716
.option('--target [target[,target...]]', 'The comma-separated deployment targets, defaults to "github"')
1817
.option('--dry-run', "Triggers a publish dry run which saves state and doesn't upload anything")
@@ -24,15 +23,17 @@ import workingDir from './util/working-dir';
2423
})
2524
.parse(process.argv);
2625

26+
const options = program.opts();
27+
2728
initializeProxy();
2829

2930
const publishOpts: PublishOptions = {
3031
dir,
3132
interactive: true,
32-
dryRun: program.dryRun,
33-
dryRunResume: program.fromDryRun,
33+
dryRun: options.dryRun,
34+
dryRunResume: options.fromDryRun,
3435
};
35-
if (program.target) publishOpts.publishTargets = program.target.split(',');
36+
if (options.target) publishOpts.publishTargets = options.target.split(',');
3637

3738
publishOpts.makeOptions = await getMakeOptions();
3839

packages/api/cli/src/electron-forge-start.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import path from 'node:path';
2-
31
import { api, StartOptions } from '@electron-forge/core';
42
import { ElectronProcess } from '@electron-forge/shared-types';
5-
import program from 'commander';
6-
import fs from 'fs-extra';
3+
import { program } from 'commander';
74

85
import './util/terminate';
6+
import packageJSON from '../package.json';
7+
98
import workingDir from './util/working-dir';
109

1110
(async () => {
@@ -20,43 +19,46 @@ import workingDir from './util/working-dir';
2019

2120
let dir = process.cwd();
2221
program
23-
.version((await fs.readJson(path.resolve(__dirname, '../package.json'))).version, '-V, --version', 'Output the current version')
22+
.version(packageJSON.version, '-V, --version', 'Output the current version')
2423
.arguments('[cwd]')
2524
.option('-p, --app-path <path>', "Override the path to the Electron app to launch (defaults to '.')")
2625
.option('-l, --enable-logging', 'Enable advanced logging. This will log internal Electron things')
2726
.option('-n, --run-as-node', 'Run the Electron app as a Node.JS script')
2827
.option('--vscode', 'Used to enable arg transformation for debugging Electron through VSCode. Do not use yourself.')
2928
.option('-i, --inspect-electron', 'Triggers inspect mode on Electron to allow debugging the main process. Electron >1.7 only')
3029
.option('--inspect-brk-electron', 'Triggers inspect-brk mode on Electron to allow debugging the main process. Electron >1.7 only')
31-
.helpOption('-h, --help', 'Output usage information')
30+
.addHelpText(
31+
'after',
32+
`
33+
Any arguments found after "--" will be passed to the Electron app. For example...
34+
35+
$ npx electron-forge start /path/to/project --enable-logging -- -d -f foo.txt
36+
37+
...will pass the arguments "-d -f foo.txt" to the Electron app.`
38+
)
39+
.passThroughOptions(true) // allows args to be passed down to the Electron executable
3240
.action((cwd) => {
3341
dir = workingDir(dir, cwd);
3442
})
3543
.parse(commandArgs);
3644

37-
program.on('--help', () => {
38-
console.log(' Any arguments found after "--" will be passed to the Electron app, e.g.');
39-
console.log('');
40-
console.log(' $ electron-forge /path/to/project -l -- -d -f foo.txt');
41-
console.log('');
42-
console.log(' will pass the arguments "-d -f foo.txt" to the Electron app');
43-
});
45+
const options = program.opts();
4446

4547
const opts: StartOptions = {
4648
dir,
4749
interactive: true,
48-
enableLogging: !!program.enableLogging,
49-
runAsNode: !!program.runAsNode,
50-
inspect: !!program.inspectElectron,
51-
inspectBrk: !!program.inspectBrkElectron,
50+
enableLogging: !!options.enableLogging,
51+
runAsNode: !!options.runAsNode,
52+
inspect: !!options.inspectElectron,
53+
inspectBrk: !!options.inspectBrkElectron,
5254
};
5355

54-
if (program.vscode && appArgs) {
56+
if (options.vscode && appArgs) {
5557
// Args are in the format ~arg~ so we need to strip the "~"
5658
appArgs = appArgs.map((arg) => arg.substr(1, arg.length - 2)).filter((arg) => arg.length > 0);
5759
}
5860

59-
if (program.appPath) opts.appPath = program.appPath;
61+
if (options.appPath) opts.appPath = options.appPath;
6062
if (appArgs) opts.args = appArgs;
6163

6264
const spawned = await api.start(opts);

packages/api/cli/src/electron-forge.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,17 @@
22
// This file requires a shebang above. If it is missing, this is an error.
33

44
import chalk from 'chalk';
5-
import program from 'commander';
5+
import { program } from 'commander';
66
import { Listr } from 'listr2';
77

88
import './util/terminate';
99

10-
import { checkSystem } from './util/check-system';
11-
12-
// eslint-disable-next-line @typescript-eslint/no-require-imports
13-
const metadata = require('../package.json');
14-
15-
const originalSC = program.executeSubCommand.bind(program);
16-
program.executeSubCommand = (argv: string[], args: string[], unknown: string[]) => {
17-
let indexOfDoubleDash = process.argv.indexOf('--');
18-
indexOfDoubleDash = indexOfDoubleDash < 0 ? process.argv.length + 1 : indexOfDoubleDash;
10+
import packageJSON from '../package.json';
1911

20-
const passThroughArgs = args.filter((arg) => process.argv.indexOf(arg) > indexOfDoubleDash);
21-
const normalArgs = args.filter((arg) => process.argv.indexOf(arg) <= indexOfDoubleDash);
22-
23-
let newArgs = args;
24-
let newUnknown = unknown;
25-
if (passThroughArgs.length > 0) {
26-
newArgs = normalArgs.concat(unknown).concat('--').concat(passThroughArgs);
27-
newUnknown = [];
28-
}
29-
return originalSC(argv, newArgs, newUnknown);
30-
};
12+
import { checkSystem } from './util/check-system';
3113

3214
program
33-
.version(metadata.version, '-V, --version', 'Output the current version')
15+
.version(packageJSON.version, '-V, --version', 'Output the current version')
3416
.option('--verbose', 'Enables verbose mode')
3517
.helpOption('-h, --help', 'Output usage information')
3618
.command('init', 'Initialize a new Electron application')
@@ -39,13 +21,8 @@ program
3921
.command('package', 'Package the current Electron application')
4022
.command('make', 'Generate distributables for the current Electron application')
4123
.command('publish', 'Publish the current Electron application')
42-
.on('command:*', async (commands) => {
43-
if (!program._execs.has(commands[0])) {
44-
console.error();
45-
console.error(chalk.red(`Unknown command "${program.args.join(' ')}".`));
46-
console.error('See --help for a list of available commands.');
47-
process.exit(1);
48-
} else if (!process.argv.includes('--help') && !process.argv.includes('--h')) {
24+
.hook('preSubcommand', async () => {
25+
if (!process.argv.includes('--help') && !process.argv.includes('-h')) {
4926
const runner = new Listr<never>(
5027
[
5128
{
@@ -66,7 +43,7 @@ program
6643
if (runner.errors.length) {
6744
console.error(
6845
chalk.red(`\nIt looks like you are missing some dependencies you need to get Electron running.
69-
Make sure you have git installed and Node.js version ${metadata.engines.node}`)
46+
Make sure you have git installed and Node.js version ${packageJSON.engines.node}`)
7047
);
7148
process.exit(1);
7249
}

tsconfig.base.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"esModuleInterop": true,
1212
"declaration": true,
1313
"composite": true,
14-
"declarationMap": true
14+
"declarationMap": true,
15+
"resolveJsonModule": true
1516
},
1617
"exclude": ["node_modules", "dist", "test", "index.ts", "spec", "tmpl"]
1718
}

0 commit comments

Comments
 (0)