Skip to content

Commit d7e2947

Browse files
committed
Update publish script to use tag pointing at HEAD
1 parent eb88c52 commit d7e2947

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

scripts/publish-release.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,59 @@ import { getPackageDir, getPackageFile } from './utils/packages.js';
66
import { logAndExec } from './utils/process.js';
77
import { isValidVersion } from './utils/semver.js';
88

9-
let packageName = process.argv[2];
10-
let version = process.argv[3];
11-
12-
// Support passing a tag directly, e.g. `[email protected]`
13-
if (packageName.includes('@')) {
14-
let split = packageName.split('@');
15-
packageName = split[0];
16-
version = split[1];
9+
let tag = process.argv[2];
10+
11+
// If no argument provided, try to detect a tag at HEAD
12+
if (tag === undefined) {
13+
let currentTags = cp
14+
.execSync('git tag --points-at HEAD')
15+
.toString()
16+
.trim()
17+
.split('\n')
18+
.filter(Boolean);
19+
20+
// Look for tags that match the package@version format
21+
let packageTags = currentTags.filter((tag) => {
22+
let match = tag.match(/^([^@]+)@(\d+\.\d+\.\d+.*)$/);
23+
return match && isValidVersion(match[2]);
24+
});
25+
26+
if (packageTags.length === 0) {
27+
console.error('No package tags found at HEAD');
28+
console.error(`Usage:
29+
node publish-release.js <tag>
30+
node publish-release.js # auto-detect tag at HEAD`);
31+
process.exit(1);
32+
}
33+
34+
// TODO: Support tagging and publishing multiple packages at once
35+
if (packageTags.length > 1) {
36+
console.error('Multiple package tags found at HEAD:');
37+
packageTags.forEach((tag) => console.error(` - ${tag}`));
38+
console.error('Please specify which tag to publish');
39+
process.exit(1);
40+
}
41+
42+
// Use the single tag found
43+
tag = packageTags[0];
44+
console.log(`Auto-detected tag: ${tag}`);
1745
}
1846

19-
if (packageName === undefined || version === undefined) {
20-
console.error(`Usage:
21-
node publish-release.js <packageName> <version>
22-
node publish-release.js <tag>`);
47+
// Parse the tag
48+
if (!tag.includes('@')) {
49+
console.error(`Invalid tag format: "${tag}"`);
50+
console.error('Tag must be in format: packageName@version');
2351
process.exit(1);
2452
}
2553

26-
let tag = `${packageName}@${version}`;
54+
let split = tag.split('@');
55+
let packageName = split[0];
56+
let version = split[1];
2757

58+
if (!packageName || !version) {
59+
console.error(`Invalid tag: "${tag}"`);
60+
process.exit(1);
61+
}
2862
if (packageName === '' || !isValidVersion(version)) {
2963
console.error(`Invalid tag: "${tag}"`);
3064
process.exit(1);

0 commit comments

Comments
 (0)