Skip to content

fix: check hoisted postcss version #6372

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 2 commits into from
Mar 24, 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
31 changes: 0 additions & 31 deletions packages/@vue/cli-service/bin/postinstall.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/@vue/cli-service/generator/hotfix-npm6only.js

This file was deleted.

7 changes: 0 additions & 7 deletions packages/@vue/cli-service/generator/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const fs = require('fs-extra')
const path = require('path')

module.exports = (api, options) => {
api.render('./template', {
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
Expand Down Expand Up @@ -77,8 +74,4 @@ module.exports = (api, options) => {
if (options.configs) {
api.extendPackage(options.configs)
}

if (fs.existsSync(path.resolve(__dirname, './hotfix.js'))) {
require('./hotfix')(api, options, options)
}
}
14 changes: 14 additions & 0 deletions packages/@vue/cli-service/lib/config/css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs')
const path = require('path')
const { chalk, semver, loadModule } = require('@vue/cli-shared-utils')
const isAbsoluteUrl = require('../util/isAbsoluteUrl')

const findExisting = (context, files) => {
Expand Down Expand Up @@ -58,6 +59,19 @@ module.exports = (api, rootOptions) => {
]))

if (!hasPostCSSConfig) {
// #6342
// NPM 6 may incorrectly hoist postcss 7 to the same level of autoprefixer
// So we have to run a preflight check to tell the users how to fix it
const autoprefixerDirectory = path.dirname(require.resolve('autoprefixer/package.json'))
const postcssPkg = loadModule('postcss/package.json', autoprefixerDirectory)
const postcssVersion = postcssPkg.version
if (!semver.satisfies(postcssVersion, '8.x')) {
throw new Error(
`The package manager has hoisted a wrong version of ${chalk.cyan('postcss')}, ` +
`please run ${chalk.cyan('npm i postcss@8 -D')} to fix it.`
)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if hasPostCSSConfig is true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means the user is not likely using the built-in autoprefixer plugin.
In that case, they should take care of the peer dependency requirements of their own installed plugins.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Projects created by Vue CLI < 4.1.0 may have a PostCSS configuration (which only adds autoprefixer) but no direct dependency installed. That's a bad practice. We can implement a migrator to help remove these configurations.

loaderOptions.postcss = {
postcssOptions: {
plugins: [
Expand Down
3 changes: 0 additions & 3 deletions packages/@vue/cli-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"bin": {
"vue-cli-service": "bin/vue-cli-service.js"
},
"scripts": {
"postinstall": "node bin/postinstall.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/vue-cli.git",
Expand Down