Skip to content

Commit be61c20

Browse files
committed
build: update dependency yargs to v18
See associated pull request for more information. Closes #30399 as a pr takeover
1 parent dd9153a commit be61c20

File tree

6 files changed

+59
-32
lines changed

6 files changed

+59
-32
lines changed

packages/angular/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"pacote": "21.0.0",
3838
"resolve": "1.22.10",
3939
"semver": "7.7.2",
40-
"yargs": "17.7.2"
40+
"yargs": "18.0.0"
4141
},
4242
"ng-update": {
4343
"migrations": "@schematics/angular/migrations/migration-collection.json",

packages/angular/cli/src/command-builder/command-runner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
demandCommandFailureMessage,
2828
} from './utilities/command';
2929
import { jsonHelpUsage } from './utilities/json-help';
30-
import { normalizeOptionsMiddleware } from './utilities/normalize-options-middleware';
30+
import { createNormalizeOptionsMiddleware } from './utilities/normalize-options-middleware';
3131

3232
const yargsParser = Parser as unknown as typeof Parser.default;
3333

@@ -88,7 +88,7 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
8888
if (jsonHelp) {
8989
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9090
const usageInstance = (localYargs as any).getInternalMethods().getUsageInstance();
91-
usageInstance.help = () => jsonHelpUsage();
91+
usageInstance.help = () => jsonHelpUsage(localYargs);
9292
}
9393

9494
// Add default command to support version option when no subcommand is specified
@@ -127,7 +127,7 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
127127
.epilogue('For more information, see https://angular.dev/cli/.\n')
128128
.demandCommand(1, demandCommandFailureMessage)
129129
.recommendCommands()
130-
.middleware(normalizeOptionsMiddleware)
130+
.middleware(createNormalizeOptionsMiddleware(localYargs))
131131
.version(false)
132132
.showHelpOnFail(false)
133133
.strict()

packages/angular/cli/src/command-builder/utilities/json-help.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import yargs from 'yargs';
9+
import { Argv } from 'yargs';
1010
import { FullDescribe } from '../command-module';
1111

1212
interface JsonHelpOption {
@@ -42,9 +42,9 @@ export interface JsonHelp extends JsonHelpDescription {
4242

4343
const yargsDefaultCommandRegExp = /^\$0|\*/;
4444

45-
export function jsonHelpUsage(): string {
45+
export function jsonHelpUsage(localYargs: Argv): string {
4646
// eslint-disable-next-line @typescript-eslint/no-explicit-any
47-
const localYargs = yargs as any;
47+
const localYargsInstance = localYargs as any;
4848
const {
4949
deprecatedOptions,
5050
alias: aliases,
@@ -56,13 +56,13 @@ export function jsonHelpUsage(): string {
5656
demandedOptions,
5757
default: defaultVal,
5858
hiddenOptions = [],
59-
} = localYargs.getOptions();
59+
} = localYargsInstance.getOptions();
6060

61-
const internalMethods = localYargs.getInternalMethods();
61+
const internalMethods = localYargsInstance.getInternalMethods();
6262
const usageInstance = internalMethods.getUsageInstance();
6363
const context = internalMethods.getContext();
6464
const descriptions = usageInstance.getDescriptions();
65-
const groups = localYargs.getGroups();
65+
const groups = localYargsInstance.getGroups();
6666
const positional = groups[usageInstance.getPositionalGroupName()] as string[] | undefined;
6767

6868
const hidden = new Set(hiddenOptions);
@@ -124,7 +124,7 @@ export function jsonHelpUsage(): string {
124124

125125
const output: JsonHelp = {
126126
name: [...context.commands].pop(),
127-
command: `${command?.replace(yargsDefaultCommandRegExp, localYargs['$0'])}${defaultSubCommand}`,
127+
command: `${command?.replace(yargsDefaultCommandRegExp, localYargsInstance['$0'])}${defaultSubCommand}`,
128128
...parseDescription(rawDescription),
129129
options: normalizeOptions.sort((a, b) => a.name.localeCompare(b.name)),
130130
subcommands: otherSubcommands.length ? otherSubcommands : undefined,

packages/angular/cli/src/command-builder/utilities/normalize-options-middleware.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import * as yargs from 'yargs';
9+
import type { Arguments, Argv } from 'yargs';
1010

1111
/**
1212
* A Yargs middleware that normalizes non Array options when the argument has been provided multiple times.
@@ -17,21 +17,23 @@ import * as yargs from 'yargs';
1717
*
1818
* See: https://github.com/yargs/yargs-parser/pull/163#issuecomment-516566614
1919
*/
20-
export function normalizeOptionsMiddleware(args: yargs.Arguments): void {
21-
// `getOptions` is not included in the types even though it's public API.
22-
// https://github.com/yargs/yargs/issues/2098
23-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24-
const { array } = (yargs as any).getOptions();
25-
const arrayOptions = new Set(array);
20+
export function createNormalizeOptionsMiddleware(localeYargs: Argv): (args: Arguments) => void {
21+
return (args: Arguments) => {
22+
// `getOptions` is not included in the types even though it's public API.
23+
// https://github.com/yargs/yargs/issues/2098
24+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25+
const { array } = (localeYargs as any).getOptions();
26+
const arrayOptions = new Set(array);
2627

27-
for (const [key, value] of Object.entries(args)) {
28-
if (key !== '_' && Array.isArray(value) && !arrayOptions.has(key)) {
29-
const newValue = value.pop();
30-
// eslint-disable-next-line no-console
31-
console.warn(
32-
`Option '${key}' has been specified multiple times. The value '${newValue}' will be used.`,
33-
);
34-
args[key] = newValue;
28+
for (const [key, value] of Object.entries(args)) {
29+
if (key !== '_' && Array.isArray(value) && !arrayOptions.has(key)) {
30+
const newValue = value.pop();
31+
// eslint-disable-next-line no-console
32+
console.warn(
33+
`Option '${key}' has been specified multiple times. The value '${newValue}' will be used.`,
34+
);
35+
args[key] = newValue;
36+
}
3537
}
36-
}
38+
};
3739
}

packages/angular/cli/src/commands/completion/cli.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { join } from 'node:path';
10-
import yargs, { Argv } from 'yargs';
10+
import { Argv } from 'yargs';
1111
import { CommandModule, CommandModuleImplementation } from '../../command-builder/command-module';
1212
import { addCommandModuleToYargs } from '../../command-builder/utilities/command';
1313
import { colors } from '../../utilities/color';
@@ -64,11 +64,13 @@ class CompletionScriptCommandModule extends CommandModule implements CommandModu
6464
describe = 'Generate a bash and zsh real-time type-ahead autocompletion script.';
6565
longDescriptionPath = undefined;
6666

67+
private localYargs: Argv | undefined;
68+
6769
builder(localYargs: Argv): Argv {
68-
return localYargs;
70+
return (this.localYargs = localYargs);
6971
}
7072

7173
run(): void {
72-
yargs.showCompletionScript();
74+
this.localYargs?.showCompletionScript();
7375
}
7476
}

pnpm-lock.yaml

Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)