Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ linkStyle default opacity:0.5
changesets_lint --> auto_changelog;
changesets_utils --> auto_changelog;
create_release_branch --> auto_changelog;
create_release_branch --> changesets_utils;
```

<!-- end dependency graph -->
Expand Down
3 changes: 2 additions & 1 deletion packages/changesets-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `parseChangesetSummary` for parsing categorized Changeset summaries, and `GrammarError` for structured parse failures ([#41](https://github.com/MetaMask/release-tools/pull/41))
- Summaries contain one entry: a level-two `## <category>` heading followed by exactly one top-level bullet. Heading categories match case-insensitively and are returned in canonical spelling as `Added`, `Changed`, `Removed`, `Fixed`, `Security`, or `Deprecated` for plugin use.
- Add `filterChangesets` for filtering changesets down to selected package releases ([#76](https://github.com/MetaMask/release-tools/pull/76))
- Add `filterChangesets` for filtering changesets down to selected package releases ([#76](https://github.com/MetaMask/release-tools/pull/76), [#168](https://github.com/MetaMask/release-tools/pull/168))
- Returns new changeset and release objects, preserves summaries and metadata, drops changesets with no selected releases, and does not mutate its inputs.
- Keeps the `none` releases of a kept changeset, and keeps changesets with only `none` releases, so that a release consumes them.
- Add `restoreResidualChangesets` for rewriting Changeset files after a partial release ([#78](https://github.com/MetaMask/release-tools/pull/78))
- Writes back only the releases for packages that were not released, preserves the original summary and bump types, leaves fully consumed Changeset files deleted, and is safe to run more than once.
- Export the supported changeset categories for changelog plugins ([#87](https://github.com/MetaMask/release-tools/pull/87)).
Expand Down
45 changes: 45 additions & 0 deletions packages/changesets-utils/src/filter-changesets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@ describe('filterChangesets', () => {
expect(filterChangesets([changeset], ['@scope/two'])).toStrictEqual([]);
});

it('keeps the none releases of a kept changeset', () => {
const changeset: NewChangesetWithCommit = {
id: 'entry-one',
summary: 'Summary',
releases: [
{ name: '@scope/one', type: 'minor' },
{ name: '@scope/two', type: 'none' },
{ name: '@scope/three', type: 'patch' },
],
};

expect(filterChangesets([changeset], ['@scope/one'])).toStrictEqual([
{
...changeset,
releases: [
{ name: '@scope/one', type: 'minor' },
{ name: '@scope/two', type: 'none' },
],
},
]);
});

it('keeps a changeset with only none releases', () => {
const changeset: NewChangesetWithCommit = {
id: 'entry-one',
summary: 'Summary',
releases: [{ name: '@scope/one', type: 'none' }],
};

expect(filterChangesets([changeset], [])).toStrictEqual([changeset]);
});

it('drops a changeset without selected releases, with its none releases', () => {
const changeset: NewChangesetWithCommit = {
id: 'entry-one',
summary: 'Summary',
releases: [
{ name: '@scope/one', type: 'major' },
{ name: '@scope/two', type: 'none' },
],
};

expect(filterChangesets([changeset], ['@scope/three'])).toStrictEqual([]);
});

it('preserves metadata and clones returned objects', () => {
const changeset: NewChangesetWithCommit = {
id: 'entry-one',
Expand Down
17 changes: 14 additions & 3 deletions packages/changesets-utils/src/filter-changesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import type { NewChangesetWithCommit } from '@changesets/types';
/**
* Returns changesets with releases limited to the selected package names.
*
* A kept changeset also keeps its `none` releases, and a changeset with only
* `none` releases is always kept, so that a release consumes them.
*
* The returned changesets and releases are shallow clones. The input values
* are not modified.
*
* @param changesets - Changesets to filter.
* @param selected - Package names to keep.
* @returns Changesets that retain at least one selected release.
* @returns Changesets that retain at least one selected release, and
* changesets with only `none` releases.
*/
export function filterChangesets(
changesets: readonly NewChangesetWithCommit[],
Expand All @@ -17,10 +21,17 @@ export function filterChangesets(
const selectedNames = new Set(selected);

return changesets.flatMap((changeset) => {
const isKept =
changeset.releases.every(({ type }) => type === 'none') ||
changeset.releases.some(({ name }) => selectedNames.has(name));
if (!isKept) {
return [];
}

const releases = changeset.releases
.filter(({ name }) => selectedNames.has(name))
.filter(({ name, type }) => type === 'none' || selectedNames.has(name))
.map((release) => ({ ...release }));

return releases.length > 0 ? [{ ...changeset, releases }] : [];
return [{ ...changeset, releases }];
});
}
2 changes: 2 additions & 0 deletions packages/create-release-branch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
"test:watch": "vitest --watch"
},
"dependencies": {
"@changesets/assemble-release-plan": "^7.0.0",
"@changesets/config": "^4.0.1",
"@changesets/get-release-plan": "^5.0.2",
"@changesets/types": "^7.0.0",
"@clack/prompts": "^1.8.1",
"@manypkg/get-packages": "^3.1.0",
"@metamask/action-utils": "^2.0.0",
"@metamask/auto-changelog": "^7.1.0",
"@metamask/changesets-utils": "^0.0.0",
"@metamask/utils": "^11.12.0",
"debug": "^4.3.4",
"execa": "^8.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-release-branch/src/core/release-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type IncrementableVersionPart =
(typeof IncrementableVersionParts)[keyof typeof IncrementableVersionParts];

export const SKIP_PACKAGE_DIRECTIVE = null;
const INTENTIONALLY_SKIP_PACKAGE_DIRECTIVE = 'intentionally-skip';
export const INTENTIONALLY_SKIP_PACKAGE_DIRECTIVE = 'intentionally-skip';

/**
* The maintainer's choice for each package, as given: a bump type, an exact
Expand Down
Loading
Loading