@lorrylurui/code-intelligence-mcp 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/config/env.js +23 -6
  2. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import dotenv from 'dotenv';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { existsSync, readFileSync } from 'node:fs';
4
5
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
6
  const projectRoot = path.resolve(__dirname, '../../');
6
7
  // 解析命令行参数 --key=value 格式,注入到 process.env
@@ -15,13 +16,29 @@ dotenv.config({
15
16
  path: path.resolve(projectRoot, '.env'),
16
17
  override: false,
17
18
  });
18
- // 尝试从第三方项目目录加载 .env(INDEX_ROOT 或 cwd)
19
+ // 尝试从第三方项目目录加载 .env,按变量维度覆盖(只覆盖第三方明确配置的变量)
19
20
  const clientProjectRoot = process.env.INDEX_ROOT || process.cwd();
20
- console.error(`[Config] Loading .env from client project root: ${clientProjectRoot}`);
21
- dotenv.config({
22
- path: path.resolve(clientProjectRoot, '.env'),
23
- override: true,
24
- });
21
+ const clientEnvPath = path.resolve(clientProjectRoot, '.env');
22
+ if (existsSync(clientEnvPath)) {
23
+ console.error(`[Config] Merging .env from client project root: ${clientProjectRoot}`);
24
+ // 手动解析第三方 .env,只覆盖其明确配置的变量
25
+ const clientEnvContent = readFileSync(clientEnvPath, 'utf-8');
26
+ for (const line of clientEnvContent.split('\n')) {
27
+ const trimmed = line.trim();
28
+ if (!trimmed || trimmed.startsWith('#'))
29
+ continue;
30
+ const eqIdx = trimmed.indexOf('=');
31
+ if (eqIdx === -1)
32
+ continue;
33
+ const key = trimmed.slice(0, eqIdx).trim();
34
+ const value = trimmed.slice(eqIdx + 1).trim();
35
+ // 移除引号
36
+ const cleanValue = value.replace(/^["']|["']$/g, '');
37
+ if (key) {
38
+ process.env[key] = cleanValue;
39
+ }
40
+ }
41
+ }
25
42
  // 外部传入的 env 已在上一步保留,这里确保环境变量已正确设置
26
43
  for (const arg of process.argv) {
27
44
  const match = arg.match(/^--([A-Z_][A-Z0-9_]*)=(.+)$/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lorrylurui/code-intelligence-mcp",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "private": false,
5
5
  "description": "MCP server 提供仓库内可复用代码块(ts/tsx/js/jsx/css/less)的索引和查询能力,支持基于代码上下文的智能推荐。",
6
6
  "type": "module",