Skip to content

Commit 53c18ce

Browse files
sheerloxtravi
andauthoredNov 6, 2023
feat: add support for ESM presets (#544)
Co-authored-by: Matt Travi <programmer@travi.org>
1 parent e6781fa commit 53c18ce

4 files changed

+159
-7
lines changed
 

‎lib/load-changelog-config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { dirname } from "node:path";
22
import { fileURLToPath } from "node:url";
3-
import { promisify } from "node:util";
4-
import { isPlainObject } from "lodash-es";
5-
import importFrom from "import-from";
3+
import importFrom from "import-from-esm";
64
import conventionalChangelogAngular from "conventional-changelog-angular";
75

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

2624
if (preset) {
2725
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
28-
loadedConfig = await (importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage))(presetConfig);
26+
loadedConfig = await (
27+
(await importFrom.silent(__dirname, presetPackage)) || (await importFrom(cwd, presetPackage))
28+
)(presetConfig);
2929
} else if (config) {
30-
loadedConfig = await (importFrom.silent(__dirname, config) || importFrom(cwd, config))();
30+
loadedConfig = await ((await importFrom.silent(__dirname, config)) || (await importFrom(cwd, config)))();
3131
} else {
3232
loadedConfig = await conventionalChangelogAngular();
3333
}

‎package-lock.json

+140-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"conventional-commits-parser": "^5.0.0",
1818
"debug": "^4.0.0",
1919
"get-stream": "^7.0.0",
20-
"import-from": "^4.0.0",
20+
"import-from-esm": "^1.0.3",
2121
"into-stream": "^7.0.0",
2222
"lodash-es": "^4.17.21",
2323
"read-pkg-up": "^11.0.0"
@@ -35,6 +35,7 @@
3535
"fs-extra": "11.1.1",
3636
"prettier": "3.0.3",
3737
"semantic-release": "22.0.7",
38+
"sinon": "16.1.0",
3839
"stream-buffers": "3.0.2",
3940
"tempy": "3.1.0",
4041
"testdouble": "3.20.0"

‎test/load-changelog-config.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import test from "ava";
2+
import importFrom from "import-from-esm";
3+
import sinon from "sinon";
4+
25
import conventionalChangelogAngular from "conventional-changelog-angular";
36
import loadChangelogConfig from "../lib/load-changelog-config.js";
47

@@ -173,3 +176,12 @@ test('Throw error if "config" doesn`t exist', async (t) => {
173176
test('Throw error if "preset" doesn`t exist', async (t) => {
174177
await t.throwsAsync(loadChangelogConfig({ preset: "unknown-preset" }, { cwd }), { code: "MODULE_NOT_FOUND" });
175178
});
179+
180+
test.serial("Load preset and config correctly when importFrom.silent fails", async (t) => {
181+
sinon.stub(importFrom, "silent").returns(undefined);
182+
183+
await loadPreset(t, "angular");
184+
await loadConfig(t, "angular");
185+
186+
sinon.restore();
187+
});

0 commit comments

Comments
 (0)
Please sign in to comment.