diff --git a/.changeset/changelog.cjs b/.changeset/changelog.mjs similarity index 53% rename from .changeset/changelog.cjs rename to .changeset/changelog.mjs index 763af6676..876a7afa1 100644 --- a/.changeset/changelog.cjs +++ b/.changeset/changelog.mjs @@ -11,26 +11,48 @@ governing permissions and limitations under the License. */ /* eslint-env node */ -/* global require, module, process */ +/* global process */ // Wrapper around changesets to use @changesets/changelog-github when there is a GITHUB_TOKEN // and @changesets/cli/changelog otherwise. -const defaultChangelog = require("@changesets/cli/changelog"); +import * as defaultChangelogModule from "@changesets/cli/changelog"; -let githubChangelog; -try { - githubChangelog = require("@changesets/changelog-github"); -} catch { - githubChangelog = null; -} +const githubChangelogPromise = import("@changesets/changelog-github").catch( + () => null, +); -const canUseGithubChangelog = () => - Boolean(githubChangelog && process.env.GITHUB_TOKEN); +const unwrapModule = (module) => module?.default ?? module; -module.exports = { +const defaultChangelog = unwrapModule(defaultChangelogModule); + +const getGithubChangelogIfAvailable = async () => { + const githubModule = await githubChangelogPromise; + if (!githubModule) { + return null; + } + + const githubImpl = unwrapModule(githubModule); + + if (!process.env.GITHUB_TOKEN) { + return null; + } + + if (typeof githubImpl.getReleaseLine !== "function") { + return null; + } + + if (typeof githubImpl.getDependencyReleaseLine !== "function") { + return null; + } + + return githubImpl; +}; + +export default { getReleaseLine: async (changeset, type, options) => { - if (canUseGithubChangelog()) { - return githubChangelog.getReleaseLine(changeset, type, options); + const githubImpl = await getGithubChangelogIfAvailable(); + if (githubImpl) { + return githubImpl.getReleaseLine(changeset, type, options); } return defaultChangelog.getReleaseLine(changeset, type, options); }, @@ -39,8 +61,9 @@ module.exports = { dependenciesUpdated, options, ) => { - if (canUseGithubChangelog()) { - return githubChangelog.getDependencyReleaseLine( + const githubImpl = await getGithubChangelogIfAvailable(); + if (githubImpl) { + return githubImpl.getDependencyReleaseLine( changesets, dependenciesUpdated, options, diff --git a/.changeset/config.json b/.changeset/config.json index be7b46339..8f2bdbc88 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,7 +1,7 @@ { "$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json", "changelog": [ - "./changelog.cjs", + "./changelog.mjs", { "repo": "adobe/alloy" }