<commit_before>import {CliConfig as CliConfigBase} from './config/config';
import {CliConfig as ConfigInterface} from '../lib/config/schema';
import { oneLine } from 'common-tags';
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';
import { homedir } from 'os';

import {findUp} from '../utilities/find-up';


export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';


const configCacheMap = new Map<string, CliConfigBase<ConfigInterface>>();


export class CliConfig extends CliConfigBase<ConfigInterface> {
  static configFilePath(projectPath?: string): string {
    const configNames = [CLI_CONFIG_FILE_NAME, CLI_CONFIG_FILE_NAME_ALT];
    // Find the configuration, either where specified, in the Angular CLI project
    // (if it's in node_modules) or from the current process.
    return (projectPath && findUp(configNames, projectPath))
        || findUp(configNames, process.cwd())
        || findUp(configNames, __dirname);
  }

  static getValue(jsonPath: string): any {
    let value;

    const projectConfig = CliConfig.fromProject();
    if (projectConfig) {
      value = projectConfig.get(jsonPath);
    } else {
      const globalConfig = CliConfig.fromGlobal();
      if (globalConfig) {
        value = globalConfig.get(jsonPath);
      }
    }

    return value;
  }

  static globalConfigFilePath(): string {
    const globalConfigPath = path.join(homedir(), CLI_CONFIG_FILE_NAME);
    if (fs.existsSync(globalConfigPath)) {
      return globalConfigPath;
    }

    const altGlobalConfigPath = path.join(homedir(), CLI_CONFIG_FILE_NAME_ALT);
    if (fs.existsSync(altGlobalConfigPath)) {
      return altGlobalConfigPath;
    }

    return globalConfigPath;
  }

  static fromGlobal(): CliConfig {
    const globalConfigPath = this.globalConfigFilePath();

    if (configCacheMap.has(globalConfigPath)) {
      return configCacheMap.get(globalConfigPath);
    }

    const cliConfig = CliConfigBase.fromConfigPath<ConfigInterface>(globalConfigPath);<commit_msg>fix(@angular/cli): Prevent re-reading config file if project & global are the same<commit_after>import {CliConfig as CliConfigBase} from './config/config';
import {CliConfig as ConfigInterface} from '../lib/config/schema';
import { oneLine } from 'common-tags';
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';
import { homedir } from 'os';

import {findUp} from '../utilities/find-up';


export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';


const configCacheMap = new Map<string, CliConfigBase<ConfigInterface>>();


export class CliConfig extends CliConfigBase<ConfigInterface> {
  static configFilePath(projectPath?: string): string {
    const configNames = [CLI_CONFIG_FILE_NAME, CLI_CONFIG_FILE_NAME_ALT];
    // Find the configuration, either where specified, in the Angular CLI project
    // (if it's in node_modules) or from the current process.
    return (projectPath && findUp(configNames, projectPath))
        || findUp(configNames, process.cwd())
        || findUp(configNames, __dirname);
  }

  static getValue(jsonPath: string): any {
    let value;

    const projectConfig = CliConfig.fromProject();
    if (projectConfig) {
      value = projectConfig.get(jsonPath);
    } else if (CliConfig.globalConfigFilePath() !== CliConfig.configFilePath()) {
      const globalConfig = CliConfig.fromGlobal();
      if (globalConfig) {
        value = globalConfig.get(jsonPath);
      }
    }

    return value;
  }

  static globalConfigFilePath(): string {
    const globalConfigPath = path.join(homedir(), CLI_CONFIG_FILE_NAME);
    if (fs.existsSync(globalConfigPath)) {
      return globalConfigPath;
    }

    const altGlobalConfigPath = path.join(homedir(), CLI_CONFIG_FILE_NAME_ALT);
    if (fs.existsSync(altGlobalConfigPath)) {
      return altGlobalConfigPath;
    }

    return globalConfigPath;
  }

  static fromGlobal(): CliConfig {
    const globalConfigPath = this.globalConfigFilePath();

    if (configCacheMap.has(globalConfigPath)) {
      return configCacheMap.get(globalConfigPath);
    }

    const cliConfig = CliConfigBase.fromConfigPath<ConfigInterface>(globalConfigPath);
{'fraction_non_alphanumeric': 0.1092436974789916, 'fraction_numerical': 0.0, 'mean_word_length': 4.113365155131265, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6424078', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1218, 'n_words': 310}