Skip to content

Commit

Permalink
fix(conventional-commits): Improve logging during preset resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Feb 14, 2019
1 parent 237d1c5 commit d4a16a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("conventional-commits", () => {
await recommendVersion(pkg1, "fixed", { changelogPreset: "garbage" });
} catch (err) {
expect(err.message).toBe(
"Unable to load conventional-commits preset 'garbage' (conventional-changelog-garbage)"
"Unable to load conventional-changelog preset 'garbage' (conventional-changelog-garbage)"
);
}

Expand Down Expand Up @@ -177,7 +177,7 @@ describe("conventional-commits", () => {
await recommendVersion(pkg1, "fixed", { changelogPreset: "conventional-changelog-garbage" });
} catch (err) {
expect(err.message).toBe(
"Unable to load conventional-commits preset 'conventional-changelog-garbage'"
"Unable to load conventional-changelog preset 'conventional-changelog-garbage'"
);
}

Expand All @@ -192,7 +192,7 @@ describe("conventional-commits", () => {
await recommendVersion(pkg1, "fixed", { changelogPreset: "conventional-changelog-garbage/pail" });
} catch (err) {
expect(err.message).toMatch(
"Unable to load conventional-commits preset 'conventional-changelog-garbage/pail'"
"Unable to load conventional-changelog preset 'conventional-changelog-garbage/pail'"
);
}

Expand Down
11 changes: 9 additions & 2 deletions core/conventional-commits/lib/get-changelog-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ function isFunction(config) {
}

function resolveConfigPromise(presetPackageName) {
log.verbose("getChangelogConfig", "Attempting to resolve preset %j", presetPackageName);

// eslint-disable-next-line global-require, import/no-dynamic-require
let config = require(presetPackageName);

log.info("getChangelogConfig", "Successfully resolved preset %j", presetPackageName);

// legacy presets export an errback function instead of Q.all()
if (isFunction(config)) {
config = pify(config)();
Expand All @@ -34,6 +38,9 @@ function getChangelogConfig(changelogPreset = "conventional-changelog-angular",
// https://github.com/npm/npm-package-arg#result-object
const parsed = npa(presetPackageName, rootPath);

log.verbose("getChangelogConfig", "using preset %j", presetPackageName);
log.silly("npa", parsed);

if (parsed.type === "directory") {
if (parsed.raw[0] === "@") {
// npa parses scoped subpath reference as a directory
Expand All @@ -58,7 +65,7 @@ function getChangelogConfig(changelogPreset = "conventional-changelog-angular",
return Promise.resolve(config);
} catch (err) {
log.verbose("getChangelogConfig", err.message);
log.info("getChangelogConfig", `Auto-prefixing conventional-commits preset '${changelogPreset}'`);
log.info("getChangelogConfig", "Auto-prefixing conventional-changelog preset %j", changelogPreset);

// probably a deep shorthand subpath :P
parsed.name = parsed.raw;
Expand Down Expand Up @@ -86,7 +93,7 @@ function getChangelogConfig(changelogPreset = "conventional-changelog-angular",

throw new ValidationError(
"EPRESET",
`Unable to load conventional-commits preset '${changelogPreset}'${
`Unable to load conventional-changelog preset '${changelogPreset}'${
changelogPreset !== presetPackageName ? ` (${presetPackageName})` : ""
}`
);
Expand Down

0 comments on commit d4a16a5

Please sign in to comment.