release-it 16.1.5 → 16.2.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.
package/README.md CHANGED
@@ -42,7 +42,7 @@ npm install -D release-it
42
42
  "release": "release-it"
43
43
  },
44
44
  "devDependencies": {
45
- "release-it": "^15.10.0"
45
+ "release-it": "^16.1.0"
46
46
  }
47
47
  }
48
48
  ```
@@ -252,6 +252,7 @@ changelog
252
252
  name
253
253
  repo.remote, repo.protocol, repo.host, repo.owner, repo.repository, repo.project
254
254
  branchName
255
+ releaseUrl
255
256
  ```
256
257
 
257
258
  All variables are available in all hooks. The only exception is that the additional variables listed above are not yet
package/lib/config.js CHANGED
@@ -49,12 +49,23 @@ class Config {
49
49
  }
50
50
 
51
51
  expandPreReleaseShorthand(options) {
52
- const { increment, preRelease, preReleaseId } = options;
52
+ const { increment, preRelease, preReleaseId, snapshot } = options;
53
+ const isPreRelease = Boolean(preRelease) || Boolean(snapshot);
54
+ const inc = snapshot ? 'prerelease' : increment;
55
+ const preId = typeof preRelease === 'string' ? preRelease : typeof snapshot === 'string' ? snapshot : preReleaseId;
53
56
  options.version = {
54
- increment,
55
- isPreRelease: Boolean(preRelease),
56
- preReleaseId: typeof preRelease === 'string' ? preRelease : preReleaseId
57
+ increment: inc,
58
+ isPreRelease,
59
+ preReleaseId: preId
57
60
  };
61
+ if (typeof snapshot === 'string' && options.git) {
62
+ // Pre set and hard code some options
63
+ options.git.tagMatch = `0.0.0-${snapshot}.[0-9]*`;
64
+ options.git.getLatestTagFromAllRefs = true;
65
+ options.git.requireBranch = '!main';
66
+ options.git.requireUpstream = false;
67
+ options.npm.ignoreVersion = true;
68
+ }
58
69
  return options;
59
70
  }
60
71
 
package/lib/index.js CHANGED
@@ -69,6 +69,12 @@ const runTasks = async (opts, di) => {
69
69
 
70
70
  const incrementBase = { latestVersion, increment, isPreRelease, preReleaseId };
71
71
 
72
+ const { snapshot } = config.options;
73
+ if (snapshot && !incrementBase.latestVersion.startsWith('0.0.0')) {
74
+ // Reading the latest version first allows to increment the final counter, fake it if it's not a snapshot:
75
+ incrementBase.latestVersion = `0.0.0-${snapshot}.-1`;
76
+ }
77
+
72
78
  let version;
73
79
  if (config.isIncrement) {
74
80
  incrementBase.increment = await reduceUntil(plugins, plugin => plugin.getIncrement(incrementBase));
@@ -32,6 +32,7 @@ class GitBase extends Plugin {
32
32
  }
33
33
 
34
34
  async getChangelog() {
35
+ const { snapshot } = this.config.getContext();
35
36
  const { latestTag, secondLatestTag } = this.config.getContext();
36
37
  const context = { latestTag, from: latestTag, to: 'HEAD' };
37
38
  const { changelog } = this.options;
@@ -42,6 +43,9 @@ class GitBase extends Plugin {
42
43
  context.to = `${latestTag}^1`;
43
44
  }
44
45
 
46
+ // For now, snapshots do not get a changelog, as it often goes haywire (easy to add to release manually)
47
+ if (snapshot) return '';
48
+
45
49
  if (!context.from && changelog.includes('${from}')) {
46
50
  return this.exec(changelogFallback);
47
51
  }
@@ -95,7 +95,14 @@ class Git extends GitBase {
95
95
  async isRequiredBranch() {
96
96
  const branch = await this.getBranchName();
97
97
  const requiredBranches = _.castArray(this.options.requireBranch);
98
- return matcher(requiredBranches)(branch);
98
+ const [branches, negated] = requiredBranches.reduce(
99
+ ([p, n], b) => (b.startsWith('!') ? [p, [...n, b.slice(1)]] : [[...p, b], n]),
100
+ [[], []]
101
+ );
102
+ return (
103
+ (branches.length > 0 ? matcher(branches)(branch) : true) &&
104
+ (negated.length > 0 ? !matcher(negated)(branch) : true)
105
+ );
99
106
  }
100
107
 
101
108
  async hasUpstreamBranch() {
@@ -248,6 +248,7 @@ class GitHub extends Release {
248
248
  this.debug(response.data);
249
249
  const { html_url, upload_url, id } = response.data;
250
250
  this.setContext({ isReleased: true, releaseId: id, releaseUrl: html_url, upload_url });
251
+ this.config.setContext({ isReleased: true, releaseId: id, releaseUrl: html_url, upload_url });
251
252
  this.log.verbose(`octokit repos.createRelease: done (${response.headers.location})`);
252
253
  return response.data;
253
254
  } catch (err) {
@@ -219,6 +219,7 @@ class GitLab extends Release {
219
219
  await this.request(endpoint, options);
220
220
  this.log.verbose('gitlab releases#createRelease: done');
221
221
  this.setContext({ isReleased: true, releaseUrl });
222
+ this.config.setContext({ isReleased: true, releaseUrl });
222
223
  return true;
223
224
  } catch (err) {
224
225
  this.debug(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "release-it",
3
- "version": "16.1.5",
3
+ "version": "16.2.0",
4
4
  "description": "Generic CLI tool to automate versioning and package publishing-related tasks.",
5
5
  "keywords": [
6
6
  "build",
@@ -65,12 +65,12 @@
65
65
  "@octokit/rest": "19.0.13",
66
66
  "async-retry": "1.3.3",
67
67
  "chalk": "5.3.0",
68
- "cosmiconfig": "8.2.0",
68
+ "cosmiconfig": "8.3.6",
69
69
  "execa": "7.2.0",
70
70
  "git-url-parse": "13.1.0",
71
71
  "globby": "13.2.2",
72
72
  "got": "13.0.0",
73
- "inquirer": "9.2.10",
73
+ "inquirer": "9.2.11",
74
74
  "is-ci": "3.0.1",
75
75
  "issue-parser": "6.0.0",
76
76
  "lodash": "4.17.21",
@@ -80,8 +80,8 @@
80
80
  "open": "9.1.0",
81
81
  "ora": "7.0.1",
82
82
  "os-name": "5.1.0",
83
- "promise.allsettled": "1.0.6",
84
- "proxy-agent": "6.3.0",
83
+ "promise.allsettled": "1.0.7",
84
+ "proxy-agent": "6.3.1",
85
85
  "semver": "7.5.4",
86
86
  "shelljs": "0.8.5",
87
87
  "update-notifier": "6.0.2",
@@ -92,17 +92,17 @@
92
92
  "devDependencies": {
93
93
  "@octokit/request-error": "3.0.3",
94
94
  "ava": "5.3.1",
95
- "eslint": "8.46.0",
95
+ "eslint": "8.50.0",
96
96
  "eslint-config-prettier": "9.0.0",
97
97
  "eslint-plugin-ava": "14.0.0",
98
- "eslint-plugin-import": "2.28.0",
98
+ "eslint-plugin-import": "2.28.1",
99
99
  "eslint-plugin-prettier": "5.0.0",
100
100
  "fs-monkey": "1.0.4",
101
101
  "knip": "2.19.1",
102
- "memfs": "4.2.1",
102
+ "memfs": "4.4.0",
103
103
  "mock-stdio": "1.0.3",
104
- "nock": "13.3.2",
105
- "prettier": "3.0.1",
104
+ "nock": "13.3.3",
105
+ "prettier": "3.0.3",
106
106
  "remark-cli": "11.0.0",
107
107
  "remark-preset-webpro": "0.0.3",
108
108
  "sinon": "15.2.0",
package/test/config.js CHANGED
@@ -131,3 +131,14 @@ test('should expand pre-release shortcut (including increment and npm.tag)', t =
131
131
  preReleaseId: 'rc'
132
132
  });
133
133
  });
134
+
135
+ test('should expand pre-release shortcut (snapshot)', t => {
136
+ const config = new Config({ snapshot: 'feat' });
137
+ t.deepEqual(config.options.version, {
138
+ increment: 'prerelease',
139
+ isPreRelease: true,
140
+ preReleaseId: 'feat'
141
+ });
142
+ t.is(config.options.git.tagMatch, '0.0.0-feat.[0-9]*');
143
+ t.true(config.options.git.getLatestTagFromAllRefs);
144
+ });
package/test/git.init.js CHANGED
@@ -26,6 +26,13 @@ test.serial('should throw if on wrong branch', async t => {
26
26
  await t.throwsAsync(gitClient.init(), { message: /^Must be on branch dev/ });
27
27
  });
28
28
 
29
+ test.serial('should throw if on negated branch', async t => {
30
+ const options = { git: { requireBranch: '!main' } };
31
+ const gitClient = factory(Git, { options });
32
+ sh.exec('git checkout -b main');
33
+ await t.throwsAsync(gitClient.init(), { message: /^Must be on branch !main/ });
34
+ });
35
+
29
36
  test.serial('should not throw if required branch matches', async t => {
30
37
  const options = { git: { requireBranch: 'ma?*' } };
31
38
  const gitClient = factory(Git, { options });