diff --git a/package.json b/package.json index 170178a2..d2d4c4bf 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "@types/mocha": "^8", "@types/nock": "^11.1.0", "@types/node": "^15.14.9", - "@types/sinon-chai": "^3.2.9", "chai": "^4", "eslint": "^7.3.1", "eslint-config-oclif": "^3.1.0", @@ -29,8 +28,6 @@ "nyc": "^15.1.0", "oclif": "^3.12.0", "shx": "^0.3.3", - "sinon": "^12.0.1", - "sinon-chai": "^3.7.0", "ts-node": "^9.0.0", "tslib": "^2.6.2", "typescript": "4.6.3" diff --git a/src/commands/autocomplete/index.ts b/src/commands/autocomplete/index.ts index 2772b444..24b9c4c9 100644 --- a/src/commands/autocomplete/index.ts +++ b/src/commands/autocomplete/index.ts @@ -1,11 +1,24 @@ import {Args, ux, Flags} from '@oclif/core' import {EOL} from 'os' -import {bold, cyan} from 'chalk' +import chalk from 'chalk' import {AutocompleteBase} from '../../base' import Create from './create' +const noteFromShell = (shell: string) => { + switch (shell) { + case 'zsh': + return `After sourcing, you can run \`${chalk.cyan('$ compaudit -D')}\` to ensure no permissions conflicts are present` + case 'bash': + return 'If your terminal starts as a login shell you may need to print the init script into ~/.bash_profile or ~/.profile.' + case 'powershell': + return `Use the \`MenuComplete\` mode to get matching completions printed below the command line:\n${chalk.cyan('Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete')}` + default: + return '' + } +} + export default class Index extends AutocompleteBase { static description = 'display autocomplete installation instructions' @@ -37,7 +50,7 @@ export default class Index extends AutocompleteBase { this.error(`PowerShell completion is not supported in CLIs using colon as the topic separator.${EOL}See: https://oclif.io/docs/topic_separator`) } - ux.action.start(`${bold('Building the autocomplete cache')}`) + ux.action.start(`${chalk.bold('Building the autocomplete cache')}`) await Create.run([], this.config) ux.action.stop() @@ -50,34 +63,24 @@ export default class Index extends AutocompleteBase { Add-Content -Path $PROFILE -Value (Invoke-Expression -Command "${bin} autocomplete${this.config.topicSeparator}script ${shell}"); .$PROFILE` : `$ printf "eval $(${bin} autocomplete${this.config.topicSeparator}script ${shell})" >> ~/.${shell}rc; source ~/.${shell}rc` - let note = '' - - switch (shell) { - case 'zsh': - note = `After sourcing, you can run \`${cyan('$ compaudit -D')}\` to ensure no permissions conflicts are present` - break - case 'bash': - note = 'If your terminal starts as a login shell you may need to print the init script into ~/.bash_profile or ~/.profile.' - break - case 'powershell': - note = `Use the \`MenuComplete\` mode to get matching completions printed below the command line:\n${cyan('Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete')}` - } + const note = noteFromShell(shell) this.log(` -${bold(`Setup Instructions for ${bin.toUpperCase()} CLI Autocomplete ---`)} +${chalk.bold(`Setup Instructions for ${bin.toUpperCase()} CLI Autocomplete ---`)} 1) Add the autocomplete ${shell === 'powershell' ? 'file' : 'env var'} to your ${shell} profile and source it -${cyan(instructions)} +${chalk.cyan(instructions)} -${bold('NOTE')}: ${note} +${chalk.bold('NOTE')}: ${note} 2) Test it out, e.g.: -${cyan(`$ ${bin} ${tabStr}`)} # Command completion -${cyan(`$ ${bin} command --${tabStr}`)} # Flag completion +${chalk.cyan(`$ ${bin} ${tabStr}`)} # Command completion +${chalk.cyan(`$ ${bin} command --${tabStr}`)} # Flag completion Enjoy! `) } } } + diff --git a/test/base.test.ts b/test/base.test.ts index 745dcb80..3965fa97 100644 --- a/test/base.test.ts +++ b/test/base.test.ts @@ -1,15 +1,10 @@ import {Config} from '@oclif/core' -import * as Chai from 'chai' +import {expect} from 'chai' import * as path from 'path' -import * as fs from 'fs' -import * as Sinon from 'sinon' -import * as SinonChai from 'sinon-chai' +import {readFile, rm} from 'fs/promises' import {AutocompleteBase} from '../src/base' -Chai.use(SinonChai) -const expect = Chai.expect - class AutocompleteTest extends AutocompleteBase { async run() { return null @@ -22,19 +17,11 @@ const config = new Config({root}) const cmd = new AutocompleteTest([], config) describe('AutocompleteBase', () => { - let fsWriteStub: Sinon.SinonStub - let fsOpenSyncStub: Sinon.SinonStub - - before(() => { - fsWriteStub = Sinon.stub(fs, 'writeSync') - fsOpenSyncStub = Sinon.stub(fs, 'openSync').returns(7) - }) - beforeEach(async () => { await config.load() }) - it('#convertWindowsBash', async () => { + it('#convertWindowsBash', () => { expect(cmd.determineShell('bash')).to.eq('bash') expect(cmd.determineShell('zsh')).to.eq('zsh') expect(cmd.determineShell('fish')).to.eq('fish') @@ -44,15 +31,16 @@ describe('AutocompleteBase', () => { }).to.throw() }) - it('#autocompleteCacheDir', async () => { + it('#autocompleteCacheDir', () => { expect(cmd.autocompleteCacheDir).to.eq(path.join(config.cacheDir, 'autocomplete')) }) it('#acLogfile', async () => { expect(cmd.acLogfilePath).to.eq(path.join(config.cacheDir, 'autocomplete.log')) - + await rm(cmd.acLogfilePath, {force: true, recursive: true}) cmd.writeLogFile('testing') - expect(fsOpenSyncStub).to.have.been.calledOnce - expect(fsWriteStub).to.be.been.calledWith(7) + + const logs = await readFile(cmd.acLogfilePath, 'utf8') + expect(logs).to.include('testing') }) }) diff --git a/test/tsconfig.json b/test/tsconfig.json index 04c22f3b..4ee3ca44 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -2,7 +2,8 @@ "declaration": false, "extends": "../tsconfig", "compilerOptions": { - "sourceMap": true + "sourceMap": true, + "esModuleInterop": true }, "include": [ "./**/*", diff --git a/tsconfig.json b/tsconfig.json index 30db9f51..3f96cdcd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "declaration": true, "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, "importHelpers": true, "module": "commonjs", "outDir": "./lib", diff --git a/yarn.lock b/yarn.lock index 5cccd34a..e6ff6f97 100644 --- a/yarn.lock +++ b/yarn.lock @@ -584,41 +584,6 @@ resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f" integrity sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw== -"@sinonjs/commons@^1.6.0", "@sinonjs/commons@^1.7.0", "@sinonjs/commons@^1.8.3": - version "1.8.3" - resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.3.tgz#3802ddd21a50a949b6721ddd72da36e67e7f1b2d" - integrity sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ== - dependencies: - type-detect "4.0.8" - -"@sinonjs/fake-timers@^7.0.4": - version "7.1.2" - resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-7.1.2.tgz#2524eae70c4910edccf99b2f4e6efc5894aff7b5" - integrity sha512-iQADsW4LBMISqZ6Ci1dupJL9pprqwcVFTcOsEmQOEhW+KLCVn/Y4Jrvg2k19fIHCp+iFprriYPTdRcQR8NbUPg== - dependencies: - "@sinonjs/commons" "^1.7.0" - -"@sinonjs/fake-timers@^8.1.0": - version "8.1.0" - resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-8.1.0.tgz#3fdc2b6cb58935b21bfb8d1625eb1300484316e7" - integrity sha512-OAPJUAtgeINhh/TAlUID4QTs53Njm7xzddaVlEs/SXwgtiD1tW22zAB/W1wdqfrpmikgaWQ9Fw6Ws+hsiRm5Vg== - dependencies: - "@sinonjs/commons" "^1.7.0" - -"@sinonjs/samsam@^6.0.2": - version "6.0.2" - resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-6.0.2.tgz#a0117d823260f282c04bff5f8704bdc2ac6910bb" - integrity sha512-jxPRPp9n93ci7b8hMfJOFDPRLFYadN6FSpeROFTR4UNF4i5b+EK6m4QXPO46BDhFgRy1JuS87zAnFOzCUwMJcQ== - dependencies: - "@sinonjs/commons" "^1.6.0" - lodash.get "^4.4.2" - type-detect "^4.0.8" - -"@sinonjs/text-encoding@^0.7.1": - version "0.7.1" - resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz#8da5c6530915653f3a1f38fd5f101d8c3f8079c5" - integrity sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ== - "@szmarczak/http-timer@^4.0.5": version "4.0.6" resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-4.0.6.tgz#b4a914bb62e7c272d4e5989fe4440f812ab1d807" @@ -756,14 +721,6 @@ dependencies: "@types/node" "*" -"@types/sinon-chai@^3.2.9": - version "3.2.9" - resolved "https://registry.yarnpkg.com/@types/sinon-chai/-/sinon-chai-3.2.9.tgz#71feb938574bbadcb176c68e5ff1a6014c5e69d4" - integrity sha512-/19t63pFYU0ikrdbXKBWj9PCdnKyTd0Qkz0X91Ta081cYsq90OxYdcWwK/dwEoDa6dtXgj2HJfmzgq+QZTHdmQ== - dependencies: - "@types/chai" "*" - "@types/sinon" "*" - "@types/sinon@*": version "9.0.4" resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-9.0.4.tgz#e934f904606632287a6e7f7ab0ce3f08a0dad4b1" @@ -2768,11 +2725,6 @@ is-wsl@^2.2.0: dependencies: is-docker "^2.0.0" -isarray@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" - integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= - isarray@^1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" @@ -2969,11 +2921,6 @@ just-diff@^5.0.1: resolved "https://registry.npmjs.org/just-diff/-/just-diff-5.0.1.tgz#db8fe1cfeea1156f2374bfb289826dca28e7e390" integrity sha512-X00TokkRIDotUIf3EV4xUm6ELc/IkqhS/vPSHdWnsM5y0HoNMfEqrazizI7g78lpHvnRSRt/PFfKtRqJCOGIuQ== -just-extend@^4.0.2: - version "4.2.1" - resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-4.2.1.tgz#ef5e589afb61e5d66b24eca749409a8939a8c744" - integrity sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg== - keyv@^4.0.0: version "4.5.2" resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.2.tgz#0e310ce73bf7851ec702f2eaf46ec4e3805cce56" @@ -3427,17 +3374,6 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== -nise@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.0.tgz#713ef3ed138252daef20ec035ab62b7a28be645c" - integrity sha512-W5WlHu+wvo3PaKLsJJkgPup2LrsXCcm7AWwyNZkUnn5rwPkuPBi3Iwk5SQtN0mv+K65k7nKKjwNQ30wg3wLAQQ== - dependencies: - "@sinonjs/commons" "^1.7.0" - "@sinonjs/fake-timers" "^7.0.4" - "@sinonjs/text-encoding" "^0.7.1" - just-extend "^4.0.2" - path-to-regexp "^1.7.0" - nock@*, nock@^13.3.3: version "13.3.3" resolved "https://registry.yarnpkg.com/nock/-/nock-13.3.3.tgz#179759c07d3f88ad3e794ace885629c1adfd3fe7" @@ -3909,13 +3845,6 @@ path-parse@^1.0.6: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== -path-to-regexp@^1.7.0: - version "1.8.0" - resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.8.0.tgz#887b3ba9d84393e87a0a0b9f4cb756198b53548a" - integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA== - dependencies: - isarray "0.0.1" - path-type@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" @@ -4376,23 +4305,6 @@ signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3: resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz#24e630c4b0f03fea446a2bd299e62b4a6ca8d0af" integrity sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ== -sinon-chai@^3.7.0: - version "3.7.0" - resolved "https://registry.yarnpkg.com/sinon-chai/-/sinon-chai-3.7.0.tgz#cfb7dec1c50990ed18c153f1840721cf13139783" - integrity sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g== - -sinon@^12.0.1: - version "12.0.1" - resolved "https://registry.yarnpkg.com/sinon/-/sinon-12.0.1.tgz#331eef87298752e1b88a662b699f98e403c859e9" - integrity sha512-iGu29Xhym33ydkAT+aNQFBINakjq69kKO6ByPvTsm3yyIACfyQttRTP03aBP/I8GfhFmLzrnKwNNkr0ORb1udg== - dependencies: - "@sinonjs/commons" "^1.8.3" - "@sinonjs/fake-timers" "^8.1.0" - "@sinonjs/samsam" "^6.0.2" - diff "^5.0.0" - nise "^5.1.0" - supports-color "^7.2.0" - slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -4617,7 +4529,7 @@ supports-color@^5.3.0: dependencies: has-flag "^3.0.0" -supports-color@^7.0.0, supports-color@^7.1.0, supports-color@^7.2.0: +supports-color@^7.0.0, supports-color@^7.1.0: version "7.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== @@ -4776,7 +4688,7 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" -type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5, type-detect@^4.0.8: +type-detect@^4.0.0, type-detect@^4.0.5: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==