Skip to content

Commit dd9b76f

Browse files
dotansimhaAndarist
andauthored
Make snapshot. useCalculatedVersion a stable option and introduce snapshot.prereleaseTemplate option (changesets#858)
* Added `getCurrentCommitId` helper * Added snapshotPreidTemplate * added changeset * fix lint * fix ts build issues * moved experimental docs to a new file added docs for all existing experimental flags fixed typos * use regex for replacing placeholders * improve Date mocks in tests * prevent `--snapshot name` without `{tag}` placeholder * fix lint * Allow `--snapshot-preid-template` in cli * simplify cli->assembleReleasePlan interface improve validation for snapshot tags * remove the dateRef from assembleReleasePlan and calcualte it internally * Migrate to unified `snapshot` flag in config * Make `snapshot` stable, avoid breaking changes and keep supporting `useCalculatedVersionForSnapshots` * Tweak `mockGlobalDate` * Refactor code around creating snapshot suffix * Bring back the comment related to 0.0.0 versions used in snapshots by default * Update .changeset/strong-geckos-divide.md * Update .changeset/olive-ducks-camp.md * Fixed `--snapshot-prerelease-template` CLI param in the help string * Remove `null` from `WrittenConfig["snapshot"]["prereleaseTemplate"]` * Juggle some docs and update `schema.json` * Only get the current commit if the template uses the `{commit}` variable Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
1 parent 5af3f2f commit dd9b76f

21 files changed

Lines changed: 604 additions & 135 deletions

File tree

.changeset/olive-ducks-camp.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
"@changesets/cli": patch
3+
"@changesets/config": patch
4+
---
5+
6+
A possibility to use the calculated version for snapshot releases is now stable 🥳 All snapshot-related config parameters are now grouped under a single config property called `snapshot`.
7+
8+
To migrate, make sure to update your `config.json`.
9+
10+
Old usage (still works, but comes with a deprecated warning):
11+
12+
```json
13+
{
14+
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
15+
"useCalculatedVersionForSnapshots": true
16+
}
17+
}
18+
```
19+
20+
New usage:
21+
22+
```json
23+
{
24+
"snapshot": {
25+
"useCalculatedVersion": true
26+
}
27+
}
28+
```

.changeset/quick-squids-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/cli": minor
3+
---
4+
5+
Added a new config flag for `changesets version --snapshot` mode: `--snapshot-prerelease-template`

.changeset/short-cats-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/git": minor
3+
---
4+
5+
Added a new helper function: `getCurrentCommitId`

.changeset/strong-geckos-divide.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@changesets/assemble-release-plan": minor
3+
"@changesets/cli": minor
4+
"@changesets/config": minor
5+
"@changesets/types": minor
6+
---
7+
8+
Added a new config option: `snapshot.prereleaseTemplate` for customizing the way snapshot release numbers are being composed.

.vscode/settings.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib"
3-
}
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"grammarly.selectors": [
4+
{
5+
"language": "markdown",
6+
"scheme": "file"
7+
}
8+
]
9+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ To make releasing easier, you can use [this changesets github action](https://gi
5555
- [Prereleases](./docs/prereleases.md)
5656
- [Problems publishing in monorepos](./docs/problems-publishing-in-monorepos.md)
5757
- [Snapshot releases](./docs/snapshot-releases.md)
58+
- [Experimental Options](./docs/experimental-options.md)
5859

5960
## Cool Projects already using Changesets for versioning and changelogs
6061

docs/config-file-options.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Changesets has a minimal amount of configuration options. Mostly these are for w
1414
}
1515
```
1616

17-
> NOTE: the `linked`, `updateInternalDependencies`, and `ignore` options are only for behaviour in monorepos.
17+
> NOTE: the `linked`, `fixed`, `updateInternalDependencies`, `bumpVersionsWithWorkspaceProtocolOnly`, and `ignore` options are only for behaviour in monorepos.
1818
1919
## `commit` (`boolean`, or module path as a `string`, or a tuple like `[modulePath: string, options: any]`)
2020

@@ -156,3 +156,40 @@ You would specify our github changelog generator with:
156156
```
157157

158158
For more details on these functions and information on how to write your own see [changelog-functions](./modifying-changelog-format.md)
159+
160+
## `bumpVersionsWithWorkspaceProtocolOnly` (boolean)
161+
162+
Determines whether Changesets should only bump dependency ranges that use workspace protocol of packages that are part of the workspace.
163+
164+
## `snapshot` (object or undefined)
165+
166+
Default value: `undefined`
167+
168+
### `useCalculatedVersion` (optional boolean)
169+
170+
Default value: `false`
171+
172+
When `changesets version --snapshot` is used, the default behavior is to use `0.0.0` as the base version for the snapshot release.
173+
174+
Setting `useCalculatedVersion: true` will change the default behavior and will use the calculated version, based on the changeset files.
175+
176+
### `prereleaseTemplate` (optional string)
177+
178+
Default value: `undefined` (see note below)
179+
180+
Configures the suffix for the snapshot releases, using a template with placeholders.
181+
182+
**Available placeholders:**
183+
184+
You can use the following placeholders for customizing the snapshot release version:
185+
186+
- `{tag}` - the name of the snapshot tag, as specified in `--snapshot something`
187+
- `{commit}` - the Git commit ID
188+
- `{timestamp}` - Unix timestamp of the time of the release
189+
- `{datetime}` - date and time of the release (14 characters, for example, `20211213000730`)
190+
191+
> Note: if you are using `--snapshot` with empty tag name, you cannot use `{tag}` as placeholder - this will result in error.
192+
193+
**Default behavior**
194+
195+
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.

docs/experimental-options.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Experimental Options
2+
3+
All experimental options are configured in `config.json` under `___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH` flag.
4+
5+
> Please use these experimental flags with caution, and please pay attention to release notes - these config flags might change in patch versions.
6+
7+
## `updateInternalDependents` (type: `'out-of-range' | 'always'`)
8+
9+
Default value: `out-of-range`.
10+
11+
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.
12+
13+
## `onlyUpdatePeerDependentsWhenOutOfRange` (type: `boolean`)
14+
15+
Default value: `false`
16+
17+
When set to `true`, Changesets will only bump peer dependents when `peerDependencies` are leaving the range.

packages/apply-release-plan/src/index.test.ts

Lines changed: 90 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ class FakeReleasePlan {
5151
ignore: [],
5252
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
5353
onlyUpdatePeerDependentsWhenOutOfRange: false,
54-
updateInternalDependents: "out-of-range",
55-
useCalculatedVersionForSnapshots: false
54+
updateInternalDependents: "out-of-range"
55+
},
56+
snapshot: {
57+
useCalculatedVersion: false,
58+
prereleaseTemplate: null
5659
},
5760
...config
5861
};
@@ -87,10 +90,13 @@ async function testSetup(
8790
baseBranch: "main",
8891
updateInternalDependencies: "patch",
8992
ignore: [],
93+
snapshot: {
94+
useCalculatedVersion: false,
95+
prereleaseTemplate: null
96+
},
9097
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
9198
onlyUpdatePeerDependentsWhenOutOfRange: false,
92-
updateInternalDependents: "out-of-range",
93-
useCalculatedVersionForSnapshots: false
99+
updateInternalDependents: "out-of-range"
94100
}
95101
};
96102
}
@@ -490,8 +496,11 @@ describe("apply release plan", () => {
490496
ignore: [],
491497
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
492498
onlyUpdatePeerDependentsWhenOutOfRange: false,
493-
updateInternalDependents: "out-of-range",
494-
useCalculatedVersionForSnapshots: false
499+
updateInternalDependents: "out-of-range"
500+
},
501+
snapshot: {
502+
useCalculatedVersion: false,
503+
prereleaseTemplate: null
495504
}
496505
}
497506
);
@@ -553,8 +562,11 @@ describe("apply release plan", () => {
553562
ignore: [],
554563
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
555564
onlyUpdatePeerDependentsWhenOutOfRange: false,
556-
updateInternalDependents: "out-of-range",
557-
useCalculatedVersionForSnapshots: false
565+
updateInternalDependents: "out-of-range"
566+
},
567+
snapshot: {
568+
useCalculatedVersion: false,
569+
prereleaseTemplate: null
558570
}
559571
}
560572
);
@@ -743,8 +755,11 @@ describe("apply release plan", () => {
743755
ignore: [],
744756
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
745757
onlyUpdatePeerDependentsWhenOutOfRange: false,
746-
updateInternalDependents: "out-of-range",
747-
useCalculatedVersionForSnapshots: false
758+
updateInternalDependents: "out-of-range"
759+
},
760+
snapshot: {
761+
useCalculatedVersion: false,
762+
prereleaseTemplate: null
748763
}
749764
}
750765
);
@@ -828,8 +843,11 @@ describe("apply release plan", () => {
828843
ignore: [],
829844
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
830845
onlyUpdatePeerDependentsWhenOutOfRange: false,
831-
updateInternalDependents: "out-of-range",
832-
useCalculatedVersionForSnapshots: false
846+
updateInternalDependents: "out-of-range"
847+
},
848+
snapshot: {
849+
useCalculatedVersion: false,
850+
prereleaseTemplate: null
833851
}
834852
}
835853
);
@@ -905,8 +923,11 @@ describe("apply release plan", () => {
905923
ignore: [],
906924
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
907925
onlyUpdatePeerDependentsWhenOutOfRange: false,
908-
updateInternalDependents: "out-of-range",
909-
useCalculatedVersionForSnapshots: false
926+
updateInternalDependents: "out-of-range"
927+
},
928+
snapshot: {
929+
useCalculatedVersion: false,
930+
prereleaseTemplate: null
910931
}
911932
}
912933
);
@@ -982,8 +1003,11 @@ describe("apply release plan", () => {
9821003
ignore: [],
9831004
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
9841005
onlyUpdatePeerDependentsWhenOutOfRange: false,
985-
updateInternalDependents: "out-of-range",
986-
useCalculatedVersionForSnapshots: false
1006+
updateInternalDependents: "out-of-range"
1007+
},
1008+
snapshot: {
1009+
useCalculatedVersion: false,
1010+
prereleaseTemplate: null
9871011
}
9881012
}
9891013
);
@@ -1062,8 +1086,11 @@ describe("apply release plan", () => {
10621086
ignore: [],
10631087
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
10641088
onlyUpdatePeerDependentsWhenOutOfRange: false,
1065-
updateInternalDependents: "out-of-range",
1066-
useCalculatedVersionForSnapshots: false
1089+
updateInternalDependents: "out-of-range"
1090+
},
1091+
snapshot: {
1092+
useCalculatedVersion: false,
1093+
prereleaseTemplate: null
10671094
}
10681095
}
10691096
);
@@ -1147,8 +1174,11 @@ describe("apply release plan", () => {
11471174
ignore: [],
11481175
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
11491176
onlyUpdatePeerDependentsWhenOutOfRange: false,
1150-
updateInternalDependents: "out-of-range",
1151-
useCalculatedVersionForSnapshots: false
1177+
updateInternalDependents: "out-of-range"
1178+
},
1179+
snapshot: {
1180+
useCalculatedVersion: false,
1181+
prereleaseTemplate: null
11521182
}
11531183
}
11541184
);
@@ -1224,8 +1254,11 @@ describe("apply release plan", () => {
12241254
ignore: [],
12251255
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
12261256
onlyUpdatePeerDependentsWhenOutOfRange: false,
1227-
updateInternalDependents: "out-of-range",
1228-
useCalculatedVersionForSnapshots: false
1257+
updateInternalDependents: "out-of-range"
1258+
},
1259+
snapshot: {
1260+
useCalculatedVersion: false,
1261+
prereleaseTemplate: null
12291262
}
12301263
}
12311264
);
@@ -1301,8 +1334,11 @@ describe("apply release plan", () => {
13011334
ignore: [],
13021335
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
13031336
onlyUpdatePeerDependentsWhenOutOfRange: false,
1304-
updateInternalDependents: "out-of-range",
1305-
useCalculatedVersionForSnapshots: false
1337+
updateInternalDependents: "out-of-range"
1338+
},
1339+
snapshot: {
1340+
useCalculatedVersion: false,
1341+
prereleaseTemplate: null
13061342
}
13071343
}
13081344
);
@@ -1382,8 +1418,11 @@ describe("apply release plan", () => {
13821418
ignore: [],
13831419
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
13841420
onlyUpdatePeerDependentsWhenOutOfRange: true,
1385-
updateInternalDependents: "out-of-range",
1386-
useCalculatedVersionForSnapshots: false
1421+
updateInternalDependents: "out-of-range"
1422+
},
1423+
snapshot: {
1424+
useCalculatedVersion: false,
1425+
prereleaseTemplate: null
13871426
}
13881427
}
13891428
);
@@ -1544,8 +1583,11 @@ describe("apply release plan", () => {
15441583
ignore: [],
15451584
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
15461585
onlyUpdatePeerDependentsWhenOutOfRange: false,
1547-
updateInternalDependents: "out-of-range",
1548-
useCalculatedVersionForSnapshots: false
1586+
updateInternalDependents: "out-of-range"
1587+
},
1588+
snapshot: {
1589+
useCalculatedVersion: false,
1590+
prereleaseTemplate: null
15491591
}
15501592
}
15511593
);
@@ -1649,8 +1691,11 @@ describe("apply release plan", () => {
16491691
ignore: [],
16501692
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
16511693
onlyUpdatePeerDependentsWhenOutOfRange: false,
1652-
updateInternalDependents: "out-of-range",
1653-
useCalculatedVersionForSnapshots: false
1694+
updateInternalDependents: "out-of-range"
1695+
},
1696+
snapshot: {
1697+
useCalculatedVersion: false,
1698+
prereleaseTemplate: null
16541699
}
16551700
}
16561701
);
@@ -1734,8 +1779,11 @@ describe("apply release plan", () => {
17341779
ignore: [],
17351780
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
17361781
onlyUpdatePeerDependentsWhenOutOfRange: false,
1737-
updateInternalDependents: "out-of-range",
1738-
useCalculatedVersionForSnapshots: false
1782+
updateInternalDependents: "out-of-range"
1783+
},
1784+
snapshot: {
1785+
useCalculatedVersion: false,
1786+
prereleaseTemplate: null
17391787
}
17401788
}
17411789
);
@@ -1823,8 +1871,11 @@ describe("apply release plan", () => {
18231871
ignore: [],
18241872
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
18251873
onlyUpdatePeerDependentsWhenOutOfRange: false,
1826-
updateInternalDependents: "out-of-range",
1827-
useCalculatedVersionForSnapshots: false
1874+
updateInternalDependents: "out-of-range"
1875+
},
1876+
snapshot: {
1877+
useCalculatedVersion: false,
1878+
prereleaseTemplate: null
18281879
}
18291880
}
18301881
);
@@ -1926,8 +1977,11 @@ describe("apply release plan", () => {
19261977
ignore: [],
19271978
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
19281979
onlyUpdatePeerDependentsWhenOutOfRange: false,
1929-
updateInternalDependents: "out-of-range",
1930-
useCalculatedVersionForSnapshots: false
1980+
updateInternalDependents: "out-of-range"
1981+
},
1982+
snapshot: {
1983+
useCalculatedVersion: false,
1984+
prereleaseTemplate: null
19311985
}
19321986
}
19331987
);

0 commit comments

Comments
 (0)