Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(cli): resolve plugins relative to the package context #5794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions 17 packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PluginAPI = require('./PluginAPI')
const dotenv = require('dotenv')
const dotenvExpand = require('dotenv-expand')
const defaultsDeep = require('lodash.defaultsdeep')
const { chalk, warn, error, isPlugin, resolvePluginId, loadModule, resolvePkg } = require('@vue/cli-shared-utils')
const { chalk, warn, error, isPlugin, resolvePluginId, loadModule, resolvePkg, resolveModule } = require('@vue/cli-shared-utils')

const { defaults, validate } = require('./options')
const checkWebpack = require('@vue/cli-service/lib/util/checkWebpack')
Expand Down Expand Up @@ -143,9 +143,9 @@ module.exports = class Service {
}

resolvePlugins (inlinePlugins, useBuiltIn) {
const idToPlugin = id => ({
const idToPlugin = (id, absolutePath) => ({
id: id.replace(/^.\//, 'built-in:'),
apply: require(id)
apply: require(absolutePath || id)
})

let plugins
Expand All @@ -161,7 +161,7 @@ module.exports = class Service {
'./config/css',
'./config/prod',
'./config/app'
].map(idToPlugin)
].map((id) => idToPlugin(id))

if (inlinePlugins) {
plugins = useBuiltIn !== false
Expand All @@ -176,16 +176,15 @@ module.exports = class Service {
this.pkg.optionalDependencies &&
id in this.pkg.optionalDependencies
) {
let apply = () => {}
try {
apply = require(id)
} catch (e) {
let apply = loadModule(id, this.pkgContext)
if (!apply) {
warn(`Optional dependency ${id} is not installed.`)
apply = () => {}
}

return { id, apply }
} else {
return idToPlugin(id)
return idToPlugin(id, resolveModule(id, this.pkgContext))
fangbinwei marked this conversation as resolved.
Show resolved Hide resolved
}
})
plugins = builtInPlugins.concat(projectPlugins)
Expand Down
7 changes: 7 additions & 0 deletions 7 packages/@vue/cli-shared-utils/lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ const resolve = semver.satisfies(process.version, '>=10.0.0')
: resolveFallback

exports.resolveModule = function (request, context) {
// createRequire doesn't work with jest mock modules
// (which we used in migrator for inquirer, and in tests for cli-service)
// TODO: it's supported in Jest 25
if (process.env.VUE_CLI_TEST && (request.endsWith('migrator') || context === '/')) {
return request
}

let resolvedPath
try {
try {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.