Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: remove @oclif/plugin-help (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Dec 14, 2021
1 parent 4771020 commit 3a00d2a
Show file tree
Hide file tree
Showing 11 changed files with 1,325 additions and 1,235 deletions.
12 changes: 11 additions & 1 deletion .eslintrc
Expand Up @@ -3,5 +3,15 @@
"oclif",
"oclif-typescript"
],
"rules": {}
"rules": {
"unicorn/prefer-node-protocol": "off",
"node/no-missing-import": "off",
"@typescript-eslint/no-empty-function": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-regexp-test": "off",
"default-param-last": "off",
"unicorn/prefer-array-some": "off",
"unicorn/consistent-function-scoping": "off",
"unicorn/import-style": "off"
}
}
8 changes: 2 additions & 6 deletions package.json
Expand Up @@ -8,7 +8,7 @@
"@oclif/config": "^1.18.2",
"@oclif/errors": "^1.3.5",
"@oclif/parser": "^3.8.6",
"@oclif/plugin-help": "3.2.14",
"@oclif/help": "^1.0.0",
"debug": "^4.1.1",
"semver": "^7.3.2"
},
Expand Down Expand Up @@ -50,7 +50,6 @@
"main": "lib/index.js",
"oclif": {
"devPlugins": [
"@oclif/plugin-help",
"@oclif/plugin-plugins"
]
},
Expand All @@ -64,8 +63,5 @@
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"pretest": "yarn build --noEmit && tsc -p test --noEmit"
},
"types": "lib/index.d.ts",
"resolutions": {
"@oclif/plugin-help": "3.2.14"
}
"types": "lib/index.d.ts"
}
7 changes: 5 additions & 2 deletions src/command.ts
Expand Up @@ -2,12 +2,11 @@ const pjson = require('../package.json')
import * as Config from '@oclif/config'
import * as Errors from '@oclif/errors'
import * as Parser from '@oclif/parser'
import {HelpBase} from '@oclif/plugin-help'
import {HelpBase, getHelpClass} from '@oclif/help'
import {format, inspect} from 'util'

import * as flags from './flags'
import {sortBy, uniqBy} from './util'
import {getHelpClass} from '@oclif/plugin-help'
import {PrettyPrintableError} from '@oclif/errors'

/**
Expand Down Expand Up @@ -167,14 +166,17 @@ export default abstract class Command {
if (err.message.match(/Unexpected arguments?: (-h|--help|help)(,|\n)/)) {
return this._help()
}

if (err.message.match(/Unexpected arguments?: (-v|--version|version)(,|\n)/)) {
return this._version()
}

try {
const {cli} = require('cli-ux')
const chalk = require('chalk') // eslint-disable-line node/no-extraneous-require
cli.action.stop(chalk.bold.red('!'))
} catch {}

throw err
}

Expand Down Expand Up @@ -206,6 +208,7 @@ export default abstract class Command {
if (arg === '--help') return true
if (arg === '--') return false
}

return false
}

Expand Down
1 change: 1 addition & 0 deletions src/flags.ts
Expand Up @@ -52,6 +52,7 @@ const _enum = <T = string>(opts: Parser.flags.EnumFlagOptions<T>): IOptionFlag<T
...opts,
})() as IOptionFlag<T>
}

export {_enum as enum}

const stringFlag = build({})
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Expand Up @@ -10,13 +10,15 @@ function checkCWD() {
}
}
}

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()

Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
@@ -1,8 +1,7 @@
import * as Config from '@oclif/config'
import {HelpBase} from '@oclif/plugin-help'
import {HelpBase, getHelpClass} from '@oclif/help'

import Command from './command'
import {getHelpClass} from '@oclif/plugin-help'

const ROOT_INDEX_CMD_ID = ''

Expand All @@ -28,6 +27,7 @@ export class Main extends Command {
argv = this.argv
}
}

await this.config.runCommand(id, argv)
}

Expand All @@ -39,6 +39,7 @@ export class Main extends Command {
if (arg === '--help') return true
if (arg === '--') return false
}

return false
}

Expand Down
1 change: 1 addition & 0 deletions src/util.ts
Expand Up @@ -8,6 +8,7 @@ export function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[] {
return !arr.find((b, j) => j > i && fn(b) === aVal)
})
}

export namespace sort {
export type Types = string | number | undefined | boolean
}
Expand Down
34 changes: 28 additions & 6 deletions test/command.test.ts
Expand Up @@ -3,9 +3,9 @@ import {expect, fancy} from 'fancy-test'

import Base, {flags} from '../src'
import {TestHelpClassConfig} from './helpers/test-help-in-src/src/test-help-plugin'
import * as PluginHelp from '@oclif/plugin-help'
import * as OclifHelp from '@oclif/help'

const originalgetHelpClass = PluginHelp.getHelpClass
const originalgetHelpClass = OclifHelp.getHelpClass

// const pjson = require('../package.json')

Expand Down Expand Up @@ -290,14 +290,18 @@ USAGE

fancy
.stdout()
.stub(PluginHelp, 'getHelpClass', function (config: any) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: any) {
return originalgetHelpClass(config, '')
})
.add('config', async () => {
const config: TestHelpClassConfig = await Config.load()
config.pjson.oclif.helpClass = undefined
return config
})
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(async ({config}) => {
class CMD extends Command {
config = config
Expand All @@ -310,7 +314,9 @@ USAGE
describe('from a help class', () => {
fancy
.stdout()
.stub(PluginHelp, 'getHelpClass', function (config: Config.IConfig) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-lib/`,
Expand All @@ -323,6 +329,8 @@ USAGE
config.pjson.oclif.helpClass = './lib/test-help-plugin'
return config
})
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(async ({config}) => {
class CMD extends Command {
static id = 'test-command-for-help-plugin'
Expand All @@ -332,6 +340,8 @@ USAGE
await CMD.run(['-h'])
})
.catch(/EEXIT: 0/)
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.it('-h via a plugin in lib dir (compiled to js)', ctx => {
expect(ctx.stdout).to.equal('hello from test-help-plugin #showCommandHelp in the lib folder and in compiled javascript\n')
expect(ctx.config.showCommandHelpSpy!.getCalls().length).to.equal(1)
Expand All @@ -343,7 +353,9 @@ USAGE

fancy
.stdout()
.stub(PluginHelp, 'getHelpClass', function (config: Config.IConfig) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
Expand All @@ -356,6 +368,8 @@ USAGE
config.pjson.oclif.helpClass = './lib/test-help-plugin'
return config
})
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(async ({config}) => {
class CMD extends Command {
static id = 'test-command-for-help-plugin'
Expand All @@ -365,6 +379,8 @@ USAGE
await CMD.run(['-h'])
})
.catch(/EEXIT: 0/)
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.it('-h via a plugin in src dir (source in ts)', ctx => {
expect(ctx.stdout).to.equal('hello from test-help-plugin #showCommandHelp\n')
expect(ctx.config.showCommandHelpSpy!.getCalls().length).to.equal(1)
Expand All @@ -376,7 +392,9 @@ USAGE

fancy
.stdout()
.stub(PluginHelp, 'getHelpClass', function (config: Config.IConfig) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
Expand All @@ -389,6 +407,8 @@ USAGE
config.pjson.oclif.helpClass = './lib/test-help-plugin'
return config
})
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(async ({config}) => {
class CMD extends Command {
static id = 'test-command-for-help-plugin'
Expand All @@ -400,6 +420,8 @@ USAGE
return CMD.run(['--help'])
})
.catch(/EEXIT: 0/)
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.it('--help via a plugin in src dir (source in ts)', ctx => {
expect(ctx.stdout).to.equal('hello from test-help-plugin #showCommandHelp\n')
expect(ctx.config.showCommandHelpSpy!.getCalls().length).to.equal(1)
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/test-help-in-src/src/test-help-plugin.ts
@@ -1,4 +1,4 @@
import {HelpBase} from '@oclif/plugin-help'
import {HelpBase} from '@oclif/help'
import {spy, SinonSpy} from 'sinon'
import {IConfig} from '@oclif/config'

Expand Down
23 changes: 17 additions & 6 deletions test/main.test.ts
@@ -1,13 +1,13 @@
import {expect, fancy} from 'fancy-test'

import {Main} from '../src/main'
import * as PluginHelp from '@oclif/plugin-help'
import * as OclifHelp from '@oclif/help'
import * as Config from '@oclif/config'
import {TestHelpClassConfig} from './helpers/test-help-in-src/src/test-help-plugin'

const pjson = require('../package.json')
const version = `@oclif/command/${pjson.version} ${process.platform}-${process.arch} node-${process.version}`
const originalgetHelpClass = PluginHelp.getHelpClass
const originalgetHelpClass = OclifHelp.getHelpClass

describe('main', () => {
fancy
Expand Down Expand Up @@ -39,7 +39,6 @@ TOPICS
plugins list installed plugins
COMMANDS
help display help for @oclif/command
plugins list installed plugins
`))
Expand All @@ -59,7 +58,9 @@ COMMANDS

fancy
.stdout()
.stub(PluginHelp, 'getHelpClass', function (config: Config.IConfig) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
Expand All @@ -69,12 +70,16 @@ COMMANDS
})
.do(async () => (await getMainWithHelpClass()).run(['-h']))
.catch('EEXIT: 0')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(output => expect(output.stdout).to.equal('hello showHelp\n'))
.it('works with -h')

fancy
.stdout()
.stub(PluginHelp, 'getHelpClass', function (config: Config.IConfig) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
Expand All @@ -84,12 +89,16 @@ COMMANDS
})
.do(async () => (await getMainWithHelpClass()).run(['--help']))
.catch('EEXIT: 0')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(output => expect(output.stdout).to.equal('hello showHelp\n'))
.it('works with --help')

fancy
.stdout()
.stub(PluginHelp, 'getHelpClass', function (config: Config.IConfig) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
Expand All @@ -99,6 +108,8 @@ COMMANDS
})
.do(async () => (await getMainWithHelpClass()).run(['help']))
.catch('EEXIT: 0')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(output => expect(output.stdout).to.equal('hello showHelp\n'))
.it('works with help')
})
Expand Down

0 comments on commit 3a00d2a

Please sign in to comment.