Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New config flag: snapshot.prereleaseTemplate, and make snapshot feature stable #858

Merged
merged 24 commits into from Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
df1750c
Added `getCurrentCommitId` helper
dotansimha Jul 3, 2022
8668392
Added snapshotPreidTemplate
dotansimha Jul 5, 2022
ff191b8
added changeset
dotansimha Jul 5, 2022
198bbe1
fix lint
dotansimha Jul 5, 2022
ae64c8f
fix ts build issues
dotansimha Jul 5, 2022
b777f57
moved experimental docs to a new file
dotansimha Jul 6, 2022
4703ca3
use regex for replacing placeholders
dotansimha Jul 6, 2022
ec232f4
improve Date mocks in tests
dotansimha Jul 6, 2022
5692abb
prevent `--snapshot name` without `{tag}` placeholder
dotansimha Jul 6, 2022
0a639c3
fix lint
dotansimha Jul 6, 2022
255d122
Allow `--snapshot-preid-template` in cli
dotansimha Jul 7, 2022
5cb90c2
simplify cli->assembleReleasePlan interface
dotansimha Jul 10, 2022
272b016
remove the dateRef from assembleReleasePlan and calcualte it internally
dotansimha Jul 10, 2022
e1d6c96
Migrate to unified `snapshot` flag in config
dotansimha Jul 17, 2022
a2a664f
Make `snapshot` stable, avoid breaking changes and keep supporting `u…
dotansimha Jul 18, 2022
10e1dac
Tweak `mockGlobalDate`
Andarist Jul 22, 2022
abd7a76
Refactor code around creating snapshot suffix
Andarist Jul 22, 2022
3513f1a
Bring back the comment related to 0.0.0 versions used in snapshots by…
Andarist Jul 22, 2022
806b4dd
Update .changeset/strong-geckos-divide.md
Andarist Jul 22, 2022
d5541b7
Update .changeset/olive-ducks-camp.md
Andarist Jul 22, 2022
665bb7b
Fixed `--snapshot-prerelease-template` CLI param in the help string
Andarist Jul 22, 2022
7c0d677
Remove `null` from `WrittenConfig["snapshot"]["prereleaseTemplate"]`
Andarist Jul 22, 2022
5b9d69f
Juggle some docs and update `schema.json`
Andarist Jul 22, 2022
d046aaa
Only get the current commit if the template uses the `{commit}` variable
Andarist Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions .changeset/olive-ducks-camp.md
@@ -0,0 +1,32 @@
---
"@changesets/cli": patch
"@changesets/config": patch
---

**NOTE: BREAKING CHANGE**
dotansimha marked this conversation as resolved.
Show resolved Hide resolved

Group snapshot config parameters under a single property called `snapshot`.

To migrate, make sure to update your `config.json`.

Old usage:

```json
{
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"useCalculatedVersionForSnapshots": true
}
}
```

New usage:

```json
{
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"snapshot": {
"useCalculatedVersion": true
}
}
}
```
5 changes: 5 additions & 0 deletions .changeset/quick-squids-dance.md
@@ -0,0 +1,5 @@
---
"@changesets/cli": minor
---

Added a new config flag for `changesets version --snapshot` mode: `--snapshot-prerelease-template`
5 changes: 5 additions & 0 deletions .changeset/short-cats-invent.md
@@ -0,0 +1,5 @@
---
"@changesets/git": minor
---

Added a new helper function: `getCurrentCommitId`
8 changes: 8 additions & 0 deletions .changeset/strong-geckos-divide.md
@@ -0,0 +1,8 @@
---
"@changesets/assemble-release-plan": minor
"@changesets/cli": minor
"@changesets/config": minor
"@changesets/types": minor
---

Added a new config option: `snapshotPrereleaseTemplate` for customizing the way snapshot release numbers are being composed.
Andarist marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 8 additions & 2 deletions .vscode/settings.json
@@ -1,3 +1,9 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
"typescript.tsdk": "node_modules/typescript/lib",
"grammarly.selectors": [
{
"language": "markdown",
"scheme": "file"
}
]
}
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -55,6 +55,7 @@ To make releasing easier, you can use [this changesets github action](https://gi
- [Prereleases](./docs/prereleases.md)
- [Problems publishing in monorepos](./docs/problems-publishing-in-monorepos.md)
- [Snapshot releases](./docs/snapshot-releases.md)
- [Experimental Options](./docs/experimental-options.md)

## Cool Projects already using Changesets for versioning and changelogs

Expand Down
54 changes: 54 additions & 0 deletions docs/experimental-options.md
@@ -0,0 +1,54 @@
# Experimental Options

All experimental options are configured in `config.json` under `___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH` flag.

> Please use these experimental flags with caution, and please pay attention to release notes - these config flags might change in patch versions.

## `updateInternalDependents` (type: `'out-of-range' | 'always'`)

Default value: `out-of-range`.

The config flag can be used to add dependent packages to the release (if they are not already a part of it) with patch bumps.

## `onlyUpdatePeerDependentsWhenOutOfRange` (type: `boolean`)

Default value: `false`

When set to `true`, Changesets will only bump peer dependents when `peerDependencies` are leaving the range.

## `snapshot` (type: `object`)
dotansimha marked this conversation as resolved.
Show resolved Hide resolved

Default value: `undefined`

#### `useCalculatedVersion` (type: `boolean`)

Default value: `false`

When `changesets version --snapshot` is used, the default behavior is to use `0.0.0` as the base version for the snapshot release.

Setting `useCalculatedVersion: true` will change the default behavior and will the planned version, based on the changesets files.

#### `prereleaseTemplate` (type: `string | undefined`)

Default value: `undefined` (see note below)

Configures the suffix for the snapshot releases, using a template with placeholders.

**Available placeholders:**

You can use the following placeholders for customizing the snapshot release version:

- `{tag}` - the name of the snapshot tag, as specified in `--snapshot something`
- `{commit}` - the Git commit ID
- `{timestamp}` - Unix timestamp of the time of the release
- `{datetime}` - date and time of the release (14 characters, for example, `20211213000730`)

> Note: if you are using `--snapshot` with empty tag name, you cannot use `{tag}` as placeholder - this will result in error.

### Integration with `useCalculatedVersion`

You can still use and pass `useCalculatedVersion: boolean` if you wish to have the snapshot releases based on the planned release of changesets, instead of `0.0.0`.

### Default behavior

If you are not specifying `prereleaseTemplate`, the default behavior will fall back to using the following template: `{tag}-{datetime}`, and in cases where the tag is empty (`--snapshot` with no tag name), it will use `{datetime}` only.
90 changes: 72 additions & 18 deletions packages/apply-release-plan/src/index.test.ts
Expand Up @@ -52,7 +52,10 @@ class FakeReleasePlan {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
},
...config
};
Expand Down Expand Up @@ -90,7 +93,10 @@ async function testSetup(
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
};
}
Expand Down Expand Up @@ -491,7 +497,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -554,7 +563,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -744,7 +756,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -829,7 +844,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -906,7 +924,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -983,7 +1004,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1063,7 +1087,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1148,7 +1175,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1225,7 +1255,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1302,7 +1335,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1383,7 +1419,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: true,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1545,7 +1584,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1650,7 +1692,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1735,7 +1780,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1824,7 +1872,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down Expand Up @@ -1927,7 +1978,10 @@ describe("apply release plan", () => {
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
}
);
Expand Down
8 changes: 6 additions & 2 deletions packages/assemble-release-plan/src/index.test.ts
Expand Up @@ -37,7 +37,9 @@ describe("assemble-release-plan", () => {
setup.packages,
defaultConfig,
undefined,
true
{
tag: undefined
}
);

expect(releases.length).toBe(1);
Expand All @@ -50,7 +52,9 @@ describe("assemble-release-plan", () => {
setup.packages,
defaultConfig,
undefined,
"foo"
{
tag: "foo"
}
);

expect(releases.length).toBe(1);
Expand Down