@npmcli/template-oss 4.19.0 → 4.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +35 -11
  2. package/bin/release-manager.js +23 -271
  3. package/bin/release-please.js +20 -55
  4. package/lib/config.js +98 -119
  5. package/lib/content/{_job-matrix.yml → _job-matrix-yml.hbs} +1 -1
  6. package/lib/content/_job-release-integration-yml.hbs +51 -0
  7. package/lib/content/{_job.yml → _job-yml.hbs} +1 -1
  8. package/lib/content/_step-node-yml.hbs +15 -0
  9. package/lib/content/_steps-setup-yml.hbs +15 -0
  10. package/lib/content/action-create-check-yml.hbs +50 -0
  11. package/lib/content/action-install-latest-npm-yml.hbs +55 -0
  12. package/lib/content/{audit.yml → audit-yml.hbs} +2 -2
  13. package/lib/content/ci-release-yml.hbs +49 -0
  14. package/lib/content/ci-yml.hbs +13 -0
  15. package/lib/content/{codeql-analysis.yml → codeql-analysis-yml.hbs} +1 -1
  16. package/lib/content/{eslintrc.js → eslintrc-js.hbs} +11 -1
  17. package/lib/content/{gitignore → gitignore.hbs} +2 -0
  18. package/lib/content/index.js +55 -40
  19. package/lib/content/{pkg.json → package-json.hbs} +19 -5
  20. package/lib/content/{post-dependabot.yml → post-dependabot-yml.hbs} +1 -1
  21. package/lib/content/{pull-request.yml → pull-request-yml.hbs} +3 -5
  22. package/lib/content/release-integration-yml.hbs +24 -0
  23. package/lib/content/release-please-config-json.hbs +23 -0
  24. package/lib/content/release-yml.hbs +245 -0
  25. package/lib/content/tsconfig-json.hbs +17 -0
  26. package/lib/release/changelog.js +184 -0
  27. package/lib/release/node-workspace-format.js +107 -0
  28. package/lib/release/node-workspace.js +95 -0
  29. package/lib/release/release-manager.js +287 -0
  30. package/lib/release/release-please.js +180 -0
  31. package/lib/release/util.js +42 -0
  32. package/lib/util/files.js +29 -20
  33. package/lib/util/get-cmd-path.js +36 -0
  34. package/lib/util/git.js +6 -2
  35. package/lib/util/import-or-require.js +29 -0
  36. package/lib/util/parser.js +6 -1
  37. package/lib/util/path.js +13 -0
  38. package/lib/util/template.js +9 -6
  39. package/package.json +21 -13
  40. package/lib/content/_job-release-integration.yml +0 -59
  41. package/lib/content/_step-checks.yml +0 -54
  42. package/lib/content/_step-node.yml +0 -57
  43. package/lib/content/_steps-setup.yml +0 -6
  44. package/lib/content/ci-release.yml +0 -37
  45. package/lib/content/ci.yml +0 -13
  46. package/lib/content/release-please-config.json +0 -13
  47. package/lib/content/release.yml +0 -217
  48. package/lib/release-please/changelog.js +0 -92
  49. package/lib/release-please/github.js +0 -72
  50. package/lib/release-please/index.js +0 -262
  51. package/lib/release-please/node-workspace.js +0 -192
  52. package/lib/release-please/util.js +0 -14
  53. package/lib/release-please/version.js +0 -103
  54. /package/lib/content/{CODEOWNERS → CODEOWNERS.hbs} +0 -0
  55. /package/lib/content/{CODE_OF_CONDUCT.md → CODE_OF_CONDUCT-md.hbs} +0 -0
  56. /package/lib/content/{CONTRIBUTING.md → CONTRIBUTING-md.hbs} +0 -0
  57. /package/lib/content/{LICENSE.md → LICENSE-md.hbs} +0 -0
  58. /package/lib/content/{SECURITY.md → SECURITY-md.hbs} +0 -0
  59. /package/lib/content/{_on-ci.yml → _on-ci-yml.hbs} +0 -0
  60. /package/lib/content/{_step-audit.yml → _step-audit-yml.hbs} +0 -0
  61. /package/lib/content/{_step-deps.yml → _step-deps-yml.hbs} +0 -0
  62. /package/lib/content/{_step-git.yml → _step-git-yml.hbs} +0 -0
  63. /package/lib/content/{_step-lint.yml → _step-lint-yml.hbs} +0 -0
  64. /package/lib/content/{_step-test.yml → _step-test-yml.hbs} +0 -0
  65. /package/lib/content/{bug.yml → bug-yml.hbs} +0 -0
  66. /package/lib/content/{commitlintrc.js → commitlintrc-js.hbs} +0 -0
  67. /package/lib/content/{config.yml → config-yml.hbs} +0 -0
  68. /package/lib/content/{dependabot.yml → dependabot-yml.hbs} +0 -0
  69. /package/lib/content/{npmrc → npmrc.hbs} +0 -0
  70. /package/lib/content/{release-please-manifest.json → release-please-manifest-json.hbs} +0 -0
  71. /package/lib/content/{settings.yml → settings-yml.hbs} +0 -0
  72. /package/lib/content/{tap.json → tap-json.hbs} +0 -0
@@ -1,262 +0,0 @@
1
- const RP = require('release-please')
2
- const { CheckpointLogger } = require('release-please/build/src/util/logger.js')
3
- const ChangelogNotes = require('./changelog.js')
4
- const Version = require('./version.js')
5
- const NodeWs = require('./node-workspace.js')
6
-
7
- const logger = new CheckpointLogger(true, true)
8
- RP.setLogger(logger)
9
- RP.registerChangelogNotes('default', (o) => new ChangelogNotes(o))
10
- RP.registerVersioningStrategy('default', (o) => new Version(o))
11
- RP.registerPlugin('node-workspace', (o) => new NodeWs(o.github, o.targetBranch, o.repositoryConfig))
12
-
13
- const omit = (obj, ...keys) => {
14
- const res = {}
15
- for (const [key, value] of Object.entries(obj)) {
16
- if (!keys.includes(key)) {
17
- res[key] = value
18
- }
19
- }
20
- return res
21
- }
22
-
23
- const getManifest = async ({ repo: fullRepo, token, branch }) => {
24
- const fullRepoParts = fullRepo.split('/')
25
- const github = await RP.GitHub.create({
26
- owner: fullRepoParts[0],
27
- repo: fullRepoParts[1],
28
- token,
29
- })
30
-
31
- const { octokit, repository: { owner, repo, defaultBranch } } = github
32
-
33
- const baseBranch = branch ?? defaultBranch
34
-
35
- // This is mostly for testing and debugging. Use environs with the
36
- // format `RELEASE_PLEASE_<manfiestOverrideConfigName>` (eg
37
- // `RELEASE_PLEASE_lastReleaseSha=<SHA>`) to set one-off config items
38
- // for the release please run without needing to commit and push the config.
39
- const manifestOverrides = Object.entries(process.env)
40
- .filter(([k, v]) => k.startsWith('RELEASE_PLEASE_') && v != null)
41
- .map(([k, v]) => [k.replace('RELEASE_PLEASE_', ''), v])
42
-
43
- const manifest = await RP.Manifest.fromManifest(
44
- github,
45
- baseBranch,
46
- undefined,
47
- undefined,
48
- Object.fromEntries(manifestOverrides)
49
- )
50
-
51
- return {
52
- github,
53
- manifest,
54
- octokit,
55
- owner,
56
- repo,
57
- baseBranch,
58
- }
59
- }
60
-
61
- const getReleasesFromPr = async ({ manifest, github, number }) => {
62
- const baseUrl = `https://github.com/${github.repository.owner}/${github.repository.repo}`
63
- // get the release please formatted pull request
64
- let pullRequest
65
- const prGenerator = github.pullRequestIterator(this.targetBranch, 'MERGED', 200, false)
66
- for await (const pr of prGenerator) {
67
- if (pr.number === number) {
68
- pullRequest = pr
69
- break
70
- }
71
- }
72
- const strategiesByPath = await manifest.getStrategiesByPath()
73
- const releases = []
74
- for (const path in manifest.repositoryConfig) {
75
- const config = manifest.repositoryConfig[path]
76
- const release = await strategiesByPath[path].buildRelease(pullRequest)
77
- if (release) {
78
- const { tag, ...rest } = release
79
- releases.push({
80
- ...rest,
81
- ...tag.version,
82
- tagName: tag.toString(),
83
- version: tag.version.toString(),
84
- path,
85
- draft: false,
86
- url: `${baseUrl}/releases/tag/${tag.toString()}`,
87
- prerelease: config.prerelease && !!tag.version.preRelease,
88
- })
89
- }
90
- }
91
- return releases
92
- }
93
-
94
- const getReleaseArtifacts = async ({ dryRun, manifest, forceReleases }) => {
95
- let pullRequests = []
96
- let releases = []
97
-
98
- if (forceReleases) {
99
- releases = forceReleases
100
- } else if (dryRun) {
101
- pullRequests = await manifest.buildPullRequests()
102
- releases = await manifest.buildReleases()
103
- } else {
104
- pullRequests = await manifest.createPullRequests()
105
- releases = await manifest.createReleases()
106
- }
107
-
108
- return {
109
- pullRequests: pullRequests.filter(Boolean),
110
- releases: releases.filter(Boolean),
111
- }
112
- }
113
-
114
- // XXX(hack): to get release please to recreate a pull request it needs
115
- // to have a different body string so we append a message a message that CI
116
- // is running. This will force release-please to rebase the PR but it
117
- // wont update the body again, so we only append to it.
118
- const touchPullRequest = async ({ octokit, owner, repo, releasePr }) => {
119
- const id = process.env.GITHUB_RUN_ID
120
- ? `by https://github.com/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`
121
- : `manually starting at ${new Date().toJSON()}`
122
-
123
- await octokit.pulls.update({
124
- owner,
125
- repo,
126
- pull_number: releasePr.number,
127
- body: `${releasePr.body.trim()}\n- This PR is being recreated ${id}`,
128
- })
129
- }
130
-
131
- const main = async ({ repo: fullRepo, token, dryRun, branch, forcePullRequest }) => {
132
- if (!token) {
133
- throw new Error('Token is required')
134
- }
135
-
136
- if (!fullRepo) {
137
- throw new Error('Repo is required')
138
- }
139
-
140
- const {
141
- github,
142
- octokit,
143
- manifest,
144
- owner,
145
- repo,
146
- baseBranch,
147
- } = await getManifest({ repo: fullRepo, token, branch })
148
-
149
- let forceReleases = null
150
-
151
- if (forcePullRequest) {
152
- const { data: releasePr } = await octokit.rest.pulls.get({
153
- owner,
154
- repo,
155
- pull_number: forcePullRequest,
156
- })
157
-
158
- if (!releasePr) {
159
- throw new Error(`Could not find PR from number: ${forcePullRequest}`)
160
- }
161
-
162
- if (releasePr.state === 'open') {
163
- await touchPullRequest({ octokit, owner, repo, releasePr })
164
- } else if (releasePr.state === 'closed' && releasePr.merged) {
165
- forceReleases = await getReleasesFromPr({ manifest, github, number: releasePr.number })
166
- } else {
167
- throw new Error(`Could not run workflow on PR with wrong state: ${JSON.stringify(
168
- releasePr,
169
- null,
170
- 2
171
- )}`)
172
- }
173
- }
174
-
175
- const { pullRequests, releases } = await getReleaseArtifacts({ dryRun, manifest, forceReleases })
176
-
177
- // We only ever get a single pull request with our current release-please settings
178
- // Update this if we start creating individual PRs per workspace release
179
- const rootPr = pullRequests[0]
180
- let rootRelease = releases[0]
181
-
182
- logger.debug(`pull requests: ${pullRequests.length}`)
183
- logger.debug(`releases: ${releases.length}`)
184
-
185
- if (rootPr) {
186
- logger.debug(`root pr: ${JSON.stringify(omit(rootPr, 'body'), null, 2)}`)
187
- }
188
-
189
- if (rootPr?.number) {
190
- const commits = await octokit.paginate(octokit.rest.pulls.listCommits, {
191
- owner,
192
- repo,
193
- pull_number: rootPr.number,
194
- })
195
-
196
- const prSha = commits?.[commits.length - 1]?.sha
197
- if (!prSha) {
198
- throw new Error(`Could not find a latest sha for pull request: ${rootPr.number}`)
199
- }
200
-
201
- rootPr.sha = prSha
202
- }
203
-
204
- for (const release of releases) {
205
- const { path, sha } = release
206
- const prefix = path === '.' ? '' : path
207
- const isRoot = !prefix
208
- const packagePath = `${prefix}/package.json`
209
-
210
- logger.debug(`release: ${JSON.stringify({
211
- ...omit(release, 'notes'),
212
- isRoot,
213
- prefix,
214
- }, null, 2)}`)
215
-
216
- const releasePrNumber = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
217
- owner,
218
- repo,
219
- commit_sha: sha,
220
- per_page: 1,
221
- }).then(r => r.data[0]?.number)
222
-
223
- if (!releasePrNumber) {
224
- throw new Error(`Could not find release PR number from commit: "${sha}"`)
225
- }
226
-
227
- logger.debug(`pr from ${sha}: ${releasePrNumber}`)
228
-
229
- const releasePkgName = await octokit.rest.repos.getContent({
230
- owner,
231
- repo,
232
- ref: baseBranch,
233
- path: packagePath,
234
- }).then(r => {
235
- try {
236
- return JSON.parse(Buffer.from(r.data.content, r.data.encoding)).name
237
- } catch {
238
- return null
239
- }
240
- })
241
-
242
- if (!releasePkgName) {
243
- throw new Error(`Could not find package name for release at: "${packagePath}#${baseBranch}"`)
244
- }
245
-
246
- logger.debug(`pkg name from ${packagePath}#${baseBranch}: "${releasePkgName}"`)
247
-
248
- release.prNumber = releasePrNumber
249
- release.pkgName = releasePkgName
250
- if (isRoot) {
251
- rootRelease = release
252
- }
253
- }
254
-
255
- return {
256
- pr: rootPr ?? null,
257
- release: rootRelease ?? null,
258
- releases: releases.length ? releases : null,
259
- }
260
- }
261
-
262
- module.exports = main
@@ -1,192 +0,0 @@
1
- const localeCompare = require('@isaacs/string-locale-compare')('en')
2
- const { NodeWorkspace } = require('release-please/build/src/plugins/node-workspace.js')
3
- const { RawContent } = require('release-please/build/src/updaters/raw-content.js')
4
- const { jsonStringify } = require('release-please/build/src/util/json-stringify.js')
5
- const { addPath } = require('release-please/build/src/plugins/workspace.js')
6
- const { TagName } = require('release-please/build/src/util/tag-name.js')
7
- const { ROOT_PROJECT_PATH } = require('release-please/build/src/manifest.js')
8
- const makeGh = require('./github.js')
9
- const { link, code } = require('./util.js')
10
-
11
- const SCOPE = '__REPLACE_WORKSPACE_DEP__'
12
- const WORKSPACE_DEP = new RegExp(`${SCOPE}: (\\S+) (\\S+)`, 'gm')
13
-
14
- module.exports = class extends NodeWorkspace {
15
- constructor (github, ...args) {
16
- super(github, ...args)
17
- this.gh = makeGh(github)
18
- }
19
-
20
- async preconfigure (strategiesByPath, commitsByPath, releasesByPath) {
21
- // First build a list of all releases that will happen based on
22
- // the conventional commits
23
- const candidates = []
24
- for (const path in strategiesByPath) {
25
- const pullRequest = await strategiesByPath[path].buildReleasePullRequest(
26
- commitsByPath[path],
27
- releasesByPath[path]
28
- )
29
- if (pullRequest?.version) {
30
- candidates.push({ path, pullRequest })
31
- }
32
- }
33
-
34
- // Then build the graph of all those releases + any other connected workspaces
35
- const { allPackages, candidatesByPackage } = await this.buildAllPackages(candidates)
36
- const orderedPackages = this.buildGraphOrder(
37
- await this.buildGraph(allPackages),
38
- Object.keys(candidatesByPackage)
39
- )
40
-
41
- // Then build a list of all the updated versions
42
- const updatedVersions = new Map()
43
- for (const pkg of orderedPackages) {
44
- const path = this.pathFromPackage(pkg)
45
- const packageName = this.packageNameFromPackage(pkg)
46
-
47
- let version = null
48
- const existingCandidate = candidatesByPackage[packageName]
49
- if (existingCandidate) {
50
- // If there is an existing pull request use that version
51
- version = existingCandidate.pullRequest.version
52
- } else {
53
- // Otherwise build another pull request (that will be discarded) just
54
- // to see what the version would be if it only contained a deps commit.
55
- // This is to make sure we use any custom versioning or release strategy.
56
- const strategy = strategiesByPath[path]
57
- const depsSection = strategy.changelogSections.find(c => c.section === 'Dependencies')
58
- const releasePullRequest = await strategiesByPath[path].buildReleasePullRequest(
59
- [{ message: `${depsSection.type}:` }],
60
- releasesByPath[path]
61
- )
62
- version = releasePullRequest.version
63
- }
64
-
65
- updatedVersions.set(packageName, version)
66
- }
67
-
68
- // Save some data about the preconfiugred releases so we can look it up later
69
- // when rewriting the changelogs
70
- this.releasesByPackage = new Map()
71
- this.pathsByComponent = new Map()
72
-
73
- // Then go through all the packages again and add deps commits
74
- // for each updated workspace
75
- for (const pkg of orderedPackages) {
76
- const path = this.pathFromPackage(pkg)
77
- const packageName = this.packageNameFromPackage(pkg)
78
- const graphPackage = this.packageGraph.get(pkg.name)
79
-
80
- // Update dependency versions
81
- for (const [depName, resolved] of graphPackage.localDependencies) {
82
- const depVersion = updatedVersions.get(depName)
83
- const isNotDir = resolved.type !== 'directory'
84
-
85
- // Due to some bugs in release-please we need to create `deps:` commits
86
- // for all dev and prod dependencies even though we normally would only
87
- // do a `chore:` commit to bump a dev dep. The tradeoff is an extra
88
- // patch release to workspaces that depend on other workspaces as dev
89
- // dependencies.
90
- if (depVersion && isNotDir) {
91
- commitsByPath[path].push({
92
- message: `deps(${SCOPE}): ${depName} ${depVersion.toString()}`,
93
- })
94
- }
95
- }
96
-
97
- const component = await strategiesByPath[path].getComponent()
98
- this.pathsByComponent.set(component, path)
99
- this.releasesByPackage.set(packageName, {
100
- path,
101
- component,
102
- })
103
- }
104
-
105
- return strategiesByPath
106
- }
107
-
108
- // This is copied from the release-please node-workspace plugin
109
- // except it only updates the package.json instead of appending
110
- // anything to changelogs since we've already done that in preconfigure.
111
- updateCandidate (candidate, pkg, updatedVersions) {
112
- const newVersion = updatedVersions.get(pkg.name)
113
- const graphPackage = this.packageGraph.get(pkg.name)
114
-
115
- const updatedPackage = pkg.clone()
116
- updatedPackage.version = newVersion.toString()
117
- for (const [depName, resolved] of graphPackage.localDependencies) {
118
- const depVersion = updatedVersions.get(depName)
119
- if (depVersion && resolved.type !== 'directory') {
120
- updatedPackage.updateLocalDependency(resolved, depVersion.toString(), '^')
121
- }
122
- }
123
-
124
- for (const update of candidate.pullRequest.updates) {
125
- if (update.path === addPath(candidate.path, 'package.json')) {
126
- update.updater = new RawContent(
127
- jsonStringify(updatedPackage.toJSON(), updatedPackage.rawContent)
128
- )
129
- }
130
- }
131
-
132
- return candidate
133
- }
134
-
135
- postProcessCandidates (candidates) {
136
- for (const candidate of candidates) {
137
- for (const release of candidate.pullRequest.body.releaseData) {
138
- // Update notes with a link to each workspaces release notes
139
- // now that we have all of the releases in a single pull request
140
- release.notes = release.notes.replace(WORKSPACE_DEP, (_, depName, depVersion) => {
141
- const { path, component } = this.releasesByPackage.get(depName)
142
-
143
- const url = this.gh.release(new TagName(
144
- depVersion,
145
- component,
146
- this.repositoryConfig[path].tagSeparator,
147
- this.repositoryConfig[path].includeVInTag
148
- ))
149
-
150
- return `${link('Workspace', url)}: ${code(`${depName}@${depVersion}`)}`
151
- })
152
-
153
- // Find the associated changelog and update that too
154
- const path = this.pathsByComponent.get(release.component)
155
- for (const update of candidate.pullRequest.updates) {
156
- if (update.path === addPath(path, 'CHANGELOG.md')) {
157
- update.updater.changelogEntry = release.notes
158
- }
159
- }
160
- }
161
-
162
- // Sort root release to the top of the pull request
163
- candidate.pullRequest.body.releaseData.sort((a, b) => {
164
- const aPath = this.pathsByComponent.get(a.component)
165
- const bPath = this.pathsByComponent.get(b.component)
166
- if (aPath === ROOT_PROJECT_PATH) {
167
- return -1
168
- }
169
- // release please pre sorts based on graph order so
170
- // this is never called in normal circumstances
171
- /* istanbul ignore next */
172
- if (bPath === ROOT_PROJECT_PATH) {
173
- return 1
174
- }
175
- return localeCompare(aPath, bPath)
176
- })
177
- }
178
-
179
- return candidates
180
- }
181
-
182
- // Stub these methods with errors since the preconfigure method should negate these
183
- // ever being called from the release please base class. If they are called then
184
- // something has changed that would likely break us in other ways.
185
- bumpVersion () {
186
- throw new Error('Should not bump packages. This should be done in preconfigure.')
187
- }
188
-
189
- newCandidate () {
190
- throw new Error('Should not create new candidates. This should be done in preconfigure.')
191
- }
192
- }
@@ -1,14 +0,0 @@
1
- const semver = require('semver')
2
-
3
- module.exports.specRe = new RegExp(`([^\\s]+@${semver.src[semver.tokens.FULLPLAIN]})`, 'g')
4
-
5
- module.exports.code = (c) => `\`${c}\``
6
- module.exports.link = (text, url) => url ? `[${text}](${url})` : text
7
- module.exports.list = (text) => `* ${text}`
8
-
9
- module.exports.dateFmt = (date = new Date()) => {
10
- const year = date.getFullYear()
11
- const month = (date.getMonth() + 1).toString().padStart(2, '0')
12
- const day = date.getDate().toString().padStart(2, '0')
13
- return [year, month, day].join('-')
14
- }
@@ -1,103 +0,0 @@
1
- const semver = require('semver')
2
- const { Version } = require('release-please/build/src/version.js')
3
-
4
- // A way to compare the "level" of a release since we ignore some things during prereleases
5
- const LEVELS = new Map([['prerelease', 4], ['major', 3], ['minor', 2], ['patch', 1]]
6
- .flatMap((kv) => [kv, kv.slice().reverse()]))
7
-
8
- const parseVersion = (v) => {
9
- const { prerelease, minor, patch, version } = semver.parse(v)
10
-
11
- // This looks at whether there are 0s in certain positions of the version
12
- // 1.0.0 => major
13
- // 1.5.0 => minor
14
- // 1.5.6 => patch
15
- const release = !patch
16
- ? (minor ? LEVELS.get('minor') : LEVELS.get('major'))
17
- : LEVELS.get('patch')
18
-
19
- // Keep track of whether the version has any prerelease identifier
20
- const hasPre = prerelease.length > 0
21
- // Even if it is a prerelease version, this might be an empty string
22
- const preId = prerelease.filter(p => typeof p === 'string').join('.')
23
-
24
- return {
25
- version,
26
- release,
27
- prerelease: hasPre,
28
- preId,
29
- }
30
- }
31
-
32
- const parseCommits = (commits, prerelease) => {
33
- // Default is a patch level change
34
- let release = LEVELS.get('patch')
35
-
36
- for (const commit of commits) {
37
- if (commit.breaking) {
38
- // If any breaking commit is present, its a major
39
- release = LEVELS.get('major')
40
- break
41
- } else if (['feat', 'feature'].includes(commit.type)) {
42
- // Otherwise a feature is a minor release
43
- release = LEVELS.get('minor')
44
- }
45
- }
46
-
47
- return {
48
- release,
49
- prerelease: !!prerelease,
50
- }
51
- }
52
-
53
- const preInc = ({ version, prerelease, preId }, release) => {
54
- if (!release.startsWith('pre')) {
55
- release = `pre${release}`
56
- }
57
-
58
- // `pre` is the default prerelease identifier when creating a new
59
- // prerelease version
60
- return semver.inc(version, release, prerelease ? preId : 'pre')
61
- }
62
-
63
- const semverToVersion = (v) => {
64
- const { major, minor, patch, prerelease } = semver.parse(v)
65
- return new Version(major, minor, patch, prerelease.join('.'))
66
- }
67
-
68
- // This does not account for pre v1 semantics since we don't publish those
69
- // Always 1.0.0 your initial versions!
70
- module.exports = class DefaultVersioningStrategy {
71
- constructor (options) {
72
- this.prerelease = options.prerelease
73
- }
74
-
75
- bump (currentVersion, commits) {
76
- const next = parseCommits(commits, this.prerelease)
77
- // Release please passes in a version class with a toString() method
78
- const current = parseVersion(currentVersion.toString())
79
-
80
- // This is a special case where semver doesn't align exactly with what we want.
81
- // We are currently at a prerelease and our next is also a prerelease.
82
- // In this case we want to ignore the release type we got from our conventional
83
- // commits if the "level" of the next release is <= the level of the current one.
84
- //
85
- // This has the effect of only bumping the prerelease identifier and nothing else
86
- // when we are actively working (and breaking) a prerelease. For example:
87
- //
88
- // `9.0.0-pre.4` + breaking changes = `9.0.0-pre.5`
89
- // `8.5.0-pre.4` + breaking changes = `9.0.0-pre.0`
90
- // `8.5.0-pre.4` + feature or patch changes = `8.5.0-pre.5`
91
- if (current.prerelease && next.prerelease && next.release <= current.release) {
92
- next.release = LEVELS.get('prerelease')
93
- }
94
-
95
- const release = LEVELS.get(next.release)
96
- const releaseVersion = next.prerelease
97
- ? preInc(current, release)
98
- : semver.inc(current.version, release)
99
- return semverToVersion(releaseVersion)
100
- }
101
- }
102
-
103
- module.exports.semverToVersion = semverToVersion
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes