From 6de4f36d7b8869119ed46dbc57d40250d0d91dbf Mon Sep 17 00:00:00 2001 From: puppypaduk2 Date: Wed, 26 Apr 2017 10:19:00 -0500 Subject: [PATCH] Adding verbose output for config file search (#3236) --- src/config.js | 2 +- src/registries/base-registry.js | 6 +++++- src/registries/npm-registry.js | 14 ++++++++++---- src/registries/yarn-registry.js | 7 ++++--- src/reporters/lang/en.js | 3 +++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/config.js b/src/config.js index e8dab1ebe..3ad67243c 100644 --- a/src/config.js +++ b/src/config.js @@ -216,7 +216,7 @@ export default class Config { const Registry = registries[key]; // instantiate registry - const registry = new Registry(this.cwd, this.registries, this.requestManager); + const registry = new Registry(this.cwd, this.registries, this.requestManager, this.reporter); await registry.init(); this.registries[key] = registry; diff --git a/src/registries/base-registry.js b/src/registries/base-registry.js index ddbd2c0b2..742717f77 100644 --- a/src/registries/base-registry.js +++ b/src/registries/base-registry.js @@ -1,5 +1,6 @@ /* @flow */ +import type Reporter from '../reporters/base-reporter.js'; import type RequestManager, {RequestMethods} from '../util/request-manager.js'; import type Config from '../config.js'; import type {ConfigRegistries} from './index.js'; @@ -24,7 +25,8 @@ export type CheckOutdatedReturn = Promise<{ }>; export default class BaseRegistry { - constructor(cwd: string, registries: ConfigRegistries, requestManager: RequestManager) { + constructor(cwd: string, registries: ConfigRegistries, requestManager: RequestManager, reporter: Reporter) { + this.reporter = reporter; this.requestManager = requestManager; this.registries = registries; this.config = {}; @@ -37,6 +39,8 @@ export default class BaseRegistry { // the filename to use for package metadata static filename: string; + // + reporter: Reporter // registries: ConfigRegistries; diff --git a/src/registries/npm-registry.js b/src/registries/npm-registry.js index 83641b9a8..523053d96 100644 --- a/src/registries/npm-registry.js +++ b/src/registries/npm-registry.js @@ -1,5 +1,6 @@ /* @flow */ +import type Reporter from '../reporters/base-reporter.js'; import type RequestManager from '../util/request-manager.js'; import type {RegistryRequestOptions, CheckOutdatedReturn} from './base-registry.js'; import type Config from '../config.js'; @@ -38,8 +39,8 @@ function getGlobalPrefix(): string { } export default class NpmRegistry extends Registry { - constructor(cwd: string, registries: ConfigRegistries, requestManager: RequestManager) { - super(cwd, registries, requestManager); + constructor(cwd: string, registries: ConfigRegistries, requestManager: RequestManager, reporter: Reporter) { + super(cwd, registries, requestManager, reporter); this.folder = 'node_modules'; } @@ -96,7 +97,10 @@ export default class NpmRegistry extends Registry { }; } - async getPossibleConfigLocations(filename: string): Promise> { + async getPossibleConfigLocations( + filename: string, + reporter: Reporter, + ): Promise> { const possibles = [ [false, path.join(this.cwd, filename)], [true, this.config.userconfig || path.join(userHome, filename)], @@ -111,7 +115,9 @@ export default class NpmRegistry extends Registry { const actuals = []; for (const [isHome, loc] of possibles) { + reporter.verbose(reporter.lang('configPossibleFile', loc)); if (await fs.exists(loc)) { + reporter.verbose(reporter.lang('configFileFound', loc)); actuals.push([ isHome, loc, @@ -126,7 +132,7 @@ export default class NpmRegistry extends Registry { // docs: https://docs.npmjs.com/misc/config this.mergeEnv('npm_config_'); - for (const [, loc, file] of await this.getPossibleConfigLocations('.npmrc')) { + for (const [, loc, file] of await this.getPossibleConfigLocations('.npmrc', this.reporter)) { const config = Registry.normalizeConfig(ini.parse(file)); for (const key: string in config) { config[key] = envReplace(config[key]); diff --git a/src/registries/yarn-registry.js b/src/registries/yarn-registry.js index 7510bb043..f768add79 100644 --- a/src/registries/yarn-registry.js +++ b/src/registries/yarn-registry.js @@ -1,5 +1,6 @@ /* @flow */ +import type Reporter from '../reporters/base-reporter.js'; import type RequestManager from '../util/request-manager.js'; import type {ConfigRegistries} from './index.js'; import {YARN_REGISTRY} from '../constants.js'; @@ -43,8 +44,8 @@ const npmMap = { }; export default class YarnRegistry extends NpmRegistry { - constructor(cwd: string, registries: ConfigRegistries, requestManager: RequestManager) { - super(cwd, registries, requestManager); + constructor(cwd: string, registries: ConfigRegistries, requestManager: RequestManager, reporter: Reporter) { + super(cwd, registries, requestManager, reporter); this.homeConfigLoc = path.join(userHome, '.yarnrc'); this.homeConfig = {}; @@ -76,7 +77,7 @@ export default class YarnRegistry extends NpmRegistry { } async loadConfig(): Promise { - for (const [isHome, loc, file] of await this.getPossibleConfigLocations('.yarnrc')) { + for (const [isHome, loc, file] of await this.getPossibleConfigLocations('.yarnrc', this.reporter)) { const config = parse(file, loc); if (isHome) { diff --git a/src/reporters/lang/en.js b/src/reporters/lang/en.js index b0fbe904d..7b7fd92c5 100644 --- a/src/reporters/lang/en.js +++ b/src/reporters/lang/en.js @@ -205,6 +205,9 @@ const messages = { cleanRemovedFiles: 'Removed $0 files', cleanSavedSize: 'Saved $0 MB.', + configFileFound: 'Found configuration file $0.', + configPossibleFile: 'Checking for configuration file $0.', + npmUsername: 'npm username', npmPassword: 'npm password', npmEmail: 'npm email',