cc-team-viewer 1.4.34 → 1.4.36

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.
package/cli/cli.js CHANGED
@@ -137,9 +137,27 @@ function removeShellHook() {
137
137
  function injectCliJs() {
138
138
  const content = readFileSync(cliPath, 'utf-8');
139
139
  if (content.includes(INJECT_START)) {
140
+ // 已经是自己的注入
140
141
  return 'exists';
141
142
  }
142
- const lines = content.split('\n');
143
+
144
+ // 检测其他 cc-viewer/cc-team-viewer 变体的注入标记,并移除
145
+ const otherMarkers = [
146
+ "# >>> CC-Viewer Auto-Inject >>>",
147
+ "# >>> CC-Team-Viewer Auto-Inject >>>",
148
+ "import '../../cc-viewer/interceptor.js';",
149
+ "import '../../cc-team-viewer/proxy/interceptor.js';",
150
+ ];
151
+ let cleaned = content;
152
+ for (const marker of otherMarkers) {
153
+ cleaned = cleaned.replace(new RegExp(`\\n?${marker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n?[\\s\\S]*?<<< (CC-Viewer|CC-Team-Viewer) Auto-Inject <<<\\n?`, 'g'), '\n');
154
+ // 也移除只有 import 语句的情况(没有完整 hook 块)
155
+ cleaned = cleaned.replace(new RegExp(`\\n?${marker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n?`, 'g'), '\n');
156
+ }
157
+ // 去掉重复的空行
158
+ cleaned = cleaned.replace(/\n{3,}/g, '\n\n').trim() + '\n';
159
+
160
+ const lines = cleaned.split('\n');
143
161
  lines.splice(2, 0, INJECT_BLOCK);
144
162
  writeFileSync(cliPath, lines.join('\n'));
145
163
  return 'injected';
@@ -160,6 +178,12 @@ function removeCliJsInjection() {
160
178
 
161
179
  async function runProxyCommand(args) {
162
180
  try {
181
+ // 确保注入有效(被 npm 更新覆盖时会丢失)
182
+ const injectResult = injectCliJs();
183
+ if (injectResult === 'injected') {
184
+ console.log('[cctv] 已重新注入 interceptor 到 cli.js');
185
+ }
186
+
163
187
  // Dynamic import to avoid side effects when just installing
164
188
  const { startProxy } = await import('../proxy/proxy.js');
165
189
  const proxyPort = await startProxy();