@@ -4,6 +4,7 @@ import { oneLine } from 'common-tags';
44import * as chalk from 'chalk' ;
55import * as fs from 'fs' ;
66import * as path from 'path' ;
7+ import { homedir } from 'os' ;
78
89import { findUp } from '../utilities/find-up' ;
910
@@ -12,16 +13,6 @@ export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
1213const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json' ;
1314
1415
15- function getUserHome ( ) {
16- const envHomeName = ( process . platform . startsWith ( 'win' ) ) ? 'USERPROFILE' : 'HOME' ;
17- const env = process . env [ envHomeName ] ;
18- if ( env == null ) {
19- throw new Error ( 'Missing environment variable ' + envHomeName ) ;
20- }
21- return env ;
22- }
23-
24-
2516const configCacheMap = new Map < string , CliConfigBase < ConfigInterface > > ( ) ;
2617
2718
@@ -52,11 +43,16 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
5243 }
5344
5445 static globalConfigFilePath ( ) : string {
55- let globalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME ) ;
56- const altGlobalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME_ALT ) ;
57- if ( ! fs . existsSync ( globalConfigPath ) && fs . existsSync ( altGlobalConfigPath ) ) {
46+ const globalConfigPath = path . join ( homedir ( ) , CLI_CONFIG_FILE_NAME ) ;
47+ if ( fs . existsSync ( globalConfigPath ) ) {
48+ return globalConfigPath ;
49+ }
50+
51+ const altGlobalConfigPath = path . join ( homedir ( ) , CLI_CONFIG_FILE_NAME_ALT ) ;
52+ if ( fs . existsSync ( altGlobalConfigPath ) ) {
5853 return altGlobalConfigPath ;
5954 }
55+
6056 return globalConfigPath ;
6157 }
6258
@@ -109,12 +105,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
109105 return configCacheMap . get ( configPath ) ;
110106 }
111107
112- let globalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME ) ;
113- const altGlobalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME_ALT ) ;
114- if ( ! fs . existsSync ( globalConfigPath ) && fs . existsSync ( altGlobalConfigPath ) ) {
115- globalConfigPath = altGlobalConfigPath ;
116- }
117-
108+ const globalConfigPath = CliConfig . globalConfigFilePath ( ) ;
118109 const cliConfig = CliConfigBase . fromConfigPath < ConfigInterface > ( configPath , [ globalConfigPath ] ) ;
119110
120111 const aliases = [
0 commit comments