release-it 15.3.0 → 15.4.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.
@@ -7,16 +7,18 @@ const changelogFallback = 'git log --pretty=format:"* %s (%h)"';
7
7
 
8
8
  class GitBase extends Plugin {
9
9
  async init() {
10
- this.remoteUrl = await this.getRemoteUrl();
11
- await this.fetch();
10
+ const remoteUrl = await this.getRemoteUrl();
11
+ await this.fetch(remoteUrl);
12
+
12
13
  const branchName = await this.getBranchName();
13
- this.setContext({ branchName });
14
- const repo = parseGitUrl(this.remoteUrl);
15
- const latestTag = await this.getLatestTagName(repo);
14
+ const repo = parseGitUrl(remoteUrl);
15
+ this.setContext({ remoteUrl, branchName, repo });
16
+ this.config.setContext({ remoteUrl, branchName, repo });
17
+
18
+ const latestTag = await this.getLatestTagName();
16
19
  const secondLatestTag = !this.config.isIncrement ? await this.getSecondLatestTagName(latestTag) : null;
17
20
  const tagTemplate = this.options.tagName || ((latestTag || '').match(/^v/) ? 'v${version}' : '${version}');
18
- this.setContext({ repo });
19
- this.config.setContext({ tagTemplate, latestTag, secondLatestTag, branchName });
21
+ this.config.setContext({ latestTag, secondLatestTag, tagTemplate });
20
22
  }
21
23
 
22
24
  getName() {
@@ -81,15 +83,15 @@ class GitBase extends Plugin {
81
83
  return this.exec(`git config --get branch.${branch}.remote`, { options }).catch(() => null);
82
84
  }
83
85
 
84
- fetch() {
86
+ fetch(remoteUrl) {
85
87
  return this.exec('git fetch').catch(err => {
86
88
  this.debug(err);
87
- throw new Error(`Unable to fetch from ${this.remoteUrl}${EOL}${err.message}`);
89
+ throw new Error(`Unable to fetch from ${remoteUrl}${EOL}${err.message}`);
88
90
  });
89
91
  }
90
92
 
91
- getLatestTagName(repo) {
92
- const context = Object.assign({ repo }, this.getContext(), { version: '*' });
93
+ getLatestTagName() {
94
+ const context = Object.assign({}, this.config.getContext(), { version: '*' });
93
95
  const match = format(this.options.tagMatch || this.options.tagName || '${version}', context);
94
96
  return this.exec(`git describe --tags --match=${match} --abbrev=0`, { options }).then(
95
97
  stdout => stdout || null,
@@ -39,7 +39,8 @@ class Git extends GitBase {
39
39
 
40
40
  await super.init();
41
41
 
42
- if (this.options.push && !this.remoteUrl) {
42
+ const remoteUrl = this.getContext('remoteUrl');
43
+ if (this.options.push && !remoteUrl) {
43
44
  throw e(`Could not get remote Git url.${EOL}Please add a remote repository.`, docs);
44
45
  }
45
46
  if (this.options.requireUpstream && !(await this.hasUpstreamBranch())) {
@@ -48,7 +49,6 @@ class Git extends GitBase {
48
49
  if (this.options.requireCommits && (await this.getCommitsSinceLatestTag()) === 0) {
49
50
  throw e(`There are no commits since the latest tag.`, docs);
50
51
  }
51
- this.config.setContext({ repo: this.getContext('repo') });
52
52
  }
53
53
 
54
54
  rollback() {
@@ -29,6 +29,7 @@ class npm extends Plugin {
29
29
  async init() {
30
30
  const { name, version: latestVersion, private: isPrivate, publishConfig } = readJSON(path.resolve(MANIFEST_PATH));
31
31
  this.setContext({ name, latestVersion, private: isPrivate, publishConfig });
32
+ this.config.setContext({ npm: { name } });
32
33
 
33
34
  const { publish, skipChecks } = this.options;
34
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "release-it",
3
- "version": "15.3.0",
3
+ "version": "15.4.0",
4
4
  "description": "Generic CLI tool to automate versioning and package publishing related tasks.",
5
5
  "keywords": [
6
6
  "build",
package/test/tasks.js CHANGED
@@ -194,17 +194,22 @@ test.serial('should release with correct tag name', async t => {
194
194
  const { stdout } = sh.exec('git rev-parse --abbrev-ref HEAD');
195
195
  const branchName = stdout.trim();
196
196
  gitAdd(`{"name":"${pkgName}","version":"1.0.0"}`, 'package.json', 'Add package.json');
197
- sh.exec(`git tag ${branchName}-1.0.0`);
197
+ sh.exec(`git tag ${pkgName}-${branchName}-1.0.0`);
198
198
  const sha = gitAdd('line', 'file', 'More file');
199
199
 
200
200
  interceptGitHubCreate({
201
201
  owner,
202
202
  project,
203
- body: { tag_name: `${branchName}-1.0.1`, name: 'Release 1.0.1', body: `* More file (${sha})`, prerelease: false }
203
+ body: {
204
+ tag_name: `${pkgName}-${branchName}-1.0.1`,
205
+ name: 'Release 1.0.1',
206
+ body: `* More file (${sha})`,
207
+ prerelease: false
208
+ }
204
209
  });
205
210
 
206
211
  const container = getContainer({
207
- git: { tagName: '${branchName}-${version}' },
212
+ git: { tagName: '${npm.name}-${branchName}-${version}' },
208
213
  github: { release: true, skipChecks: true, pushRepo: `https://github.com/${owner}/${project}` }
209
214
  });
210
215
 
@@ -214,9 +219,11 @@ test.serial('should release with correct tag name', async t => {
214
219
 
215
220
  const gitArgs = getArgs(container.shell.exec.args, 'git');
216
221
 
217
- t.true(gitArgs.includes(`git tag --annotate --message Release 1.0.1 ${branchName}-1.0.1`));
222
+ t.true(gitArgs.includes(`git tag --annotate --message Release 1.0.1 ${pkgName}-${branchName}-1.0.1`));
218
223
  t.true(
219
- log.log.secondCall.args[0].endsWith(`https://github.com/${owner}/${project}/releases/tag/${branchName}-1.0.1`)
224
+ log.log.secondCall.args[0].endsWith(
225
+ `https://github.com/${owner}/${project}/releases/tag/${pkgName}-${branchName}-1.0.1`
226
+ )
220
227
  );
221
228
 
222
229
  exec.restore();