From 835ab33dc979bd37fb73760993ade6004c24f7e7 Mon Sep 17 00:00:00 2001 From: sdirosa Date: Thu, 4 Aug 2022 12:44:33 +0200 Subject: [PATCH 1/4] Skip generating changelogs when config.changelog is set to false --- .changeset/mean-mugs-return.md | 6 +++ packages/apply-release-plan/src/index.test.ts | 17 ++++++++ packages/apply-release-plan/src/index.ts | 39 ++++++++++--------- packages/config/src/index.test.ts | 6 +-- packages/config/src/index.ts | 2 +- 5 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 .changeset/mean-mugs-return.md diff --git a/.changeset/mean-mugs-return.md b/.changeset/mean-mugs-return.md new file mode 100644 index 000000000..eb4d0fdca --- /dev/null +++ b/.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 diff --git a/packages/apply-release-plan/src/index.test.ts b/packages/apply-release-plan/src/index.test.ts index 0fe9b3256..5daeafd28 100644 --- a/packages/apply-release-plan/src/index.test.ts +++ b/packages/apply-release-plan/src/index.test.ts @@ -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( diff --git a/packages/apply-release-plan/src/index.ts b/packages/apply-release-plan/src/index.ts index 5e5709629..5a5c22e96 100644 --- a/packages/apply-release-plan/src/index.ts +++ b/packages/apply-release-plan/src/index.ts @@ -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; + } + 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( diff --git a/packages/config/src/index.test.ts b/packages/config/src/index.test.ts index 0407271c3..bc313e871 100644 --- a/packages/config/src/index.test.ts +++ b/packages/config/src/index.test.ts @@ -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", () => { @@ -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", () => { @@ -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", () => { diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 1ab73d037..5a96293e1 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -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 }])` ); } From 750cba12b88e7815abc36bbbd34d712f547ca901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 4 Aug 2022 19:24:28 +0200 Subject: [PATCH 2/4] Update packages/apply-release-plan/src/index.ts --- packages/apply-release-plan/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/apply-release-plan/src/index.ts b/packages/apply-release-plan/src/index.ts index 5a5c22e96..9ef29eb7a 100644 --- a/packages/apply-release-plan/src/index.ts +++ b/packages/apply-release-plan/src/index.ts @@ -180,9 +180,13 @@ async function getNewChangelogEntry( config: Config, cwd: string ) { - // Skip generating changelog entries if config.changelog is false if (!config.changelog) { - return releasesWithPackage; + return Promise.resolve( + releasesWithPackage.map(release => ({ + ...release, + changelog: null + })) + ); } let getChangelogFuncs: ChangelogFunctions = { From e5604ad763ddccc202fa4ae679032b98fc42652e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 4 Aug 2022 20:20:10 +0200 Subject: [PATCH 3/4] tweak changesets --- .changeset/friendly-vans-hammer.md | 5 +++++ .changeset/mean-mugs-return.md | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/friendly-vans-hammer.md diff --git a/.changeset/friendly-vans-hammer.md b/.changeset/friendly-vans-hammer.md new file mode 100644 index 000000000..85a0004dc --- /dev/null +++ b/.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. diff --git a/.changeset/mean-mugs-return.md b/.changeset/mean-mugs-return.md index eb4d0fdca..9ab9d81d7 100644 --- a/.changeset/mean-mugs-return.md +++ b/.changeset/mean-mugs-return.md @@ -1,6 +1,6 @@ --- "@changesets/apply-release-plan": patch -"@changesets/config": patch +"@changesets/cli": patch --- -Fix: skip generating changelogs when config.changelog is set to false +Fixed an issue with generating changelogs not being skipped when the `changelog` config option was set to `false`. From 747e2cb178b5ddf02215276303a809b79485ac83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 4 Aug 2022 20:22:26 +0200 Subject: [PATCH 4/4] Tweak the assertion code in the added test --- packages/apply-release-plan/src/index.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/apply-release-plan/src/index.test.ts b/packages/apply-release-plan/src/index.test.ts index 5daeafd28..d7ede0296 100644 --- a/packages/apply-release-plan/src/index.test.ts +++ b/packages/apply-release-plan/src/index.test.ts @@ -1465,11 +1465,9 @@ describe("apply release plan", () => { } ); - let readmePath = changedFiles.find(a => - a.endsWith(`pkg-a${path.sep}CHANGELOG.md`) - ); - - if (readmePath) throw new Error(`should not have found a changelog`); + 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();