fix(core): forward args provided to the nx add command to the invoked init generator (#22855)

This commit is contained in:
Leosvel Pérez Espinosa 2024-04-18 09:55:20 +02:00 committed by GitHub
parent 7f0dc268a0
commit 125c1d2786
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -119,6 +119,10 @@ async function initializePlugin(
await runNxAsync( await runNxAsync(
`g ${pkgName}:${initGenerator} --keepExistingVersions${ `g ${pkgName}:${initGenerator} --keepExistingVersions${
updatePackageScripts ? ' --updatePackageScripts' : '' updatePackageScripts ? ' --updatePackageScripts' : ''
}${
options.__overrides_unparsed__.length
? ' ' + options.__overrides_unparsed__.join(' ')
: ''
}`, }`,
{ {
silent: !options.verbose, silent: !options.verbose,

View File

@ -1,9 +1,11 @@
import { CommandModule } from 'yargs'; import { CommandModule } from 'yargs';
import { withOverrides } from '../yargs-utils/shared-options';
export interface AddOptions { export interface AddOptions {
packageSpecifier: string; packageSpecifier: string;
updatePackageScripts?: boolean; updatePackageScripts?: boolean;
verbose?: boolean; verbose?: boolean;
__overrides_unparsed__: string[];
} }
export const yargsAddCommand: CommandModule< export const yargsAddCommand: CommandModule<
@ -14,6 +16,10 @@ export const yargsAddCommand: CommandModule<
describe: 'Install a plugin and initialize it.', describe: 'Install a plugin and initialize it.',
builder: (yargs) => builder: (yargs) =>
yargs yargs
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
})
.positional('packageSpecifier', { .positional('packageSpecifier', {
type: 'string', type: 'string',
description: description:
@ -41,5 +47,6 @@ export const yargsAddCommand: CommandModule<
'$0 add @nx/react@17.0.0', '$0 add @nx/react@17.0.0',
'Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator' 'Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator'
) as any, ) as any,
handler: (args) => import('./add').then((m) => m.addHandler(args)), handler: (args) =>
import('./add').then((m) => m.addHandler(withOverrides(args))),
}; };