diff --git a/lib/release-ops.js b/lib/release-ops.js index 3c1acfa..470b29f 100644 --- a/lib/release-ops.js +++ b/lib/release-ops.js @@ -139,7 +139,9 @@ function getPrereleaseVersion(currentVersion, prereleaseId, releaseType) { * @private */ function getVersionTags() { - const tags = ShellOps.execSilent("git tag").trim().split("\n"); + + // Using `--merged` to only list tags whose commits are reachable from HEAD + const tags = ShellOps.execSilent("git tag --merged").trim().split("\n"); return tags.reduce((list, tag) => { if (semver.valid(tag)) { @@ -370,9 +372,10 @@ function writeChangelog(releaseInfo) { * Creates a release version tag and pushes to origin and npm. * @param {string} [prereleaseId] The prerelease ID (alpha, beta, rc, etc.). * Only include when doing a prerelease. + * @param {string} [packageTag] Tag added to the package submitted to the npm registry. * @returns {Object} The information about the release. */ -function generateRelease(prereleaseId) { +function generateRelease(prereleaseId, packageTag = prereleaseId ? "next" : "latest") { validateSetup(); @@ -382,7 +385,10 @@ function generateRelease(prereleaseId) { console.log("Calculating changes for release"); const releaseInfo = calculateReleaseInfo(prereleaseId); + releaseInfo.packageTag = packageTag; + console.log("Release is %s", releaseInfo.version); + console.log("Package tag is %s", releaseInfo.packageTag); console.log("Generating changelog"); writeChangelog(releaseInfo); @@ -444,7 +450,8 @@ function publishReleaseToGitHub(releaseInfo) { return repo.createRelease({ tag_name: tag, // eslint-disable-line camelcase body: generateReleaseBody(releaseInfo.changelog), - prerelease: !!semver.prerelease(releaseInfo.version) + prerelease: !!semver.prerelease(releaseInfo.version), + make_latest: String(releaseInfo.packageTag === "latest") // eslint-disable-line camelcase }).then(() => { console.log("Posted release notes to GitHub"); }).catch(ex => { @@ -480,11 +487,7 @@ function publishRelease() { // if there's a prerelease ID, publish under "next" tag console.log("Publishing to npm"); - let command = "npm publish"; - - if (semver.prerelease(releaseInfo.version)) { - command += " --tag next"; - } + let command = `npm publish --tag ${releaseInfo.packageTag}`; if (process.env.NPM_OTP && /^\d+$/.test(process.env.NPM_OTP)) { command += ` --otp=${process.env.NPM_OTP}`;