22
33import { dirname , resolve } from 'node:path' ;
44import { fileURLToPath } from 'node:url' ;
5- import { execSync } from 'node:child_process' ;
65import * as esbuild from 'esbuild' ;
76import { replace } from 'esbuild-plugin-replace' ;
7+ import getPackageVersion from "./getPackageVersion.mjs" ;
88
99// import.meta.dirname is not available before Node 20
1010const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
@@ -46,27 +46,6 @@ const cjsBundleConfig = {
4646 sourcemap : 'linked' ,
4747} ;
4848
49- // 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)
50- const getVersion = ( ) => {
51- let version ;
52- // During release, use the version being released
53- // see .releaserc.json where the `NEXT_VERSION` env variable is set
54- if ( process . env . NEXT_VERSION ) {
55- version = process . env . NEXT_VERSION ;
56- } else {
57- // Otherwise use the latest git tag
58- try {
59- version = execSync ( 'git describe --tags --abbrev=0' ) . toString ( ) . trim ( ) ;
60- } catch ( error ) {
61- console . error ( error ) ;
62- console . warn ( 'Could not get latest version from git tags, falling back to package.json' ) ;
63- version = packageJson . default . version ;
64- }
65- }
66- console . log ( `Determined the build package version to be ${ version } ` ) ;
67- return version ;
68- } ;
69-
7049
7150// We build two CJS bundles: for browser and for node. The latter one can be
7251// used e.g. during SSR (although it makes little sence to SSR chat, but still
@@ -78,7 +57,7 @@ const bundles = ['browser', 'node'].map((platform) =>
7857 platform,
7958 plugins : [
8059 replace ( {
81- '__STREAM_CHAT_REACT_VERSION__' : getVersion ( ) ,
60+ '__STREAM_CHAT_REACT_VERSION__' : getPackageVersion ( ) ,
8261 } ) ,
8362 ] ,
8463 } ) ,
0 commit comments