Skip to content

Commit

Permalink
Adding verbose output for config file search (#3236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelypuppy0607 committed Apr 26, 2017
1 parent 7bb1c1a commit 6de4f36
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/registries/base-registry.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 = {};
Expand All @@ -37,6 +39,8 @@ export default class BaseRegistry {
// the filename to use for package metadata
static filename: string;

//
reporter: Reporter
//
registries: ConfigRegistries;

Expand Down
14 changes: 10 additions & 4 deletions src/registries/npm-registry.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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';
}

Expand Down Expand Up @@ -96,7 +97,10 @@ export default class NpmRegistry extends Registry {
};
}

async getPossibleConfigLocations(filename: string): Promise<Array<[boolean, string, string]>> {
async getPossibleConfigLocations(
filename: string,
reporter: Reporter,
): Promise<Array<[boolean, string, string]>> {
const possibles = [
[false, path.join(this.cwd, filename)],
[true, this.config.userconfig || path.join(userHome, filename)],
Expand All @@ -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,
Expand All @@ -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]);
Expand Down
7 changes: 4 additions & 3 deletions src/registries/yarn-registry.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -76,7 +77,7 @@ export default class YarnRegistry extends NpmRegistry {
}

async loadConfig(): Promise<void> {
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) {
Expand Down
3 changes: 3 additions & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6de4f36

Please sign in to comment.