Skip to content

fix: load-parser-config.js returned config #790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions lib/load-parser-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { fileURLToPath } from "node:url";
import importFrom from "import-from-esm";
import conventionalChangelogAngular from "conventional-changelog-angular";

import debugFactory from "debug";
const debug = debugFactory(
"semantic-release:commit-analyser:lib:load-parser-config"
);

/**
* Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
*
Expand All @@ -15,20 +20,46 @@ import conventionalChangelogAngular from "conventional-changelog-angular";
*
* @return {Promise<Object>} a `Promise` that resolve to the `conventional-changelog-parser` options.
*/
export default async ({ preset, config, parserOpts, presetConfig }, { cwd }) => {
export default async (
{ preset, config, parserOpts, presetConfig },
{ cwd }
) => {
let loadedConfig;
const __dirname = dirname(fileURLToPath(import.meta.url));

if (preset) {
debug("Loading preset: %s", preset);

const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
debug("Using preset package: %s", presetPackage);

loadedConfig = await (
(await importFrom.silent(__dirname, presetPackage)) || (await importFrom(cwd, presetPackage))
(await importFrom.silent(__dirname, presetPackage)) ||
(await importFrom(cwd, presetPackage))
)(presetConfig);
} else if (config) {
loadedConfig = await ((await importFrom.silent(__dirname, config)) || (await importFrom(cwd, config)))();
debug("No preset defined, loading config instead: %s", config);
loadedConfig = await (
(await importFrom.silent(__dirname, config)) ||
(await importFrom(cwd, config))
)();
} else {
debug(
"No preset or config provided, using conventional-changelog-angular as default"
);
loadedConfig = await conventionalChangelogAngular();
}

return { ...loadedConfig.parser, ...parserOpts };
debug("Loaded parser config: ", JSON.stringify(loadedConfig, null, 2));
debug("Applying parser options: ", parserOpts);

// Most modern conventional changelog presets (including conventionalcommits) export parserOpts.
// Some older ones (like conventional-changelog-angular) export parser.
const mergedConfig = {
...(loadedConfig.parserOpts || loadedConfig.parser),
...parserOpts,
};
debug("Merged parser config: ", JSON.stringify(mergedConfig, null, 2));
// Merge the loaded parser config with the provided parserOpts
return mergedConfig;
};