diff --git a/CHANGELOG.md b/CHANGELOG.md index b1b58a090..343ffc9ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ 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. +### 14.2.2 + +### Bug Fixes + +* temporary fix for libraries that call Object.freeze() ([#1483](https://www.github.com/yargs/yargs/issues/1483)) ([99c2dc8](https://www.github.com/yargs/yargs/commit/99c2dc850e67c606644f8b0c0bca1a59c87dcbcd)) + ### [14.2.1](https://github.com/yargs/yargs/compare/v14.2.0...v14.2.1) (2019-10-30) diff --git a/package.json b/package.json index 3b8843c0a..525e91649 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yargs", - "version": "14.2.1", + "version": "14.2.2", "description": "yargs the modern, pirate-themed, successor to optimist.", "main": "./index.js", "contributors": [ diff --git a/test/yargs.js b/test/yargs.js index 5ceb6f8e2..7c93d948a 100644 --- a/test/yargs.js +++ b/test/yargs.js @@ -2327,4 +2327,20 @@ describe('yargs dsl tests', () => { }) }) }) + + // see: https://github.com/babel/babel/pull/10733 + it('should not fail if command handler freezes object', () => { + const argv = yargs() + .command('cmd', 'a command', (yargs) => { + yargs.parserConfiguration({ 'populate--': true }) + }, (argv) => { + Object.freeze(argv) + argv._.should.eql(['cmd']) + argv['--'].should.eql(['foo']) + }).parse(['cmd', '--', 'foo']) + argv._.should.eql(['cmd', 'foo']) + // This should actually not be undefined, once we fix + // #1482. + argv['--'].should.eql(['foo']) + }) }) diff --git a/yargs.js b/yargs.js index 5cb663c2d..886398801 100644 --- a/yargs.js +++ b/yargs.js @@ -1191,9 +1191,15 @@ function Yargs (processArgs, cwd, parentRequire) { // we temporarily populate '--' rather than _, with arguments // after the '--' directive. After the parse, we copy these back. self._copyDoubleDash = function (argv) { - if (!argv._) return argv + if (!argv._ || !argv['--']) return argv argv._.push.apply(argv._, argv['--']) - delete argv['--'] + + // TODO(bcoe): refactor command parsing such that this delete is not + // necessary: https://github.com/yargs/yargs/issues/1482 + try { + delete argv['--'] + } catch (_err) {} + return argv }