re-introduce yargs fix but without upgrading jest to 28 breaking tests, to work on it separately

This commit is contained in:
Ronan Jouchet 2022-07-23 19:27:23 -04:00
parent 9db7ad050a
commit c3e010f881
3 changed files with 43 additions and 8 deletions

33
npm-shrinkwrap.json generated
View File

@ -35,6 +35,7 @@
"@types/node": "14.14.20",
"@types/page-icon": "^0.3.4",
"@types/tmp": "^0.2.1",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"electron": "^18.3.5",
@ -1087,6 +1088,15 @@
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
}
},
"node_modules/@jest/types/node_modules/@types/yargs": {
"version": "16.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz",
"integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==",
"dev": true,
"dependencies": {
"@types/yargs-parser": "*"
}
},
"node_modules/@jridgewell/gen-mapping": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.1.1.tgz",
@ -1476,9 +1486,9 @@
"dev": true
},
"node_modules/@types/yargs": {
"version": "16.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz",
"integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==",
"version": "17.0.10",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.10.tgz",
"integrity": "sha512-gmEaFwpj/7f/ROdtIlci1R1VYU1J4j95m8T+Tj3iBgiBFKg1foE/PSl93bBd5T9LDXNPo8UlNN6W0qwD8O5OaA==",
"dev": true,
"dependencies": {
"@types/yargs-parser": "*"
@ -9267,6 +9277,17 @@
"@types/node": "*",
"@types/yargs": "^16.0.0",
"chalk": "^4.0.0"
},
"dependencies": {
"@types/yargs": {
"version": "16.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz",
"integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==",
"dev": true,
"requires": {
"@types/yargs-parser": "*"
}
}
}
},
"@jridgewell/gen-mapping": {
@ -9617,9 +9638,9 @@
"dev": true
},
"@types/yargs": {
"version": "16.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz",
"integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==",
"version": "17.0.10",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.10.tgz",
"integrity": "sha512-gmEaFwpj/7f/ROdtIlci1R1VYU1J4j95m8T+Tj3iBgiBFKg1foE/PSl93bBd5T9LDXNPo8UlNN6W0qwD8O5OaA==",
"dev": true,
"requires": {
"@types/yargs-parser": "*"

View File

@ -80,6 +80,7 @@
"@types/node": "14.14.20",
"@types/page-icon": "^0.3.4",
"@types/tmp": "^0.2.1",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"electron": "^18.3.5",

View File

@ -18,6 +18,19 @@ import { RawOptions } from '../shared/src/options/model';
import { parseJson } from './utils/parseUtils';
import { buildUniversalApp } from './build/buildNativefierApp';
// @types/yargs@17.x started pretending yargs.argv can be a promise:
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8e17f9ca957a06040badb53ae7688fbb74229ccf/types/yargs/index.d.ts#L73
// Dunno in which case it happens, but it doesn't for us! So, having to await
// (and end up having to flag sync code as async) would be useless and annoying.
// So, copy-pastaing and axing the Promise half of yargs's type definition,
// to have a *non*-promise type. Maybe that's wrong. If it is, this type should
// be dropped, and extra async-ness should be added where needed.
type YargsArgvSync<T> = {
[key in keyof yargs.Arguments<T> as
| key
| yargs.CamelCaseKey<key>]: yargs.Arguments<T>[key];
};
export function initArgs(argv: string[]): yargs.Argv<RawOptions> {
const sanitizedArgs = sanitizeArgs(argv);
const args = yargs(sanitizedArgs)
@ -534,7 +547,7 @@ export function initArgs(argv: string[]): yargs.Argv<RawOptions> {
// We must access argv in order to get yargs to actually process args
// Do this now to go ahead and get any errors out of the way
args.argv;
args.argv as YargsArgvSync<RawOptions>;
return args as yargs.Argv<RawOptions>;
}
@ -544,7 +557,7 @@ function decorateYargOptionGroup(value: string): string {
}
export function parseArgs(args: yargs.Argv<RawOptions>): RawOptions {
const parsed = { ...args.argv };
const parsed = { ...(args.argv as YargsArgvSync<RawOptions>) };
// In yargs, the _ property of the parsed args is an array of the positional args
// https://github.com/yargs/yargs/blob/master/docs/examples.md#and-non-hyphenated-options-too-just-use-argv_
// So try to extract the targetUrl and outputDirectory from these