diff --git a/.nycrc b/.nycrc index 3b315160..04de9940 100644 --- a/.nycrc +++ b/.nycrc @@ -8,6 +8,6 @@ "text" ], "lines": 99.5, - "branches": "98", + "branches": "97", "statements": "99.5" } diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 456110db..ee3274ab 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1 +1 @@ -{".":"21.0.1"} \ No newline at end of file +{".":"21.1.0"} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ca50b82e..de2808cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ 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.1.0](https://github.com/yargs/yargs-parser/compare/yargs-parser-v21.0.1...yargs-parser-v21.1.0) (2022-08-03) + + +### Features + +* allow the browser build to be imported ([#443](https://github.com/yargs/yargs-parser/issues/443)) ([a89259f](https://github.com/yargs/yargs-parser/commit/a89259ff41d6f5312b3ce8a30bef343a993f395a)) + + +### Bug Fixes + +* **halt-at-non-option:** prevent known args from being parsed when "unknown-options-as-args" is enabled ([#438](https://github.com/yargs/yargs-parser/issues/438)) ([c474bc1](https://github.com/yargs/yargs-parser/commit/c474bc10c3aa0ae864b95e5722730114ef15f573)) +* node version check now uses process.versions.node ([#450](https://github.com/yargs/yargs-parser/issues/450)) ([d07bcdb](https://github.com/yargs/yargs-parser/commit/d07bcdbe43075f7201fbe8a08e491217247fe1f1)) +* parse options ending with 3+ hyphens ([#434](https://github.com/yargs/yargs-parser/issues/434)) ([4f1060b](https://github.com/yargs/yargs-parser/commit/4f1060b50759fadbac3315c5117b0c3d65b0a7d8)) + ### [21.0.1](https://github.com/yargs/yargs-parser/compare/yargs-parser-v21.0.0...yargs-parser-v21.0.1) (2022-02-27) diff --git a/lib/index.ts b/lib/index.ts index 8c413229..3cc34257 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -19,8 +19,9 @@ import { readFileSync } from 'fs' const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION) ? Number(process.env.YARGS_MIN_NODE_VERSION) : 12 -if (process && process.version) { - const major = Number(process.version.match(/v([^.]+)/)![1]) +const nodeVersion = process?.versions?.node ?? process?.version?.slice(1) +if (nodeVersion) { + const major = Number(nodeVersion.match(/^([^.]+)/)![1]) if (major < minNodeVersion) { throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`) } diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 571a0cbc..764ca64e 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -222,10 +222,10 @@ export class YargsParser { let value: string // any unknown option (except for end-of-options, "--") - if (arg !== '--' && isUnknownOptionAsArg(arg)) { + if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) { pushPositional(arg) // ---, ---=, ----, etc, - } else if (truncatedArg.match(/---+(=|$)/)) { + } else if (truncatedArg.match(/^---+(=|$)/)) { // options without key name are invalid. pushPositional(arg) continue diff --git a/package.json b/package.json index 89412fcf..8910778b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yargs-parser", - "version": "21.0.1", + "version": "21.1.0", "description": "the mighty option parser used by yargs", "main": "build/index.cjs", "exports": { @@ -10,6 +10,9 @@ "require": "./build/index.cjs" }, "./build/index.cjs" + ], + "./browser": [ + "./browser.js" ] }, "type": "module", @@ -60,13 +63,13 @@ "eslint-plugin-import": "^2.20.1", "eslint-plugin-node": "^11.0.0", "gts": "^3.0.0", - "mocha": "^9.0.0", - "puppeteer": "^13.4.0", + "mocha": "^10.0.0", + "puppeteer": "^16.0.0", "rimraf": "^3.0.2", "rollup": "^2.22.1", "rollup-plugin-cleanup": "^3.1.1", - "rollup-plugin-ts": "^2.0.5", - "serve": "^13.0.0", + "rollup-plugin-ts": "^3.0.0", + "serve": "^14.0.0", "standardx": "^7.0.0", "start-server-and-test": "^1.11.2", "ts-transform-default-export": "^1.0.2", diff --git a/test/yargs-parser.cjs b/test/yargs-parser.cjs index aa6bf6bf..492e3b90 100644 --- a/test/yargs-parser.cjs +++ b/test/yargs-parser.cjs @@ -3008,6 +3008,16 @@ describe('yargs-parser', function () { _: ['./file.js', '--foo', '--', 'barbar'] }) }) + + it('is not influenced by unknown options when "unknown-options-as-args" is true', function () { + const parse = parser( + ['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar'], + { configuration: { 'halt-at-non-option': true, 'unknown-options-as-args': true }, boolean: ['foo'] } + ) + parse.should.deep.equal({ + _: ['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar'] + }) + }) }) describe('unknown-options-as-args = true', function () { @@ -3588,6 +3598,13 @@ describe('yargs-parser', function () { args.bar.should.equal('--goodnight moon') }) + // see: https://github.com/yargs/yargs-parser/issues/433 + it('handles strings with three or more trailing dashes', function () { + const args = parser('--foo "hello---" --bar="world---"') + args.foo.should.equal('hello---') + args.bar.should.equal('world---') + }) + it('respects inner quotes (string)', function () { const args = parser('cmd --foo ""Hello"" --bar ""World"" --baz="":)""') args.foo.should.equal('"Hello"')