1- const fs = require ( 'fs' )
1+ const fs = require ( 'fs-extra ' )
22const os = require ( 'os' )
33const 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