Skip to content

Commit 920160a

Browse files
committed
refactor: rename the version parameter to versionRange
1 parent 3656416 commit 920160a

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

packages/@vue/cli/lib/Generator.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -301,22 +301,24 @@ module.exports = class Generator {
301301
debug('vue:cli-files')(this.files)
302302
}
303303

304-
hasPlugin (_id, _version) {
305-
return [
304+
hasPlugin (id, versionRange) {
305+
const pluginExists = [
306306
...this.plugins.map(p => p.id),
307307
...this.allPluginIds
308-
].some(id => {
309-
if (!matchesPluginId(_id, id)) {
310-
return false
311-
}
308+
].some(pid => matchesPluginId(id, pid))
312309

313-
if (!_version) {
314-
return true
315-
}
310+
if (!pluginExists) {
311+
return false
312+
}
316313

317-
const version = this.pm.getInstalledVersion(id)
318-
return semver.satisfies(version, _version)
319-
})
314+
if (!versionRange) {
315+
return pluginExists
316+
}
317+
318+
return semver.satisfies(
319+
this.pm.getInstalledVersion(id),
320+
versionRange
321+
)
320322
}
321323

322324
printExitLogs () {

packages/@vue/cli/lib/GeneratorAPI.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ class GeneratorAPI {
168168
* @param {string} version - Plugin version. Defaults to ''
169169
* @return {boolean}
170170
*/
171-
hasPlugin (id, version) {
172-
return this.generator.hasPlugin(id, version)
171+
hasPlugin (id, versionRange) {
172+
return this.generator.hasPlugin(id, versionRange)
173173
}
174174

175175
/**

packages/@vue/cli/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ declare class GeneratorAPI {
8484
* Check if the project has a given plugin.
8585
*
8686
* @param id - Plugin id, can omit the (@vue/|vue-|@scope/vue)-cli-plugin- prefix
87-
* @param version - Plugin version. Defaults to ''
87+
* @param versionRange - Plugin version range. Defaults to '*'
8888
* @return `boolean`
8989
*/
90-
hasPlugin(id: string, version?: string): boolean
90+
hasPlugin(id: string, versionRange?: string): boolean
9191

9292
/**
9393
* Configure how config files are extracted.

0 commit comments

Comments
 (0)