Skip to content

Commit 871aed1

Browse files
re-taroAndarist
andauthored
Detect root package as potential workspace (#94)
* fix: improve package.json detection * add test --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
1 parent d9dcad2 commit 871aed1

2 files changed

Lines changed: 74 additions & 2 deletions

File tree

‎get-changed-packages.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const getChangedPackages = async ({
112112
if (!item.path) {
113113
continue;
114114
}
115-
if (item.path.endsWith("/package.json")) {
115+
if (nodePath.basename(item.path) === "package.json") {
116116
const dirPath = nodePath.dirname(item.path);
117117
potentialWorkspaceDirectories.push(dirPath);
118118
} else if (item.path === "pnpm-workspace.yaml") {
@@ -132,7 +132,10 @@ export const getChangedPackages = async ({
132132
const id = res[1];
133133

134134
changesetPromises.push(
135-
fetchTextFile(item.path).then((text) => ({ ...parseChangeset(text), id })),
135+
fetchTextFile(item.path).then((text) => ({
136+
...parseChangeset(text),
137+
id,
138+
})),
136139
);
137140
}
138141
}

‎test/index.test.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,75 @@ describe.concurrent("changeset-bot", () => {
457457
`);
458458
});
459459

460+
it("shows release details for the root package when workspaces explicitly include dot", async ({
461+
expect,
462+
task,
463+
}) => {
464+
const probot = setupProbot(task.id);
465+
const { requests } = usePrState(server, {
466+
files: {
467+
".changeset/config.json": JSON.stringify({}),
468+
".changeset/root-change.md": [
469+
{
470+
status: "added",
471+
},
472+
`---
473+
"root-package": patch
474+
---
475+
476+
thing
477+
`,
478+
],
479+
"package.json": JSON.stringify({
480+
name: "root-package",
481+
version: "1.0.0",
482+
workspaces: [".", "packages/*"],
483+
}),
484+
"packages/a/package.json": JSON.stringify({
485+
name: "pkg-a",
486+
}),
487+
},
488+
comments: [],
489+
});
490+
491+
await probot.receive({
492+
name: "pull_request",
493+
payload: pullRequestOpen,
494+
} as never);
495+
496+
const commentRequests = requests.filter((request) => request.path.includes("/comments"));
497+
498+
expect(commentRequests).toMatchInlineSnapshot(`
499+
[
500+
{
501+
"body": {
502+
"body": "### 🦋 Changeset detected
503+
504+
Latest commit: c4d7edfd758bd44f7d4264fb55f6033f56d79540
505+
506+
**The changes in this PR will be included in the next version bump.**
507+
508+
<details><summary>This PR includes changesets to release 1 package</summary>
509+
510+
| Name | Type |
511+
| ------------ | ----- |
512+
| root-package | Patch |
513+
514+
</details>
515+
516+
Not sure what this means? [Click here to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
517+
518+
[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/changesets/bot/new/test?filename=.changeset/<CHANGESET_FILE>.md&value=---%0A%0A---%0A%0Athing%0A)
519+
520+
",
521+
},
522+
"method": "POST",
523+
"path": "/repos/changesets/bot/issues/2/comments",
524+
},
525+
]
526+
`);
527+
});
528+
460529
it("includes only changed yarn workspace packages in the add-changeset link", async ({
461530
expect,
462531
task,

0 commit comments

Comments
 (0)