Skip to content

Commit b60dd4b

Browse files
committed
fix: revert windows config path change, close #1961
1 parent 4b5a634 commit b60dd4b

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ const { exit } = require('@vue/cli-shared-utils/lib/exit')
55
const { error } = require('@vue/cli-shared-utils/lib/logger')
66
const { createSchema, validate } = require('@vue/cli-shared-utils/lib/validate')
77

8-
const rcPath = exports.rcPath = (
9-
process.env.VUE_CLI_CONFIG_PATH ||
10-
getRcPath('.vuerc')
11-
)
8+
const rcPath = exports.rcPath = getRcPath('.vuerc')
129

1310
const presetSchema = createSchema(joi => joi.object().keys({
1411
useConfigFiles: joi.boolean(),

packages/@vue/cli/lib/util/rcPath.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22
const os = require('os')
33
const path = require('path')
44

@@ -7,37 +7,41 @@ const xdgConfigPath = file => {
77
if (xdgConfigHome) {
88
const rcDir = path.join(xdgConfigHome, 'vue')
99
if (!fs.existsSync(rcDir)) {
10-
fs.mkdirSync(rcDir, 0o700)
10+
fs.ensureDirSync(rcDir, 0o700)
1111
}
1212
return path.join(rcDir, file)
1313
}
1414
}
1515

16-
const windowsConfigPath = file => {
16+
// migration for 3.0.0-rc.7
17+
// we introduced a change storing .vuerc in AppData, but the benefit isn't
18+
// really obvious so we are reverting it to keep consistency across OSes
19+
const migrateWindowsConfigPath = file => {
1720
if (process.platform !== 'win32') {
1821
return
1922
}
2023
const appData = process.env.APPDATA
2124
if (appData) {
2225
const rcDir = path.join(appData, 'vue')
23-
if (!fs.existsSync(rcDir)) {
24-
fs.mkdirSync(rcDir)
25-
}
26-
const rcPath = path.join(rcDir, file)
27-
// migration for < 3.0.0-rc.7
28-
const oldRcFile = path.join(os.homedir(), file)
29-
if (fs.existsSync(oldRcFile)) {
30-
fs.writeFileSync(rcPath, fs.readFileSync(oldRcFile))
31-
const chalk = require('chalk')
32-
console.log(`Detected ${chalk.cyan(file)} in ${chalk.cyan(path.dirname(oldRcFile))}...`)
33-
console.log(`Migrated to ${chalk.cyan(rcPath)}.`)
26+
const rcFile = path.join(rcDir, file)
27+
const properRcFile = path.join(os.homedir(), file)
28+
if (fs.existsSync(rcFile)) {
29+
try {
30+
if (fs.existsSync(properRcFile)) {
31+
fs.removeSync(rcFile)
32+
} else {
33+
fs.moveSync(rcFile, properRcFile)
34+
}
35+
} catch (e) {}
3436
}
35-
return rcPath
3637
}
3738
}
3839

39-
exports.getRcPath = file => (
40-
xdgConfigPath(file) ||
41-
windowsConfigPath(file) ||
42-
path.join(os.homedir(), file)
43-
)
40+
exports.getRcPath = file => {
41+
migrateWindowsConfigPath(file)
42+
return (
43+
process.env.VUE_CLI_CONFIG_PATH ||
44+
xdgConfigPath(file) ||
45+
path.join(os.homedir(), file)
46+
)
47+
}

0 commit comments

Comments
 (0)