Skip to content
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

feat: add support for ESM presets #544

Merged
merged 7 commits into from Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/load-changelog-config.js
@@ -1,8 +1,6 @@
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { isPlainObject } from "lodash-es";
import importFrom from "import-from";
import importFrom from "import-from-esm";
import conventionalChangelogAngular from "conventional-changelog-angular";

/**
Expand All @@ -25,9 +23,11 @@ export default async ({ preset, config, parserOpts, writerOpts, presetConfig },

if (preset) {
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
loadedConfig = await (importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage))(presetConfig);
loadedConfig = await (
(await importFrom.silent(__dirname, presetPackage)) || (await importFrom(cwd, presetPackage))
)(presetConfig);
} else if (config) {
loadedConfig = await (importFrom.silent(__dirname, config) || importFrom(cwd, config))();
loadedConfig = await ((await importFrom.silent(__dirname, config)) || (await importFrom(cwd, config)))();
} else {
loadedConfig = await conventionalChangelogAngular();
}
Expand Down
141 changes: 140 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
Expand Up @@ -17,7 +17,7 @@
"conventional-commits-parser": "^5.0.0",
"debug": "^4.0.0",
"get-stream": "^7.0.0",
"import-from": "^4.0.0",
"import-from-esm": "^1.0.3",
"into-stream": "^7.0.0",
"lodash-es": "^4.17.21",
"read-pkg-up": "^11.0.0"
Expand All @@ -35,6 +35,7 @@
"fs-extra": "11.1.1",
"prettier": "3.0.3",
"semantic-release": "22.0.7",
"sinon": "16.1.0",
"stream-buffers": "3.0.2",
"tempy": "3.1.0",
"testdouble": "3.20.0"
Expand Down
12 changes: 12 additions & 0 deletions test/load-changelog-config.test.js
@@ -1,4 +1,7 @@
import test from "ava";
import importFrom from "import-from-esm";
import sinon from "sinon";

import conventionalChangelogAngular from "conventional-changelog-angular";
import loadChangelogConfig from "../lib/load-changelog-config.js";

Expand Down Expand Up @@ -173,3 +176,12 @@ test('Throw error if "config" doesn`t exist', async (t) => {
test('Throw error if "preset" doesn`t exist', async (t) => {
await t.throwsAsync(loadChangelogConfig({ preset: "unknown-preset" }, { cwd }), { code: "MODULE_NOT_FOUND" });
});

test.serial("Load preset and config correctly when importFrom.silent fails", async (t) => {
sinon.stub(importFrom, "silent").returns(undefined);

await loadPreset(t, "angular");
await loadConfig(t, "angular");

sinon.restore();
});