File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7171 "@rollup/plugin-inject" : " ^5.0.5" ,
7272 "@rollup/plugin-json" : " ^6.1.0" ,
7373 "@rollup/plugin-node-resolve" : " ^16.0.0" ,
74+ "@rollup/plugin-replace" : " ^6.0.2" ,
7475 "@rollup/plugin-terser" : " ^0.4.4" ,
7576 "@rollup/plugin-typescript" : " ^12.1.2" ,
7677 "@types/express" : " ^5.0.3" ,
Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ import typescript from '@rollup/plugin-typescript';
44import json from '@rollup/plugin-json' ;
55import dts from 'rollup-plugin-dts' ;
66import terser from '@rollup/plugin-terser' ;
7+ import replace from '@rollup/plugin-replace' ;
8+ import { readFileSync } from 'fs' ;
9+
10+ // 读取 package.json 获取版本号
11+ const packageJson = JSON . parse ( readFileSync ( './package.json' , 'utf-8' ) ) ;
12+ const version = packageJson . version ;
713
814// 只将 Node.js 内置模块设为外部依赖,npm 依赖都打包进最终产物
915const external = [
@@ -128,6 +134,13 @@ const baseConfig = {
128134 unknownGlobalSideEffects : false
129135 } ,
130136 plugins : [
137+ // 版本号注入,需要在 typescript 插件之前
138+ replace ( {
139+ preventAssignment : true ,
140+ values : {
141+ '__MCP_VERSION__' : JSON . stringify ( version )
142+ }
143+ } ) ,
131144 resolve ( {
132145 preferBuiltins : true ,
133146 exportConditions : [ 'node' ] ,
Original file line number Diff line number Diff line change @@ -2,12 +2,11 @@ import os from 'os';
22import crypto from 'crypto' ;
33import https from 'https' ;
44import http from 'http' ;
5- import { createRequire } from 'module' ;
65import { debug } from './logger.js' ;
76import { loadEnvIdFromUserConfig } from '../tools/interactive.js' ;
87
9- const require = createRequire ( import . meta . url ) ;
10- const packageJson = require ( '../../package.json' ) ;
8+ // 构建时注入的版本号
9+ declare const __MCP_VERSION__ : string ;
1110
1211/**
1312 * 数据上报类
@@ -61,8 +60,8 @@ class TelemetryReporter {
6160 const nodeVersion = process . version ; // Node.js版本
6261 const arch = os . arch ( ) ; // 系统架构
6362
64- // 从package.json获取MCP版本信息
65- const mcpVersion = process . env . npm_package_version || packageJson . version || 'unknown' ;
63+ // 从构建时注入的版本号获取MCP版本信息
64+ const mcpVersion = process . env . npm_package_version || __MCP_VERSION__ || 'unknown' ;
6665
6766 return {
6867 userAgent : `${ osType } ${ osRelease } ${ arch } ${ nodeVersion } CloudBase-MCP/${ mcpVersion } ` ,
You can’t perform that action at this time.
0 commit comments