Skip to content

fix: cannot find module with package exports and support previous non-function configurations #588

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions lib/load-parser-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import importFrom from "import-from-esm";
import importFrom from "import-from";
import conventionalChangelogAngular from "conventional-changelog-angular";

/**
Expand All @@ -21,11 +21,15 @@ export default async ({ preset, config, parserOpts, presetConfig }, { cwd }) =>

if (preset) {
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
loadedConfig = await (
(await importFrom.silent(__dirname, presetPackage)) || (await importFrom(cwd, presetPackage))
)(presetConfig);
loadedConfig = await (importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage));
if (typeof loadedConfig === "function") {
loadedConfig = await loadedConfig(presetConfig);
}
} else if (config) {
loadedConfig = await ((await importFrom.silent(__dirname, config)) || (await importFrom(cwd, config)))();
loadedConfig = await (importFrom.silent(__dirname, config) || importFrom(cwd, config))();
if (typeof loadedConfig === "function") {
loadedConfig = await loadedConfig();
}
} else {
loadedConfig = await conventionalChangelogAngular();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/load-release-rules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { isUndefined } from "lodash-es";
import importFrom from "import-from-esm";
import importFrom from "import-from";
import RELEASE_TYPES from "./default-release-types.js";

/**
Expand All @@ -24,7 +24,7 @@ export default async ({ releaseRules }, { cwd }) => {
if (releaseRules) {
loadedReleaseRules =
typeof releaseRules === "string"
? (await importFrom.silent(__dirname, releaseRules)) || (await importFrom(cwd, releaseRules))
? importFrom.silent(__dirname, releaseRules) || importFrom(cwd, releaseRules)
: releaseRules;

if (!Array.isArray(loadedReleaseRules)) {
Expand Down
39 changes: 38 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"conventional-commits-filter": "^4.0.0",
"conventional-commits-parser": "^5.0.0",
"debug": "^4.0.0",
"import-from-esm": "^1.0.3",
"import-from": "^4.0.0",
"lodash-es": "^4.17.21",
"micromatch": "^4.0.2"
},
Expand All @@ -34,6 +34,7 @@
"conventional-changelog-eslint": "5.0.0",
"conventional-changelog-express": "4.0.0",
"conventional-changelog-jshint": "4.0.0",
"conventional-changelog-techor": "2.5.24",
"prettier": "3.2.4",
"semantic-release": "23.0.0",
"sinon": "17.0.1"
Expand Down
21 changes: 21 additions & 0 deletions test/presets.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import test from "ava";
import { stub } from "sinon";
import { analyzeCommits } from "../index.js";

const cwd = process.cwd();

test.beforeEach((t) => {
const log = stub();
t.context.log = log;
t.context.logger = { log };
});

test('Accept "preset" option', async (t) => {
const commits = [
{ hash: "123", message: "Fix: First fix (fixes #123)" },
{ hash: "456", message: "Update: Second feature (fixes #456)" },
];
const releaseType = await analyzeCommits({ preset: "techor" }, { cwd, commits, logger: t.context.logger });

t.is(releaseType, null);
});