Skip to content

Commit

Permalink
fix: use core v2 (#350)
Browse files Browse the repository at this point in the history
* fix: use core v2

* chore: tests
  • Loading branch information
mdonnalley committed Jan 23, 2023
1 parent 4660e4d commit b317662
Show file tree
Hide file tree
Showing 4 changed files with 441 additions and 307 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"bugs": "https://github.com/oclif/plugin-not-found/issues",
"dependencies": {
"@oclif/color": "^1.0.3",
"@oclif/core": "^1.25.0",
"@oclif/core": "^2.0.3",
"fast-levenshtein": "^3.0.0",
"lodash": "^4.17.21"
},
Expand All @@ -36,7 +36,7 @@
"eslint-config-oclif": "^4",
"eslint-config-oclif-typescript": "^1.0.3",
"mocha": "^9",
"oclif": "^2.6.3",
"oclif": "^3.6.1",
"ts-node": "^9.1.1",
"typescript": "^4.6.3"
},
Expand Down Expand Up @@ -64,4 +64,4 @@
"postpublish": "rm oclif.manifest.json"
},
"types": "lib/index.d.ts"
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {color} from '@oclif/color'
import {CliUx, Hook, toConfiguredId} from '@oclif/core'
import {ux, Hook, toConfiguredId} from '@oclif/core'
import * as Levenshtein from 'fast-levenshtein'
import * as _ from 'lodash'

Expand Down Expand Up @@ -29,7 +29,7 @@ const hook: Hook.CommandNotFound = async function (opts) {

let response = ''
try {
response = await CliUx.ux.prompt(`Did you mean ${color.blueBright(readableSuggestion)}? [y/n]`, {timeout: 4900})
response = await ux.prompt(`Did you mean ${color.blueBright(readableSuggestion)}? [y/n]`, {timeout: 4900})
} catch (error) {
this.log('')
this.debug(error)
Expand Down
8 changes: 4 additions & 4 deletions test/hooks/not-found.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk, {color} from '@oclif/color'
import {expect, test} from '@oclif/test'
import {CliUx} from '@oclif/core'
import {ux} from '@oclif/core'

const yes = () => 'y'
const no = () => 'n'
Expand All @@ -9,7 +9,7 @@ color(chalk, 'enabled', 0)

describe('command_not_found', () => {
test
.stub(CliUx.ux, 'prompt', () => yes)
.stub(ux, 'prompt', yes)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
.stub(process, 'argv', [])
Expand All @@ -23,7 +23,7 @@ describe('command_not_found', () => {

test
.stderr()
.stub(CliUx.ux, 'prompt', yes)
.stub(ux, 'prompt', yes)
.hook('command_not_found', {id: 'commans', argv: ['foo', '--bar', 'baz']})
.catch((error: Error) => error.message.includes('Unexpected arguments: foo, --bar, baz\nSee more help with --help'))
.end('runs hook with suggested command and provided args on yes', (ctx: any) => {
Expand All @@ -32,7 +32,7 @@ describe('command_not_found', () => {

test
.stderr()
.stub(CliUx.ux, 'prompt', () => no)
.stub(ux, 'prompt', () => no)
.hook('command_not_found', {id: 'commans'})
.catch((error: Error) => error.message.includes('Run @oclif/plugin-not-found help for a list of available commands.'))
.end('runs hook with not found error on no', (ctx: any) => {
Expand Down
Loading

0 comments on commit b317662

Please sign in to comment.