From 7d998eeb16064b5442ebc49ad31dec7b841d504e Mon Sep 17 00:00:00 2001 From: Surai Date: Thu, 4 Aug 2022 21:16:07 +0200 Subject: [PATCH] Fixed an issue with generating changelogs not being skipped when the `changelog` config option was set to `false` (#900) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Skip generating changelogs when config.changelog is set to false * Update packages/apply-release-plan/src/index.ts * tweak changesets * Tweak the assertion code in the added test Co-authored-by: Mateusz BurzyƄski --- .changeset/friendly-vans-hammer.md | 5 +++ .changeset/mean-mugs-return.md | 6 +++ packages/apply-release-plan/src/index.test.ts | 15 +++++++ packages/apply-release-plan/src/index.ts | 43 +++++++++++-------- packages/config/src/index.test.ts | 6 +-- packages/config/src/index.ts | 2 +- 6 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 .changeset/friendly-vans-hammer.md create mode 100644 .changeset/mean-mugs-return.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 new file mode 100644 index 000000000..9ab9d81d7 --- /dev/null +++ b/.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`. diff --git a/packages/apply-release-plan/src/index.test.ts b/packages/apply-release-plan/src/index.test.ts index 0fe9b3256..d7ede0296 100644 --- a/packages/apply-release-plan/src/index.test.ts +++ b/packages/apply-release-plan/src/index.test.ts @@ -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( diff --git a/packages/apply-release-plan/src/index.ts b/packages/apply-release-plan/src/index.ts index 5e5709629..9ef29eb7a 100644 --- a/packages/apply-release-plan/src/index.ts +++ b/packages/apply-release-plan/src/index.ts @@ -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( 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 }])` ); }