File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,16 +46,21 @@ export const devCommand = new Command('dev')
4646 // 检测 development 源码是否可用(仅 monorepo 环境)
4747 const devSourcesAvailable = fs . existsSync ( path . join ( cwd , 'node_modules/zhin.js/src' ) ) ;
4848
49- // 设置环境变量
50- const nodeOptions = ( process . env . NODE_OPTIONS || '' )
49+ // 构建干净的环境变量:剔除 pnpm 注入的 npm_config_* 以免子进程中
50+ // npm 读到不认识的配置项而报 warn 甚至阻塞
51+ const cleanEnv : Record < string , string | undefined > = { } ;
52+ for ( const [ key , value ] of Object . entries ( process . env ) ) {
53+ if ( / ^ n p m _ / i. test ( key ) ) continue ;
54+ cleanEnv [ key ] = value ;
55+ }
56+ const nodeOptions = ( cleanEnv . NODE_OPTIONS || '' )
5157 + ( devSourcesAvailable ? ' --conditions=development' : '' ) ;
5258 const env = {
53- ...process . env ,
59+ ...cleanEnv ,
5460 NODE_ENV : 'development' ,
5561 ZHIN_DEV_MODE : 'true' ,
5662 ZHIN_HMR_PORT : options . port ,
5763 ZHIN_VERBOSE : options . verbose ? 'true' : 'false' ,
58- // 仅当框架源码可用时才添加 development 条件(monorepo 环境)
5964 NODE_OPTIONS : nodeOptions
6065 } ;
6166
Original file line number Diff line number Diff line change @@ -36,9 +36,15 @@ export const startCommand = new Command('start')
3636
3737 // 启动机器人的函数
3838 const startBot = async ( ) : Promise < ChildProcess > => {
39- // 设置环境变量
39+ // 构建干净的环境变量:剔除 pnpm 注入的 npm_config_* 以免子进程中
40+ // npm 读到不认识的配置项而报 warn 甚至阻塞
41+ const cleanEnv : Record < string , string | undefined > = { } ;
42+ for ( const [ key , value ] of Object . entries ( process . env ) ) {
43+ if ( / ^ n p m _ / i. test ( key ) ) continue ;
44+ cleanEnv [ key ] = value ;
45+ }
4046 const env = {
41- ...process . env ,
47+ ...cleanEnv ,
4248 NODE_ENV : 'production'
4349 } ;
4450 // 配置stdio
You can’t perform that action at this time.
0 commit comments