Skip to content

feat: Inline code to detect current locale from environment#1356

Merged
bcoe merged 1 commit intoyargs:masterfrom
coreyfarrell:inline-os-locale
Jun 10, 2019
Merged

feat: Inline code to detect current locale from environment#1356
bcoe merged 1 commit intoyargs:masterfrom
coreyfarrell:inline-os-locale

Conversation

@coreyfarrell
Copy link
Contributor

This eliminates half the dependencies of yargs without any change in
functionality. The extra dependencies were used by the os-locale module
to execute detection utilities, this execution functionality was always
disabled by yargs.

Fixes #1354

This eliminates half the dependencies of yargs without any change in
functionality.  The extra dependencies were used by the os-locale module
to execute detection utilities, this execution functionality was always
disabled by yargs.

Fixes yargs#1354
self.locale(osLocale.sync({ spawn: false }))
const { env } = process
const locale = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || 'en_US'
self.locale(locale.replace(/[.:].*/, ''))
Copy link
Contributor Author

@coreyfarrell coreyfarrell Jun 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we the try / catch block is no longer needed but the way os-locale was used I think it was impossible for it to throw, therefore I assume that it's possible for self.locale() to cause an exception.

@bcoe
Copy link
Member

bcoe commented Jun 10, 2019

@coreyfarrell incredible work, thanks for doing this.

@bcoe bcoe merged commit 4dfa19b into yargs:master Jun 10, 2019
@bcoe
Copy link
Member

bcoe commented Jun 10, 2019

@coreyfarrell when you have a sec try npm i yargs@next, has your refactor landed.

@coreyfarrell coreyfarrell deleted the inline-os-locale branch June 10, 2019 14:26
@coreyfarrell
Copy link
Contributor Author

It works for my (admittedly simple) use case, npm i yargs@next installs 26 packages (including yargs) where yargs@latest installs 53 packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace os-locale with inline code

2 participants