| 73 | }); |
| 74 | |
| 75 | function runScript(args, env) { |
| 76 | return new Promise((resolvePromise) => { |
| 77 | const child = spawn(process.execPath, [scriptPath, ...args], { |
| 78 | cwd: repositoryRoot, |
| 79 | env: { |
| 80 | ...process.env, |
| 81 | ...env, |
| 82 | }, |
| 83 | stdio: ["ignore", "pipe", "pipe"], |
| 84 | }); |
| 85 | let stdout = ""; |
| 86 | let stderr = ""; |
| 87 | child.stdout.setEncoding("utf8"); |
| 88 | child.stderr.setEncoding("utf8"); |
| 89 | child.stdout.on("data", (chunk) => { |
| 90 | stdout += chunk; |
| 91 | }); |
| 92 | child.stderr.on("data", (chunk) => { |
| 93 | stderr += chunk; |
| 94 | }); |
| 95 | child.once("exit", (code) => { |
| 96 | resolvePromise({ |
| 97 | code: code ?? 1, |
| 98 | stderr, |
| 99 | stdout, |
| 100 | }); |
| 101 | }); |
| 102 | child.once("error", (error) => { |
| 103 | resolvePromise({ |
| 104 | code: 1, |
| 105 | stderr: error instanceof Error ? error.message : String(error), |
| 106 | stdout, |
| 107 | }); |
| 108 | }); |
| 109 | }); |
| 110 | } |