Skip to content

Commit

Permalink
Make snapshot. useCalculatedVersion a stable option and introduce `…
Browse files Browse the repository at this point in the history
…snapshot.prereleaseTemplate` option (#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>
  • Loading branch information
dotansimha and Andarist committed Jul 22, 2022
1 parent 5af3f2f commit dd9b76f
Show file tree
Hide file tree
Showing 21 changed files with 604 additions and 135 deletions.
28 changes: 28 additions & 0 deletions .changeset/olive-ducks-camp.md
@@ -0,0 +1,28 @@
---
"@changesets/cli": patch
"@changesets/config": patch
---

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`.

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

Old usage (still works, but comes with a deprecated warning):

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

New usage:

```json
{
"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: `snapshot.prereleaseTemplate` for customizing the way snapshot release numbers are being composed.
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
39 changes: 38 additions & 1 deletion docs/config-file-options.md
Expand Up @@ -14,7 +14,7 @@ Changesets has a minimal amount of configuration options. Mostly these are for w
}
```

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

Expand Down Expand Up @@ -156,3 +156,40 @@ You would specify our github changelog generator with:
```

For more details on these functions and information on how to write your own see [changelog-functions](./modifying-changelog-format.md)

## `bumpVersionsWithWorkspaceProtocolOnly` (boolean)

Determines whether Changesets should only bump dependency ranges that use workspace protocol of packages that are part of the workspace.

## `snapshot` (object or undefined)

Default value: `undefined`

### `useCalculatedVersion` (optional 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 use the calculated version, based on the changeset files.

### `prereleaseTemplate` (optional string)

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.
**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.
17 changes: 17 additions & 0 deletions docs/experimental-options.md
@@ -0,0 +1,17 @@
# 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.
126 changes: 90 additions & 36 deletions packages/apply-release-plan/src/index.test.ts
Expand Up @@ -51,8 +51,11 @@ class FakeReleasePlan {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
},
...config
};
Expand Down Expand Up @@ -87,10 +90,13 @@ async function testSetup(
baseBranch: "main",
updateInternalDependencies: "patch",
ignore: [],
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
},
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
}
};
}
Expand Down Expand Up @@ -490,8 +496,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -553,8 +562,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -743,8 +755,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -828,8 +843,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -905,8 +923,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -982,8 +1003,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1062,8 +1086,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1147,8 +1174,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1224,8 +1254,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1301,8 +1334,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1382,8 +1418,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: true,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1544,8 +1583,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1649,8 +1691,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1734,8 +1779,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1823,8 +1871,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down Expand Up @@ -1926,8 +1977,11 @@ describe("apply release plan", () => {
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
updateInternalDependents: "out-of-range",
useCalculatedVersionForSnapshots: false
updateInternalDependents: "out-of-range"
},
snapshot: {
useCalculatedVersion: false,
prereleaseTemplate: null
}
}
);
Expand Down

0 comments on commit dd9b76f

Please sign in to comment.