Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: skip generating changelogs when config.changelog is set to false #900

Merged
merged 4 commits into from Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/mean-mugs-return.md
@@ -0,0 +1,6 @@
---
"@changesets/apply-release-plan": patch
"@changesets/config": patch
---

Fix: skip generating changelogs when config.changelog is set to false
17 changes: 17 additions & 0 deletions packages/apply-release-plan/src/index.test.ts
Expand Up @@ -1454,6 +1454,23 @@ describe("apply release plan", () => {
});
});
describe("changelogs", () => {
it("should not generate any changelogs", async () => {
const releasePlan = new FakeReleasePlan();
let { changedFiles } = await testSetup(
"simple-project",
releasePlan.getReleasePlan(),
{
...releasePlan.config,
changelog: false
}
);

let readmePath = changedFiles.find(a =>
a.endsWith(`pkg-a${path.sep}CHANGELOG.md`)
);

if (readmePath) throw new Error(`should not have found a changelog`);
});
it("should update a changelog for one package", async () => {
const releasePlan = new FakeReleasePlan();
let { changedFiles } = await testSetup(
Expand Down
39 changes: 21 additions & 18 deletions packages/apply-release-plan/src/index.ts
Expand Up @@ -180,28 +180,31 @@ async function getNewChangelogEntry(
config: Config,
cwd: string
) {
// Skip generating changelog entries if config.changelog is false
if (!config.changelog) {
return releasesWithPackage;
}
Andarist marked this conversation as resolved.
Show resolved Hide resolved

let getChangelogFuncs: ChangelogFunctions = {
getReleaseLine: () => Promise.resolve(""),
getDependencyReleaseLine: () => Promise.resolve("")
};
let changelogOpts: any;
if (config.changelog) {
changelogOpts = config.changelog[1];
let changesetPath = path.join(cwd, ".changeset");
let changelogPath = resolveFrom(changesetPath, config.changelog[0]);

let possibleChangelogFunc = require(changelogPath);
if (possibleChangelogFunc.default) {
possibleChangelogFunc = possibleChangelogFunc.default;
}
if (
typeof possibleChangelogFunc.getReleaseLine === "function" &&
typeof possibleChangelogFunc.getDependencyReleaseLine === "function"
) {
getChangelogFuncs = possibleChangelogFunc;
} else {
throw new Error("Could not resolve changelog generation functions");
}

const changelogOpts = config.changelog[1];
let changesetPath = path.join(cwd, ".changeset");
let changelogPath = resolveFrom(changesetPath, config.changelog[0]);

let possibleChangelogFunc = require(changelogPath);
if (possibleChangelogFunc.default) {
possibleChangelogFunc = possibleChangelogFunc.default;
}
if (
typeof possibleChangelogFunc.getReleaseLine === "function" &&
typeof possibleChangelogFunc.getDependencyReleaseLine === "function"
) {
getChangelogFuncs = possibleChangelogFunc;
} else {
throw new Error("Could not resolve changelog generation functions");
}

let commits = await getCommitsThatAddChangesets(
Expand Down
6 changes: 3 additions & 3 deletions packages/config/src/index.test.ts
Expand Up @@ -337,7 +337,7 @@ describe("parser errors", () => {
unsafeParse({ changelog: {} }, defaultPackages);
}).toThrowErrorMatchingInlineSnapshot(`
"Some errors occurred when validating the changesets config:
The \`changelog\` option is set as {} when the only valid values are undefined, a module path(e.g. \\"@changesets/cli/changelog\\" or \\"./some-module\\") or a tuple with a module path and config for the changelog generator(e.g. [\\"@changesets/cli/changelog\\", { someOption: true }])"
The \`changelog\` option is set as {} when the only valid values are undefined, false, a module path(e.g. \\"@changesets/cli/changelog\\" or \\"./some-module\\") or a tuple with a module path and config for the changelog generator(e.g. [\\"@changesets/cli/changelog\\", { someOption: true }])"
`);
});
test("changelog array with 3 values", () => {
Expand All @@ -352,7 +352,7 @@ The \`changelog\` option is set as [
\\"some-module\\",
\\"something\\",
\\"other\\"
] when the only valid values are undefined, a module path(e.g. \\"@changesets/cli/changelog\\" or \\"./some-module\\") or a tuple with a module path and config for the changelog generator(e.g. [\\"@changesets/cli/changelog\\", { someOption: true }])"
] when the only valid values are undefined, false, a module path(e.g. \\"@changesets/cli/changelog\\" or \\"./some-module\\") or a tuple with a module path and config for the changelog generator(e.g. [\\"@changesets/cli/changelog\\", { someOption: true }])"
`);
});
test("changelog array with first value not string", () => {
Expand All @@ -363,7 +363,7 @@ The \`changelog\` option is set as [
The \`changelog\` option is set as [
false,
\\"something\\"
] when the only valid values are undefined, a module path(e.g. \\"@changesets/cli/changelog\\" or \\"./some-module\\") or a tuple with a module path and config for the changelog generator(e.g. [\\"@changesets/cli/changelog\\", { someOption: true }])"
] when the only valid values are undefined, false, a module path(e.g. \\"@changesets/cli/changelog\\" or \\"./some-module\\") or a tuple with a module path and config for the changelog generator(e.g. [\\"@changesets/cli/changelog\\", { someOption: true }])"
`);
});
test("access other string", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/index.ts
Expand Up @@ -116,7 +116,7 @@ export let parse = (json: WrittenConfig, packages: Packages): Config => {
json.changelog,
null,
2
)} when the only valid values are undefined, a module path(e.g. "@changesets/cli/changelog" or "./some-module") or a tuple with a module path and config for the changelog generator(e.g. ["@changesets/cli/changelog", { someOption: true }])`
)} when the only valid values are undefined, false, a module path(e.g. "@changesets/cli/changelog" or "./some-module") or a tuple with a module path and config for the changelog generator(e.g. ["@changesets/cli/changelog", { someOption: true }])`
);
}

Expand Down