Upgrade Ava to v4

This commit is contained in:
Henry Mercer 2022-02-01 18:01:11 +00:00
parent 9a40cc5274
commit ce89f1b611
1153 changed files with 27264 additions and 95308 deletions

View file

@ -2,6 +2,23 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [21.0.0](https://www.github.com/yargs/yargs-parser/compare/yargs-parser-v20.2.9...yargs-parser-v21.0.0) (2021-11-15)
### ⚠ BREAKING CHANGES
* drops support for 10 (#421)
### Bug Fixes
* esm json import ([#416](https://www.github.com/yargs/yargs-parser/issues/416)) ([90f970a](https://www.github.com/yargs/yargs-parser/commit/90f970a6482dd4f5b5eb18d38596dd6f02d73edf))
* parser should preserve inner quotes ([#407](https://www.github.com/yargs/yargs-parser/issues/407)) ([ae11f49](https://www.github.com/yargs/yargs-parser/commit/ae11f496a8318ea8885aa25015d429b33713c314))
### Code Refactoring
* drops support for 10 ([#421](https://www.github.com/yargs/yargs-parser/issues/421)) ([3aaf878](https://www.github.com/yargs/yargs-parser/commit/3aaf8784f5c7f2aec6108c1c6a55537fa7e3b5c1))
### [20.2.9](https://www.github.com/yargs/yargs-parser/compare/yargs-parser-v20.2.8...yargs-parser-v20.2.9) (2021-06-20)

View file

@ -1,8 +1,8 @@
'use strict';
var util = require('util');
var fs = require('fs');
var path = require('path');
var fs = require('fs');
function camelCase(str) {
const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();
@ -125,6 +125,7 @@ class YargsParser {
key: undefined
}, options);
const args = tokenizeArgString(argsInput);
const inputIsString = typeof argsInput === 'string';
const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
const configuration = Object.assign({
'boolean-negation': true,
@ -272,7 +273,7 @@ class YargsParser {
i = eatNargs(i, m[1], args, m[2]);
}
else {
setArg(m[1], m[2]);
setArg(m[1], m[2], true);
}
}
}
@ -509,7 +510,7 @@ class YargsParser {
}
else {
if (!isUndefined(argAfterEqualSign)) {
argsToSet.push(processValue(key, argAfterEqualSign));
argsToSet.push(processValue(key, argAfterEqualSign, true));
}
for (let ii = i + 1; ii < args.length; ii++) {
if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||
@ -519,7 +520,7 @@ class YargsParser {
if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
break;
i = ii;
argsToSet.push(processValue(key, next));
argsToSet.push(processValue(key, next, inputIsString));
}
}
if (typeof nargsCount === 'number' && ((nargsCount && argsToSet.length < nargsCount) ||
@ -529,14 +530,14 @@ class YargsParser {
setArg(key, argsToSet);
return i;
}
function setArg(key, val) {
function setArg(key, val, shouldStripQuotes = inputIsString) {
if (/-/.test(key) && configuration['camel-case-expansion']) {
const alias = key.split('.').map(function (prop) {
return camelCase(prop);
}).join('.');
addNewAlias(key, alias);
}
const value = processValue(key, val);
const value = processValue(key, val, shouldStripQuotes);
const splitKey = key.split('.');
setKey(argv, splitKey, value);
if (flags.aliases[key]) {
@ -580,11 +581,9 @@ class YargsParser {
addNewAlias(alias, key);
}
}
function processValue(key, val) {
if (typeof val === 'string' &&
(val[0] === "'" || val[0] === '"') &&
val[val.length - 1] === val[0]) {
val = val.substring(1, val.length - 1);
function processValue(key, val, shouldStripQuotes) {
if (shouldStripQuotes) {
val = stripQuotes(val);
}
if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
if (typeof val === 'string')
@ -997,10 +996,17 @@ function sanitizeKey(key) {
return '___proto___';
return key;
}
function stripQuotes(val) {
return (typeof val === 'string' &&
(val[0] === "'" || val[0] === '"') &&
val[val.length - 1] === val[0])
? val.substring(1, val.length - 1)
: val;
}
const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
? Number(process.env.YARGS_MIN_NODE_VERSION)
: 10;
: 12;
if (process && process.version) {
const major = Number(process.version.match(/v([^.]+)/)[1]);
if (major < minNodeVersion) {
@ -1021,7 +1027,7 @@ const parser = new YargsParser({
return require(path);
}
else if (path.match(/\.json$/)) {
return fs.readFileSync(path, 'utf8');
return JSON.parse(fs.readFileSync(path, 'utf8'));
}
else {
throw Error('only .json config files are supported in ESM');

View file

@ -7,15 +7,15 @@
* SPDX-License-Identifier: ISC
*/
import { format } from 'util';
import { readFileSync } from 'fs';
import { normalize, resolve } from 'path';
import { camelCase, decamelize, looksLikeNumber } from './string-utils.js';
import { YargsParser } from './yargs-parser.js';
import { readFileSync } from 'fs';
// See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
// version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
? Number(process.env.YARGS_MIN_NODE_VERSION)
: 10;
: 12;
if (process && process.version) {
const major = Number(process.version.match(/v([^.]+)/)[1]);
if (major < minNodeVersion) {
@ -39,7 +39,8 @@ const parser = new YargsParser({
return require(path);
}
else if (path.match(/\.json$/)) {
return readFileSync(path, 'utf8');
// Addresses: https://github.com/yargs/yargs/issues/2040
return JSON.parse(readFileSync(path, 'utf8'));
}
else {
throw Error('only .json config files are supported in ESM');

View file

@ -33,6 +33,9 @@ export class YargsParser {
// allow a string argument to be passed in rather
// than an argv array.
const args = tokenizeArgString(argsInput);
// tokenizeArgString adds extra quotes to args if argsInput is a string
// only strip those extra quotes in processValue if argsInput is a string
const inputIsString = typeof argsInput === 'string';
// aliases might have transitive relationships, normalize this.
const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
const configuration = Object.assign({
@ -200,7 +203,7 @@ export class YargsParser {
i = eatNargs(i, m[1], args, m[2]);
}
else {
setArg(m[1], m[2]);
setArg(m[1], m[2], true);
}
}
}
@ -474,7 +477,7 @@ export class YargsParser {
else {
// value in --option=value is eaten as is
if (!isUndefined(argAfterEqualSign)) {
argsToSet.push(processValue(key, argAfterEqualSign));
argsToSet.push(processValue(key, argAfterEqualSign, true));
}
for (let ii = i + 1; ii < args.length; ii++) {
if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||
@ -484,7 +487,7 @@ export class YargsParser {
if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
break;
i = ii;
argsToSet.push(processValue(key, next));
argsToSet.push(processValue(key, next, inputIsString));
}
}
// If both array and nargs are configured, create an error if less than
@ -497,14 +500,14 @@ export class YargsParser {
setArg(key, argsToSet);
return i;
}
function setArg(key, val) {
function setArg(key, val, shouldStripQuotes = inputIsString) {
if (/-/.test(key) && configuration['camel-case-expansion']) {
const alias = key.split('.').map(function (prop) {
return camelCase(prop);
}).join('.');
addNewAlias(key, alias);
}
const value = processValue(key, val);
const value = processValue(key, val, shouldStripQuotes);
const splitKey = key.split('.');
setKey(argv, splitKey, value);
// handle populating aliases of the full key
@ -555,12 +558,10 @@ export class YargsParser {
addNewAlias(alias, key);
}
}
function processValue(key, val) {
function processValue(key, val, shouldStripQuotes) {
// strings may be quoted, clean this up as we assign values.
if (typeof val === 'string' &&
(val[0] === "'" || val[0] === '"') &&
val[val.length - 1] === val[0]) {
val = val.substring(1, val.length - 1);
if (shouldStripQuotes) {
val = stripQuotes(val);
}
// handle parsing boolean arguments --foo=true --bar false.
if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
@ -1035,3 +1036,10 @@ function sanitizeKey(key) {
return '___proto___';
return key;
}
function stripQuotes(val) {
return (typeof val === 'string' &&
(val[0] === "'" || val[0] === '"') &&
val[val.length - 1] === val[0])
? val.substring(1, val.length - 1)
: val;
}

View file

@ -1,6 +1,6 @@
{
"name": "yargs-parser",
"version": "20.2.9",
"version": "21.0.0",
"description": "the mighty option parser used by yargs",
"main": "build/index.cjs",
"exports": {
@ -19,6 +19,7 @@
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js' && standardx --fix '**/*.cjs'",
"pretest": "rimraf build && tsc -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs",
"test": "c8 --reporter=text --reporter=html mocha test/*.cjs",
"test:esm": "c8 --reporter=text --reporter=html mocha test/*.mjs",
"test:browser": "start-server-and-test 'serve ./ -p 8080' http://127.0.0.1:8080/package.json 'node ./test/browser/yargs-test.cjs'",
"pretest:typescript": "npm run pretest",
"test:typescript": "c8 mocha ./build/test/typescript/*.js",
@ -48,8 +49,8 @@
"license": "ISC",
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.0",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.4",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"@wessberg/rollup-plugin-ts": "^1.2.28",
@ -61,11 +62,11 @@
"eslint-plugin-node": "^11.0.0",
"gts": "^3.0.0",
"mocha": "^9.0.0",
"puppeteer": "^10.0.0",
"puppeteer": "^11.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.22.1",
"rollup-plugin-cleanup": "^3.1.1",
"serve": "^12.0.0",
"serve": "^13.0.0",
"standardx": "^7.0.0",
"start-server-and-test": "^1.11.2",
"ts-transform-default-export": "^1.0.2",
@ -77,7 +78,7 @@
"!*.d.ts"
],
"engines": {
"node": ">=10"
"node": ">=12"
},
"standardx": {
"ignore": [