1+ import { execSync } from 'node:child_process' ;
12import { dirname , resolve } from 'node:path' ;
23import { fileURLToPath } from 'node:url' ;
34
45// import.meta.dirname is not available before Node 20
56const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
67
78const packageJson = await import ( resolve ( __dirname , '../package.json' ) , {
8- assert : { type : 'json' } ,
9+ assert : { type : 'json' } ,
910} ) ;
1011
1112// Get the latest version so that magic string __STREAM_CHAT_REACT_VERSION__ can be replaced with it in the source code (used for reporting purposes)
1213export default function getPackageVersion ( ) {
13- let version ;
14- // During release, use the version being released
15- // see .releaserc.json where the `NEXT_VERSION` env variable is set
16- if ( process . env . NEXT_VERSION ) {
17- version = process . env . NEXT_VERSION ;
18- } else {
19- // Otherwise use the latest git tag
20- try {
21- version = execSync ( 'git describe --tags --abbrev=0' ) . toString ( ) . trim ( ) ;
22- } catch ( error ) {
23- console . error ( error ) ;
24- console . warn ( 'Could not get latest version from git tags, falling back to package.json' ) ;
25- version = packageJson . default . version ;
26- }
14+ let version ;
15+ // During release, use the version being released
16+ // see .releaserc.json where the `NEXT_VERSION` env variable is set
17+ if ( process . env . NEXT_VERSION ) {
18+ version = process . env . NEXT_VERSION ;
19+ } else {
20+ // Otherwise use the latest git tag
21+ try {
22+ version = execSync ( 'git describe --tags --abbrev=0' ) . toString ( ) . trim ( ) ;
23+ } catch ( error ) {
24+ console . error ( error ) ;
25+ console . warn ( 'Could not get latest version from git tags, falling back to package.json' ) ;
26+ version = packageJson . default . version ;
2727 }
28- console . log ( `Determined the build package version to be ${ version } ` ) ;
29- return version ;
30- } ;
28+ }
29+ console . log ( `Determined the build package version to be ${ version } ` ) ;
30+ return version ;
31+ }
0 commit comments