Skip to content

Commit

Permalink
Fixed an issue with generating changelogs not being skipped when the …
Browse files Browse the repository at this point in the history
…`changelog` config option was set to `false` (#900)

* 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 <mateuszburzynski@gmail.com>
  • Loading branch information
Surai and Andarist committed Aug 4, 2022
1 parent c926b4a commit 7d998ee
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
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

0 comments on commit 7d998ee

Please sign in to comment.