@changesets/assemble-release-plan
Advanced tools
Comparing version 5.1.3 to 5.2.0
# @changesets/assemble-release-plan | ||
## 5.2.0 | ||
### Minor Changes | ||
- [#858](https://github.com/changesets/changesets/pull/858) [`dd9b76f`](https://github.com/changesets/changesets/commit/dd9b76f162a546ae8b412e0cb10277f971f3585e) Thanks [@dotansimha](https://github.com/dotansimha)! - Added a new config option: `snapshot.prereleaseTemplate` for customizing the way snapshot release numbers are being composed. | ||
### Patch Changes | ||
- Updated dependencies [[`dd9b76f`](https://github.com/changesets/changesets/commit/dd9b76f162a546ae8b412e0cb10277f971f3585e)]: | ||
- @changesets/types@5.1.0 | ||
- @changesets/get-dependents-graph@1.3.3 | ||
## 5.1.3 | ||
@@ -4,0 +16,0 @@ |
@@ -447,14 +447,36 @@ 'use strict'; | ||
function getSnapshotSuffix(snapshot) { | ||
if (snapshot === undefined) { | ||
return; | ||
function getSnapshotSuffix(template, snapshotParameters) { | ||
let snapshotRefDate = new Date(); | ||
const placeholderValues = { | ||
commit: snapshotParameters.commit, | ||
tag: snapshotParameters.tag, | ||
timestamp: snapshotRefDate.getTime().toString(), | ||
datetime: snapshotRefDate.toISOString().replace(/\.\d{3}Z$/, "").replace(/[^\d]/g, "") | ||
}; // We need a special handling because we need to handle a case where `--snapshot` is used without any template, | ||
// and the resulting version needs to be composed without a tag. | ||
if (!template) { | ||
return [placeholderValues.tag, placeholderValues.datetime].filter(Boolean).join("-"); | ||
} | ||
let dateAndTime = new Date().toISOString().replace(/\.\d{3}Z$/, "").replace(/[^\d]/g, ""); | ||
let tag = ""; | ||
if (typeof snapshot === "string") tag = `-${snapshot}`; | ||
return `${tag}-${dateAndTime}`; | ||
const placeholders = Object.keys(placeholderValues); | ||
if (!template.includes(`{tag}`) && placeholderValues.tag !== undefined) { | ||
throw new Error(`Failed to compose snapshot version: "{tag}" placeholder is missing, but the snapshot parameter is defined (value: '${placeholderValues.tag}')`); | ||
} | ||
return placeholders.reduce((prev, key) => { | ||
return prev.replace(new RegExp(`\\{${key}\\}`, "g"), () => { | ||
const value = placeholderValues[key]; | ||
if (value === undefined) { | ||
throw new Error(`Failed to compose snapshot version: "{${key}}" placeholder is used without having a value defined!`); | ||
} | ||
return value; | ||
}); | ||
}, template); | ||
} | ||
function getNewVersion(release, preInfo, snapshotSuffix, useCalculatedVersionForSnapshots) { | ||
function getSnapshotVersion(release, preInfo, useCalculatedVersion, snapshotSuffix) { | ||
if (release.type === "none") { | ||
@@ -470,26 +492,26 @@ return release.oldVersion; | ||
* | ||
* You can set `useCalculatedVersionForSnapshots` flag to true to use calculated versions if you don't care about the above problem. | ||
* You can set `snapshot.useCalculatedVersion` flag to true to use calculated versions if you don't care about the above problem. | ||
*/ | ||
if (snapshotSuffix && !useCalculatedVersionForSnapshots) { | ||
return `0.0.0${snapshotSuffix}`; | ||
} | ||
const baseVersion = useCalculatedVersion ? incrementVersion(release, preInfo) : `0.0.0`; | ||
return `${baseVersion}-${snapshotSuffix}`; | ||
} | ||
const calculatedVersion = incrementVersion(release, preInfo); | ||
if (snapshotSuffix && useCalculatedVersionForSnapshots) { | ||
return `${calculatedVersion}${snapshotSuffix}`; | ||
function getNewVersion(release, preInfo) { | ||
if (release.type === "none") { | ||
return release.oldVersion; | ||
} | ||
return calculatedVersion; | ||
return incrementVersion(release, preInfo); | ||
} | ||
function assembleReleasePlan(changesets, packages, config, // intentionally not using an optional parameter here so the result of `readPreState` has to be passed in here | ||
preState, snapshot) { | ||
preState, // snapshot: undefined -> not using snaphot | ||
// snapshot: { tag: undefined } -> --snapshot (empty tag) | ||
// snapshot: { tag: "canary" } -> --snapshot canary | ||
snapshot) { | ||
let packagesByName = new Map(packages.packages.map(x => [x.packageJson.name, x])); | ||
const relevantChangesets = getRelevantChangesets(changesets, config.ignore, preState); | ||
const preInfo = getPreInfo(changesets, packagesByName, config, preState); // Caching the snapshot version here and use this if it is snapshot release | ||
const snapshotSuffix = getSnapshotSuffix(snapshot); // releases is, at this point a list of all packages we are going to releases, | ||
const preInfo = getPreInfo(changesets, packagesByName, config, preState); // releases is, at this point a list of all packages we are going to releases, | ||
// flattened down to one release per package, having a reference back to their | ||
@@ -539,4 +561,6 @@ // changesets, and with a calculated new versions | ||
} | ||
} | ||
} // Caching the snapshot version here and use this if it is snapshot release | ||
const snapshotSuffix = snapshot && getSnapshotSuffix(config.snapshot.prereleaseTemplate, snapshot); | ||
return { | ||
@@ -546,3 +570,3 @@ changesets: relevantChangesets, | ||
return _objectSpread2(_objectSpread2({}, incompleteRelease), {}, { | ||
newVersion: getNewVersion(incompleteRelease, preInfo, snapshotSuffix, config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.useCalculatedVersionForSnapshots) | ||
newVersion: snapshotSuffix ? getSnapshotVersion(incompleteRelease, preInfo, config.snapshot.useCalculatedVersion, snapshotSuffix) : getNewVersion(incompleteRelease, preInfo) | ||
}); | ||
@@ -549,0 +573,0 @@ }), |
@@ -222,18 +222,32 @@ "use strict"; | ||
function getSnapshotSuffix(snapshot) { | ||
if (void 0 === snapshot) return; | ||
let tag = ""; | ||
return "string" == typeof snapshot && (tag = "-" + snapshot), `${tag}-${(new Date).toISOString().replace(/\.\d{3}Z$/, "").replace(/[^\d]/g, "")}`; | ||
function getSnapshotSuffix(template, snapshotParameters) { | ||
let snapshotRefDate = new Date; | ||
const placeholderValues = { | ||
commit: snapshotParameters.commit, | ||
tag: snapshotParameters.tag, | ||
timestamp: snapshotRefDate.getTime().toString(), | ||
datetime: snapshotRefDate.toISOString().replace(/\.\d{3}Z$/, "").replace(/[^\d]/g, "") | ||
}; | ||
if (!template) return [ placeholderValues.tag, placeholderValues.datetime ].filter(Boolean).join("-"); | ||
const placeholders = Object.keys(placeholderValues); | ||
if (!template.includes("{tag}") && void 0 !== placeholderValues.tag) throw new Error(`Failed to compose snapshot version: "{tag}" placeholder is missing, but the snapshot parameter is defined (value: '${placeholderValues.tag}')`); | ||
return placeholders.reduce(((prev, key) => prev.replace(new RegExp(`\\{${key}\\}`, "g"), (() => { | ||
const value = placeholderValues[key]; | ||
if (void 0 === value) throw new Error(`Failed to compose snapshot version: "{${key}}" placeholder is used without having a value defined!`); | ||
return value; | ||
}))), template); | ||
} | ||
function getNewVersion(release, preInfo, snapshotSuffix, useCalculatedVersionForSnapshots) { | ||
function getSnapshotVersion(release, preInfo, useCalculatedVersion, snapshotSuffix) { | ||
if ("none" === release.type) return release.oldVersion; | ||
if (snapshotSuffix && !useCalculatedVersionForSnapshots) return "0.0.0" + snapshotSuffix; | ||
const calculatedVersion = incrementVersion(release, preInfo); | ||
return snapshotSuffix && useCalculatedVersionForSnapshots ? `${calculatedVersion}${snapshotSuffix}` : calculatedVersion; | ||
return `${useCalculatedVersion ? incrementVersion(release, preInfo) : "0.0.0"}-${snapshotSuffix}`; | ||
} | ||
function getNewVersion(release, preInfo) { | ||
return "none" === release.type ? release.oldVersion : incrementVersion(release, preInfo); | ||
} | ||
function assembleReleasePlan(changesets, packages, config, preState, snapshot) { | ||
let packagesByName = new Map(packages.packages.map((x => [ x.packageJson.name, x ]))); | ||
const relevantChangesets = getRelevantChangesets(changesets, config.ignore, preState), preInfo = getPreInfo(changesets, packagesByName, config, preState), snapshotSuffix = getSnapshotSuffix(snapshot); | ||
const relevantChangesets = getRelevantChangesets(changesets, config.ignore, preState), preInfo = getPreInfo(changesets, packagesByName, config, preState); | ||
let releases = flattenReleases(relevantChangesets, packagesByName, config.ignore), dependencyGraph = getDependentsGraph.getDependentsGraph(packages, { | ||
@@ -261,6 +275,7 @@ bumpVersionsWithWorkspaceProtocolOnly: config.bumpVersionsWithWorkspaceProtocolOnly | ||
} | ||
const snapshotSuffix = snapshot && getSnapshotSuffix(config.snapshot.prereleaseTemplate, snapshot); | ||
return { | ||
changesets: relevantChangesets, | ||
releases: [ ...releases.values() ].map((incompleteRelease => _objectSpread2(_objectSpread2({}, incompleteRelease), {}, { | ||
newVersion: getNewVersion(incompleteRelease, preInfo, snapshotSuffix, config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.useCalculatedVersionForSnapshots) | ||
newVersion: snapshotSuffix ? getSnapshotVersion(incompleteRelease, preInfo, config.snapshot.useCalculatedVersion, snapshotSuffix) : getNewVersion(incompleteRelease, preInfo) | ||
}))), | ||
@@ -267,0 +282,0 @@ preState: null == preInfo ? void 0 : preInfo.state |
@@ -439,14 +439,36 @@ import semver, { inc, parse } from 'semver'; | ||
function getSnapshotSuffix(snapshot) { | ||
if (snapshot === undefined) { | ||
return; | ||
function getSnapshotSuffix(template, snapshotParameters) { | ||
let snapshotRefDate = new Date(); | ||
const placeholderValues = { | ||
commit: snapshotParameters.commit, | ||
tag: snapshotParameters.tag, | ||
timestamp: snapshotRefDate.getTime().toString(), | ||
datetime: snapshotRefDate.toISOString().replace(/\.\d{3}Z$/, "").replace(/[^\d]/g, "") | ||
}; // We need a special handling because we need to handle a case where `--snapshot` is used without any template, | ||
// and the resulting version needs to be composed without a tag. | ||
if (!template) { | ||
return [placeholderValues.tag, placeholderValues.datetime].filter(Boolean).join("-"); | ||
} | ||
let dateAndTime = new Date().toISOString().replace(/\.\d{3}Z$/, "").replace(/[^\d]/g, ""); | ||
let tag = ""; | ||
if (typeof snapshot === "string") tag = `-${snapshot}`; | ||
return `${tag}-${dateAndTime}`; | ||
const placeholders = Object.keys(placeholderValues); | ||
if (!template.includes(`{tag}`) && placeholderValues.tag !== undefined) { | ||
throw new Error(`Failed to compose snapshot version: "{tag}" placeholder is missing, but the snapshot parameter is defined (value: '${placeholderValues.tag}')`); | ||
} | ||
return placeholders.reduce((prev, key) => { | ||
return prev.replace(new RegExp(`\\{${key}\\}`, "g"), () => { | ||
const value = placeholderValues[key]; | ||
if (value === undefined) { | ||
throw new Error(`Failed to compose snapshot version: "{${key}}" placeholder is used without having a value defined!`); | ||
} | ||
return value; | ||
}); | ||
}, template); | ||
} | ||
function getNewVersion(release, preInfo, snapshotSuffix, useCalculatedVersionForSnapshots) { | ||
function getSnapshotVersion(release, preInfo, useCalculatedVersion, snapshotSuffix) { | ||
if (release.type === "none") { | ||
@@ -462,26 +484,26 @@ return release.oldVersion; | ||
* | ||
* You can set `useCalculatedVersionForSnapshots` flag to true to use calculated versions if you don't care about the above problem. | ||
* You can set `snapshot.useCalculatedVersion` flag to true to use calculated versions if you don't care about the above problem. | ||
*/ | ||
if (snapshotSuffix && !useCalculatedVersionForSnapshots) { | ||
return `0.0.0${snapshotSuffix}`; | ||
} | ||
const baseVersion = useCalculatedVersion ? incrementVersion(release, preInfo) : `0.0.0`; | ||
return `${baseVersion}-${snapshotSuffix}`; | ||
} | ||
const calculatedVersion = incrementVersion(release, preInfo); | ||
if (snapshotSuffix && useCalculatedVersionForSnapshots) { | ||
return `${calculatedVersion}${snapshotSuffix}`; | ||
function getNewVersion(release, preInfo) { | ||
if (release.type === "none") { | ||
return release.oldVersion; | ||
} | ||
return calculatedVersion; | ||
return incrementVersion(release, preInfo); | ||
} | ||
function assembleReleasePlan(changesets, packages, config, // intentionally not using an optional parameter here so the result of `readPreState` has to be passed in here | ||
preState, snapshot) { | ||
preState, // snapshot: undefined -> not using snaphot | ||
// snapshot: { tag: undefined } -> --snapshot (empty tag) | ||
// snapshot: { tag: "canary" } -> --snapshot canary | ||
snapshot) { | ||
let packagesByName = new Map(packages.packages.map(x => [x.packageJson.name, x])); | ||
const relevantChangesets = getRelevantChangesets(changesets, config.ignore, preState); | ||
const preInfo = getPreInfo(changesets, packagesByName, config, preState); // Caching the snapshot version here and use this if it is snapshot release | ||
const snapshotSuffix = getSnapshotSuffix(snapshot); // releases is, at this point a list of all packages we are going to releases, | ||
const preInfo = getPreInfo(changesets, packagesByName, config, preState); // releases is, at this point a list of all packages we are going to releases, | ||
// flattened down to one release per package, having a reference back to their | ||
@@ -531,4 +553,6 @@ // changesets, and with a calculated new versions | ||
} | ||
} | ||
} // Caching the snapshot version here and use this if it is snapshot release | ||
const snapshotSuffix = snapshot && getSnapshotSuffix(config.snapshot.prereleaseTemplate, snapshot); | ||
return { | ||
@@ -538,3 +562,3 @@ changesets: relevantChangesets, | ||
return _objectSpread2(_objectSpread2({}, incompleteRelease), {}, { | ||
newVersion: getNewVersion(incompleteRelease, preInfo, snapshotSuffix, config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.useCalculatedVersionForSnapshots) | ||
newVersion: snapshotSuffix ? getSnapshotVersion(incompleteRelease, preInfo, config.snapshot.useCalculatedVersion, snapshotSuffix) : getNewVersion(incompleteRelease, preInfo) | ||
}); | ||
@@ -541,0 +565,0 @@ }), |
import { ReleasePlan, Config, NewChangeset, PreState } from "@changesets/types"; | ||
import { Packages } from "@manypkg/get-packages"; | ||
declare function assembleReleasePlan(changesets: NewChangeset[], packages: Packages, config: Config, preState: PreState | undefined, snapshot?: string | boolean): ReleasePlan; | ||
declare type SnapshotReleaseParameters = { | ||
tag?: string | undefined; | ||
commit?: string | undefined; | ||
}; | ||
declare function assembleReleasePlan(changesets: NewChangeset[], packages: Packages, config: Config, preState: PreState | undefined, snapshot?: SnapshotReleaseParameters): ReleasePlan; | ||
export default assembleReleasePlan; |
{ | ||
"name": "@changesets/assemble-release-plan", | ||
"version": "5.1.3", | ||
"version": "5.2.0", | ||
"description": "Reads changesets and adds information on dependents that need bumping", | ||
@@ -12,4 +12,4 @@ "main": "dist/assemble-release-plan.cjs.js", | ||
"@changesets/errors": "^0.1.4", | ||
"@changesets/get-dependents-graph": "^1.3.2", | ||
"@changesets/types": "^5.0.0", | ||
"@changesets/get-dependents-graph": "^1.3.3", | ||
"@changesets/types": "^5.1.0", | ||
"@manypkg/get-packages": "^1.1.3", | ||
@@ -16,0 +16,0 @@ "semver": "^5.4.1" |
@@ -40,3 +40,5 @@ import { defaultConfig } from "@changesets/config"; | ||
undefined, | ||
true | ||
{ | ||
tag: undefined | ||
} | ||
); | ||
@@ -54,3 +56,5 @@ | ||
undefined, | ||
"foo" | ||
{ | ||
tag: "foo" | ||
} | ||
); | ||
@@ -57,0 +61,0 @@ |
112
src/index.ts
@@ -19,2 +19,7 @@ import { | ||
type SnapshotReleaseParameters = { | ||
tag?: string | undefined; | ||
commit?: string | undefined; | ||
}; | ||
function getPreVersion(version: string) { | ||
@@ -31,23 +36,55 @@ let parsed = semver.parse(version)!; | ||
function getSnapshotSuffix(snapshot?: string | boolean): string | undefined { | ||
if (snapshot === undefined) { | ||
return; | ||
function getSnapshotSuffix( | ||
template: Config["snapshot"]["prereleaseTemplate"], | ||
snapshotParameters: SnapshotReleaseParameters | ||
): string { | ||
let snapshotRefDate = new Date(); | ||
const placeholderValues = { | ||
commit: snapshotParameters.commit, | ||
tag: snapshotParameters.tag, | ||
timestamp: snapshotRefDate.getTime().toString(), | ||
datetime: snapshotRefDate | ||
.toISOString() | ||
.replace(/\.\d{3}Z$/, "") | ||
.replace(/[^\d]/g, "") | ||
}; | ||
// We need a special handling because we need to handle a case where `--snapshot` is used without any template, | ||
// and the resulting version needs to be composed without a tag. | ||
if (!template) { | ||
return [placeholderValues.tag, placeholderValues.datetime] | ||
.filter(Boolean) | ||
.join("-"); | ||
} | ||
let dateAndTime = new Date() | ||
.toISOString() | ||
.replace(/\.\d{3}Z$/, "") | ||
.replace(/[^\d]/g, ""); | ||
let tag = ""; | ||
const placeholders = Object.keys(placeholderValues) as Array< | ||
keyof typeof placeholderValues | ||
>; | ||
if (typeof snapshot === "string") tag = `-${snapshot}`; | ||
if (!template.includes(`{tag}`) && placeholderValues.tag !== undefined) { | ||
throw new Error( | ||
`Failed to compose snapshot version: "{tag}" placeholder is missing, but the snapshot parameter is defined (value: '${placeholderValues.tag}')` | ||
); | ||
} | ||
return `${tag}-${dateAndTime}`; | ||
return placeholders.reduce((prev, key) => { | ||
return prev.replace(new RegExp(`\\{${key}\\}`, "g"), () => { | ||
const value = placeholderValues[key]; | ||
if (value === undefined) { | ||
throw new Error( | ||
`Failed to compose snapshot version: "{${key}}" placeholder is used without having a value defined!` | ||
); | ||
} | ||
return value; | ||
}); | ||
}, template); | ||
} | ||
function getNewVersion( | ||
function getSnapshotVersion( | ||
release: InternalRelease, | ||
preInfo: PreInfo | undefined, | ||
snapshotSuffix: string | undefined, | ||
useCalculatedVersionForSnapshots: boolean | ||
useCalculatedVersion: boolean, | ||
snapshotSuffix: string | ||
): string { | ||
@@ -57,2 +94,3 @@ if (release.type === "none") { | ||
} | ||
/** | ||
@@ -65,15 +103,20 @@ * Using version as 0.0.0 so that it does not hinder with other version release | ||
* | ||
* You can set `useCalculatedVersionForSnapshots` flag to true to use calculated versions if you don't care about the above problem. | ||
* You can set `snapshot.useCalculatedVersion` flag to true to use calculated versions if you don't care about the above problem. | ||
*/ | ||
if (snapshotSuffix && !useCalculatedVersionForSnapshots) { | ||
return `0.0.0${snapshotSuffix}`; | ||
} | ||
const baseVersion = useCalculatedVersion | ||
? incrementVersion(release, preInfo) | ||
: `0.0.0`; | ||
const calculatedVersion = incrementVersion(release, preInfo); | ||
return `${baseVersion}-${snapshotSuffix}`; | ||
} | ||
if (snapshotSuffix && useCalculatedVersionForSnapshots) { | ||
return `${calculatedVersion}${snapshotSuffix}`; | ||
function getNewVersion( | ||
release: InternalRelease, | ||
preInfo: PreInfo | undefined | ||
): string { | ||
if (release.type === "none") { | ||
return release.oldVersion; | ||
} | ||
return calculatedVersion; | ||
return incrementVersion(release, preInfo); | ||
} | ||
@@ -87,3 +130,6 @@ | ||
preState: PreState | undefined, | ||
snapshot?: string | boolean | ||
// snapshot: undefined -> not using snaphot | ||
// snapshot: { tag: undefined } -> --snapshot (empty tag) | ||
// snapshot: { tag: "canary" } -> --snapshot canary | ||
snapshot?: SnapshotReleaseParameters | ||
): ReleasePlan { | ||
@@ -102,5 +148,2 @@ let packagesByName = new Map( | ||
// Caching the snapshot version here and use this if it is snapshot release | ||
const snapshotSuffix = getSnapshotSuffix(snapshot); | ||
// releases is, at this point a list of all packages we are going to releases, | ||
@@ -167,2 +210,6 @@ // flattened down to one release per package, having a reference back to their | ||
// Caching the snapshot version here and use this if it is snapshot release | ||
const snapshotSuffix = | ||
snapshot && getSnapshotSuffix(config.snapshot.prereleaseTemplate, snapshot); | ||
return { | ||
@@ -173,9 +220,10 @@ changesets: relevantChangesets, | ||
...incompleteRelease, | ||
newVersion: getNewVersion( | ||
incompleteRelease, | ||
preInfo, | ||
snapshotSuffix, | ||
config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH | ||
.useCalculatedVersionForSnapshots | ||
) | ||
newVersion: snapshotSuffix | ||
? getSnapshotVersion( | ||
incompleteRelease, | ||
preInfo, | ||
config.snapshot.useCalculatedVersion, | ||
snapshotSuffix | ||
) | ||
: getNewVersion(incompleteRelease, preInfo) | ||
}; | ||
@@ -182,0 +230,0 @@ }), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162526
3625