From e4b1f60a662895d98b70a929b04e41df81dd2ed1 Mon Sep 17 00:00:00 2001 From: nocci Date: Tue, 30 Dec 2025 14:31:17 +0000 Subject: [PATCH] chore: use execFile for git commands in version check --- src/version.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/version.js b/src/version.js index bfcd12a..cd054d8 100644 --- a/src/version.js +++ b/src/version.js @@ -1,15 +1,15 @@ // check if running the latest version import { log } from 'console'; -import { exec } from 'child_process'; +import { execFile } from 'child_process'; -const execp = cmd => new Promise((resolve, reject) => { - exec(cmd, (error, stdout, stderr) => { +const runGit = (...args) => new Promise((resolve, reject) => { + execFile('git', args, { cwd: process.cwd() }, (error, stdout, stderr) => { if (stderr) console.error(`stderr: ${stderr}`); // if (stdout) console.log(`stdout: ${stdout}`); if (error) { console.log(`error: ${error.message}`); - if (error.message.includes('command not found')) { + if (error.code === 'ENOENT' || error.message.includes('command not found')) { console.info('Install git to check for updates!'); } return reject(error); @@ -29,8 +29,8 @@ if (process.env.NOVNC_PORT) { date = process.env.NOW; } else { log('Not running inside Docker.'); - sha = await execp('git rev-parse HEAD'); - date = await execp('git show -s --format=%cD'); // same as format as `date -R` (RFC2822) + sha = await runGit('rev-parse', 'HEAD'); + date = await runGit('show', '-s', '--format=%cD'); // same as format as `date -R` (RFC2822) // date = await execp('git show -s --format=%ch'); // %ch is same as --date=human (short/relative) }