Skip to content

Commit 4601cc3

Browse files
committed
refactor: move more into pluginResolution util
1 parent 2d89c51 commit 4601cc3

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

packages/@vue/cli-shared-utils/lib/pluginResolution.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,20 @@ exports.matchesPluginId = (input, full) => {
4040
short === input.replace(scopeRE, '')
4141
)
4242
}
43+
44+
exports.getPluginLink = id => {
45+
if (officialRE.test(id)) {
46+
return `https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-${
47+
exports.toShortPluginId(id)
48+
}`
49+
}
50+
let pkg = {}
51+
try {
52+
pkg = require(`${id}/package.json`)
53+
} catch (e) {}
54+
return (
55+
pkg.homepage ||
56+
(pkg.repository && pkg.repository.url) ||
57+
`https://www.npmjs.com/package/${id.replace(`/`, `%2F`)}`
58+
)
59+
}

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,12 @@ const globby = require('globby')
55
const isBinary = require('isbinaryfile')
66
const yaml = require('yaml-front-matter')
77
const mergeDeps = require('./util/mergeDeps')
8-
const { isOfficialPlugin, toShortPluginId } = require('@vue/cli-shared-utils')
8+
const { getPluginLink, toShortPluginId } = require('@vue/cli-shared-utils')
99

1010
const isString = val => typeof val === 'string'
1111
const isFunction = val => typeof val === 'function'
1212
const isObject = val => val && typeof val === 'object'
1313

14-
// get link for a 3rd party plugin.
15-
function getLink (id) {
16-
let pkg = {}
17-
try {
18-
pkg = require(`${id}/package.json`)
19-
} catch (e) {}
20-
return (
21-
pkg.homepage ||
22-
(pkg.repository && pkg.repository.url) ||
23-
`https://www.npmjs.com/package/${id.replace(`/`, `%2F`)}`
24-
)
25-
}
26-
2714
class GeneratorAPI {
2815
/**
2916
* @param {string} id - Id of the owner plugin
@@ -39,15 +26,10 @@ class GeneratorAPI {
3926

4027
this.pluginsData = generator.plugins
4128
.filter(({ id }) => id !== `@vue/cli-service`)
42-
.map(({ id }) => {
43-
const name = toShortPluginId(id)
44-
return {
45-
name: name,
46-
link: isOfficialPlugin(id)
47-
? `https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-${name}`
48-
: getLink(id)
49-
}
50-
})
29+
.map(({ id }) => ({
30+
name: toShortPluginId(id),
31+
link: getPluginLink(id)
32+
}))
5133
}
5234

5335
/**

0 commit comments

Comments
 (0)