@d5render/cli 0.1.82 → 0.1.84

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/bin/d5cli +23 -21
  2. package/package.json +1 -1
package/bin/d5cli CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { argv, env, platform } from "node:process";
3
- import { execSync, spawn, spawnSync } from "node:child_process";
3
+ import { execSync, spawn } from "node:child_process";
4
4
  import { createHash } from "node:crypto";
5
5
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
6
6
  import { dirname, join } from "node:path";
@@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url";
8
8
 
9
9
  //#region package.json
10
10
  var name$1 = "@d5render/cli";
11
- var version = "0.1.82";
11
+ var version = "0.1.84";
12
12
 
13
13
  //#endregion
14
14
  //#region packages/env.ts
@@ -311,6 +311,10 @@ async function deploy() {
311
311
  //#endregion
312
312
  //#region review/copilot/index.ts
313
313
  const bind = "copilot";
314
+ /** 单引号包裹并转义,用于 shell 内联,避免子进程 env 被改写 */
315
+ function shellEscape(val) {
316
+ return `'${val.replace(/'/g, "'\\''")}'`;
317
+ }
314
318
  async function cli() {
315
319
  await deploy();
316
320
  const httpProxy = env.HTTP_PROXY || env.http_proxy || "";
@@ -318,36 +322,34 @@ async function cli() {
318
322
  if (httpProxy) env.HTTP_PROXY = httpProxy;
319
323
  if (httpsProxy) env.HTTPS_PROXY = httpsProxy;
320
324
  console.log("@d5render/cli version:", VERSION);
321
- const childEnv = platform === "win32" ? void 0 : env;
322
- if (childEnv) {
323
- console.log("child env keys count:", Object.keys(childEnv).length);
324
- console.log("child env token keys present:", [
325
- "COPILOT_GITHUB_TOKEN",
326
- "GH_TOKEN",
327
- "GITHUB_TOKEN"
328
- ].filter((k) => childEnv[k]).join(", ") || "(none)");
329
- const check = spawnSync(process.execPath, ["-e", "console.log(process.env.COPILOT_GITHUB_TOKEN ? 'env injected: OK' : 'env injected: MISSING')"], {
330
- env: childEnv,
331
- encoding: "utf8"
332
- });
333
- console.log(check.stdout?.trim() || check.stderr?.trim() || "env check: (no output)");
334
- } else console.log("child env: inherits process.env (win32)");
335
- const child = spawn(bind, [
325
+ const args = [
336
326
  ...tools,
337
327
  "-p",
338
328
  `"${common_review_prompt.replace(/"/g, "\\\"")}"`
339
- ], {
329
+ ];
330
+ const opts = {
340
331
  cwd: env.CI_PROJECT_DIR,
341
332
  stdio: [
342
333
  "inherit",
343
334
  "pipe",
344
335
  "pipe"
345
- ],
346
- ...platform === "win32" ? { shell: true } : { env: childEnv }
336
+ ]
337
+ };
338
+ let child;
339
+ if (platform === "win32") child = spawn(bind, args, {
340
+ ...opts,
341
+ shell: true
347
342
  });
343
+ else {
344
+ const token = env.COPILOT_GITHUB_TOKEN || env.GH_TOKEN || env.GITHUB_TOKEN || env.GITHUB_COPILOT_TOKEN;
345
+ child = spawn("sh", ["-c", `${token !== void 0 && token !== "" ? `export COPILOT_GITHUB_TOKEN=${shellEscape(token)} GH_TOKEN=${shellEscape(token)} GITHUB_TOKEN=${shellEscape(token)}; ` : ""}exec ${bind} ${args.map((a) => shellEscape(a)).join(" ")}`], {
346
+ ...opts,
347
+ env
348
+ });
349
+ }
348
350
  child.stdout.on("data", (chunk) => console.log(String(chunk)));
349
351
  child.stderr.on("data", (chunk) => console.error(String(chunk)));
350
- return new Promise((res, rej) => child.on("close", (code) => getCopilotUsage().then((res) => console.log("本次Token积累使用量:", res)).catch(() => {}).finally(() => {
352
+ return new Promise((res, rej) => child.on("close", (code) => getCopilotUsage().then((r) => console.log("本次Token积累使用量:", r)).catch(() => {}).finally(() => {
351
353
  if (code === 0) res();
352
354
  else rej(/* @__PURE__ */ new Error(`${bind} exited with code ${code}`));
353
355
  })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d5render/cli",
3
- "version": "0.1.82",
3
+ "version": "0.1.84",
4
4
  "license": "MIT",
5
5
  "author": "jasirou",
6
6
  "bin": {