Skip to content

Commit fa46ed4

Browse files
authored
fix: check hoisted postcss version (#6372)
Also reverts #6358
1 parent bb01585 commit fa46ed4

File tree

5 files changed

+14
-49
lines changed

5 files changed

+14
-49
lines changed

packages/@vue/cli-service/bin/postinstall.js

-31
This file was deleted.

packages/@vue/cli-service/generator/hotfix-npm6only.js

-8
This file was deleted.

packages/@vue/cli-service/generator/index.js

-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const fs = require('fs-extra')
2-
const path = require('path')
3-
41
module.exports = (api, options) => {
52
api.render('./template', {
63
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
@@ -77,8 +74,4 @@ module.exports = (api, options) => {
7774
if (options.configs) {
7875
api.extendPackage(options.configs)
7976
}
80-
81-
if (fs.existsSync(path.resolve(__dirname, './hotfix.js'))) {
82-
require('./hotfix')(api, options, options)
83-
}
8477
}

packages/@vue/cli-service/lib/config/css.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs')
22
const path = require('path')
3+
const { chalk, semver, loadModule } = require('@vue/cli-shared-utils')
34
const isAbsoluteUrl = require('../util/isAbsoluteUrl')
45

56
const findExisting = (context, files) => {
@@ -58,6 +59,19 @@ module.exports = (api, rootOptions) => {
5859
]))
5960

6061
if (!hasPostCSSConfig) {
62+
// #6342
63+
// NPM 6 may incorrectly hoist postcss 7 to the same level of autoprefixer
64+
// So we have to run a preflight check to tell the users how to fix it
65+
const autoprefixerDirectory = path.dirname(require.resolve('autoprefixer/package.json'))
66+
const postcssPkg = loadModule('postcss/package.json', autoprefixerDirectory)
67+
const postcssVersion = postcssPkg.version
68+
if (!semver.satisfies(postcssVersion, '8.x')) {
69+
throw new Error(
70+
`The package manager has hoisted a wrong version of ${chalk.cyan('postcss')}, ` +
71+
`please run ${chalk.cyan('npm i postcss@8 -D')} to fix it.`
72+
)
73+
}
74+
6175
loaderOptions.postcss = {
6276
postcssOptions: {
6377
plugins: [

packages/@vue/cli-service/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"bin": {
88
"vue-cli-service": "bin/vue-cli-service.js"
99
},
10-
"scripts": {
11-
"postinstall": "node bin/postinstall.js"
12-
},
1310
"repository": {
1411
"type": "git",
1512
"url": "git+https://github.com/vuejs/vue-cli.git",

0 commit comments

Comments
 (0)