From 7ac5ca5f16f0af0d98d5ec38c53f4c3e3ba363f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Thu, 18 Apr 2024 09:55:20 +0200 Subject: [PATCH] fix(core): forward args provided to the nx add command to the invoked init generator (#22855) (cherry picked from commit 125c1d278685b2473c8f1dcc205be7dc2a4fb493) --- packages/nx/src/command-line/add/add.ts | 4 ++++ packages/nx/src/command-line/add/command-object.ts | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/command-line/add/add.ts b/packages/nx/src/command-line/add/add.ts index d1f30ae659a7d..a5e61c28b772e 100644 --- a/packages/nx/src/command-line/add/add.ts +++ b/packages/nx/src/command-line/add/add.ts @@ -119,6 +119,10 @@ async function initializePlugin( await runNxAsync( `g ${pkgName}:${initGenerator} --keepExistingVersions${ updatePackageScripts ? ' --updatePackageScripts' : '' + }${ + options.__overrides_unparsed__.length + ? ' ' + options.__overrides_unparsed__.join(' ') + : '' }`, { silent: !options.verbose, diff --git a/packages/nx/src/command-line/add/command-object.ts b/packages/nx/src/command-line/add/command-object.ts index 8822667670563..21bbbae903e07 100644 --- a/packages/nx/src/command-line/add/command-object.ts +++ b/packages/nx/src/command-line/add/command-object.ts @@ -1,9 +1,11 @@ import { CommandModule } from 'yargs'; +import { withOverrides } from '../yargs-utils/shared-options'; export interface AddOptions { packageSpecifier: string; updatePackageScripts?: boolean; verbose?: boolean; + __overrides_unparsed__: string[]; } export const yargsAddCommand: CommandModule< @@ -14,6 +16,10 @@ export const yargsAddCommand: CommandModule< describe: 'Install a plugin and initialize it.', builder: (yargs) => yargs + .parserConfiguration({ + 'strip-dashed': true, + 'unknown-options-as-args': true, + }) .positional('packageSpecifier', { type: 'string', description: @@ -41,5 +47,6 @@ export const yargsAddCommand: CommandModule< '$0 add @nx/react@17.0.0', 'Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator' ) as any, - handler: (args) => import('./add').then((m) => m.addHandler(args)), + handler: (args) => + import('./add').then((m) => m.addHandler(withOverrides(args))), };