Use execFile to run safily pass arguments

This commit is contained in:
Volodymyr Zotov
2025-12-16 10:29:54 -06:00
parent 2f243ca4fa
commit b4962e1861

View File

@@ -1,4 +1,4 @@
import { exec } from "child_process"; import { execFile } from "child_process";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { promisify } from "util"; import { promisify } from "util";
@@ -13,7 +13,7 @@ import {
} from "./cli-installer"; } from "./cli-installer";
import { type Installer } from "./installer"; import { type Installer } from "./installer";
const execAsync = promisify(exec); const execFileAsync = promisify(execFile);
export class MacOsInstaller extends CliInstaller implements Installer { export class MacOsInstaller extends CliInstaller implements Installer {
private readonly platform: SupportedPlatform = "darwin"; // Node.js platform identifier for macOS private readonly platform: SupportedPlatform = "darwin"; // Node.js platform identifier for macOS
@@ -35,7 +35,7 @@ export class MacOsInstaller extends CliInstaller implements Installer {
fs.renameSync(pkgPath, pkgWithExtension); fs.renameSync(pkgPath, pkgWithExtension);
const expandDir = "temp-pkg"; const expandDir = "temp-pkg";
await execAsync(`pkgutil --expand "${pkgWithExtension}" "${expandDir}"`); await execFileAsync("pkgutil", ["--expand", pkgWithExtension, expandDir]);
const payloadPath = path.join(expandDir, "op.pkg", "Payload"); const payloadPath = path.join(expandDir, "op.pkg", "Payload");
console.info("Installing 1Password CLI"); console.info("Installing 1Password CLI");
const cliPath = await tc.extractTar(payloadPath); const cliPath = await tc.extractTar(payloadPath);