File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
15
15
import { LIB_NAME , LIB_VERSION } from '@/src/version' ;
16
+ import * as path from "path" ;
17
+ import * as fs from "fs" ;
16
18
17
19
export const RAGSTACK_REQUESTED_WITH = ( ( ) => {
20
+ /**
21
+ * Do not use require() here, it will break the build in some environments such as NextJS application
22
+ * if @datastax/ragstack-ai is not installed (which is perfectly fine).
23
+ */
18
24
try {
19
- // eslint-disable-next-line @typescript-eslint/no-var-requires
20
- const ragstack = require ( '@datastax/ragstack-ai' ) ;
21
- const version = ragstack [ 'RAGSTACK_VERSION' ] || "?" ;
22
- return `ragstack-ai-ts/${ version } `
25
+ const expectedFilePath = path . join ( '@datastax' , 'ragstack-ai' , 'package.json' ) ;
26
+ for ( const nodeModulesPath of module . paths ) {
27
+ const fullFilePath = path . join ( nodeModulesPath , expectedFilePath ) ;
28
+ if ( fs . existsSync ( fullFilePath ) ) {
29
+ const packageJson = JSON . parse ( fs . readFileSync ( fullFilePath , 'utf8' ) )
30
+ return `ragstack-ai-ts/${ packageJson . version } `
31
+ }
32
+ }
33
+ return ''
23
34
} catch ( e ) {
24
35
return '' ;
25
36
}
You can’t perform that action at this time.
0 commit comments