From c3e010f881ef7e84ca156d4e8a8270f281b0c712 Mon Sep 17 00:00:00 2001 From: Ronan Jouchet Date: Sat, 23 Jul 2022 19:27:23 -0400 Subject: [PATCH] re-introduce yargs fix but without upgrading jest to 28 breaking tests, to work on it separately --- npm-shrinkwrap.json | 33 +++++++++++++++++++++++++++------ package.json | 1 + src/cli.ts | 17 +++++++++++++++-- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 6c676b6..f212030 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -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": "*" diff --git a/package.json b/package.json index d33f54e..1eb1e10 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli.ts b/src/cli.ts index 13b0c87..e8fd133 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -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 = { + [key in keyof yargs.Arguments as + | key + | yargs.CamelCaseKey]: yargs.Arguments[key]; +}; + export function initArgs(argv: string[]): yargs.Argv { const sanitizedArgs = sanitizeArgs(argv); const args = yargs(sanitizedArgs) @@ -534,7 +547,7 @@ export function initArgs(argv: string[]): yargs.Argv { // 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; return args as yargs.Argv; } @@ -544,7 +557,7 @@ function decorateYargOptionGroup(value: string): string { } export function parseArgs(args: yargs.Argv): RawOptions { - const parsed = { ...args.argv }; + const parsed = { ...(args.argv as YargsArgvSync) }; // 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