Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9bb7447

Browse filesBrowse files
committed
build: update dependency yargs to v18
See associated pull request for more information. Closes #30399 as a pr takeover
1 parent 7d5f392 commit 9bb7447
Copy full SHA for 9bb7447

File tree

Expand file treeCollapse file tree

10 files changed

+71
-43
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+71
-43
lines changed

‎packages/angular/cli/package.json

Copy file name to clipboardExpand all lines: packages/angular/cli/package.json
+1-1Lines 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-module.ts

Copy file name to clipboardExpand all lines: packages/angular/cli/src/command-builder/command-module.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import { logging, schema } from '@angular-devkit/core';
1010
import { readFileSync } from 'node:fs';
1111
import * as path from 'node:path';
12-
import yargs from 'yargs';
1312
import type {
1413
ArgumentsCamelCase,
1514
Argv,
@@ -47,6 +46,7 @@ export interface CommandContext {
4746
globalConfiguration: AngularWorkspace;
4847
logger: logging.Logger;
4948
packageManager: PackageManagerUtils;
49+
yargsInstance: Argv<{}>;
5050

5151
/** Arguments parsed in free-from without parser configuration. */
5252
args: {
@@ -250,7 +250,7 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
250250

251251
private reportCommandRunAnalytics(analytics: AnalyticsCollector): void {
252252
// eslint-disable-next-line @typescript-eslint/no-explicit-any
253-
const internalMethods = (yargs as any).getInternalMethods();
253+
const internalMethods = (this.context.yargsInstance as any).getInternalMethods();
254254
// $0 generate component [name] -> generate_component
255255
// $0 add <collection> -> add
256256
const fullCommand = (internalMethods.getUsageInstance().getUsage()[0][0] as string)

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

Copy file name to clipboardExpand all lines: packages/angular/cli/src/command-builder/command-runner.ts
+7-5Lines changed: 7 additions & 5 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

@@ -62,11 +62,14 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
6262
}
6363

6464
const root = workspace?.basePath ?? process.cwd();
65+
const localYargs = yargs(args);
66+
6567
const context: CommandContext = {
6668
globalConfiguration,
6769
workspace,
6870
logger,
6971
currentDirectory: process.cwd(),
72+
yargsInstance: localYargs,
7073
root,
7174
packageManager: new PackageManagerUtils({ globalConfiguration, workspace, root }),
7275
args: {
@@ -80,15 +83,14 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
8083
},
8184
};
8285

83-
let localYargs = yargs(args);
8486
for (const CommandModule of await getCommandsToRegister(positional[0])) {
85-
localYargs = addCommandModuleToYargs(localYargs, CommandModule, context);
87+
addCommandModuleToYargs(CommandModule, context);
8688
}
8789

8890
if (jsonHelp) {
8991
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9092
const usageInstance = (localYargs as any).getInternalMethods().getUsageInstance();
91-
usageInstance.help = () => jsonHelpUsage();
93+
usageInstance.help = () => jsonHelpUsage(localYargs);
9294
}
9395

9496
// Add default command to support version option when no subcommand is specified
@@ -127,7 +129,7 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
127129
.epilogue('For more information, see https://angular.dev/cli/.\n')
128130
.demandCommand(1, demandCommandFailureMessage)
129131
.recommendCommands()
130-
.middleware(normalizeOptionsMiddleware)
132+
.middleware(createNormalizeOptionsMiddleware(localYargs))
131133
.version(false)
132134
.showHelpOnFail(false)
133135
.strict()

‎packages/angular/cli/src/command-builder/utilities/command.ts

Copy file name to clipboardExpand all lines: packages/angular/cli/src/command-builder/utilities/command.ts
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ export type CommandModuleConstructor = Partial<CommandModuleImplementation> & {
2020
new (context: CommandContext): Partial<CommandModuleImplementation> & CommandModule;
2121
};
2222

23-
export function addCommandModuleToYargs<T extends object, U extends CommandModuleConstructor>(
24-
localYargs: Argv<T>,
23+
export function addCommandModuleToYargs<U extends CommandModuleConstructor>(
2524
commandModule: U,
2625
context: CommandContext,
27-
): Argv<T> {
26+
): void {
2827
const cmd = new commandModule(context);
2928
const {
3029
args: {
@@ -35,7 +34,7 @@ export function addCommandModuleToYargs<T extends object, U extends CommandModul
3534

3635
const describe = jsonHelp ? cmd.fullDescribe : cmd.describe;
3736

38-
return localYargs.command({
37+
context.yargsInstance.command({
3938
command: cmd.command,
4039
aliases: cmd.aliases,
4140
describe:
@@ -58,7 +57,7 @@ export function addCommandModuleToYargs<T extends object, U extends CommandModul
5857
);
5958
}
6059

61-
return cmd.builder(argv) as Argv<T>;
60+
return cmd.builder(argv) as Argv;
6261
},
6362
handler: (args) => cmd.handler(args),
6463
});

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

Copy file name to clipboardExpand all lines: packages/angular/cli/src/command-builder/utilities/json-help.ts
+7-7Lines 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

Copy file name to clipboardExpand all lines: packages/angular/cli/src/command-builder/utilities/normalize-options-middleware.ts
+18-16Lines 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/analytics/cli.ts

Copy file name to clipboardExpand all lines: packages/angular/cli/src/commands/analytics/cli.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class AnalyticsCommandModule
4141
].sort(); // sort by class name.
4242

4343
for (const module of subcommands) {
44-
localYargs = addCommandModuleToYargs(localYargs, module, this.context);
44+
addCommandModuleToYargs(module, this.context);
4545
}
4646

4747
return localYargs.demandCommand(1, demandCommandFailureMessage).strict();

‎packages/angular/cli/src/commands/cache/cli.ts

Copy file name to clipboardExpand all lines: packages/angular/cli/src/commands/cache/cli.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class CacheCommandModule
4040
].sort();
4141

4242
for (const module of subcommands) {
43-
localYargs = addCommandModuleToYargs(localYargs, module, this.context);
43+
addCommandModuleToYargs(module, this.context);
4444
}
4545

4646
return localYargs.demandCommand(1, demandCommandFailureMessage).strict();

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

Copy file name to clipboardExpand all lines: packages/angular/cli/src/commands/completion/cli.ts
+5-3Lines 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';
@@ -23,7 +23,9 @@ export default class CompletionCommandModule
2323
longDescriptionPath = join(__dirname, 'long-description.md');
2424

2525
builder(localYargs: Argv): Argv {
26-
return addCommandModuleToYargs(localYargs, CompletionScriptCommandModule, this.context);
26+
addCommandModuleToYargs(CompletionScriptCommandModule, this.context);
27+
28+
return localYargs;
2729
}
2830

2931
async run(): Promise<number> {
@@ -69,6 +71,6 @@ class CompletionScriptCommandModule extends CommandModule implements CommandModu
6971
}
7072

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

‎pnpm-lock.yaml

Copy file name to clipboardExpand all lines: pnpm-lock.yaml
+25-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.