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 all commits
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
5 changes: 5 additions & 0 deletions .changeset/friendly-vans-hammer.md
@@ -0,0 +1,5 @@
---
"@changesets/config": patch
---

Include the information about `false` being a valid value for the `changelog` option in the validation message for the `changelog` option.
6 changes: 6 additions & 0 deletions .changeset/mean-mugs-return.md
@@ -0,0 +1,6 @@
---
"@changesets/apply-release-plan": patch
"@changesets/cli": patch
---

Fixed an issue with generating changelogs not being skipped when the `changelog` config option was set to `false`.
15 changes: 15 additions & 0 deletions packages/apply-release-plan/src/index.test.ts
Expand Up @@ -1454,6 +1454,21 @@ 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
}
);

expect(
changedFiles.find(a => a.endsWith(`pkg-a${path.sep}CHANGELOG.md`))
).toBeUndefined();
});
it("should update a changelog for one package", async () => {
const releasePlan = new FakeReleasePlan();
let { changedFiles } = await testSetup(
Expand Down
43 changes: 25 additions & 18 deletions packages/apply-release-plan/src/index.ts
Expand Up @@ -180,28 +180,35 @@ async function getNewChangelogEntry(
config: Config,
cwd: string
) {
if (!config.changelog) {
return Promise.resolve(
releasesWithPackage.map(release => ({
...release,
changelog: null
}))
);
}

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