Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 38 additions & 15 deletions .changeset/changelog.cjs → .changeset/changelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
"changelog": [
"./changelog.cjs",
"./changelog.mjs",
{
"repo": "adobe/alloy"
}
Expand Down
Loading