8000 fix(resolve-extends): add import attribute for JSON config files by macieklamberski · Pull Request #4551 · conventional-changelog/commitlint · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
6 changes: 6 additions & 0 deletions @commitlint/resolve-extends/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createRequire } from "node:module";
import fs from "node:fs";
import path from "node:path";
import { pathToFileURL, fileURLToPath } from "node:url";
Expand All @@ -10,6 +11,11 @@ import { validateConfig } from "@commitlint/config-validator";
import type { ParserPreset, UserConfig } from "@commitlint/types";

const dynamicImport = async <T>(id: string): Promise<T> => {
if (id.endsWith(".json")) {
const require = createRequire(import.meta.url);
return require(id);
}

const imported = await import(
path.isAbsolute(id) ? pathToFileURL(id).toString() : id
);
Expand Down
0