release-it 15.6.1 → 15.7.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/bin/release-it.js CHANGED
@@ -38,5 +38,5 @@ const options = parseCliArguments([].slice.call(process.argv, 2));
38
38
  updater({ pkg: pkg }).notify();
39
39
  release(options).then(
40
40
  () => process.exit(0),
41
- () => process.exit(1)
41
+ ({ code }) => process.exit(Number.isInteger(code) ? code : 1)
42
42
  );
@@ -6,6 +6,8 @@
6
6
  "requireBranch": false,
7
7
  "requireUpstream": true,
8
8
  "requireCommits": false,
9
+ "requireCommitsFail": true,
10
+ "commitsPath": "",
9
11
  "addUntrackedFiles": false,
10
12
  "commit": true,
11
13
  "commitMessage": "Release ${version}",
@@ -46,8 +46,8 @@ class Git extends GitBase {
46
46
  if (this.options.requireUpstream && !(await this.hasUpstreamBranch())) {
47
47
  throw e(`No upstream configured for current branch.${EOL}Please set an upstream branch.`, docs);
48
48
  }
49
- if (this.options.requireCommits && (await this.getCommitsSinceLatestTag()) === 0) {
50
- throw e(`There are no commits since the latest tag.`, docs);
49
+ if (this.options.requireCommits && (await this.getCommitsSinceLatestTag(this.options.commitsPath)) === 0) {
50
+ throw e(`There are no commits since the latest tag.`, docs, this.options.requireCommitsFail);
51
51
  }
52
52
  }
53
53
 
@@ -120,10 +120,10 @@ class Git extends GitBase {
120
120
  );
121
121
  }
122
122
 
123
- async getCommitsSinceLatestTag() {
123
+ async getCommitsSinceLatestTag(commitsPath = '') {
124
124
  const latestTagName = await this.getLatestTagName();
125
125
  const ref = latestTagName ? `${latestTagName}..HEAD` : 'HEAD';
126
- return this.exec(`git rev-list ${ref} --count`, { options }).then(Number);
126
+ return this.exec(`git rev-list ${ref} --count ${commitsPath}`, { options }).then(Number);
127
127
  }
128
128
 
129
129
  async getUpstreamArgs(pushRepo) {
package/lib/util.js CHANGED
@@ -89,7 +89,11 @@ const parseVersion = raw => {
89
89
  };
90
90
  };
91
91
 
92
- const e = (message, docs) => new Error(docs ? `${message}${EOL}Documentation: ${docs}${EOL}` : message);
92
+ const e = (message, docs, fail = true) => {
93
+ const error = new Error(docs ? `${message}${EOL}Documentation: ${docs}${EOL}` : message);
94
+ error.code = fail ? 1 : 0;
95
+ return error;
96
+ };
93
97
 
94
98
  export {
95
99
  getSystemInfo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "release-it",
3
- "version": "15.6.1",
3
+ "version": "15.7.0",
4
4
  "description": "Generic CLI tool to automate versioning and package publishing related tasks.",
5
5
  "keywords": [
6
6
  "build",
package/test/git.init.js CHANGED
@@ -72,6 +72,36 @@ test.serial('should not throw if there are commits', async t => {
72
72
  await t.notThrowsAsync(gitClient.init());
73
73
  });
74
74
 
75
+ test.serial('should fail (exit code 1) if there are no commits', async t => {
76
+ const options = { git: { requireCommits: true } };
77
+ const gitClient = factory(Git, { options });
78
+ sh.exec('git tag 1.0.0');
79
+ await t.throwsAsync(gitClient.init(), { code: 1 });
80
+ });
81
+
82
+ test.serial('should not fail (exit code 0) if there are no commits', async t => {
83
+ const options = { git: { requireCommits: true, requireCommitsFail: false } };
84
+ const gitClient = factory(Git, { options });
85
+ sh.exec('git tag 1.0.0');
86
+ await t.throwsAsync(gitClient.init(), { code: 0 });
87
+ });
88
+
89
+ test.serial('should throw if there are no commits in specified path', async t => {
90
+ const options = { git: { requireCommits: true, commitsPath: 'dir' } };
91
+ const gitClient = factory(Git, { options });
92
+ sh.mkdir('dir');
93
+ sh.exec('git tag 1.0.0');
94
+ await t.throwsAsync(gitClient.init(), { message: /^There are no commits since the latest tag/ });
95
+ });
96
+
97
+ test.serial('should not throw if there are commits in specified path', async t => {
98
+ const options = { git: { requireCommits: true, commitsPath: 'dir' } };
99
+ const gitClient = factory(Git, { options });
100
+ sh.exec('git tag 1.0.0');
101
+ gitAdd('line', 'dir/file', 'Add file');
102
+ await t.notThrowsAsync(gitClient.init());
103
+ });
104
+
75
105
  test.serial('should not throw if there are no tags', async t => {
76
106
  const options = { git: { requireCommits: true } };
77
107
  const gitClient = factory(Git, { options });
@@ -30,7 +30,7 @@ const interceptListReleases = ({
30
30
  upload_url: `https://uploads.${host}/repos/${owner}/${project}/releases/1/assets{?name,label}`,
31
31
  html_url: `https://${host}/${owner}/${project}/releases/tag/${tag_name}`,
32
32
  tag_name,
33
- target_commitish: 'master',
33
+ target_commitish: 'main',
34
34
  name: `Release ${tag_name}`,
35
35
  body: 'Description of the release',
36
36
  draft: false,
package/test/tasks.js CHANGED
@@ -51,6 +51,10 @@ const getContainer = options => {
51
51
  };
52
52
  };
53
53
 
54
+ test.before(t => {
55
+ t.timeout(90 * 1000);
56
+ });
57
+
54
58
  test.serial.beforeEach(t => {
55
59
  const bare = mkTmpDir();
56
60
  const target = mkTmpDir();
@@ -10,9 +10,14 @@ const mkTmpDir = () => {
10
10
 
11
11
  const readFile = file => fs.promises.readFile(path.resolve(file), 'utf8');
12
12
 
13
- const gitAdd = (content, file, message) => {
14
- sh.ShellString(content).toEnd(file);
15
- sh.exec(`git add ${file}`);
13
+ const gitAdd = (content, filePath, message) => {
14
+ const pathSegments = filePath.split('/').filter(Boolean);
15
+ pathSegments.pop();
16
+ if (pathSegments.length) {
17
+ sh.mkdir('-p', pathSegments.join('/'));
18
+ }
19
+ sh.ShellString(content).toEnd(filePath);
20
+ sh.exec(`git add ${filePath}`);
16
21
  const { stdout } = sh.exec(`git commit -m "${message}"`);
17
22
  const match = stdout.match(/\[.+([a-z0-9]{7})\]/);
18
23
  return match ? match[1] : null;