Skip to content

fix: coerce should play well with parser configuration#2308

Merged
bcoe merged 7 commits intoyargs:mainfrom
shadowspawn:fix/2307
Apr 28, 2023
Merged

fix: coerce should play well with parser configuration#2308
bcoe merged 7 commits intoyargs:mainfrom
shadowspawn:fix/2307

Conversation

@shadowspawn
Copy link
Member

@shadowspawn shadowspawn commented Mar 10, 2023

Relates to #2307 and #2161. Yargs does the coerce separately after yargs-parser, and should both apply the coerce values to the aliases and camel-case variations, but also not add them back if the parser configuration said not to include them in the results.

Use the fact that yargs-parser has already decided what variations belong in the results, and update just the naming variations already present in the results.

Fixes #2307, fixes #2311

@shadowspawn
Copy link
Member Author

shadowspawn commented Mar 10, 2023

I noticed a subtle problem that if strip-dashed is true then the argv does not contain the parsed option with the dashed name so coerce is ignored, although the option was present in the input arguments. May or may not attempt to fix that in this PR too... So many permutations!

  • camel-case expansion
  • strip-aliased
  • strip-dashed

@shadowspawn
Copy link
Member Author

In #1872 coerce handling got promoted out of yargs-parser to support async, so the current code is relatively new and has been iteratively improving to fully reimplement the original behaviours and coverage.

@shadowspawn
Copy link
Member Author

shadowspawn commented Mar 10, 2023

Looking at the yargs-parser implementation, that code works with argv and aliases without checking configuration options. That makes me more confident that heading in the right direction in this PR.

@bcoe
Copy link
Member

bcoe commented Mar 13, 2023

@shadowspawn thanks for the contribution 😄

@dleavitt
Copy link

dleavitt commented Jun 1, 2024

@shadowspawn @bcoe anything we could do to help get this released? In addition to the good stuff on main, there are some solid-looking PRs waiting in the wings (e.g. #2332) that a release might clear the way for.

Thanks!

@shadowspawn
Copy link
Member Author

Note: here is a change to the minimum node version on main: #2384

Nothing to do to help at the moment, thanks.

renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jun 1, 2025
| datasource | package | from   | to     |
| ---------- | ------- | ------ | ------ |
| npm        | yargs   | 17.7.2 | 18.0.0 |


## [v18.0.0](https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1800-2025-05-26)

##### ⚠ BREAKING CHANGES

-   command names are not derived from modules passed to `command`.
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed.
-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`.
-   yargs is now ESM first

##### Features

-   commandDir now works with ESM files ([#2461](yargs/yargs#2461)) ([27eec18](yargs/yargs@27eec18))
-   **locale:** adds hebrew translation ([#2357](yargs/yargs#2357)) ([4266485](yargs/yargs@4266485))
-   yargs is now ESM first ([d90af45](yargs/yargs@d90af45))
-   **zsh:** Add default completion as fallback ([#2331](yargs/yargs#2331)) ([e02c91b](yargs/yargs@e02c91b))

##### Bug Fixes

-   addDirectory do not support absolute command dir ([#2465](yargs/yargs#2465)) ([3a40a78](yargs/yargs@3a40a78))
-   allows ESM modules commands to be extensible using visit option ([#2468](yargs/yargs#2468)) ([200e1aa](yargs/yargs@200e1aa))
-   **browser:** fix shims so that yargs continues working in browser context ([#2457](yargs/yargs#2457)) ([4ae5f57](yargs/yargs@4ae5f57))
-   **build:** address problems with typescript compilation ([#2445](yargs/yargs#2445)) ([8d72fb3](yargs/yargs@8d72fb3))
-   coerce should play well with parser configuration ([#2308](yargs/yargs#2308)) ([8343c66](yargs/yargs@8343c66))
-   **deps:** update dependency yargs-parser to v22 ([#2470](yargs/yargs#2470)) ([639130d](yargs/yargs@639130d))
-   exit after async handler done ([#2313](yargs/yargs#2313)) ([e326cde](yargs/yargs@e326cde))
-   handle spaces in bash completion ([#2452](yargs/yargs#2452)) ([83b7788](yargs/yargs@83b7788))
-   parser-configuration should work well with generated completion script ([#2332](yargs/yargs#2332)) ([888db19](yargs/yargs@888db19))
-   propagate Dictionary including undefined in value type ([#2393](yargs/yargs#2393)) ([2b2f7f5](yargs/yargs@2b2f7f5))
-   **zsh:** completion no longer requires double tab when using autoloaded ([0dd8fe4](yargs/yargs@0dd8fe4))

##### Code Refactoring

-   command names are not derived from modules passed to `command`. ([d90af45](yargs/yargs@d90af45))
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed. ([d90af45](yargs/yargs@d90af45))

##### Build System

-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`. ([d90af45](yargs/yargs@d90af45))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jun 6, 2025
| datasource | package | from   | to     |
| ---------- | ------- | ------ | ------ |
| npm        | yargs   | 17.7.2 | 18.0.0 |


## [v18.0.0](https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1800-2025-05-26)

##### ⚠ BREAKING CHANGES

-   command names are not derived from modules passed to `command`.
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed.
-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`.
-   yargs is now ESM first

##### Features

-   commandDir now works with ESM files ([#2461](yargs/yargs#2461)) ([27eec18](yargs/yargs@27eec18))
-   **locale:** adds hebrew translation ([#2357](yargs/yargs#2357)) ([4266485](yargs/yargs@4266485))
-   yargs is now ESM first ([d90af45](yargs/yargs@d90af45))
-   **zsh:** Add default completion as fallback ([#2331](yargs/yargs#2331)) ([e02c91b](yargs/yargs@e02c91b))

##### Bug Fixes

-   addDirectory do not support absolute command dir ([#2465](yargs/yargs#2465)) ([3a40a78](yargs/yargs@3a40a78))
-   allows ESM modules commands to be extensible using visit option ([#2468](yargs/yargs#2468)) ([200e1aa](yargs/yargs@200e1aa))
-   **browser:** fix shims so that yargs continues working in browser context ([#2457](yargs/yargs#2457)) ([4ae5f57](yargs/yargs@4ae5f57))
-   **build:** address problems with typescript compilation ([#2445](yargs/yargs#2445)) ([8d72fb3](yargs/yargs@8d72fb3))
-   coerce should play well with parser configuration ([#2308](yargs/yargs#2308)) ([8343c66](yargs/yargs@8343c66))
-   **deps:** update dependency yargs-parser to v22 ([#2470](yargs/yargs#2470)) ([639130d](yargs/yargs@639130d))
-   exit after async handler done ([#2313](yargs/yargs#2313)) ([e326cde](yargs/yargs@e326cde))
-   handle spaces in bash completion ([#2452](yargs/yargs#2452)) ([83b7788](yargs/yargs@83b7788))
-   parser-configuration should work well with generated completion script ([#2332](yargs/yargs#2332)) ([888db19](yargs/yargs@888db19))
-   propagate Dictionary including undefined in value type ([#2393](yargs/yargs#2393)) ([2b2f7f5](yargs/yargs@2b2f7f5))
-   **zsh:** completion no longer requires double tab when using autoloaded ([0dd8fe4](yargs/yargs@0dd8fe4))

##### Code Refactoring

-   command names are not derived from modules passed to `command`. ([d90af45](yargs/yargs@d90af45))
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed. ([d90af45](yargs/yargs@d90af45))

##### Build System

-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`. ([d90af45](yargs/yargs@d90af45))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jun 8, 2025
| datasource | package | from   | to     |
| ---------- | ------- | ------ | ------ |
| npm        | yargs   | 17.7.2 | 18.0.0 |


## [v18.0.0](https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1800-2025-05-26)

##### ⚠ BREAKING CHANGES

-   command names are not derived from modules passed to `command`.
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed.
-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`.
-   yargs is now ESM first

##### Features

-   commandDir now works with ESM files ([#2461](yargs/yargs#2461)) ([27eec18](yargs/yargs@27eec18))
-   **locale:** adds hebrew translation ([#2357](yargs/yargs#2357)) ([4266485](yargs/yargs@4266485))
-   yargs is now ESM first ([d90af45](yargs/yargs@d90af45))
-   **zsh:** Add default completion as fallback ([#2331](yargs/yargs#2331)) ([e02c91b](yargs/yargs@e02c91b))

##### Bug Fixes

-   addDirectory do not support absolute command dir ([#2465](yargs/yargs#2465)) ([3a40a78](yargs/yargs@3a40a78))
-   allows ESM modules commands to be extensible using visit option ([#2468](yargs/yargs#2468)) ([200e1aa](yargs/yargs@200e1aa))
-   **browser:** fix shims so that yargs continues working in browser context ([#2457](yargs/yargs#2457)) ([4ae5f57](yargs/yargs@4ae5f57))
-   **build:** address problems with typescript compilation ([#2445](yargs/yargs#2445)) ([8d72fb3](yargs/yargs@8d72fb3))
-   coerce should play well with parser configuration ([#2308](yargs/yargs#2308)) ([8343c66](yargs/yargs@8343c66))
-   **deps:** update dependency yargs-parser to v22 ([#2470](yargs/yargs#2470)) ([639130d](yargs/yargs@639130d))
-   exit after async handler done ([#2313](yargs/yargs#2313)) ([e326cde](yargs/yargs@e326cde))
-   handle spaces in bash completion ([#2452](yargs/yargs#2452)) ([83b7788](yargs/yargs@83b7788))
-   parser-configuration should work well with generated completion script ([#2332](yargs/yargs#2332)) ([888db19](yargs/yargs@888db19))
-   propagate Dictionary including undefined in value type ([#2393](yargs/yargs#2393)) ([2b2f7f5](yargs/yargs@2b2f7f5))
-   **zsh:** completion no longer requires double tab when using autoloaded ([0dd8fe4](yargs/yargs@0dd8fe4))

##### Code Refactoring

-   command names are not derived from modules passed to `command`. ([d90af45](yargs/yargs@d90af45))
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed. ([d90af45](yargs/yargs@d90af45))

##### Build System

-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`. ([d90af45](yargs/yargs@d90af45))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jun 14, 2025
| datasource | package | from   | to     |
| ---------- | ------- | ------ | ------ |
| npm        | yargs   | 17.7.2 | 18.0.0 |


## [v18.0.0](https://github.com/yargs/yargs/blob/HEAD/CHANGELOG.md#1800-2025-05-26)

##### ⚠ BREAKING CHANGES

-   command names are not derived from modules passed to `command`.
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed.
-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`.
-   yargs is now ESM first

##### Features

-   commandDir now works with ESM files ([#2461](yargs/yargs#2461)) ([27eec18](yargs/yargs@27eec18))
-   **locale:** adds hebrew translation ([#2357](yargs/yargs#2357)) ([4266485](yargs/yargs@4266485))
-   yargs is now ESM first ([d90af45](yargs/yargs@d90af45))
-   **zsh:** Add default completion as fallback ([#2331](yargs/yargs#2331)) ([e02c91b](yargs/yargs@e02c91b))

##### Bug Fixes

-   addDirectory do not support absolute command dir ([#2465](yargs/yargs#2465)) ([3a40a78](yargs/yargs@3a40a78))
-   allows ESM modules commands to be extensible using visit option ([#2468](yargs/yargs#2468)) ([200e1aa](yargs/yargs@200e1aa))
-   **browser:** fix shims so that yargs continues working in browser context ([#2457](yargs/yargs#2457)) ([4ae5f57](yargs/yargs@4ae5f57))
-   **build:** address problems with typescript compilation ([#2445](yargs/yargs#2445)) ([8d72fb3](yargs/yargs@8d72fb3))
-   coerce should play well with parser configuration ([#2308](yargs/yargs#2308)) ([8343c66](yargs/yargs@8343c66))
-   **deps:** update dependency yargs-parser to v22 ([#2470](yargs/yargs#2470)) ([639130d](yargs/yargs@639130d))
-   exit after async handler done ([#2313](yargs/yargs#2313)) ([e326cde](yargs/yargs@e326cde))
-   handle spaces in bash completion ([#2452](yargs/yargs#2452)) ([83b7788](yargs/yargs@83b7788))
-   parser-configuration should work well with generated completion script ([#2332](yargs/yargs#2332)) ([888db19](yargs/yargs@888db19))
-   propagate Dictionary including undefined in value type ([#2393](yargs/yargs#2393)) ([2b2f7f5](yargs/yargs@2b2f7f5))
-   **zsh:** completion no longer requires double tab when using autoloaded ([0dd8fe4](yargs/yargs@0dd8fe4))

##### Code Refactoring

-   command names are not derived from modules passed to `command`. ([d90af45](yargs/yargs@d90af45))
-   singleton usage of yargs yargs.foo, yargs().argv, has been removed. ([d90af45](yargs/yargs@d90af45))

##### Build System

-   minimum node.js versions now `^20.19.0 || ^22.12.0 || >=23`. ([d90af45](yargs/yargs@d90af45))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants