Skip to content

Commit e9e70a4

Browse files
committed
feat: use pkg folder name as tag name
1 parent de7c807 commit e9e70a4

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

src/changelog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function runGenerateChangelog(opts: ReleaseOptions) {
8080
tags: tagNames.map((name) => {
8181
const item = tags.find(s => s.name === name)!;
8282
if (item && item.name === 'HEAD') {
83-
item.name = getGitTagVersion(pkg.name, item.version, opts);
83+
item.name = getGitTagVersion(pkg.tagName, item.version, opts);
8484
}
8585

8686
return item;
@@ -205,7 +205,7 @@ async function bumpVersionAndTag(pkg: PackageInfo, opts: ReleaseOptions) {
205205
!dryRun && updatePackageVersion(pkg);
206206

207207
await run('git add .', { cwd: pkg.dir, dryRun });
208-
const tag = getGitTagVersionRelease(pkg.name, pkg.newVersion, isMonorepo);
208+
const tag = getGitTagVersionRelease(pkg.tagName, pkg.newVersion, isMonorepo);
209209
await run(`git commit -m "chore: release ${tag}"`, {
210210
cwd: pkg.dir,
211211
dryRun,

src/git.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,17 @@ export async function getGitTags(opts: ReleaseOptions) {
174174
// compatible with old version
175175
const prefixMap: Record<string, string> = {};
176176
if (isMonorepo) {
177-
pkgNames.forEach((name) => {
177+
pkgs.forEach((pkg) => {
178+
const { name, tagName } = pkg;
178179
prefixMap[getGitTagPrefix(name, { isMonorepo, scopedTag: true, lineTag: false })] = name;
179180
prefixMap[getGitTagPrefix(name, { isMonorepo, scopedTag: false, lineTag: false })] = name;
180181
prefixMap[getGitTagPrefix(name, { isMonorepo, scopedTag: true, lineTag: true })] = name;
181182
prefixMap[getGitTagPrefix(name, { isMonorepo, scopedTag: false, lineTag: true })] = name;
183+
184+
prefixMap[getGitTagPrefix(tagName, { isMonorepo, scopedTag: true, lineTag: false })] = name;
185+
prefixMap[getGitTagPrefix(tagName, { isMonorepo, scopedTag: false, lineTag: false })] = name;
186+
prefixMap[getGitTagPrefix(tagName, { isMonorepo, scopedTag: true, lineTag: true })] = name;
187+
prefixMap[getGitTagPrefix(tagName, { isMonorepo, scopedTag: false, lineTag: true })] = name;
182188
});
183189
}
184190

@@ -306,7 +312,7 @@ export async function resetGitSubmit(opts: ReleaseOptions) {
306312

307313
// remote git tag
308314
for (const pkg of pkgs) {
309-
const tag = getGitTagVersion(pkg.name, pkg.version, opts);
315+
const tag = getGitTagVersion(pkg.tagName, pkg.version, opts);
310316
const res = await run(`git tag -l ${tag}`);
311317
if (res) {
312318
await run(`git tag -d ${tag}`);

src/options.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ReleaseType } from 'semver';
22
import type { PackageInfo, ReleaseCLIOptions, ReleaseOptions } from './types';
33
import fs from 'node:fs';
4-
import path from 'node:path';
54
import { getPackages } from '@manypkg/get-packages';
65
import chalk from 'chalk';
76
import GitHost from 'hosted-git-info';
@@ -106,15 +105,9 @@ async function findPackages(opts: ReleaseOptions) {
106105
if (!rootPackage || !_packages || _packages.length === 0) {
107106
throw new Error('No root package found.');
108107
}
109-
// ignore private
110108

111-
const packages = _packages.filter((s) => {
112-
if (s.packageJson.private) {
113-
return false;
114-
}
115-
const dirname = path.dirname(s.relativeDir);
116-
return !['example', 'examples'].includes(dirname);
117-
});
109+
// ignore private
110+
const packages = _packages.filter(s => !s.packageJson.private);
118111

119112
let isMonorepo = false;
120113
if (packages.length === 0) {
@@ -139,13 +132,28 @@ async function findPackages(opts: ReleaseOptions) {
139132
const pkgs = packages
140133
.filter(s => !s.packageJson.private)
141134
.map((s) => {
135+
const scoped = isScopedPackage(s.packageJson.name);
136+
const name = s.packageJson.name;
137+
let tagName = name;
138+
if (isMonorepo) {
139+
if (s.relativeDir.startsWith('packages/')) {
140+
tagName = s.relativeDir.split('/')[1];
141+
}
142+
else if (scoped) {
143+
const names = name.split('/');
144+
tagName = names.pop() || name;
145+
}
146+
}
147+
142148
return {
143149
...s,
144-
name: s.packageJson.name,
150+
name,
151+
// use package folder name as tag name
152+
tagName,
145153
version: s.packageJson.version,
146154
newVersion: '',
147155
tag: '',
148-
scoped: isScopedPackage(s.packageJson.name),
156+
scoped,
149157
} as PackageInfo;
150158
});
151159
opts.pkgs = pkgs;

src/publish.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ async function bumpVersionAndTag(opts: ReleaseOptions) {
3838
await run('git add -A', { dryRun });
3939

4040
// git commit message
41-
const msgTags = pkgs.map(s => getGitTagVersionRelease(s.name, s.newVersion, opts.isMonorepo));
41+
const msgTags = pkgs.map(s => getGitTagVersionRelease(s.tagName, s.newVersion, opts.isMonorepo));
4242
await run(`git commit -m "chore: release ${msgTags.join(', ')}"`, {
4343
dryRun,
4444
});
4545

46-
const tags = pkgs.map(s => getGitTagVersion(s.name, s.newVersion, opts));
46+
const tags = pkgs.map(s => getGitTagVersion(s.tagName, s.newVersion, opts));
4747
for (const tag of tags) {
4848
await run(`git tag ${tag}`, { dryRun });
4949
}
@@ -174,7 +174,7 @@ async function runGithubRelease(opts: ReleaseOptions) {
174174
repoUrl.pathname += '/releases/new';
175175

176176
const { newVersion: version, changelogs } = pkg;
177-
const tag = getGitTagVersion(pkg.name, version, opts);
177+
const tag = getGitTagVersion(pkg.tagName, version, opts);
178178
repoUrl.searchParams.set('tag', tag);
179179
repoUrl.searchParams.set('title', tag);
180180
const pre = semver.parse(version)?.prerelease;

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ export interface NpmInfo {
2626
}
2727

2828
export interface PackageInfo {
29+
/** npm package name */
2930
name: string;
31+
/** git tag name */
32+
tagName: string;
33+
/** npm package version */
3034
version: string;
35+
/** npm package new version */
3136
newVersion: string;
3237
/** npm publish tag */
3338
tag: string;

0 commit comments

Comments
 (0)