MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / applyOne

Method applyOne

src/tools/network/network-optimize.ts:163–191  ·  view source on GitHub ↗

Write durable config for one ecosystem. Returns a short status string.

(eco: string, value: string)

Source from the content-addressed store, hash-verified

161
162 /** Write durable config for one ecosystem. Returns a short status string. */
163 private async applyOne(eco: string, value: string): Promise<string> {
164 if (eco === 'npm') {
165 const npmrc = path.join(os.homedir(), '.npmrc');
166 await this.upsertLine(npmrc, /^registry=.*/m, `registry=${value}`);
167 return `wrote registry to ~/.npmrc`;
168 }
169 if (eco === 'pip') {
170 // pip uses ~/.config/pip/pip.conf on macOS/Linux.
171 const dir = path.join(os.homedir(), '.config', 'pip');
172 await fs.mkdir(dir, { recursive: true });
173 const conf = path.join(dir, 'pip.conf');
174 let body = '';
175 try { body = await fs.readFile(conf, 'utf8'); } catch { /* new file */ }
176 if (!/^\[global\]/m.test(body)) body = `[global]\nindex-url = ${value}\n` + body;
177 else if (/^index-url\s*=.*/m.test(body)) body = body.replace(/^index-url\s*=.*/m, `index-url = ${value}`);
178 else body = body.replace(/^\[global\]/m, `[global]\nindex-url = ${value}`);
179 await fs.writeFile(conf, body);
180 return `wrote index-url to ~/.config/pip/pip.conf`;
181 }
182 if (eco === 'github') {
183 const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.ALL_PROXY;
184 if (!proxy) return `no proxy env set — nothing to apply (set HTTPS_PROXY first)`;
185 const r = await runProcess('git', ['config', '--global', 'http.proxy', proxy], { timeoutMs: 10_000 });
186 if (r.notFound) return `git not installed`;
187 return r.ok ? `set git http.proxy to ${proxy}` : `git config failed: ${r.stderr.trim()}`;
188 }
189 // huggingface: env-only, can't persist from a tool.
190 return `set via env: export HF_ENDPOINT=${value} (add to ~/.zshrc)`;
191 }
192
193 /** Insert or replace a single line in a config file (creating it if needed). */
194 private async upsertLine(file: string, matcher: RegExp, line: string): Promise<void> {

Callers 1

executeMethod · 0.95

Calls 2

upsertLineMethod · 0.95
runProcessFunction · 0.85

Tested by

no test coverage detected