Update ava to 4.3.3

The [release notes](https://github.com/avajs/ava/releases/tag/v4.3.3)
mention compatibility with Node 18.8.
This commit is contained in:
Henry Mercer 2022-09-02 18:02:07 +01:00
parent 21530f507f
commit bea5e4b220
160 changed files with 2647 additions and 2263 deletions

View file

@ -13,6 +13,7 @@ export class Completion {
this.completionKey = 'get-yargs-completions';
this.aliases = null;
this.customCompletionFunction = null;
this.indexAfterLastReset = 0;
this.zshShell =
(_c = (((_a = this.shim.getEnv('SHELL')) === null || _a === void 0 ? void 0 : _a.includes('zsh')) ||
((_b = this.shim.getEnv('ZSH_NAME')) === null || _b === void 0 ? void 0 : _b.includes('zsh')))) !== null && _c !== void 0 ? _c : false;
@ -23,6 +24,7 @@ export class Completion {
if (handlers[args[i]] && handlers[args[i]].builder) {
const builder = handlers[args[i]].builder;
if (isCommandBuilderCallback(builder)) {
this.indexAfterLastReset = i + 1;
const y = this.yargs.getInternalMethods().reset();
builder(y, true);
return y.argv;
@ -32,7 +34,8 @@ export class Completion {
const completions = [];
this.commandCompletions(completions, args, current);
this.optionCompletions(completions, args, argv, current);
this.choicesCompletions(completions, args, argv, current);
this.choicesFromOptionsCompletions(completions, args, argv, current);
this.choicesFromPositionalsCompletions(completions, args, argv, current);
done(null, completions);
}
commandCompletions(completions, args, current) {
@ -66,7 +69,8 @@ export class Completion {
options.boolean.includes(key);
const isPositionalKey = positionalKeys.includes(key);
if (!isPositionalKey &&
!this.argsContainKey(args, argv, key, negable)) {
!options.hiddenOptions.includes(key) &&
!this.argsContainKey(args, key, negable)) {
this.completeOptionKey(key, completions, current);
if (negable && !!options.default[key])
this.completeOptionKey(`no-${key}`, completions, current);
@ -74,11 +78,31 @@ export class Completion {
});
}
}
choicesCompletions(completions, args, argv, current) {
choicesFromOptionsCompletions(completions, args, argv, current) {
if (this.previousArgHasChoices(args)) {
const choices = this.getPreviousArgChoices(args);
if (choices && choices.length > 0) {
completions.push(...choices);
completions.push(...choices.map(c => c.replace(/:/g, '\\:')));
}
}
}
choicesFromPositionalsCompletions(completions, args, argv, current) {
if (current === '' &&
completions.length > 0 &&
this.previousArgHasChoices(args)) {
return;
}
const positionalKeys = this.yargs.getGroups()[this.usage.getPositionalGroupName()] || [];
const offset = Math.max(this.indexAfterLastReset, this.yargs.getInternalMethods().getContext().commands.length +
1);
const positionalKey = positionalKeys[argv._.length - offset - 1];
if (!positionalKey) {
return;
}
const choices = this.yargs.getOptions().choices[positionalKey] || [];
for (const choice of choices) {
if (choice.startsWith(current)) {
completions.push(choice.replace(/:/g, '\\:'));
}
}
}
@ -87,31 +111,43 @@ export class Completion {
return;
let previousArg = args[args.length - 1];
let filter = '';
if (!previousArg.startsWith('--') && args.length > 1) {
if (!previousArg.startsWith('-') && args.length > 1) {
filter = previousArg;
previousArg = args[args.length - 2];
}
if (!previousArg.startsWith('--'))
if (!previousArg.startsWith('-'))
return;
const previousArgKey = previousArg.replace(/-/g, '');
const previousArgKey = previousArg.replace(/^-+/, '');
const options = this.yargs.getOptions();
if (Object.keys(options.key).some(key => key === previousArgKey) &&
Array.isArray(options.choices[previousArgKey])) {
return options.choices[previousArgKey].filter(choice => !filter || choice.startsWith(filter));
const possibleAliases = [
previousArgKey,
...(this.yargs.getAliases()[previousArgKey] || []),
];
let choices;
for (const possibleAlias of possibleAliases) {
if (Object.prototype.hasOwnProperty.call(options.key, possibleAlias) &&
Array.isArray(options.choices[possibleAlias])) {
choices = options.choices[possibleAlias];
break;
}
}
if (choices) {
return choices.filter(choice => !filter || choice.startsWith(filter));
}
}
previousArgHasChoices(args) {
const choices = this.getPreviousArgChoices(args);
return choices !== undefined && choices.length > 0;
}
argsContainKey(args, argv, key, negable) {
if (args.indexOf(`--${key}`) !== -1)
argsContainKey(args, key, negable) {
const argsContains = (s) => args.indexOf((/^[^0-9]$/.test(s) ? '-' : '--') + s) !== -1;
if (argsContains(key))
return true;
if (negable && args.indexOf(`--no-${key}`) !== -1)
if (negable && argsContains(`no-${key}`))
return true;
if (this.aliases) {
for (const alias of this.aliases[key]) {
if (argv[alias] !== undefined)
if (argsContains(alias))
return true;
}
}