Skip to content

Commit 6c82fef

Browse files
committed
refactor: restore importFrom strategy using ESM port
1 parent 323c1fd commit 6c82fef

File tree

5 files changed

+26
-29
lines changed

5 files changed

+26
-29
lines changed

lib/load-parser-config.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { dirname } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import importFrom from "import-from-esm";
14
import conventionalChangelogAngular from "conventional-changelog-angular";
2-
import { importModule } from "./module-loader.js";
35

46
/**
57
* Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
@@ -15,12 +17,15 @@ import { importModule } from "./module-loader.js";
1517
*/
1618
export default async ({ preset, config, parserOpts, presetConfig }, { cwd }) => {
1719
let loadedConfig;
20+
const __dirname = dirname(fileURLToPath(import.meta.url));
1821

1922
if (preset) {
2023
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
21-
loadedConfig = await (await importModule(cwd, presetPackage))(presetConfig);
24+
loadedConfig = await (
25+
(await importFrom.silent(__dirname, presetPackage)) || (await importFrom(cwd, presetPackage))
26+
)(presetConfig);
2227
} else if (config) {
23-
loadedConfig = await (await importModule(cwd, config))();
28+
loadedConfig = await ((await importFrom.silent(__dirname, config)) || (await importFrom(cwd, config)))();
2429
} else {
2530
loadedConfig = await conventionalChangelogAngular();
2631
}

lib/load-release-rules.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { dirname } from "node:path";
2+
import { fileURLToPath } from "node:url";
13
import { isUndefined } from "lodash-es";
4+
import importFrom from "import-from-esm";
25
import RELEASE_TYPES from "./default-release-types.js";
3-
import { importModule } from "./module-loader.js";
46

57
/**
68
* Load and validate the `releaseRules` rules.
@@ -17,9 +19,13 @@ import { importModule } from "./module-loader.js";
1719
*/
1820
export default async ({ releaseRules }, { cwd }) => {
1921
let loadedReleaseRules;
22+
const __dirname = dirname(fileURLToPath(import.meta.url));
2023

2124
if (releaseRules) {
22-
loadedReleaseRules = typeof releaseRules === "string" ? await importModule(cwd, releaseRules) : releaseRules;
25+
loadedReleaseRules =
26+
typeof releaseRules === "string"
27+
? (await importFrom.silent(__dirname, releaseRules)) || (await importFrom(cwd, releaseRules))
28+
: releaseRules;
2329

2430
if (!Array.isArray(loadedReleaseRules)) {
2531
throw new TypeError('Error in commit-analyzer configuration: "releaseRules" must be an array of rules');

lib/module-loader.js

-24
This file was deleted.

package-lock.json

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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"conventional-commits-filter": "^4.0.0",
2222
"conventional-commits-parser": "^5.0.0",
2323
"debug": "^4.0.0",
24+
"import-from-esm": "^1.0.0",
2425
"lodash-es": "^4.17.21",
2526
"micromatch": "^4.0.2"
2627
},

0 commit comments

Comments
 (0)