@@ -6,25 +6,59 @@ import { getPackageDir, getPackageFile } from './utils/packages.js';
6
6
import { logAndExec } from './utils/process.js' ;
7
7
import { isValidVersion } from './utils/semver.js' ;
8
8
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 } ` ) ;
17
45
}
18
46
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' ) ;
23
51
process . exit ( 1 ) ;
24
52
}
25
53
26
- let tag = `${ packageName } @${ version } ` ;
54
+ let split = tag . split ( '@' ) ;
55
+ let packageName = split [ 0 ] ;
56
+ let version = split [ 1 ] ;
27
57
58
+ if ( ! packageName || ! version ) {
59
+ console . error ( `Invalid tag: "${ tag } "` ) ;
60
+ process . exit ( 1 ) ;
61
+ }
28
62
if ( packageName === '' || ! isValidVersion ( version ) ) {
29
63
console . error ( `Invalid tag: "${ tag } "` ) ;
30
64
process . exit ( 1 ) ;
0 commit comments