| 3 | import resolveFrom from "resolve-from"; |
| 4 | |
| 5 | export async function getCommitFunctions( |
| 6 | commit: false | readonly [string, any], |
| 7 | cwd: string |
| 8 | ): Promise<[CommitFunctions, any]> { |
| 9 | let commitFunctions: CommitFunctions = {}; |
| 10 | if (!commit) { |
| 11 | return [commitFunctions, null]; |
| 12 | } |
| 13 | let commitOpts: any = commit[1]; |
| 14 | let changesetPath = path.join(cwd, ".changeset"); |
| 15 | let commitPath = resolveFrom(changesetPath, commit[0]); |
| 16 | |
| 17 | let possibleCommitFunc = await import(commitPath); |
| 18 | if (possibleCommitFunc.default) { |
| 19 | possibleCommitFunc = possibleCommitFunc.default; |
| 20 | |
| 21 | // Check nested default again in case it's CJS with `__esModule` interop |
| 22 | if (possibleCommitFunc.default) { |
| 23 | possibleCommitFunc = possibleCommitFunc.default; |
| 24 | } |
| 25 | } |
| 26 | if ( |
| 27 | typeof possibleCommitFunc.getAddMessage === "function" || |
| 28 | typeof possibleCommitFunc.getVersionMessage === "function" |
| 29 | ) { |
| 30 | commitFunctions = possibleCommitFunc; |
| 31 | } else { |
| 32 | throw new Error("Could not resolve commit generation functions"); |
| 33 | } |
| 34 | return [commitFunctions, commitOpts]; |
| 35 | } |