Skip to content

Commit

Permalink
fix: check hoisted postcss version (#6372)
Browse files Browse the repository at this point in the history
Also reverts #6358
  • Loading branch information
haoqunjiang authored Mar 24, 2021
1 parent bb01585 commit fa46ed4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 49 deletions.
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.`
)
}

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

0 comments on commit fa46ed4

Please sign in to comment.