Skip to content

Commit 130bcfb

Browse files
chore: switch over to leven for command suggestion (vuejs#5166)
* chore: switch to leven * chore: update lock file * chore: iterate through all the available commands and find closest match * chore: update yarn.lock * fix: lint * chore: find the best possible match
1 parent 38a7b0f commit 130bcfb

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

packages/@vue/cli/bin/vue.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
const { chalk, semver } = require('@vue/cli-shared-utils')
77
const requiredVersion = require('../package.json').engines.node
8-
const didYouMean = require('didyoumean')
9-
10-
// Setting edit distance to 60% of the input string's length
11-
didYouMean.threshold = 0.6
8+
const leven = require('leven')
129

1310
function checkNodeVersion (wanted, id) {
1411
if (!semver.satisfies(process.version, wanted)) {
@@ -261,7 +258,15 @@ if (!process.argv.slice(2).length) {
261258
function suggestCommands (unknownCommand) {
262259
const availableCommands = program.commands.map(cmd => cmd._name)
263260

264-
const suggestion = didYouMean(unknownCommand, availableCommands)
261+
let suggestion
262+
263+
availableCommands.forEach(cmd => {
264+
const isBestMatch = leven(cmd, unknownCommand) < leven(suggestion || '', unknownCommand)
265+
if (leven(cmd, unknownCommand) < 3 && isBestMatch) {
266+
suggestion = cmd
267+
}
268+
})
269+
265270
if (suggestion) {
266271
console.log(` ` + chalk.red(`Did you mean ${chalk.yellow(suggestion)}?`))
267272
}

packages/@vue/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"commander": "^2.20.0",
3434
"debug": "^4.1.0",
3535
"deepmerge": "^4.2.2",
36-
"didyoumean": "^1.2.1",
3736
"download-git-repo": "^1.0.2",
3837
"ejs": "^2.7.1",
3938
"envinfo": "^7.5.0",
@@ -45,6 +44,7 @@
4544
"javascript-stringify": "^1.6.0",
4645
"js-yaml": "^3.13.1",
4746
"jscodeshift": "^0.7.0",
47+
"leven": "^3.1.0",
4848
"lodash.clonedeep": "^4.5.0",
4949
"lru-cache": "^5.1.1",
5050
"minimist": "^1.2.0",

yarn.lock

+2-15
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,7 @@
25292529
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
25302530
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
25312531

2532-
"@types/mocha@^5.2.4", "@types/mocha@^5.2.6":
2532+
"@types/mocha@^5.2.6":
25332533
version "5.2.7"
25342534
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
25352535
integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==
@@ -2798,14 +2798,6 @@
27982798
resolved "https://registry.yarnpkg.com/@vue/preload-webpack-plugin/-/preload-webpack-plugin-1.1.1.tgz#18723530d304f443021da2292d6ec9502826104a"
27992799
integrity sha512-8VCoJeeH8tCkzhkpfOkt+abALQkS11OIHhte5MBzYaKMTqK0A3ZAKEUVAffsOklhEv7t0yrQt696Opnu9oAx+w==
28002800

2801-
2802-
version "1.0.0-beta.29"
2803-
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.0.0-beta.29.tgz#c942cf25e891cf081b6a03332b4ae1ef430726f0"
2804-
integrity sha512-yX4sxEIHh4M9yAbLA/ikpEnGKMNBCnoX98xE1RwxfhQVcn0MaXNSj1Qmac+ZydTj6VBSEVukchBogXBTwc+9iA==
2805-
dependencies:
2806-
dom-event-types "^1.0.0"
2807-
lodash "^4.17.4"
2808-
28092801
28102802
version "1.0.0-beta.31"
28112803
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.0.0-beta.31.tgz#580d6e45f07452e497d69807d80986e713949b73"
@@ -5161,7 +5153,7 @@ chrome-trace-event@^1.0.2:
51615153
dependencies:
51625154
tslib "^1.9.0"
51635155

5164-
chromedriver@80, chromedriver@^80.0.0:
5156+
chromedriver@^80.0.0:
51655157
version "80.0.0"
51665158
resolved "https://registry.yarnpkg.com/chromedriver/-/chromedriver-80.0.0.tgz#f9e2af4c2117e7e07dc4558cf9496a70ad6c3ddc"
51675159
integrity sha512-W4tIbaOve7HeGFLnbbZMV4AUlnBaapL+H41fvDFKOXCmUvgPhxVN9y/c3EgmsOcokLQkqxpOC/txEujms1eT0w==
@@ -6778,11 +6770,6 @@ [email protected]:
67786770
dependencies:
67796771
streamsearch "0.1.2"
67806772

6781-
didyoumean@^1.2.1:
6782-
version "1.2.1"
6783-
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff"
6784-
integrity sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=
6785-
67866773
diff-sequences@^24.9.0:
67876774
version "24.9.0"
67886775
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.9.0.tgz#5715d6244e2aa65f48bba0bc972db0b0b11e95b5"

0 commit comments

Comments
 (0)