From beff7809eaaad76f78d1889aeec7fd101c7e011d Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Tue, 4 Apr 2017 12:27:28 -0700 Subject: [PATCH] Add debug() calls for config loading. --- .../src/config/build-config-chain.js | 23 ++++++++++++-- .../src/config/loading/files/configuration.js | 6 ++++ .../src/config/loading/files/plugins.js | 30 ++++++++++++------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/packages/babel-core/src/config/build-config-chain.js b/packages/babel-core/src/config/build-config-chain.js index dd10f3166c..d52a75666c 100644 --- a/packages/babel-core/src/config/build-config-chain.js +++ b/packages/babel-core/src/config/build-config-chain.js @@ -3,6 +3,9 @@ import { getEnv } from "./helpers/environment"; import path from "path"; import micromatch from "micromatch"; +import buildDebug from "debug"; + +const debug = buildDebug("babel:config:config-chain"); import { findConfigs, loadConfig } from "./loading/files"; @@ -67,7 +70,15 @@ class ConfigChainBuilder { ); } - if (this.matchesPatterns(ignore, dirname)) return true; + if (this.matchesPatterns(ignore, dirname)) { + debug( + "Ignored %o because it matched one of %O from %o", + this.filename, + ignore, + dirname, + ); + return true; + } } if (only) { @@ -77,7 +88,15 @@ class ConfigChainBuilder { ); } - if (!this.matchesPatterns(only, dirname)) return true; + if (!this.matchesPatterns(only, dirname)) { + debug( + "Ignored %o because it failed to match one of %O from %o", + this.filename, + only, + dirname, + ); + return true; + } } return false; diff --git a/packages/babel-core/src/config/loading/files/configuration.js b/packages/babel-core/src/config/loading/files/configuration.js index 73ce1565d4..688fe8e068 100644 --- a/packages/babel-core/src/config/loading/files/configuration.js +++ b/packages/babel-core/src/config/loading/files/configuration.js @@ -1,5 +1,6 @@ // @flow +import buildDebug from "debug"; import path from "path"; import fs from "fs"; import json5 from "json5"; @@ -7,6 +8,8 @@ import resolve from "resolve"; import { getEnv } from "../../helpers/environment"; import { makeStrongCache } from "../../caching"; +const debug = buildDebug("babel:config:loading:files:configuration"); + type ConfigFile = { filepath: string, dirname: string, @@ -31,6 +34,7 @@ export function findConfigs(dirname: string): Array { const ignore = readIgnoreConfig(ignoreLoc); if (ignore) { + debug("Found ignore %o from %o.", ignore.filepath, dirname); confs.push(ignore); foundIgnore = true; } @@ -57,6 +61,7 @@ export function findConfigs(dirname: string): Array { }, null); if (conf) { + debug("Found configuration %o from %o.", conf.filepath, dirname); confs.push(conf); foundConfig = true; } @@ -80,6 +85,7 @@ export function loadConfig(name: string, dirname: string): ConfigFile { throw new Error(`Config file ${filepath} contains no configuration data`); } + debug("Loaded config %o from $o.", name, dirname); return conf; } diff --git a/packages/babel-core/src/config/loading/files/plugins.js b/packages/babel-core/src/config/loading/files/plugins.js index ff65ae8f56..ca9e7d6410 100644 --- a/packages/babel-core/src/config/loading/files/plugins.js +++ b/packages/babel-core/src/config/loading/files/plugins.js @@ -4,9 +4,12 @@ * This file handles all logic for converting string-based configuration references into loaded objects. */ +import buildDebug from "debug"; import resolve from "resolve"; import path from "path"; +const debug = buildDebug("babel:config:loading:files:plugins"); + const EXACT_RE = /^module:/; const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/\/]+[/\/]|babel-plugin-)/; const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/\/]+[/\/]|babel-preset-)/; @@ -32,10 +35,10 @@ export function loadPlugin( throw new Error(`Plugin ${name} not found relative to ${dirname}`); } - return { - filepath, - value: requireModule(filepath), - }; + const value = requireModule(filepath); + debug("Loaded plugin %o from %o.", name, dirname); + + return { filepath, value }; } export function loadPreset( @@ -47,10 +50,11 @@ export function loadPreset( throw new Error(`Preset ${name} not found relative to ${dirname}`); } - return { - filepath, - value: requireModule(filepath), - }; + const value = requireModule(filepath); + + debug("Loaded preset %o from %o.", name, dirname); + + return { filepath, value }; } export function loadParser( @@ -71,10 +75,13 @@ export function loadParser( `Parser ${name} relative to ${dirname} does not export a .parse function`, ); } + const value = mod.parse; + + debug("Loaded parser %o from %o.", name, dirname); return { filepath, - value: mod.parse, + value, }; } @@ -96,10 +103,13 @@ export function loadGenerator( `Generator ${name} relative to ${dirname} does not export a .print function`, ); } + const value = mod.print; + + debug("Loaded generator %o from %o.", name, dirname); return { filepath, - value: mod.print, + value, }; }