Skip to content

Commit

Permalink
sub-package changelogs: Handle when no changes made to monorepo packages
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed May 19, 2020
1 parent a3f7aa5 commit 01352fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugins/npm/__tests__/monorepo-log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ test("should create extra change logs for sub-packages", async () => {
"packages/@foobar/release/README.md\npackages/@foobar/party/package.json"
);

execPromise.mockReturnValueOnce('@foobar/release');
execPromise.mockResolvedValueOnce("@foobar/release");

const plugin = new NpmPlugin();
const hooks = makeHooks();
Expand Down
16 changes: 11 additions & 5 deletions plugins/npm/__tests__/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,15 +1243,16 @@ describe("makeRelease", () => {
describe("beforeCommitChangelog", () => {
let updateChangelogFile: jest.Mock;

async function subPackageChangelogTest(options: INpmConfig = {}) {
async function subPackageChangelogTest(
options: INpmConfig = {},
changed = "@packages/a\n@packages/b"
) {
const plugin = new NPMPlugin(options);
const hooks = makeHooks();

// isMonorepo
execPromise.mockReturnValueOnce(
'@packages/a\n@packages/b'
);
execPromise.mockReturnValueOnce("@packages/a\n@packages/b");
execPromise.mockResolvedValue("@packages/a\n@packages/b");
execPromise.mockResolvedValue(changed);
existsSync.mockReturnValueOnce(true);
getLernaPackages.mockReturnValueOnce(monorepoPackagesResult);

Expand Down Expand Up @@ -1305,4 +1306,9 @@ describe("beforeCommitChangelog", () => {
await subPackageChangelogTest({ subPackageChangelogs: false });
expect(updateChangelogFile).not.toHaveBeenCalled();
});

test("should not create sub-package changelogs when nothing has changed", async () => {
await subPackageChangelogTest({}, "");
expect(updateChangelogFile).not.toHaveBeenCalled();
});
});
12 changes: 9 additions & 3 deletions plugins/npm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,15 @@ export default class NPMPlugin implements IPlugin {
return;
}

const changedPackages = (
await execPromise("yarn", ["lerna", "changed"])
).split("\n");
const [, changedPackagesResult = ""] = await on(
execPromise("yarn", ["lerna", "changed"])
);
const changedPackages = changedPackagesResult.split("\n");

if (!changedPackages.length) {
return;
}

const lernaPackages = await getLernaPackages();
const changelog = await auto.release.makeChangelog(bump);

Expand Down

0 comments on commit 01352fe

Please sign in to comment.