From 28f2efc504059b1dc75c793618b775c8e1b2a5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=E6=98=AF=E7=BA=B1=E9=9B=BE=E9=85=B1=E5=93=9F?= =?UTF-8?q?=EF=BD=9E?= <49941141+Dragon1573@users.noreply.github.com> Date: Sun, 19 Jul 2026 23:23:31 +0800 Subject: [PATCH] refactor(scripts): optimizes file permission changes (#7520) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaces shell-based execution of `chmod` with native Node.js filesystem API calls to improve performance - Switches to `execFileSync` in stream event handlers to avoid shell spawning overhead Signed-off-by: ❤是纱雾酱哟~ <49941141+Dragon1573@users.noreply.github.com> Co-authored-by: Tunglies --- scripts/prebuild.mjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/prebuild.mjs b/scripts/prebuild.mjs index 3aa2daf72..b506f40af 100644 --- a/scripts/prebuild.mjs +++ b/scripts/prebuild.mjs @@ -1,4 +1,4 @@ -import { execSync } from 'child_process' +import { execFileSync, execSync } from 'child_process' import { createHash } from 'crypto' import fs from 'fs' import fsp from 'fs/promises' @@ -409,7 +409,7 @@ async function resolveSidecar(binInfo) { throw new Error(`Expected binary not found in ${tempDir}`) await fsp.rename(path.join(tempDir, candidate), sidecarPath) } - if (platform !== 'win32') execSync(`chmod 755 ${sidecarPath}`) + if (platform !== 'win32') await fsp.chmod(sidecarPath, 0o755) log_success(`unzip finished: "${name}"`) } else if (zipFile.endsWith('.tgz')) { await extract({ cwd: tempDir, file: tempZip }) @@ -425,7 +425,7 @@ async function resolveSidecar(binInfo) { if (!extracted) extracted = files[0] if (!extracted) throw new Error(`Expected file not found in ${tempDir}`) await fsp.rename(path.join(tempDir, extracted), sidecarPath) - execSync(`chmod 755 ${sidecarPath}`) + await fsp.chmod(sidecarPath, 0o755) log_success(`tgz processed: "${name}"`) } else { // .gz @@ -440,7 +440,8 @@ async function resolveSidecar(binInfo) { }) .pipe(writeStream) .on('finish', () => { - if (platform !== 'win32') execSync(`chmod 755 ${sidecarPath}`) + if (platform !== 'win32') + execFileSync('chmod', ['755', sidecarPath]) resolve() }) .on('error', (e) => {