Repository: yargs/yargs (js)

Issue:
Replace os-locale with inline code
Due to yargs passing `spawn: false` to os-locale most of the functionality of that module is unused.  The following could be used as a drop-in replacement for os-locale:

```js
function osLocale() {
  const locale = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || 'en_US';
  return locale.replace(/[.:].*/, '');
}
```

The benefit is a large drop of production dependencies.  Currently a project with `yargs` as the only dependency installs 53 modules / 1.8MB to node_modules.  Without os-locale this becomes 26 modules / 1.1MB.  The size reduction is not my primary interest of this issue, the goal is cutting the number of modules that have to be audited in half.

Pull request:
feat: Inline code to detect current locale from environment
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

Patch:
diff --git a/package.json b/package.json
index 5cc7ba2..49f6b52 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,6 @@
     "cliui": "^5.0.0",
     "find-up": "^3.0.0",
     "get-caller-file": "^2.0.1",
-    "os-locale": "^3.1.0",
     "require-directory": "^2.1.1",
     "require-main-filename": "^2.0.0",
     "set-blocking": "^2.0.0",
diff --git a/yargs.js b/yargs.js
index 9a2e633..f1bf8c6 100644
--- a/yargs.js
+++ b/yargs.js
@@ -1181,8 +1181,9 @@ function Yargs (processArgs, cwd, parentRequire) {
     if (!detectLocale) return
 
     try {
-      const osLocale = require('os-locale')
-      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(/[.:].*/, ''))
     } catch (err) {
       // if we explode looking up locale just noop
       // we'll keep using the default language 'en'.


Test patch:
diff --git a/test/validation.js b/test/validation.js
index 60d2344..f704816 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -291,7 +291,6 @@ describe('validation tests', () => {
 
     function loadLocale (locale) {
       delete require.cache[require.resolve('../')]
-      delete require.cache[require.resolve('os-locale')]
       yargs = require('../')
       process.env.LC_ALL = locale
     }
diff --git a/test/yargs.js b/test/yargs.js
index fa232e2..20f1058 100644
--- a/test/yargs.js
+++ b/test/yargs.js
@@ -638,7 +638,6 @@ describe('yargs dsl tests', () => {
 
     function loadLocale (locale) {
       delete require.cache[require.resolve('../')]
-      delete require.cache[require.resolve('os-locale')]
       yargs = require('../')
       process.env.LC_ALL = locale
     }
@@ -687,17 +686,6 @@ describe('yargs dsl tests', () => {
       r.logs.join(' ').should.match(/Exibe ajuda/)
     })
 
-    it('handles os-locale throwing an exception', () => {
-      // make os-locale throw.
-      require('os-locale')
-      require.cache[require.resolve('os-locale')].exports.sync = () => { throw Error('an error!') }
-
-      delete require.cache[require.resolve('../')]
-      yargs = require('../')
-
-      yargs.locale().should.equal('en')
-    })
-
     it('uses locale string for help option default desc on .locale().help()', () => {
       const r = checkOutput(() => {
         yargs(['-h'])