forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCommitFunctions.mjs
More file actions
29 lines (29 loc) · 1.2 KB
/
Copy pathgetCommitFunctions.mjs
File metadata and controls
29 lines (29 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import path from "node:path";
import { pathToFileURL } from "node:url";
import { resolve as resolve$1 } from "import-meta-resolve";
//#region src/commit/getCommitFunctions.ts
function importResolveFromDir(specifier, dir) {
return resolve$1(specifier, pathToFileURL(path.join(dir, "x.mjs")).toString());
}
async function getCommitFunctions(commit, cwd, contextDir) {
let commitFunctions = {};
if (!commit) return [commitFunctions, null];
const commitOpts = commit[1];
const changesetPath = path.join(cwd, ".changeset");
let commitPath;
try {
commitPath = importResolveFromDir(commit[0], changesetPath);
} catch {
commitPath = importResolveFromDir(commit[0], contextDir);
}
let possibleCommitFunc = await import(commitPath);
if (possibleCommitFunc.default) {
possibleCommitFunc = possibleCommitFunc.default;
if (possibleCommitFunc.default) possibleCommitFunc = possibleCommitFunc.default;
}
if (typeof possibleCommitFunc.getAddMessage === "function" || typeof possibleCommitFunc.getVersionMessage === "function") commitFunctions = possibleCommitFunc;
else throw new Error("Could not resolve commit generation functions");
return [commitFunctions, commitOpts];
}
//#endregion
export { getCommitFunctions as t };