Repository: oclif/core
Pull request #37 (2020-09-14 14:44:26)

feat: mv Command & flag export to root

codecov[bot]: # [Codecov](https://codecov.io/gh/oclif/core/pull/37?src=pr&el=h1) Report
> Merging [#37](https://codecov.io/gh/oclif/core/pull/37?src=pr&el=desc) into [master](https://codecov.io/gh/oclif/core/commit/10c1887d2b27c85e601a72356c3114fd9e578d41?el=desc) will **not change** coverage.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/oclif/core/pull/37/graphs/tree.svg?width=650&height=150&src=pr&token=K0kGk9tefA)](https://codecov.io/gh/oclif/core/pull/37?src=pr&el=tree)

```diff
@@          Coverage Diff           @@
##           master     #37   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files           4       4           
  Lines          25      25           
  Branches        5       5           
======================================
  Misses         25      25           
```


| [Impacted Files](https://codecov.io/gh/oclif/core/pull/37?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/index.ts](https://codecov.io/gh/oclif/core/pull/37/diff?src=pr&el=tree#diff-c3JjL2luZGV4LnRz) | `0.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/oclif/core/pull/37?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/oclif/core/pull/37?src=pr&el=footer). Last update [10c1887...d015834](https://codecov.io/gh/oclif/core/pull/37?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/command/command.ts b/src/command.ts
similarity index 95%
rename from src/command/command.ts
rename to src/command.ts
index 819bf63..9599d9a 100644
--- a/src/command/command.ts
+++ b/src/command.ts
@@ -1,20 +1,20 @@
-const pjson = require('../../package.json')
-import * as Config from '../config'
-import * as Errors from '../errors'
-import * as Parser from '../parser'
-import {HelpBase} from '../help'
 import {format, inspect} from 'util'
 
+import * as Config from './config'
+import * as Errors from './errors'
+import {PrettyPrintableError} from './errors'
+import * as Parser from './parser'
+import {HelpBase, getHelpClass} from './help'
 import * as flags from './flags'
 import {sortBy, uniqBy} from './util'
-import {getHelpClass} from '../help'
-import {PrettyPrintableError} from '../errors'
+
+const pjson = require('../package.json')
 
 /**
  * swallows stdout epipe errors
  * this occurs when stdout closes such as when piping to head
  */
-process.stdout.on('error', err => {
+process.stdout.on('error', (err: any) => {
   if (err && err.code === 'EPIPE')
     return
   throw err
diff --git a/src/command/index.ts b/src/command/index.ts
deleted file mode 100644
index 7ce7cd3..0000000
--- a/src/command/index.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import * as path from 'path'
-import * as semver from 'semver'
-
-function checkCWD() {
-  try {
-    process.cwd()
-  } catch (error) {
-    if (error.code === 'ENOENT') {
-      process.stderr.write('WARNING: current directory does not exist\n')
-    }
-  }
-}
-function checkNodeVersion() {
-  const root = path.join(__dirname, '..')
-  const pjson = require(path.join(root, '../package.json'))
-  if (!semver.satisfies(process.versions.node, pjson.engines.node)) {
-    process.stderr.write(`WARNING\nWARNING Node version must be ${pjson.engines.node} to use this CLI\nWARNING Current node version: ${process.versions.node}\nWARNING\n`)
-  }
-}
-checkCWD()
-checkNodeVersion()
-
-import Command from './command'
-import * as flags from './flags'
-export {run, Main} from './main'
-
-export default Command
-export {
-  Command,
-  flags,
-}
diff --git a/src/config/debug.ts b/src/config/debug.ts
index b81e89c..c4a2e86 100644
--- a/src/config/debug.ts
+++ b/src/config/debug.ts
@@ -14,7 +14,7 @@ function displayWarnings() {
 
 export default (...scope: string[]) => {
   if (!debug) return (..._: any[]) => {}
-  const d = debug(['../config', ...scope].join(':'))
+  const d = debug(['config', ...scope].join(':'))
   if (d.enabled) displayWarnings()
   return (...args: any[]) => d(...args)
 }
diff --git a/src/command/flags.ts b/src/flags.ts
similarity index 94%
rename from src/command/flags.ts
rename to src/flags.ts
index 3e4770d..dd3f926 100644
--- a/src/command/flags.ts
+++ b/src/flags.ts
@@ -1,7 +1,6 @@
-import {IConfig} from '../config'
-import * as Parser from '../parser'
-
-import {Command} from '.'
+import {IConfig} from './config'
+import * as Parser from './parser'
+import Command from './command'
 
 export type ICompletionContext = {
   args?: { [name: string]: string };
@@ -56,7 +55,7 @@ export {_enum as enum}
 
 const stringFlag = build({})
 export {stringFlag as string}
-export {boolean, integer} from '../parser'
+export {boolean, integer} from './parser'
 
 export const version = (opts: Partial<Parser.flags.IBooleanFlag<boolean>> = {}) => {
   return Parser.flags.boolean({
diff --git a/src/index.ts b/src/index.ts
index 036946b..7c48699 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,7 +1,11 @@
-import * as Command from './command'
-import {run} from './command'
+import * as path from 'path'
+import * as semver from 'semver'
+
+import Command from './command'
+import {run} from './main'
 import * as Config from './config'
 import * as Errors from './errors'
+import * as flags from './flags'
 import * as Help from './help'
 import * as Parser from './parser'
 
@@ -9,7 +13,27 @@ export {
   Command,
   Config,
   Errors,
+  flags,
   Help,
   Parser,
   run,
 }
+
+function checkCWD() {
+  try {
+    process.cwd()
+  } catch (error) {
+    if (error.code === 'ENOENT') {
+      process.stderr.write('WARNING: current directory does not exist\n')
+    }
+  }
+}
+function checkNodeVersion() {
+  const root = path.join(__dirname, '..')
+  const pjson = require(path.join(root, 'package.json'))
+  if (!semver.satisfies(process.versions.node, pjson.engines.node)) {
+    process.stderr.write(`WARNING\nWARNING Node version must be ${pjson.engines.node} to use this CLI\nWARNING Current node version: ${process.versions.node}\nWARNING\n`)
+  }
+}
+checkCWD()
+checkNodeVersion()
diff --git a/src/command/main.ts b/src/main.ts
similarity index 92%
rename from src/command/main.ts
rename to src/main.ts
index 6c681b2..cae804d 100644
--- a/src/command/main.ts
+++ b/src/main.ts
@@ -1,8 +1,6 @@
-import * as Config from '../config'
-import {HelpBase} from '../help'
-
-import {Command} from '.'
-import {getHelpClass} from '../help'
+import * as Config from './config'
+import {HelpBase, getHelpClass} from './help'
+import Command from './command'
 
 const ROOT_INDEX_CMD_ID = ''
 


Test patch:
diff --git a/src/command/util.ts b/src/util.ts
similarity index 100%
rename from src/command/util.ts
rename to src/util.ts
diff --git a/test/command/command.test.ts b/test/command/command.test.ts
index eccffd3..5a920e4 100644
--- a/test/command/command.test.ts
+++ b/test/command/command.test.ts
@@ -1,13 +1,12 @@
-import * as Config from '../../src/config'
 import {expect, fancy} from 'fancy-test'
+import path = require('path')
 
-import Base, {flags} from '../../src/command'
+import {Config, Command as Base, flags, Help as PluginHelp} from '../../src'
 import {TestHelpClassConfig} from './helpers/test-help-in-src/src/test-help-plugin'
-import * as PluginHelp from '../../src/help'
-
-const originalgetHelpClass = PluginHelp.getHelpClass
 
 // const pjson = require('../package.json')
+const originalgetHelpClass = PluginHelp.getHelpClass
+const root = path.resolve(__dirname, '../../package.json')
 
 class Command extends Base {
   static description = 'test command'
@@ -34,11 +33,11 @@ describe('command', () => {
   fancy
   .do(async () => {
     class Command extends Base {
-        static description = 'test command'
+      static description = 'test command'
 
-        async run() {
-          return 101
-        }
+      async run() {
+        return 101
+      }
     }
 
     expect(await Command.run([])).to.equal(101)
@@ -205,14 +204,14 @@ describe('command', () => {
     .stdout()
     .it('has a flag', async ctx => {
       class CMD extends Base {
-          static flags = {
-            foo: flags.string(),
-          }
-
-          async run() {
-            const {flags} = this.parse(CMD)
-            this.log(flags.foo)
-          }
+        static flags = {
+          foo: flags.string(),
+        }
+
+        async run() {
+          const {flags} = this.parse(CMD)
+          this.log(flags.foo)
+        }
       }
 
       await CMD.run(['--foo=bar'])
@@ -225,7 +224,7 @@ describe('command', () => {
     .stdout()
     .add('config', () => Config.load())
     .do(async () => {
-      await Command.run(['--version'])
+      await Command.run(['--version'], root)
     })
     .catch(/EEXIT: 0/)
     .it('shows version', ctx => {
@@ -238,9 +237,9 @@ describe('command', () => {
     .stdout()
     .do(() => {
       class CMD extends Command {
-          static flags = {help: flags.help()}
+        static flags = {help: flags.help()}
       }
-      return CMD.run(['--help'])
+      return CMD.run(['--help'], root)
     })
     .catch(/EEXIT: 0/)
     .it('--help', ctx => {
@@ -259,7 +258,7 @@ OPTIONS
     .stdout()
     .do(async () => {
       class CMD extends Command {}
-      await CMD.run(['-h'])
+      await CMD.run(['-h'], root)
     })
     .catch(/EEXIT: 0/)
     .it('-h', ctx => {
diff --git a/test/command/main.test.ts b/test/command/main.test.ts
index a6cc154..8a975b3 100644
--- a/test/command/main.test.ts
+++ b/test/command/main.test.ts
@@ -1,32 +1,32 @@
 import {expect, fancy} from 'fancy-test'
+import path = require('path')
 
-import {Main} from '../../src/command/main'
-import * as PluginHelp from '../../src/help'
-import * as Config from '../../src/config'
+import {Main} from '../../src/main'
+import {Help as PluginHelp, Config} from '../../src'
 import {TestHelpClassConfig} from './helpers/test-help-in-src/src/test-help-plugin'
-import path = require('path')
 
-const pjson = require(path.resolve(__dirname, '../../package.json'))
+const root = path.resolve(__dirname, '../../package.json')
+const pjson = require(root)
 const version = `@oclif/core/${pjson.version} ${process.platform}-${process.arch} node-${process.version}`
 const originalgetHelpClass = PluginHelp.getHelpClass
 
 describe('main', () => {
   fancy
   .stdout()
-  .do(() => Main.run(['plugins']))
+  .do(() => Main.run(['plugins'], root))
   .do((output: any) => expect(output.stdout).to.equal('no plugins installed\n'))
   .it('runs plugins')
 
   fancy
   .stdout()
-  .do(() => Main.run(['-v']))
+  .do(() => Main.run(['-v'], root))
   .catch('EEXIT: 0')
   .do((output: any) => expect(output.stdout).to.equal(version + '\n'))
   .it('runs -v')
 
   fancy
   .stdout()
-  .do(() => Main.run(['-h']))
+  .do(() => Main.run(['-h'], root))
   .catch('EEXIT: 0')
   .do((output: any) => expect(output.stdout).to.equal(`base library for oclif CLIs
 
@@ -47,7 +47,7 @@ COMMANDS
 
   describe('with an alternative help class', async () => {
     const getMainWithHelpClass = async () => {
-      const config: TestHelpClassConfig = await Config.load()
+      const config: TestHelpClassConfig = await Config.load(root)
       config.pjson.oclif.helpClass = './src/test-help-plugin'
 
       class MainWithHelpClass extends Main {
diff --git a/test/help/format-command.test.ts b/test/help/format-command.test.ts
index c9859be..6a73338 100644
--- a/test/help/format-command.test.ts
+++ b/test/help/format-command.test.ts
@@ -1,5 +1,4 @@
-import {Command as Base, flags} from '../../src/command'
-import * as Config from '../../src/config'
+import {Command as Base, flags, Config} from '../../src'
 import {expect, test as base} from '@oclif/test'
 import stripAnsi = require('strip-ansi')