Skip to content

Commit edff5b4

Browse files
committed
refactor: extract plugin resolution into shared-utils
1 parent 0f2ee80 commit edff5b4

File tree

8 files changed

+30
-18
lines changed

8 files changed

+30
-18
lines changed

packages/@vue/cli-service/lib/PluginAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PluginAPI {
2323
/**
2424
* Check if the project has a given plugin.
2525
*
26-
* @param {string} id - Plugin id, can omit the (@vue/|vue-)-cli-plugin- prefix
26+
* @param {string} id - Plugin id, can omit the (@vue/|vue-|@scope/vue)-cli-plugin- prefix
2727
* @return {boolean}
2828
*/
2929
hasPlugin (id) {

packages/@vue/cli-service/lib/Service.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Config = require('webpack-chain')
88
const PluginAPI = require('./PluginAPI')
99
const loadEnv = require('./util/loadEnv')
1010
const defaultsDeep = require('lodash.defaultsdeep')
11-
const { warn, error } = require('@vue/cli-shared-utils')
11+
const { warn, error, isPlugin } = require('@vue/cli-shared-utils')
1212

1313
const { defaults, validate } = require('./options')
1414

@@ -104,10 +104,9 @@ module.exports = class Service {
104104
? builtInPlugins.concat(inlinePlugins)
105105
: inlinePlugins
106106
} else {
107-
const prefixRE = /^(@vue\/|vue-)cli-plugin-/
108107
const projectPlugins = Object.keys(this.pkg.dependencies || {})
109108
.concat(Object.keys(this.pkg.devDependencies || {}))
110-
.filter(p => prefixRE.test(p))
109+
.filter(isPlugin)
111110
.map(idToPlugin)
112111
return builtInPlugins.concat(projectPlugins)
113112
}

packages/@vue/cli-shared-utils/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
'logger',
44
'spinner',
55
'validate',
6-
'openBrowser'
6+
'openBrowser',
7+
'pluginResolution'
78
].forEach(m => {
89
Object.assign(exports, require(`./lib/${m}`))
910
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const pluginRE = /^(@vue\/|vue-|@[\w-]+\/vue-)cli-plugin-/
2+
3+
exports.isPlugin = id => pluginRE.test(id)
4+
5+
exports.isOfficial = id => /^@vue\//.test(id)
6+
7+
exports.toShortId = id => id.replace(pluginRE, '')

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const debug = require('debug')
44
const GeneratorAPI = require('./GeneratorAPI')
55
const sortObject = require('./util/sortObject')
66
const writeFileTree = require('./util/writeFileTree')
7+
const { toShortId } = require('@vue/cli-shared-utils')
78
const configTransforms = require('./util/configTransforms')
8-
const logger = require('@vue/cli-shared-utils/lib/logger')
9-
const { toShortId } = require('./util/pluginResolution')
109

10+
const logger = require('@vue/cli-shared-utils/lib/logger')
1111
const logTypes = {
1212
log: logger.log,
1313
info: logger.info,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const globby = require('globby')
55
const isBinary = require('isbinaryfile')
66
const yaml = require('yaml-front-matter')
77
const mergeDeps = require('./util/mergeDeps')
8+
const { isOfficial, toShortId } = require('@vue/cli-shared-utils')
89

910
const isString = val => typeof val === 'string'
1011
const isFunction = val => typeof val === 'function'
@@ -39,11 +40,10 @@ class GeneratorAPI {
3940
this.pluginsData = generator.plugins
4041
.filter(({ id }) => id !== `@vue/cli-service`)
4142
.map(({ id }) => {
42-
const name = id.replace(/^(@vue|vue-)\/cli-plugin-/, '')
43-
const isOfficial = /^@vue/.test(id)
43+
const name = toShortId(id)
4444
return {
4545
name: name,
46-
link: isOfficial
46+
link: isOfficial(id)
4747
? `https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-${name}`
4848
: getLink(id)
4949
}
@@ -87,7 +87,7 @@ class GeneratorAPI {
8787
/**
8888
* Check if the project has a given plugin.
8989
*
90-
* @param {string} id - Plugin id, can omit the (@vue/|vue-)-cli-plugin- prefix
90+
* @param {string} id - Plugin id, can omit the (@vue/|vue-|@scope/vue)-cli-plugin- prefix
9191
* @return {boolean}
9292
*/
9393
hasPlugin (id) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
4040
// attempt to locate the plugin in package.json
4141
const findPlugin = deps => {
4242
if (!deps) return
43+
44+
// custom scoped plugin
4345
let name
46+
if (pluginName.charAt(0) === '@') {
47+
const scopeRE = /^@[\w-]+\//
48+
const scopeMatch = pluginName.match(scopeRE)
49+
const shortId = pluginName.replace(scopeRE, '')
50+
if (scopeMatch && deps[name = `${scopeMatch[0]}vue-cli-plugin-${shortId}`]) {
51+
return name
52+
}
53+
}
54+
55+
// official, non-scoped & full name
4456
if (deps[name = `@vue/cli-plugin-${pluginName}`] ||
4557
deps[name = `vue-cli-plugin-${pluginName}`] ||
4658
deps[name = pluginName]) {

packages/@vue/cli/lib/util/pluginResolution.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy