diff --git a/package.json b/package.json index 8ae6a7ff7b857..85b508c9c791f 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "@types/react-router-dom": "5.1.7", "@types/semver": "^7.3.8", "@types/tmp": "^0.2.0", - "@types/yargs": "^15.0.5", + "@types/yargs": "^17.0.10", "@typescript-eslint/eslint-plugin": "5.10.1", "@typescript-eslint/experimental-utils": "5.10.1", "@typescript-eslint/parser": "5.10.1", @@ -254,8 +254,8 @@ "webpack-sources": "^3.0.2", "webpack-subresource-integrity": "^5.1.0", "xstate": "^4.25.0", - "yargs": "15.4.1", - "yargs-parser": "20.0.0", + "yargs": "^17.4.0", + "yargs-parser": "21.0.1", "zone.js": "~0.11.4" }, "author": "Victor Savkin", diff --git a/packages/add-nx-to-monorepo/package.json b/packages/add-nx-to-monorepo/package.json index 0b14ab823376d..3eae66e0b6e97 100644 --- a/packages/add-nx-to-monorepo/package.json +++ b/packages/add-nx-to-monorepo/package.json @@ -33,6 +33,6 @@ "@nrwl/devkit": "*", "nx": "*", "enquirer": "~2.3.6", - "yargs-parser": "20.0.0" + "yargs-parser": "21.0.1" } } diff --git a/packages/cra-to-nx/package.json b/packages/cra-to-nx/package.json index ba7bd513d2a92..d23d1b066d6f6 100644 --- a/packages/cra-to-nx/package.json +++ b/packages/cra-to-nx/package.json @@ -26,6 +26,6 @@ "@nrwl/devkit": "*", "nx": "*", "fs-extra": "^9.1.0", - "yargs-parser": "^20.0.0" + "yargs-parser": "21.0.1" } } diff --git a/packages/create-nx-plugin/package.json b/packages/create-nx-plugin/package.json index fad8a48037bb3..cd79fc4f45a82 100644 --- a/packages/create-nx-plugin/package.json +++ b/packages/create-nx-plugin/package.json @@ -33,6 +33,6 @@ "enquirer": "~2.3.6", "fs-extra": "^9.1.0", "tmp": "~0.2.1", - "yargs-parser": "20.0.0" + "yargs-parser": "21.0.1" } } diff --git a/packages/create-nx-workspace/package.json b/packages/create-nx-workspace/package.json index d42ae383b8f6d..6f676b2110199 100644 --- a/packages/create-nx-workspace/package.json +++ b/packages/create-nx-workspace/package.json @@ -29,7 +29,7 @@ "homepage": "https://nx.dev", "dependencies": { "tmp": "~0.2.1", - "yargs-parser": "20.0.0", + "yargs-parser": "21.0.1", "enquirer": "~2.3.6", "flat": "^5.0.2", "chalk": "4.1.0", diff --git a/packages/make-angular-cli-faster/package.json b/packages/make-angular-cli-faster/package.json index 0360c055656eb..cafbeee741891 100644 --- a/packages/make-angular-cli-faster/package.json +++ b/packages/make-angular-cli-faster/package.json @@ -33,7 +33,7 @@ "nx": "*", "semver": "7.3.4", "tmp": "~0.2.1", - "yargs": "15.4.1", - "yargs-parser": "20.0.0" + "yargs": "^17.4.0", + "yargs-parser": "21.0.1" } } diff --git a/packages/nx/bin/init-local.ts b/packages/nx/bin/init-local.ts index 0a9cbe2a66d1c..337e833fe0c5f 100644 --- a/packages/nx/bin/init-local.ts +++ b/packages/nx/bin/init-local.ts @@ -58,7 +58,10 @@ function wrapIntoQuotesIfNeeded(arg: string) { function isKnownCommand() { const commands = [ ...Object.keys( - (commandsObject as any).getCommandInstance().getCommandHandlers() + (commandsObject as any) + .getInternalMethods() + .getCommandInstance() + .getCommandHandlers() ), 'g', 'dep-graph', diff --git a/packages/nx/package.json b/packages/nx/package.json index db7608b7720bd..b8d8864f8db7e 100644 --- a/packages/nx/package.json +++ b/packages/nx/package.json @@ -52,8 +52,8 @@ "rxjs": "^6.5.4", "semver": "7.3.4", "tmp": "~0.2.1", - "yargs": "15.4.1", - "yargs-parser": "20.0.0", + "yargs": "^17.4.0", + "yargs-parser": "21.0.1", "chalk": "4.1.0", "flat": "^5.0.2", "minimatch": "3.0.4", diff --git a/packages/nx/src/command-line/nx-commands.ts b/packages/nx/src/command-line/nx-commands.ts index 7b094a1a46d1b..b31416338e6af 100644 --- a/packages/nx/src/command-line/nx-commands.ts +++ b/packages/nx/src/command-line/nx-commands.ts @@ -6,7 +6,6 @@ import { generateDaemonHelpOutput } from '../core/project-graph/daemon/client/ge import { nxVersion } from '../utils/versions'; import { examples } from './examples'; import { appRootPath } from 'nx/src/utils/app-root'; -import type { ListArgs } from './list'; import { getPackageManagerCommand } from '../utils/package-manager'; import { writeJsonFile } from 'nx/src/utils/fileutils'; @@ -45,6 +44,8 @@ ${daemonHelpOutput} aliases: ['g'], builder: (yargs) => withGenerateOptions(yargs), handler: async (args) => { + // Remove the command from the args + args._ = args._.slice(1); process.exit( await (await import('./generate')).generate(process.cwd(), args) ); @@ -237,9 +238,9 @@ ${daemonHelpOutput} command: 'workspace-generator [name]', describe: 'Runs a workspace generator from the tools/generators directory', aliases: ['workspace-schematic [name]'], - builder: (yargs) => + builder: async (yargs) => linkToNxDevAndExamples( - withWorkspaceGeneratorOptions(yargs), + await withWorkspaceGeneratorOptions(yargs), 'workspace-generator' ), handler: async () => @@ -288,11 +289,13 @@ ${daemonHelpOutput} command: 'new [_..]', describe: false, builder: (yargs) => withNewOptions(yargs), - handler: async (args) => - (await import('./generate')).newWorkspace( + handler: async (args) => { + args._ = args._.slice(1); + return (await import('./generate')).newWorkspace( args['nxWorkspaceRoot'] as string, args - ), + ); + }, }) .command( '_migrate [packageAndVersion]', @@ -612,20 +615,23 @@ function withRunOneOptions(yargs: yargs.Argv) { } } -function withWorkspaceGeneratorOptions(yargs: yargs.Argv) { - yargs.option('list-generators', { - describe: 'List the available workspace-generators', - type: 'boolean', - }); +async function withWorkspaceGeneratorOptions(yargs: yargs.Argv) { + yargs + .option('list-generators', { + describe: 'List the available workspace-generators', + type: 'boolean', + }) + .positional('name', { + type: 'string', + describe: 'The name of your generator`', + }); + /** * Don't require `name` if only listing available * schematics */ - if (yargs.argv.listGenerators !== true) { - yargs.demandOption(['name']).positional('name', { - type: 'string', - describe: 'The name of your generator`', - }); + if ((await yargs.argv).listGenerators !== true) { + yargs.demandOption('name'); } return yargs; } @@ -653,6 +659,9 @@ function withMigrationOptions(yargs: yargs.Argv) { } function parseCSV(args: string[]) { + if (!args) { + return args; + } return args .map((arg) => arg.split(',')) .reduce((acc, value) => { diff --git a/packages/nx/src/command-line/workspace-generators.ts b/packages/nx/src/command-line/workspace-generators.ts index 6a637867ec178..4d08c0fff575e 100644 --- a/packages/nx/src/command-line/workspace-generators.ts +++ b/packages/nx/src/command-line/workspace-generators.ts @@ -131,9 +131,7 @@ function listGenerators(collectionFile: string) { }); } catch (error) { logger.fatal(error.message); - return 1; } - return 0; } function parseOptions( diff --git a/packages/workspace/package.json b/packages/workspace/package.json index 4749047d2b54e..4acefe78c3065 100644 --- a/packages/workspace/package.json +++ b/packages/workspace/package.json @@ -73,8 +73,8 @@ "rxjs": "^6.5.4", "semver": "7.3.4", "tmp": "~0.2.1", - "yargs": "15.4.1", - "yargs-parser": "20.0.0", + "yargs": "^17.4.0", + "yargs-parser": "21.0.1", "chalk": "4.1.0", "flat": "^5.0.2", "minimatch": "3.0.4", diff --git a/scripts/documentation/generate-cli-data.ts b/scripts/documentation/generate-cli-data.ts index 267fbe6182ca1..1a1216e88a4d8 100644 --- a/scripts/documentation/generate-cli-data.ts +++ b/scripts/documentation/generate-cli-data.ts @@ -66,7 +66,10 @@ export async function generateCLIDocumentation() { removeSync(commandsOutputDirectory); function getCommands(command) { - return command.getCommandInstance().getCommandHandlers(); + return command + .getInternalMethods() + .getCommandInstance() + .getCommandHandlers(); } async function parseCommandInstance( name: string, @@ -89,9 +92,12 @@ export async function generateCLIDocumentation() { } // Show all the options we can get from yargs const builder = await command.builder( - importFresh('yargs')().resetOptions() + importFresh('yargs')().getInternalMethods().reset() ); - const builderDescriptions = builder.getUsageInstance().getDescriptions(); + const builderDescriptions = builder + .getInternalMethods() + .getUsageInstance() + .getDescriptions(); const builderDefaultOptions = builder.getOptions().default; const builderDeprecatedOptions = builder.getDeprecatedOptions(); return { diff --git a/yarn.lock b/yarn.lock index 978944553f442..b25d2d1bad759 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5091,7 +5091,7 @@ resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.0.tgz#0c60e537fa790f5f9472ed2776c2b71ec117351b" integrity sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA== -"@types/yargs@^15.0.0", "@types/yargs@^15.0.5": +"@types/yargs@^15.0.0": version "15.0.14" resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.14.tgz#26d821ddb89e70492160b66d10a0eb6df8f6fb06" integrity sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ== @@ -5105,6 +5105,13 @@ dependencies: "@types/yargs-parser" "*" +"@types/yargs@^17.0.10": + version "17.0.10" + resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.10.tgz#591522fce85d8739bca7b8bb90d048e4478d186a" + integrity sha512-gmEaFwpj/7f/ROdtIlci1R1VYU1J4j95m8T+Tj3iBgiBFKg1foE/PSl93bBd5T9LDXNPo8UlNN6W0qwD8O5OaA== + dependencies: + "@types/yargs-parser" "*" + "@types/yauzl@^2.9.1": version "2.9.2" resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.9.2.tgz#c48e5d56aff1444409e39fa164b0b4d4552a7b7a" @@ -23537,6 +23544,11 @@ yargs-parser@20.2.9, yargs-parser@20.x, yargs-parser@^20.2.2, yargs-parser@^20.2 resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== +yargs-parser@21.0.1, yargs-parser@^21.0.0: + version "21.0.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35" + integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg== + yargs-parser@^18.1.2: version "18.1.3" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0" @@ -23545,11 +23557,6 @@ yargs-parser@^18.1.2: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^21.0.0: - version "21.0.1" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35" - integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg== - yargs@15.4.1: version "15.4.1" resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8" @@ -23580,7 +23587,7 @@ yargs@^16.1.0, yargs@^16.2.0: y18n "^5.0.5" yargs-parser "^20.2.2" -yargs@^17.2.1: +yargs@^17.2.1, yargs@^17.4.0: version "17.4.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.4.0.tgz#9fc9efc96bd3aa2c1240446af28499f0e7593d00" integrity sha512-WJudfrk81yWFSOkZYpAZx4Nt7V4xp7S/uJkX0CnxovMCt1wCE8LNftPpNuF9X/u9gN5nsD7ycYtRcDf2pL3UiA==